# pfc — IEEE 802.1Qbb Per-Priority Pause Frames for Lossless RoCEv2 (`pfc`)

> **FrameAssembly v3.3.0** · Protocol 12 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/pfc

- **Full Protocol Name:** IEEE 802.1Qbb Priority-based Flow Control (Lossless Ethernet)
- **Keyword:** `pfc`
- **OSI Layer & Transport:** Layer 2 · EtherType 0x8808 (Opcode 0x0101)
- **Host Endpoint Rule:** MAC-Only or IP
- **Standards:** IEEE 802.1Qbb, IEEE 802.3x MAC Control
- **Wireshark Display Filter:** `macc || eth.type == 0x8808`
- **Wire Encapsulation:** `Ethernet II -> PFC (802.1Qbb) (EtherType 0x8808 (Opcode 0x0101))`

## Overview

When an AI GPU cluster’s RoCEv2 queue fills up, switches fire `0x8808` opcode `0x0101` Priority Flow Control frames on Priority `3` (`pfc q3 512`) so congested queues pause without freezing the whole link.

Priority-based Flow Control (`pfc`, IEEE 802.1Qbb) enables lossless Ethernet fabrics for **RoCEv2 AI/GPU training clusters** and Fibre Channel / NVMe storage networks without pausing unrelated best-effort traffic. Carried over Ethernet MAC Control (`EtherType 0x8808`, Opcode `0x0101`) to reserved link-local multicast MAC `01:80:c2:00:00:01`, each 60-byte PFC frame contains a 16-bit Class-Enable Vector (`enable`) followed by eight 16-bit pause timers (`q0`..`q7`, measured in 512-bit-time quanta).

FrameAssembly encodes exact 46-byte padded `0x8808` MAC Control payloads, automatically enabling individual bits in the Class-Enable Vector when you set `q0`..`q7` (or letting you override `enable` and uniform `quanta` directly) for PFC watchdog and storm analysis.

## Minimal Quickstart (`pfc_quickstart.frasm`)

```frameassembly
host leaf_tor { mac 00:1c:73:dc:00:01 }
host gpu_nic  { mac 00:1c:73:dc:00:10 }

compile {
    leaf_tor -> gpu_nic pfc q3 512
}
```

### Automatic Wire Calculations

- Sets Ethernet II EtherType to `0x8808` (MAC Control), destination MAC to `01:80:c2:00:00:01`, and MAC Control Opcode to `0x0101` (PFC).
- Automatically sets bit `i` in the 16-bit Class-Enable Vector (`enable`) whenever `q0`..`q7` is specified, unless `enable` is explicitly overridden.
- Zero-pads trailing bytes to the mandatory 46-byte Ethernet MAC Control minimum payload (`60` bytes before FCS; add `fcs` for full `64`-byte wire length).

## Practical Lab Example: Microsecond RoCEv2 Priority-3 XOFF Pause & XON Resume Sequence (`pfc_xoff_xon_lossless.frasm`)

Models a congested Top-of-Rack switch asserting IEEE 802.1Qbb XOFF backpressure (`q3 2000`) toward a GPU host NIC, draining its ingress buffer over `150us`, and sending an XON (`q3 0`) release.

```frameassembly
host tor_sw  { ip 10.80.1.1  mac 00:1c:73:80:00:01 }
host gpu_srv { ip 10.80.1.11 mac 00:1c:73:80:00:11 }

compile {
    // 1. Congested ToR asserts XOFF pause on lossless Priority 3 (512-bit quanta = 2000)
    tor_sw -> gpu_srv pfc enable 0x0008 q3 2000 fcs wait 150us
    // 2. Queue drains below watermark; ToR sends XON (quanta 0) to resume Priority 3
    tor_sw -> gpu_srv pfc enable 0x0008 q3 0 fcs wait 50us
    // 3. Multi-class pause across Priority 3 (RDMA) and Priority 4 (Storage)
    tor_sw -> gpu_srv pfc enable 0x0018 q3 512 q4 256 fcs
}
```

```bash
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show pfc_xoff_xon_lossless.frasm

# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'
frameassembly pfc_xoff_xon_lossless.frasm pfc_xoff_xon_lossless.pcap
frameassembly pfc_xoff_xon_lossless.frasm pfc_xoff_xon_lossless.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse pfc_xoff_xon_lossless.pcap pfc_xoff_xon_lossless_edited.frasm

# 4. Verify dissected protocol fields in tshark
tshark -r pfc_xoff_xon_lossless.pcap
```

## All `pfc` Keywords & Header Options

Packet line pattern: `src_host -> dst_host pfc [enable <0..65535>] [quanta <0..65535>] [q0 <0..65535>] [q1 <0..65535>] [q2 <0..65535>] [q3 <0..65535>] [q4 <0..65535>] [q5 <0..65535>] [q6 <0..65535>] [q7 <0..65535>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `enable <0..65535>` | 8-bit Class-Enable bitmask in low byte (0x00..0xff) | `Auto bitmask from q0..q7 (or 0x00ff with quanta)` | Sets the 16-bit Class-Enable Vector (`0x0008` = Priority 3, `0x00ff` = all 8 classes). |
| `quanta <0..65535>` | Default pause duration in 512-bit quanta (0..65535) | `0` | Fills enabled priority queues with a uniform 16-bit pause timer when per-queue `q0`..`q7` are omitted. |
| `q0 <0..65535> .. q7 <0..65535>` | Per-priority pause quanta (0..65535) | `0 (or quanta)` | Sets the 16-bit Time[0..7] pause timer for IEEE 802.1p Traffic Class `0` through `7` (`0` = XON unpause). |

## Cross-Layer Options Valid with `pfc`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `comment "<text>"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"`, `"de:ad:be:ef"`, or `"\x01\x02"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType 0..65535 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or standalone Layer 2 16-bit EtherType. |
| `fcs \| badfcs` | Ethernet CRC-32 trailer flags (choose one) | `Omitted` | `fcs` appends a valid IEEE 802.3 4-byte CRC-32 Frame Check Sequence trailer; `badfcs` XOR-corrupts the CRC-32 for NIC/tap negative tests. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Repeatable label stack (0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255) | `Unlabeled (auto bos=0 on outer labels, bos=1 on bottom)` | Prepends one or more 32-bit MPLS label shims (`0x8847`, e.g. `mpls 16000 mpls 24010`) ahead of Layer 2 EoMPLS or Layer 3 payloads. |

## Common Mistakes & Quick Fixes

### Include Explicit enable When Sending Zero-Quanta XON Frames

- **Avoid:** `tor_sw -> gpu_srv pfc`
- **Valid v3.3.0 Syntax:** `tor_sw -> gpu_srv pfc enable 0x0008 q3 0`

To unpause Priority 3 (`q3 0`), set `enable 0x0008` explicitly so receivers know the `0` timer applies to Traffic Class 3 rather than an ignored disabled bit.

### Use .pcapng Output to Preserve Sub-Microsecond PFC Timing

- **Avoid:** `Relying on microsecond .pcap when testing 250ns PFC bursts`
- **Valid v3.3.0 Syntax:** `tor_sw -> gpu_srv pfc q3 512 wait 250ns`

Classic `.pcap` truncates timestamps to microseconds; compile to `.pcapng` (`IfTsResol=9`) when modeling 100G/400G nanosecond pause intervals.
