# http2 — RFC 9113 Connection Prefaces & Multiplexed Frames (`http2`)

> **FrameAssembly v3.2.2** · Protocol 47 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/http2

- **Full Protocol Name:** Hypertext Transfer Protocol Version 2 Binary Framing
- **Keyword:** `http2`
- **OSI Layer & Transport:** Layer 7 · TCP 443
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 9113
- **Wireshark Display Filter:** `http2`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 443 -> HTTP/2`

## Overview

Plaintext `GET /` turned into 9-byte binary frame headers (`Length`, `Type`, `Flags`, 31-bit `Stream ID`) — start with `http2 preface` + `settings` and watch Wireshark dissect your multiplexed `streamid` flows.

HTTP/2 (`http2`, RFC 9113) replaces plain-text HTTP/1.1 lines with multiplexed binary frames over **TCP port `443`** (or cleartext `h2c` on port `80`/`8080`). Every HTTP/2 frame carries a 9-byte header: 24-bit Payload Length, 8-bit Frame Type, 8-bit Flags, and a 31-bit Stream Identifier (`streamid`).

FrameAssembly automatically builds RFC-compliant frame lengths for connection `preface` (`PRI * HTTP/2.0

SM

` + initial `SETTINGS`), `settings`, HPACK-indexed `headers`, `data`, `windowupdate` (4-byte window increment), `ping` (8-byte opaque payload), and `goaway` teardown frames.

## Minimal Quickstart (`http2_quickstart.frasm`)

```frameassembly
host app_client { ip 10.20.1.10 }
host api_gw     { ip 10.20.1.44 }

compile {
    app_client -> api_gw http2 preface dstport 8080 wait 1ms
    app_client <- api_gw http2 settings wait 1ms
    app_client -> api_gw http2 headers streamid 1 wait 1ms
    app_client <- api_gw http2 data streamid 1 payload "{\"ok\":true}"
}
```

### Automatic Wire Calculations

- Defaults to TCP destination port `443` (`psh ack`) and keeps TCP `seq` / `acknum` synchronized across multiplexed frames.
- Enforces RFC 9113 frame size rules automatically: 24-byte magic string + `SETTINGS` on `preface`, 8-byte payload on `ping` (`streamid 0`), 4-byte window increment on `windowupdate`, and 8-byte `last_stream_id + error_code` on `goaway`.
- Encodes valid HPACK indexed pseudo-headers (`:method GET`, `:scheme https`, `:path /`) on `headers` when no raw override is supplied.

## Practical Lab Example: Cleartext h2c Connection Preface, Stream 1 Request, PING & Graceful GOAWAY (`http2_multiplexed_session.frasm`)

Establishes a TCP port 8080 connection, exchanges HTTP/2 connection prefaces, serves a Stream 1 request/data exchange, tests liveness with `ping`, and closes cleanly via `goaway`.

```frameassembly
host mesh_sidecar { ip 172.16.30.11 }
host upstream_svc { ip 172.16.30.80 }

compile {
    mesh_sidecar -> upstream_svc tcp syn srcport 53080 dstport 8080 win 65535 mss 1460 wait 1ms
    mesh_sidecar <- upstream_svc tcp syn ack win 65535 mss 1460 wait 1ms
    mesh_sidecar -> upstream_svc tcp ack wait 1ms
    // 1. Client magic preface + server SETTINGS
    mesh_sidecar -> upstream_svc http2 preface wait 1ms
    mesh_sidecar <- upstream_svc http2 settings wait 1ms
    // 2. Stream 1 request headers + response data + flow-control window update
    mesh_sidecar -> upstream_svc http2 headers streamid 1 wait 2ms
    mesh_sidecar <- upstream_svc http2 headers streamid 1 wait 1ms
    mesh_sidecar <- upstream_svc http2 data streamid 1 payload "{\"items\":[]}" wait 1ms
    mesh_sidecar -> upstream_svc http2 windowupdate streamid 0 wait 5ms
    // 3. Keepalive PING & graceful connection drain (GOAWAY on stream 0)
    mesh_sidecar -> upstream_svc http2 ping streamid 0 wait 2ms
    mesh_sidecar <- upstream_svc http2 goaway streamid 0
}
```

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

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly http2_multiplexed_session.frasm http2_multiplexed_session.pcap
frameassembly http2_multiplexed_session.frasm http2_multiplexed_session.pcapng

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

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

## All `http2` Keywords & Header Options

Packet line pattern: `src_host -> dst_host http2 [preface | settings | headers | data | windowupdate | ping | goaway] [streamid <number>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `preface \| settings \| headers \| data \| windowupdate \| ping \| goaway` | HTTP/2 frame type keyword | `settings (Type 0x04, streamid 0)` | Selects the RFC 9113 HTTP/2 binary frame type (`0x0` DATA, `0x1` HEADERS, `0x4` SETTINGS, `0x6` PING, `0x7` GOAWAY, `0x8` WINDOW_UPDATE, or connection `preface`). |
| `streamid <number>` | 31-bit Stream Identifier (`0` for connection control, odd `1, 3, 5` for client streams) | `0 on control frames, 1 on headers/data` | Sets the 31-bit Stream ID in bytes 5..8 of the 9-byte HTTP/2 frame header. |

## Cross-Layer Options Valid with `http2`

| 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). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"` or `"de:ad:be:ef"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType u16 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or 16-bit EtherType for this single packet. |
| `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>]` | Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255 | `Unlabeled (at most 1 mpls tag per packet)` | Inserts a 32-bit MPLS label header (`0x8847`) ahead of the Layer 3 header. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>]` | IPv4 ID, DF/MF flags, fragment offset 0..8191 | `ipid 1, flags 0, fragoffset 0` | Sets IPv4 Identification, Do-Not-Fragment (`df`), More-Fragments (`mf`), and fragment offset (ignored over IPv6). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 443` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `seq <number> \| acknum <number> \| win\|window <0..65535> \| urgent <0..65535> \| syn \| ack \| psh \| fin \| rst \| urg \| ece \| cwr` | TCP sequence/ack numbers, window size, flags & RFC 7323 options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323 options (`mss`, `wscale`, `sackperm`, `tsval`, `tsecr`). |

## Common Mistakes & Quick Fixes

### Connection-Level Control Frames Use streamid 0

- **Valid v3.2.2 Syntax:** `app_client -> api_gw http2 ping streamid 0`

Per RFC 9113, `settings`, `ping`, and `goaway` apply to the entire connection (`streamid 0`), whereas client-initiated requests use odd stream IDs (`streamid 1`, `streamid 3`).

### No Hyphens or Underscores in windowupdate or goaway

- **Avoid:** `app_client -> api_gw http2 window_update stream_id 1`
- **Valid v3.2.2 Syntax:** `app_client -> api_gw http2 windowupdate streamid 1`

Spell HTTP/2 keywords without underscores: `windowupdate`, `goaway`, and `streamid`.
