Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ A switch has two kinds of port, which can be mixed. The port number is the order
| `p4-pifo-stfq` | Programmable scheduling: the P4 program computes the ranks of weighted fair queueing (STFQ), and a PIFO per port serves them |
| `p4-pifo-las`, `p4-pifo-edf` | Ranks for short flows first (LAS) and for deadlines (EDF): a PIFO side by side with SP-PIFO and AIFO, which serve the same ranks on a switch without PIFOs |
| `p4-pifo-hpfq` | Hierarchical fair queueing with a PIFO tree: classes keep their share when a flow of theirs stops, unlike flat fair queueing |
| `p4-pifo-shaping` | Shaping in a PIFO tree: strict priority for a class with a rate limit, which holds even when the port has nothing else to send |
| `p4-pifo-shaping` | Shaping in a PIFO tree: strict priority for a class with a rate limit (a token bucket per node, set as an attribute), which holds even when the port has nothing else to send |
| `p4-voq-fabric-throughput` | Throughput of the VOQ + fabric traffic manager |

The [paper](https://dl.acm.org/doi/10.1145/3747204.3747210) evaluates P4sim with tunnelling (a custom header) and load balancing over several paths.
Expand Down
14 changes: 10 additions & 4 deletions doc/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,18 @@ line (bridge ports only, the old timing model) and gets no more changes.
(`P4CorePsa::egress_buffer`); proposal: give it a `P4QueueScheduler` too. The
VOQ + fabric traffic manager is a path of its own and stays apart.
- PIFO trees (`ns3::P4PifoTreeScheduler`) schedule (`p4-pifo-hpfq`) and shape
(`ShapingFields`, `p4-pifo-shaping`: a rate limit per class). Open: an
(token buckets and backlog limits per node, `NodeRates` and `NodeLimits`,
`p4-pifo-shaping`; times from the program, `ShapingFields`). Open: an
example of a minimum rate (in the PIFO paper a scheduling transaction, no
shaping: the class's rank says whether it is still below its rate, from a
token bucket in the ingress); the transactions of
the parent at the time a shaped element comes out, as in the PIFO paper
(here all ranks come from the ingress). Not planned: a P4 program per node
token bucket in the ingress); the scheduling transactions of the parent at
the time a shaped element comes out, as in the PIFO paper (here the ranks
and times come from the ingress; only the built-in buckets run then);
buckets and limits per port, and changing them at run time (a command or
an API); a bucket below the root that holds its node's packets at the
output, as Linux `tbf` (now it holds the node's references in front of
the parent, which may send those that wait there back to back). Not
planned: a P4 program per node
that runs at enqueue and dequeue (as PIFO-TM), one tree shape per port,
changing the tree at run time, and dropping the largest rank in a full tree
(it would have to remove a reference at every level). The rank examples
Expand Down
24 changes: 14 additions & 10 deletions doc/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ port, set up by `SwitchedEthernetHelper`; and **bridge** ports, ordinary ns-3 de
| `p4-pifo-las` | Least attained service [15]: the rank of a packet is the bytes its TCP flow sent before it, so short flows pass two long ones without the switch knowing flow sizes. Four switches side by side with the same flows: FIFO, SP-PIFO [16] and AIFO [17] (the same ranks on a switch without PIFOs) and the PIFO; it prints the flow completion times of the short flows | v1model | switched Ethernet | `las`, `pifo_approx` |
| `p4-pifo-edf` | Earliest deadline first: the rank is the arrival time plus the deadline of the packet's class (1, 2 and 4 ms, from the flow table); three UDP flows keep a 100 Mbps port 94 % busy. FIFO, SP-PIFO, AIFO and PIFO side by side; the egress counts the packets that waited longer than their deadline | v1model | switched Ethernet | `edf`, `pifo_approx` |
| `p4-pifo-hpfq` | Hierarchical fair queueing [18] with a PIFO tree (`QueueScheduler` `ns3::P4PifoTreeScheduler`, `root(a(a1,a2),b)`): classes A and B share a 100 Mbps port 1:1, flows A1 and A2 share class A 1:1; the ingress computes a rank per level and the egress keeps a virtual time per node. Next to it, flat STFQ with weights 1:1:2. Both give 25:25:50 %; when A1 stops, flat STFQ gives B1 two thirds, the tree keeps half for class A | v1model | switched Ethernet | `hpfq`, `stfq` |
| `p4-pifo-shaping` | Strict priority with a rate limit, by shaping in a PIFO tree [13] (`root(a,b)`, `ShapingFields`): class A has priority, and the ingress gives each of its packets, at the limit's rate, the time from which the root may schedule it. Two UDP flows of 80 Mbps into 100 Mbps: with the limit of 30 Mbps, A gets 30 and B the rest; when B stops, A still gets only 30 and the port idles. Next to it, the same tree without the limit: A takes what it sends | v1model | switched Ethernet | `shaping` |
| `p4-pifo-shaping` | Strict priority with a rate limit, by shaping in a PIFO tree [13] (`root(a,b)`): class A has priority, and the token bucket of its node (`NodeRates=a:30Mbps`) limits how often the root schedules it; at most 32 packets per class (`NodeLimits`). The P4 program only classifies. Two UDP flows of 80 Mbps into 100 Mbps: with the limit of 30 Mbps, A gets 30 and B the rest; when B stops, A still gets only 30 and the port idles. Next to it, the same tree without the limit: A takes what it sends | v1model | switched Ethernet | `shaping` |
| `p4-spine-leaf-topo` | A spine-leaf network with ECMP load balancing (tutorial `load_balance` [7]) | v1model | CSMA and P4 point-to-point | `load_balance` |
| `p4-topo-fattree` | A k-ary fat tree with generated flow tables (`FattreeTopoHelper`, `BuildFlowtableHelper`); `--model=1` runs ns-3 bridges instead | v1model | CSMA and P4 point-to-point | `fat-tree` |
| `topo-fattree` | The same fat tree from plain ns-3 nodes, without P4, as a baseline | – | CSMA | – |
Expand Down Expand Up @@ -183,15 +183,19 @@ half of them more than the first. The example therefore compares A1 with what it
sent, not with 83.4. With the limit, A1 gets exactly 30.0 Mbps in both windows:
the shaper lets its packets go at a fixed rate.

The shaper is `shape0`: the ingress keeps, per class, the time from which the
class's next packet may go, and moves it on by the packet's length at the limit;
the root does not see the packet's class before that time, so B goes first even
though A has priority. Each class may have 32 packets in the queues; the ingress
drops more, so a held class does not fill the tree, whose buffer the classes
share. A weight instead of the limit would give A the whole port once B stops;
the shaper does not. Over twelve seeds A gets 30.0 Mbps in both phases, and
ns-3.49 gives the same numbers; with `--limit=10Mbps` or `50Mbps` A gets that
limit, with `90Mbps` (more than it sends) what it sends.
The shaper is the token bucket of node `a` (`NodeRates=a:30Mbps`, burst 0): a
reference to `a` enters the root once the bucket holds the bytes of its packet,
so the root does not see class A before then, and B goes first even though A
has priority. Each class may have 32 packets in the queues (`NodeLimits`); more
are dropped when they arrive, so a held class does not fill the tree, whose
buffer the classes share. A weight instead of the limit would give A the whole
port once B stops; the shaper does not. Over twelve seeds A gets 30.0 Mbps in
both phases, and ns-3.49 gives the same numbers; with `--limit=10Mbps` or
`50Mbps` A gets that limit, with `90Mbps` (more than it sends) what it sends.
`--burst=3000` lets 3000 bytes of A pass at once after an idle time and leaves
the rates over a window as they are. Until the bucket was built in, `shaping.p4`
computed the same shaper with registers (`ShapingFields`); the bucket gives the
same numbers and drops.

Results of the examples in the paper are in
[p4sim-artifact-icns3](https://github.com/HapCommSys/p4sim-artifact-icns3).
Expand Down
118 changes: 93 additions & 25 deletions doc/switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,38 +226,104 @@ p4.SetDeviceAttribute("QueueScheduler",
with `ns3::P4PifoScheduler`. The tree `root` is `ns3::P4PifoScheduler` with
`DropPolicy` `Arriving`, also for a program without a leaf field; the test
suite checks that both send the same frames at the same times.
- Shaping (the shaping transactions of [1]): `ShapingFields` (default none)
names a field per level, from the root, with a time before which the packet's
element of that level does not enter its node; until then it waits and is not
scheduled. At level 0 the element is the root's reference to the packet's
class, so a time there shapes the class: the root schedules the class no more
often than its references come in. At the leaf's level it holds the packet
itself (pacing). An element waits at least as long as the one below it. The
times are in the switch's clock, nanoseconds as `ingress_global_timestamp`;
a time not after the packet's arrival in the queues (0 too) holds nothing. An
empty name skips its level. A reference names a node, not a packet, so every
packet of a shaped class needs its time: one without lets one of the class's
waiting packets out at once.
- Shaping (non-work-conserving nodes, the shaping transactions of [1]): an
element (the packet in its leaf, a reference above) may wait before it enters
its node, and is not scheduled until then. Two things hold it: the token
bucket of the node below (`NodeRates`, built in) and a time from the P4
program (`ShapingFields`). Both are described below.
- Token buckets and backlog limits per node, without P4 code:

```cpp
p4.SetDeviceAttribute("QueueScheduler",
StringValue("ns3::P4PifoTreeScheduler[Tree=root(a,b)|"
"NodeRates=a:30Mbps:3000|NodeLimits=a:32,b:32]"));
```

`NodeRates` gives a node a token bucket, `node:rate[:burst]`, separated by
commas: the rate as ns-3's `DataRate`, the burst in bytes (default 0). It
limits how fast references to the node enter its parent: one enters once the
bucket holds the bytes of its packet (the shaping of the PIFO paper). The
bucket fills at the rate up to the burst, and holds at least one packet. With
burst 0 the references are spaced by their packets' lengths at the rate (a
leaky bucket); after an idle time, `burst` bytes pass at once, as with Linux
`tbf` and `TbfQueueDisc`. Unlike those, the bucket sits in front of the
parent, not at the output: the parent schedules the references that passed
by rank, so while it serves a sibling first, they wait there and then leave
back to back. The rate holds over time; at the output it holds exactly when
the node has priority over its siblings (as class A in `p4-pifo-shaping`),
or with the root's rate. The root's rate shapes the port: it sends a packet
once the root's bucket holds the packet's bytes. The buckets count the frame as it
entered the switch (`packet_length`, without preamble and FCS) and compute in
integers, without drift (the shaper form of GCRA).
- `NodeLimits` caps the packets in a node's subtree, the waiting ones too: a
packet beyond the limit is dropped when it arrives, and counted in
`GetDrops()` and `GetNodeDrops("a")`. A shaped class holds its packets until
its bucket lets them go; a limit keeps it from filling `QueueBufferSize`,
which all classes of the port share. Each port's tree has its own buckets and
limits.
- A packet goes up the tree one level at a time: once its element has entered
a node, the element of the level above waits for its time from the program,
then for the bucket of the node below, and enters the parent. So a bucket sees
the elements in the order in which they reach it: when their element below
entered, or at their time from the program if that is later. Nested rates
work as nested shapers: in a class of 50 Mbps whose flow `a1` is limited to
10 Mbps, `a1`'s backlog waits in `a1` and the class's other flows do not wait
behind it (the test suite checks this). A reference names a node, not a
packet: a bucket counts the bytes of the packet whose reference it holds,
while the parent sends the node's smallest packet. The bytes are exact when
the node sends its packets in their order of arrival (a FIFO leaf, as in
`p4-pifo-shaping`) and its references reach the bucket in that order too (no
time from the program holds them and no node below has a rate); otherwise
the rate holds over time, and short bursts may
differ by the lengths of the packets. The root's bucket counts the packets
that leave.
- Times from the P4 program: `ShapingFields` (default none) names a field per
level, from the root, with a time before which the packet's element of that
level does not enter its node. At level 0 the element is the root's reference
to the packet's class, so a time there shapes the class; at the leaf's level
it holds the packet itself. An element waits at least as long as the one
below it. The times are in the switch's clock, nanoseconds as
`ingress_global_timestamp`; a time not after the packet's arrival in the
queues (0 too) holds nothing. An empty name skips its level. Every packet of a
class shaped this way needs its time: a reference names a node, so one
without lets one of the class's waiting packets out at once. Times suit
pacing, the earliest-departure-time model of Carousel [7]: the program gives
each packet the time at which it may leave, for example a flow's packets a
fixed gap apart (with `Tree=root|ShapingFields=shape0`; `pace_gap` holds the
gap of each flow in ns, written by the controller):

```p4
register<bit<64>>(1024) pace_gap; // per flow: ns between its packets
register<bit<64>>(1024) pace_next; // per flow: when its next packet may leave
...
bit<64> now = (bit<64>) std.ingress_global_timestamp;
bit<64> gap;
bit<64> next;
pace_gap.read(gap, flow);
pace_next.read(next, flow);
if (next < now) {
next = now; // the flow was idle: no credit for it
}
meta.shape0 = next; // the packet waits in the leaf until then
pace_next.write(flow, next + gap);
```

The program computes its times when the packet arrives, unlike the
transactions of [1], which run for a parent when an element comes out of its
shaper. An element that waited keeps its place of arrival in its node, so of
equal ranks it goes before the elements that came while it waited. With
`NodeRates` too, an element waits for its time first, then for the bucket.
- While all packets of a port wait, the port stays idle (shaping is not
work-conserving), and the switch wakes it when the root gets its next element.
work-conserving), and the switch wakes it when the root may send next.
Waiting packets count against `QueueBufferSize`, and in `enq_qdepth` and
`deq_qdepth` of their leaf.
- In [1] the transactions of the parent run when an element comes out of a
shaper; here the P4 program computes all ranks and times in the ingress, when
the packet arrives. A rate limit in the ingress spaces the times of a class
by the lengths of its packets at the limit (see `shaping.p4`). Two things
follow from this and from references that name nodes: an element that waited
keeps its place of arrival in its node, so of equal ranks it goes before the
elements that came while it waited; and a reference spaced for one packet may
let out another, longer packet of the class, a short burst (the limit holds
for the bytes exactly when the class sends in its order of arrival, as in
`shaping.p4`).

[`p4-pifo-hpfq`](examples.md) runs hierarchical fair queueing [4] in a tree next to
flat fair queueing in one PIFO: when one flow of a class stops, the tree keeps
its share in the class. [`p4-pifo-shaping`](examples.md) gives a class strict
priority with a rate limit: while another class sends, the shaped one gets its
limit and the other the rest; alone, it still gets only its limit.
priority with a rate limit, the token bucket of its node: while another class
sends, the shaped one gets its limit and the other the rest; alone, it still
gets only its limit. Its P4 program only classifies.

PIFO trees come from the hardware design of the PIFO paper [1] and later
hardware, such as BMW-Tree [5], and NIC schedulers such as Loom [6]. The traffic
Expand All @@ -279,6 +345,8 @@ IEEE/ACM Transactions on Networking 5(5), 1997.
Implementation using Balanced Multi-Way Sorting Tree", ACM SIGCOMM 2023.
[6] B. Stephens, A. Akella, M. Swift, "Loom: Flexible and Efficient NIC Packet
Scheduling", USENIX NSDI 2019.
[7] A. Saeed et al., "Carousel: Scalable Traffic Shaping at End Hosts", ACM
SIGCOMM 2017.

## Time and random numbers in the P4 program

Expand Down
Loading