{"id":"pretrain-proto-arp","kind":"protocol_spec","title":"Address Resolution Protocol & Gratuitous ARP (arp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/arp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["arp"],"text":"# arp — Broadcast ARP Requests, Replies & GARP Failovers (`arp`)\n\n> **FrameAssembly v3.3.0** · Protocol 1 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/arp\n\n- **Full Protocol Name:** Address Resolution Protocol & Gratuitous ARP\n- **Keyword:** `arp`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x0806\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** RFC 826, RFC 5227\n- **Wireshark Display Filter:** `arp`\n- **Wire Encapsulation:** `Ethernet II -> ARP / GARP (EtherType 0x0806)`\n\n## Overview\n\nEvery network outage eventually gets blamed on DNS or ARP — with `a -> b arp` you\ncan script broadcast Who-Has queries, `a <- b arp reply` answers, and `arp\ngratuitous` VIP takeovers in three lines flat.\n\nAddress Resolution Protocol (`arp`) maps IPv4 layer-3 addresses to 48-bit Ethernet\nMAC addresses inside a 28-byte ARP payload carried directly over Ethernet II\n(`0x0806`). FrameAssembly synthesizes standard broadcast Who-Has requests\n(`request`), unicast `is-at` replies (`reply`), and broadcast Gratuitous ARP\nannouncements (`gratuitous` / `garp`) used during VRRP/HSRP failovers and\nduplicate-IP detection.\n\nBecause `arp` is a native Layer 2 protocol, endpoints may declare both `ip` and\n`mac` or operate as pure MAC-only hosts with explicit `senderip`/`targetip`\n(`spa`/`tpa`) fields—making it straightforward to craft Dynamic ARP Inspection\n(DAI) positive and negative test cases.\n\n## Minimal Quickstart (`arp_quickstart.frasm`)\n\n```frameassembly\nhost client  { ip 10.0.10.25 mac 00:1b:21:aa:00:25 }\nhost gateway { ip 10.0.10.1  mac 00:1b:21:aa:00:01 }\n\ncompile {\n    client -> gateway arp\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x0806` and broadcasts `request` frames to\n  destination MAC `ff:ff:ff:ff:ff:ff` unless `dstmac` is overridden.\n- Populates Hardware Type `1` (Ethernet), Protocol Type `0x0800` (IPv4), `hlen=6`,\n  `plen=4`, and `opcode=1` (`request`).\n- Fills `sendermac` (`sha`) and `senderip` (`spa`) from the source host, sets\n  `targetmac` (`tha`) to `00:00:00:00:00:00` on requests, and sets `targetip`\n  (`tpa`) from the destination host.\n- Pads the Ethernet frame cleanly when needed and switches `reply` frames to\n  unicast peer MACs automatically.\n\n## Practical Lab Example: VLAN-Tagged ARP Resolution Followed by Gratuitous ARP VIP Takeover (`arp_garp_failover.frasm`)\n\nSimulates a workstation resolving its default gateway on VLAN 10, followed by a\nstandby router broadcasting an RFC 5227 Gratuitous ARP announcement during a\nvirtual IP takeover.\n\n```frameassembly\nhost workstation { ip 10.10.10.50 mac 00:1b:21:10:00:50 }\nhost rtr_active  { ip 10.10.10.1  mac 00:00:5e:00:01:01 }\nhost rtr_standby { ip 10.10.10.2  mac 00:1b:21:10:00:02 }\n\ncompile {\n    // 1. Broadcast ARP Who-Has on VLAN 10\n    workstation -> rtr_active arp request vlan 10 pcp 3 wait 1ms\n    // 2. Unicast ARP Is-At reply from active gateway\n    workstation <- rtr_active arp reply vlan 10 wait 5ms\n    // 3. Standby router takes over VIP 10.10.10.1 and broadcasts GARP\n    rtr_standby -> workstation arp gratuitous sendermac 00:00:5e:00:01:01 senderip 10.10.10.1 vlan 10\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show arp_garp_failover.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly arp_garp_failover.frasm arp_garp_failover.pcap\nframeassembly arp_garp_failover.frasm arp_garp_failover.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse arp_garp_failover.pcap arp_garp_failover_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r arp_garp_failover.pcap -Y \"arp\"\n```\n\n## All `arp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host arp [request | reply | gratuitous |\ngarp] [sendermac|sha <mac>] [senderip|spa <ipv4>] [targetmac|tha <mac>]\n[targetip|tpa <ipv4>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `request \\| reply \\| gratuitous \\| garp` | Operation mode flag | `request` | Selects Opcode `1` broadcast Who-Has (`request`), Opcode `2` unicast Is-At (`reply`), or broadcast Gratuitous ARP (`gratuitous`/`garp` with `tpa = spa` and `ff:ff:ff:ff:ff:ff`). |\n| `sendermac <mac> \\| sha <mac>` | 48-bit MAC (colon, hyphen, or Cisco dot) | `Source host MAC` | Sets the 6-byte ARP Sender Hardware Address (`sha`) independently of the outer Ethernet II `srcmac`. |\n| `senderip <ipv4> \\| spa <ipv4>` | IPv4 literal | `Source host IPv4 (or 0.0.0.0 on MAC-only host)` | Sets the 4-byte ARP Sender Protocol Address (`spa`). |\n| `targetmac <mac> \\| tha <mac>` | 48-bit MAC (colon, hyphen, or Cisco dot) | `00:00:00:00:00:00 on request; peer MAC on reply` | Sets the 6-byte ARP Target Hardware Address (`tha`). |\n| `targetip <ipv4> \\| tpa <ipv4>` | IPv4 literal | `Destination host IPv4 (or senderip on garp)` | Sets the 4-byte ARP Target Protocol Address (`tpa`). |\n\n## Cross-Layer Options Valid with `arp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Use ndp for Native IPv6 Neighbor Solicitation\n\n- **Avoid:** `host6_a -> host6_b arp senderip 2001:db8::1`\n- **Valid v3.3.0 Syntax:** `host6_a -> host6_b ndp neighborsolicit target\n  2001:db8::2`\n\nARP `senderip`/`targetip` (`spa`/`tpa`) are 32-bit IPv4 fields per RFC 826. For\nIPv6 link-layer address resolution with SLLA/TLLA options and Hop Limit 255, use\n`ndp`.\n\n### Zero Underscores in Sub-Keywords\n\n- **Avoid:** `a -> b arp sender_ip 10.0.0.1 target_ip 10.0.0.2`\n- **Valid v3.3.0 Syntax:** `a -> b arp senderip 10.0.0.1 targetip 10.0.0.2`\n\nAll FrameAssembly v3.2.0 built-in modifiers are lowercase alphanumeric\n(`senderip`/`spa`, `sendermac`/`sha`, `targetip`/`tpa`, `targetmac`/`tha`).\n"}
{"id":"pretrain-proto-vlan","kind":"protocol_spec","title":"IEEE 802.1Q Virtual LAN Tagging & 802.1p QoS (vlan) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/vlan","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan"],"text":"# vlan — 802.1Q Trunk Tags (0x8100) Without NIC Stripping (`vlan`)\n\n> **FrameAssembly v3.3.0** · Protocol 2 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/vlan\n\n- **Full Protocol Name:** IEEE 802.1Q Virtual LAN Tagging & 802.1p QoS\n- **Keyword:** `vlan`\n- **OSI Layer & Transport:** Layer 2 · TPID 0x8100 (VID 1)\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEEE 802.1Q, IEEE 802.1p\n- **Wireshark Display Filter:** `vlan`\n- **Wire Encapsulation:** `Ethernet II -> 802.1Q Tag (0x8100)`\n\n## Overview\n\nLaptop OSes love silently stripping `0x8100` tags before Wireshark ever sees them\n— writing `vlan 120 pcp 5` bakes the exact 4-byte 802.1Q tag straight into your\n`.pcap` bytes.\n\nIEEE 802.1Q (`vlan`) inserts a 4-byte tag header (`TPID 0x8100` + 3-bit Priority\nCode Point `pcp` + 1-bit Drop Eligible Indicator `dei` + 12-bit VLAN Identifier\n`vid`) between the Ethernet source MAC and the encapsulated EtherType.\n\nIn FrameAssembly v3.2.0, `vlan` serves a dual role: you can emit standalone Layer\n2 802.1Q frames between MAC-only switch ports (`sw1 -> sw2 vlan 100 pcp 5 payload\n\"keepalive\"`), or append `vlan <0..4095> [pcp <0..7>] [dei <0|1>]` as a\ncross-layer modifier onto any of the other 80 protocols.\n\n## Minimal Quickstart (`vlan_quickstart.frasm`)\n\n```frameassembly\nhost access_sw { mac 00:1b:21:aa:00:01 }\nhost core_sw   { mac 00:1b:21:bb:00:02 }\n\ncompile {\n    access_sw -> core_sw vlan 100\n}\n```\n\n### Automatic Wire Calculations\n\n- Inserts outer TPID `0x8100` and packs `pcp` (3 bits), `dei` (1 bit), and `vid`\n  (12 bits) into the big-endian 16-bit Tag Control Information (TCI) word.\n- Emits default inner EtherType `0x0800` when used standalone (overridable via\n  `ethertype <0..65535>`) or preserves the exact inner protocol EtherType\n  (`0x0806`, `0x0800`, `0x86dd`, `0x8847`) when used as a cross-layer modifier.\n- Validates `vid` (`0..=4095`), `pcp` (`0..=7`), and `dei` (`0..=1`) at compile\n  time before writing `.pcap` or `.pcapng` bytes.\n\n## Practical Lab Example: Multi-VLAN Trunk Capture Mixing Standalone L2 Probes & Voice/Routing CoS (`vlan_trunk_qos.frasm`)\n\nDemonstrates standalone MAC-only 802.1Q frames alongside VLAN-tagged ARP, VoIP RTP\n(`pcp 5`, `dscp 46`), and network-control OSPF (`pcp 6`) traffic on a single\nswitch trunk.\n\n```frameassembly\nhost sw_leaf  { mac 00:1c:73:10:00:01 }\nhost sw_spine { mac 00:1c:73:20:00:01 }\nhost phone_01 { ip 10.50.20.11 mac 00:1c:73:50:00:11 }\nhost pbx_core { ip 10.50.20.10 mac 00:1c:73:50:00:10 }\n\ncompile {\n    // Standalone L2 VLAN probe on management VLAN 99\n    sw_leaf -> sw_spine vlan 99 pcp 2 dei 0 ethertype 0x88b5 payload \"trunk-health\" wait 1ms\n    // Voice VLAN 20: ARP + CoS 5 / EF RTP media packet\n    phone_01 -> pbx_core arp request vlan 20 pcp 5 wait 1ms\n    phone_01 <- pbx_core arp reply vlan 20 pcp 5 wait 2ms\n    phone_01 -> pbx_core rtp pt 0 seq 1 timestamp 160 ssrc 0x10203040 vlan 20 pcp 5 dscp 46 payload \"g711-ulaw-sample\" wait 2ms\n    // Routing VLAN 30: Priority 6 OSPF Hello\n    phone_01 -> pbx_core ospf hello routerid 10.50.20.11 areaid 0 vlan 30 pcp 6\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show vlan_trunk_qos.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly vlan_trunk_qos.frasm vlan_trunk_qos.pcap\nframeassembly vlan_trunk_qos.frasm vlan_trunk_qos.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse vlan_trunk_qos.pcap vlan_trunk_qos_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r vlan_trunk_qos.pcap -Y \"vlan\"\n```\n\n## All `vlan` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host vlan [<vid 0..4095>] [pcp <0..7>] [dei\n<0|1>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `vlan [<0..4095>]` | 12-bit unsigned integer (0..4095) | `1` | Sets the 12-bit 802.1Q VLAN Identifier (`0` = 802.1p priority-tagged frame, `1..4094` = standard VLANs, `4095` = reserved). |\n| `pcp <0..7>` | 3-bit unsigned integer (0..7) | `0` | Sets the IEEE 802.1p Priority Code Point (`0` Best Effort, `5` Voice, `6` Internetwork Control, `7` Network Control). |\n| `dei <0\\|1>` | 1-bit flag (0 or 1) | `0` | Sets the Drop Eligible Indicator bit (formerly CFI) marking frames eligible for discard under congestion. |\n| `ethertype <0..65535>` | Whole number (0..65535) (decimal or 0x hex) | `0x0800 (standalone) or inner protocol EtherType` | Overrides the 2-byte encapsulated EtherType immediately following the 802.1Q tag. |\n\n## Cross-Layer Options Valid with `vlan`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Use qinq for Double VLAN Stacking Instead of Repeating vlan\n\n- **Avoid:** `a -> b icmp vlan 500 vlan 20`\n- **Valid v3.3.0 Syntax:** `a -> b icmp qinq 500 innervlan 20`\n\nRepeating `vlan` overwrites the single 802.1Q tag field. To emit IEEE 802.1ad\nS-Tag (`0x88a8`) + C-Tag (`0x8100`) double-tagging, use `qinq <svid> innervlan\n<cvid>`.\n\n### 12-Bit VID Range Enforcement\n\n- **Avoid:** `a -> b vlan 5000`\n- **Valid v3.3.0 Syntax:** `a -> b vlan 4094 pcp 5`\n\nSemantic validation enforces `0..=4095` on `vlan` VIDs and `0..=7` on `pcp`,\nrejecting out-of-range tags at compile time.\n"}
{"id":"pretrain-proto-qinq","kind":"protocol_spec","title":"IEEE 802.1ad Provider Bridge Double VLAN Tagging (S-Tag + C-Tag) (qinq) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/qinq","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["qinq"],"text":"# qinq — Double-Tagged 802.1ad S-Tag & 802.1Q C-Tag Frames (`qinq`)\n\n> **FrameAssembly v3.3.0** · Protocol 3 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/qinq\n\n- **Full Protocol Name:** IEEE 802.1ad Provider Bridge Double VLAN Tagging (S-Tag\n  + C-Tag)\n- **Keyword:** `qinq`\n- **OSI Layer & Transport:** Layer 2 · Outer 0x88a8 + Inner 0x8100\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEEE 802.1ad, IEEE 802.1Q\n- **Wireshark Display Filter:** `vlan.etype == 0x88a8 || vlan`\n- **Wire Encapsulation:** `Ethernet II -> 802.1ad S-Tag (0x88a8) -> 802.1Q C-Tag\n  (0x8100)`\n\n## Overview\n\nBecause one VLAN tag was too mainstream for carriers: `qinq 500 innervlan 20`\nstacks an outer `0x88a8` S-Tag -> inner `0x8100` C-Tag on any packet line.\n\nIEEE 802.1ad Provider Bridging (`qinq`) encapsulates customer VLAN traffic inside\na carrier Service VLAN tag, emitting **two** consecutive 4-byte VLAN headers on\nthe wire: an outer IEEE 802.1ad S-Tag (`TPID 0x88a8`) followed by an inner IEEE\n802.1Q C-Tag (`TPID 0x8100`).\n\nLike `vlan`, `qinq` works both as a standalone Layer 2 protocol on MAC-only\nprovider switches and as an inline cross-layer modifier on any L3, L4, or L7\npacket statement—allowing carrier engineers and security teams to test\ndouble-tagged BGP, PPPoE/DHCP subscriber flows, or VLAN-hopping IDS signatures in\none line.\n\n## Minimal Quickstart (`qinq_quickstart.frasm`)\n\n```frameassembly\nhost pe_nni_a { mac 00:25:90:aa:00:01 }\nhost pe_nni_b { mac 00:25:90:bb:00:02 }\n\ncompile {\n    pe_nni_a -> pe_nni_b qinq 500 innervlan 20\n}\n```\n\n### Automatic Wire Calculations\n\n- Always writes two complete 4-byte VLAN tags: outer TPID `0x88a8` (S-VLAN,\n  default `100`) followed immediately by inner TPID `0x8100` (C-VLAN, default\n  `innervlan 1`).\n- Applies `pcp` (`0..7`) and `dei` (`0|1`) cleanly to the tag control headers and\n  preserves the inner payload EtherType (`0x0800` IPv4, `0x86dd` IPv6, `0x0806`\n  ARP).\n- Validates both outer S-VLAN and `innervlan` C-VLAN bounds (`0..=4095`) during\n  semantic validation.\n\n## Practical Lab Example: Provider NNI Trunk Carrying Multiple Customer C-VLANs Inside S-VLAN 1200 (`qinq_metro_nni.frasm`)\n\nModels a Metro Ethernet provider trunk (`S-VLAN 1200`) carrying two distinct\ncustomer tenants: Tenant A (`innervlan 100`) running BGP peering and Tenant B\n(`innervlan 200`) running ICMPv6.\n\n```frameassembly\nhost ce_v4_a { ip 172.20.0.1 mac 00:1b:21:c1:00:01 }\nhost ce_v4_b { ip 172.20.0.2 mac 00:1b:21:c1:00:02 }\nhost ce_v6_a { ip 2001:db8:200::1 mac 00:1b:21:c2:00:01 }\nhost ce_v6_b { ip 2001:db8:200::2 mac 00:1b:21:c2:00:02 }\n\ncompile {\n    // Tenant A: eBGP Keepalive inside S-VLAN 1200 / C-VLAN 100\n    ce_v4_a -> ce_v4_b tcp syn srcport 51179 dstport 179 win 65535 mss 1452 qinq 1200 innervlan 100 pcp 6 wait 1ms\n    ce_v4_a <- ce_v4_b tcp syn ack win 65535 mss 1452 qinq 1200 innervlan 100 pcp 6 wait 1ms\n    ce_v4_a -> ce_v4_b tcp ack qinq 1200 innervlan 100 pcp 6 wait 1ms\n    ce_v4_a -> ce_v4_b bgp keepalive qinq 1200 innervlan 100 pcp 6 wait 3ms\n    // Tenant B: IPv6 Echo inside S-VLAN 1200 / C-VLAN 200\n    ce_v6_a -> ce_v6_b icmp echorequest id 42 seq 1 qinq 1200 innervlan 200 pcp 3 wait 1ms\n    ce_v6_a <- ce_v6_b icmp echoreply id 42 seq 1 qinq 1200 innervlan 200 pcp 3\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show qinq_metro_nni.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly qinq_metro_nni.frasm qinq_metro_nni.pcap\nframeassembly qinq_metro_nni.frasm qinq_metro_nni.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse qinq_metro_nni.pcap qinq_metro_nni_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r qinq_metro_nni.pcap -Y \"vlan.etype == 0x88a8 || vlan\"\n```\n\n## All `qinq` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host qinq [<outer_svlan 0..4095>] [innervlan\n<inner_cvlan 0..4095>] [pcp <0..7>] [dei <0|1>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `qinq [<0..4095>]` | 12-bit outer S-VLAN ID (0..4095) | `100` | Sets the 12-bit Service VLAN ID inside the outer IEEE 802.1ad (`0x88a8`) header. |\n| `innervlan <0..4095>` | 12-bit inner C-VLAN ID (0..4095) | `1` | Sets the 12-bit Customer VLAN ID inside the inner IEEE 802.1Q (`0x8100`) header. |\n| `pcp <0..7>` | 3-bit unsigned integer (0..7) | `0` | Sets the Priority Code Point bits on the VLAN tag header. |\n| `dei <0\\|1>` | 1-bit flag (0 or 1) | `0` | Sets the Drop Eligible Indicator bit on the outer S-Tag. |\n\n## Cross-Layer Options Valid with `qinq`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Always Spell innervlan Without Underscores\n\n- **Avoid:** `a -> b qinq 500 inner_vlan 20`\n- **Valid v3.3.0 Syntax:** `a -> b qinq 500 innervlan 20`\n\nLegacy underscored spellings such as `inner_vlan` or `c_vlan` are rejected by the\nv3.2.0 lexer with a self-healing diagnostic suggesting `innervlan`.\n\n### Account for 8 Extra Header Bytes on Path MTU Tests\n\n- **Avoid:** `Assuming 1500B Ethernet payload without baby-giant MTU`\n- **Valid v3.3.0 Syntax:** `a -> b tcp syn mss 1452 qinq 500 innervlan 20`\n\nQinQ adds 8 bytes (`0x88a8` + `0x8100`) to the Layer 2 header, increasing a\nstandard 1514-byte Ethernet frame to 1522 bytes on carrier trunks.\n"}
{"id":"pretrain-proto-lldp","kind":"protocol_spec","title":"IEEE 802.1AB Link Layer Discovery Protocol (lldp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/lldp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["lldp"],"text":"# lldp — IEEE 802.1AB Neighbor Discovery TLV Frames (`lldp`)\n\n> **FrameAssembly v3.3.0** · Protocol 4 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/lldp\n\n- **Full Protocol Name:** IEEE 802.1AB Link Layer Discovery Protocol\n- **Keyword:** `lldp`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x88cc\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEEE 802.1AB\n- **Wireshark Display Filter:** `lldp`\n- **Wire Encapsulation:** `Ethernet II -> LLDP (EtherType 0x88cc)`\n\n## Overview\n\nWant your NMS or test bench to think a 400G core chassis is plugged into `Gi0/1`?\nOne `sw -> peer lldp` frame advertises Chassis ID, Port ID, TTL, and System Name\nTLVs to `01:80:c2:00:00:0e`.\n\nLink Layer Discovery Protocol (`lldp`) is the vendor-neutral IEEE 802.1AB neighbor\ndiscovery protocol sent over Ethernet II (`0x88cc`) to the bridge multicast MAC\n`01:80:c2:00:00:0e`. Switches, routers, hypervisors, and VoIP phones advertise\ntheir hostname and interface port via Type-Length-Value (TLV) fields.\n\nFrameAssembly builds a complete IEEE 802.1AB LLDPDU—Chassis ID (TLV 1), Port ID\n(TLV 2), Time-To-Live (TLV 3), optional System Name (TLV 5) and System Description\n(TLV 6), plus the required End of LLDPDU marker (TLV 0)—from a single line.\n\n## Minimal Quickstart (`lldp_quickstart.frasm`)\n\n```frameassembly\nhost leaf_sw  { mac 00:1c:73:aa:01:01 }\nhost spine_sw { mac 00:1c:73:bb:02:01 }\n\ncompile {\n    leaf_sw -> spine_sw lldp\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x88cc` and defaults the destination MAC to IEEE\n  nearest-bridge multicast `01:80:c2:00:00:0e`.\n- Encodes TLV 1 (Chassis ID, subtype `4` MAC or `7` Locally Assigned), TLV 2 (Port\n  ID, subtype `5` Interface Name), and TLV 3 (16-bit `ttl`, default `120` seconds)\n  with exact 7-bit type + 9-bit length bitfields.\n- Appends TLV 5 (`sysname`) and TLV 6 (`sysdesc`) when specified, always\n  terminating with the 2-byte End of LLDPDU (`0x0000`).\n\n## Practical Lab Example: Bidirectional Leaf-Spine LLDP Neighbor Exchange Plus Shutdown Frame (`lldp_leaf_spine.frasm`)\n\nCaptures mutual LLDP advertisements between an Arista-class spine and an access\nswitch, followed by an IEEE 802.1AB `ttl 0` neighbor withdrawal frame.\n\n```frameassembly\nhost leaf_01  { mac 00:1c:73:11:22:01 }\nhost spine_01 { mac 00:1c:73:99:88:01 }\n\ncompile {\n    leaf_01 -> spine_01 lldp chassisid \"leaf-01.dc1\" portid \"Ethernet49/1\" ttl 120 sysname \"leaf-01.dc1.internal\" sysdesc \"EOS 4.32.1F\" wait 5ms\n    spine_01 -> leaf_01 lldp chassisid \"spine-01.dc1\" portid \"Ethernet1/1\" ttl 120 sysname \"spine-01.dc1.internal\" sysdesc \"EOS 4.32.1F\" wait 10ms\n    // Graceful LLDP port shutdown advertisement (TTL = 0)\n    leaf_01 -> spine_01 lldp chassisid \"leaf-01.dc1\" portid \"Ethernet49/1\" ttl 0\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show lldp_leaf_spine.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly lldp_leaf_spine.frasm lldp_leaf_spine.pcap\nframeassembly lldp_leaf_spine.frasm lldp_leaf_spine.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse lldp_leaf_spine.pcap lldp_leaf_spine_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r lldp_leaf_spine.pcap -Y \"lldp\"\n```\n\n## All `lldp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host lldp [chassisid \"<text>\"] [portid\n\"<text>\"] [ttl <0..65535>] [sysname \"<text>\"] [sysdesc \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `chassisid \"<text>\"` | Quoted string or identifier | `\"switch\"` | Encodes Mandatory TLV Type 1 (Chassis ID) with Locally Assigned subtype. |\n| `portid <str\\|u16>` | Interface string or port number | `\"eth0\"` | Encodes Mandatory TLV Type 2 (Port ID, e.g. `\"Gi1/0/48\"` or `\"Ethernet1\"`). |\n| `ttl <0..65535>` | Whole number (0..65535) (seconds) | `120` | Encodes Mandatory TLV Type 3 (Time To Live in seconds; `0` signals neighbor entry deletion). Note: on `lldp`, `ttl` sets the 16-bit LLDP Hold TTL rather than an IPv4 TTL. |\n| `sysname \"<text>\"` | Quoted string or identifier | `Omitted unless set` | Appends Optional TLV Type 5 (System Name). |\n| `sysdesc \"<text>\"` | Quoted string | `Omitted unless set` | Appends Optional TLV Type 6 (System Description). |\n\n## Cross-Layer Options Valid with `lldp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Contextual ttl Meaning on lldp\n\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 lldp chassisid \"sw1\" portid \"eth1\" ttl 180`\n\nBecause `lldp` is a pure Layer 2 protocol with no IP header, `ttl` sets the 16-bit\nLLDP Time-To-Live TLV (`0..=65535` seconds, allowing values > 255 such as `ttl\n300`), not an 8-bit IPv4 TTL.\n\n### Quote Interface Names Containing Slashes\n\n- **Avoid:** `sw1 -> sw2 lldp portid Gi1/0/48`\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 lldp portid \"Gi1/0/48\"`\n\nSlash characters (`/`) are not part of bare identifiers—always wrap interface\nnames like `\"Gi1/0/48\"` or `\"Ethernet49/1\"` in double quotes.\n"}
{"id":"pretrain-proto-stp","kind":"protocol_spec","title":"IEEE 802.1D Spanning Tree & IEEE 802.1w Rapid Spanning Tree (stp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/stp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["stp"],"text":"# stp — IEEE 802.1D STP & 802.1w RSTP BPDU Captures (`stp`)\n\n> **FrameAssembly v3.3.0** · Protocol 5 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/stp\n\n- **Full Protocol Name:** IEEE 802.1D Spanning Tree & IEEE 802.1w Rapid Spanning\n  Tree\n- **Keyword:** `stp`\n- **OSI Layer & Transport:** Layer 2 · 802.3 LLC 0x4242 -> 01:80:c2:00:00:00\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEEE 802.1D, IEEE 802.1w\n- **Wireshark Display Filter:** `stp`\n- **Wire Encapsulation:** `Ethernet II -> STP / RSTP (802.3 LLC 0x4242 ->\n  01:80:c2:00:00:00)`\n\n## Overview\n\nElecting your laptop Root Bridge on a live corporate VLAN is a career-limiting\nmove — crafting `stp` and `stp rstp` BPDUs into a `.pcap` lets you audit BPDU\nGuard without the walk of shame.\n\nSpanning Tree Protocol (`stp`) prevents Layer 2 bridging loops by exchanging\nBridge Protocol Data Units (BPDUs) encapsulated inside **IEEE 802.3 length-framed\nEthernet + LLC (`DSAP=0x42, SSAP=0x42, Control=0x03`)** addressed to the Bridge\nGroup multicast MAC `01:80:c2:00:00:00`.\n\nFrameAssembly emits classic IEEE 802.1D Configuration BPDUs by default (`version\n0x00`, 35-byte BPDU) and switches seamlessly to IEEE 802.1w Rapid Spanning Tree\n(`rstp`, `version 0x02`, `type 0x02`, including the mandatory Version 1 Length\n`0x00` byte) when the `rstp` flag is added.\n\n## Minimal Quickstart (`stp_quickstart.frasm`)\n\n```frameassembly\nhost root_sw { mac 00:1c:73:00:00:01 }\nhost edge_sw { mac 00:1c:73:00:00:02 }\n\ncompile {\n    root_sw -> edge_sw stp rstp\n}\n```\n\n### Automatic Wire Calculations\n\n- Addresses Ethernet destination to IEEE Bridge Group multicast\n  `01:80:c2:00:00:00` and writes the exact IEEE 802.3 Payload Length field instead\n  of an Ethernet II EtherType.\n- Prepends the 3-byte LLC header (`0x42 0x42 0x03`) and Protocol Identifier\n  `0x0000` ahead of the Configuration or RSTP BPDU.\n- Converts `maxage` (`20`), `hellotime` (`2`), and `forwarddelay` (`15`) seconds\n  into IEEE 802.1D `1/256`-second timer units (`0x1400`, `0x0200`, `0x0f00`)\n  automatically.\n\n## Practical Lab Example: Normal Root RSTP Heartbeat Followed by Rogue Superior BPDU Attack (`stp_rogue_root_audit.frasm`)\n\nCaptures a legitimate distribution switch sending RSTP BPDUs (`priority 32768`),\nfollowed by a rogue access device advertising priority `4096` (`cost 0`) to\ntrigger Root Guard / BPDU Guard.\n\n```frameassembly\nhost dist_root  { mac 00:1c:73:01:00:01 }\nhost access_sw  { mac 00:1c:73:02:00:10 }\nhost rogue_port { mac 00:50:56:99:99:99 }\n\ncompile {\n    // Legitimate RSTP Proposal/Learning-Forwarding BPDU from distribution root\n    dist_root -> access_sw stp rstp rootid \"32768:00:1c:73:01:00:01\" bridgeid \"32768:00:1c:73:01:00:01\" portid 0x8001 cost 0 flags 0x3c wait 2s\n    // Downstream access switch relaying root path cost 20000\n    access_sw -> rogue_port stp rstp rootid \"32768:00:1c:73:01:00:01\" bridgeid \"32768:00:1c:73:02:00:10\" portid 0x8018 cost 20000 flags 0x3c wait 500ms\n    // Rogue device injecting a superior Root ID (priority 4096, cost 0)\n    rogue_port -> access_sw stp rstp rootid \"4096:00:50:56:99:99:99\" bridgeid \"4096:00:50:56:99:99:99\" portid 0x8001 cost 0 flags 0x0e\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show stp_rogue_root_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly stp_rogue_root_audit.frasm stp_rogue_root_audit.pcap\nframeassembly stp_rogue_root_audit.frasm stp_rogue_root_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse stp_rogue_root_audit.pcap stp_rogue_root_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r stp_rogue_root_audit.pcap -Y \"stp\"\n```\n\n## All `stp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host stp [rstp] [rootid \"<text>\"] [bridgeid\n\"<text>\"] [portid <0..65535>] [cost <number>] [maxage <0..65535>] [hellotime\n<0..65535>] [forwarddelay <0..65535>] [flags <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `rstp` | Bare boolean flag | `Omitted (classic 802.1D v0)` | Emits IEEE 802.1w Rapid STP BPDU (`Protocol Version 2`, `BPDU Type 0x02`, plus trailing 1-byte Version 1 Length `0x00`). |\n| `rootid \"<text>\"` | Bridge ID string (\"<prio>:<mac>\" or \"<mac>\") | `\"32768:<src_mac>\"` | Encodes the 8-byte Root Identifier (2-byte priority + 6-byte MAC). |\n| `bridgeid \"<text>\"` | Bridge ID string (\"<prio>:<mac>\" or \"<mac>\") | `\"32768:<src_mac>\"` | Encodes the 8-byte Bridge Identifier of the transmitting switch. |\n| `portid <0..65535>` | Whole number (0..65535) | `0x8001` | Sets the 2-byte Port Identifier (4-bit priority + 12-bit port number). |\n| `cost <number>` | Whole number | `0` | Sets the 4-byte Root Path Cost (`20000` = 1GbE, `2000` = 10GbE). |\n| `maxage <0..65535> \\| hellotime <0..65535> \\| forwarddelay <0..65535>` | 16-bit unsigned integers (seconds) | `maxage 20, hellotime 2, forwarddelay 15` | Encodes BPDU timers scaled to IEEE 802.1D `1/256`s increments. |\n| `flags <0..255>` | 8-bit bitmask | `0 (or RSTP role bits)` | Sets Topology Change (`0x01`), Proposal (`0x02`), Port Role (`bits 2..3`), Learning (`0x10`), Forwarding (`0x20`), Agreement (`0x40`), and TCA (`0x80`). |\n\n## Cross-Layer Options Valid with `stp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### portid on stp Takes a Numeric u16, Not an Interface Name\n\n- **Avoid:** `sw1 -> sw2 stp portid \"Gi1/0/1\"`\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 stp rstp portid 0x8001`\n\nUnlike `lldp portid \"Gi1/0/1\"`, IEEE 802.1D/1w STP encodes a 16-bit numeric Port\nIdentifier (`0x8001` = default priority `128`, port `1`).\n\n### Quote Priority:MAC Strings in rootid and bridgeid\n\n- **Avoid:** `sw1 -> sw2 stp rootid 32768:00:1c:73:01:00:01`\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 stp rootid \"32768:00:1c:73:01:00:01\"`\n\nComposite `<priority>:<mac>` values have 7 colon-separated groups (rather than a\n6-octet MAC literal) and should be enclosed in double quotes.\n"}
{"id":"pretrain-proto-lacp","kind":"protocol_spec","title":"IEEE 802.3ad / 802.1AX Link Aggregation Control Protocol (lacp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/lacp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["lacp"],"text":"# lacp — IEEE 802.3ad Actor/Partner Link Aggregation PDUs (`lacp`)\n\n> **FrameAssembly v3.3.0** · Protocol 6 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/lacp\n\n- **Full Protocol Name:** IEEE 802.3ad / 802.1AX Link Aggregation Control Protocol\n- **Keyword:** `lacp`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x8809 (Slow Subtype 0x01)\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEEE 802.1AX, IEEE 802.3ad\n- **Wireshark Display Filter:** `lacp`\n- **Wire Encapsulation:** `Ethernet II -> LACP (EtherType 0x8809 (Slow Subtype\n  0x01))`\n\n## Overview\n\nFew things burn a Friday night faster than two switches refusing to bundle a LAG\nbecause one side is passive and the keys disagree. `lacp` writes exact 128-byte\n`actor <-> partner` slow-protocol PDUs.\n\nLink Aggregation Control Protocol (`lacp`) negotiates and monitors bundled\nEthernet port-channels (LAG / MLAG / vPC) using Ethernet Slow Protocols\n(`EtherType 0x8809`, subtype `0x01`) addressed to `01:80:c2:00:00:02`. Every IEEE\n802.1AX LACPDU has a fixed wire structure containing Actor Information (`TLV\n0x01`, length `20`), Partner Information (`TLV 0x02`, length `20`), Collector\nInformation (`TLV 0x03`, length `16`), Terminator (`TLV 0x00`), and 50 reserved\nzero bytes.\n\nFrameAssembly constructs the complete 110-byte LACPDU payload (124-byte Ethernet\nframe) automatically, defaulting both Actor and Partner state bitmasks to `0x3d`\n(Active + Aggregatable + In-Sync + Collecting + Distributing).\n\n## Minimal Quickstart (`lacp_quickstart.frasm`)\n\n```frameassembly\nhost tor_sw  { mac 00:1c:73:aa:10:01 }\nhost host_nic { mac 00:1b:21:bb:20:01 }\n\ncompile {\n    tor_sw -> host_nic lacp\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to Slow Protocols `0x8809`, destination MAC to\n  `01:80:c2:00:00:02`, Subtype `0x01` (LACP), and Version `0x01`.\n- Builds the exact 110-byte LACPDU body: Actor TLV (`0x01`, 20B), Partner TLV\n  (`0x02`, 20B), Collector TLV (`0x03`, 16B, MaxDelay `0x8000`), Terminator TLV\n  (`0x00`), and 50 zero-pad octets.\n- Defaults `actorsys` and `partnersys` from the endpoint MACs and sets\n  `actorstate` / `partnerstate` to `0x3d` (healthy bundled active link).\n\n## Practical Lab Example: LACP Port-Channel Bring-Up From Unsynced Defaulted to Active Distributing (`lacp_negotiation.frasm`)\n\nModels a Linux bond interface and Top-of-Rack switch negotiating Port-Channel 10\n(`key 10`) from initial unsynced discovery (`actorstate 0x45`) to full `0x3f`\nFast-LACP Collecting/Distributing sync.\n\n```frameassembly\nhost srv_bond0 { mac 00:1b:21:44:55:01 }\nhost tor_leaf1 { mac 00:1c:73:88:99:01 }\n\ncompile {\n    // 1. Initial server LACPDU: Active + ShortTimeout + Aggregatable + Defaulted (0x47)\n    srv_bond0 -> tor_leaf1 lacp actorkey 10 actorport 1 actorstate 0x47 partnerkey 0 partnerport 0 partnerstate 0x00 wait 5ms\n    // 2. Switch replies recognizing server Actor as Partner and setting In-Sync (0x0f)\n    tor_leaf1 -> srv_bond0 lacp actorkey 10 actorport 49 actorstate 0x0f partnersys 00:1b:21:44:55:01 partnerkey 10 partnerport 1 partnerstate 0x47 wait 5ms\n    // 3. Both sides enter Active + Fast + Aggregatable + Sync + Collecting + Distributing (0x3f)\n    srv_bond0 -> tor_leaf1 lacp actorkey 10 actorport 1 actorstate 0x3f partnersys 00:1c:73:88:99:01 partnerkey 10 partnerport 49 partnerstate 0x0f wait 2ms\n    tor_leaf1 -> srv_bond0 lacp actorkey 10 actorport 49 actorstate 0x3f partnersys 00:1b:21:44:55:01 partnerkey 10 partnerport 1 partnerstate 0x3f\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show lacp_negotiation.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly lacp_negotiation.frasm lacp_negotiation.pcap\nframeassembly lacp_negotiation.frasm lacp_negotiation.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse lacp_negotiation.pcap lacp_negotiation_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r lacp_negotiation.pcap -Y \"lacp\"\n```\n\n## All `lacp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host lacp [actorsys <mac>] [actorkey\n<0..65535>] [actorport <0..65535>] [actorstate <0..255>] [partnersys <mac>]\n[partnerkey <0..65535>] [partnerport <0..65535>] [partnerstate <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `actorsys <mac>` | 48-bit MAC address | `Source host MAC` | Sets the 6-byte Actor System MAC identifier inside TLV `0x01`. |\n| `actorkey <0..65535> \\| actorport <0..65535>` | 16-bit unsigned integers | `actorkey 1, actorport 1` | Sets the Actor Operational Key (LAG ID) and Actor Port Number. |\n| `actorstate <0..255>` | 8-bit IEEE 802.1AX state bitmask | `0x3d` | Bitmask: `0x01` Activity, `0x02` Timeout (1=Short 1s), `0x04` Aggregation, `0x08` Sync, `0x10` Collecting, `0x20` Distributing, `0x40` Defaulted, `0x80` Expired. |\n| `partnersys <mac>` | 48-bit MAC address | `Destination host MAC` | Sets the 6-byte Partner System MAC identifier inside TLV `0x02`. |\n| `partnerkey <0..65535> \\| partnerport <0..65535>` | 16-bit unsigned integers | `partnerkey 1, partnerport 1` | Sets the Partner Operational Key and Partner Port Number. |\n| `partnerstate <0..255>` | 8-bit IEEE 802.1AX state bitmask | `0x3d` | Sets the 8-bit Partner State bitmask recorded by the sender. |\n\n## Cross-Layer Options Valid with `lacp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Zero Underscores in Actor and Partner Modifiers\n\n- **Avoid:** `sw1 -> sw2 lacp actor_key 10 actor_state 0x3d`\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 lacp actorkey 10 actorstate 0x3d`\n\nAll LACP modifiers follow the strict `[a-z0-9]+` rule: `actorsys`, `actorkey`,\n`actorport`, `actorstate`, `partnersys`, `partnerkey`, `partnerport`,\n`partnerstate`.\n\n### LACP Frames Are Never VLAN-Tagged on Native Port-Channel Members\n\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 lacp actorkey 10 actorport 1`\n\nPer IEEE 802.1AX, link-local LACPDUs (`01:80:c2:00:00:02`) are transmitted\nuntagged on physical member links unless explicitly testing provider L2 protocol\ntunneling.\n"}
{"id":"pretrain-proto-eapol","kind":"protocol_spec","title":"IEEE 802.1X Port-Based Network Access Control (EAP over LAN) (eapol) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/eapol","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["eapol"],"text":"# eapol — IEEE 802.1X Port Authentication & EAPOL Frames (`eapol`)\n\n> **FrameAssembly v3.3.0** · Protocol 7 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/eapol\n\n- **Full Protocol Name:** IEEE 802.1X Port-Based Network Access Control (EAP over\n  LAN)\n- **Keyword:** `eapol`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x888e -> 01:80:c2:00:00:03\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEEE 802.1X, RFC 3748\n- **Wireshark Display Filter:** `eapol || eap`\n- **Wire Encapsulation:** `Ethernet II -> 802.1X EAPOL (EtherType 0x888e ->\n  01:80:c2:00:00:03)`\n\n## Overview\n\nBefore your workstation even gets an IP address, `supplicant -> switch eapol\nstart` kicks off the 802.1X bouncer at the switch port so you can script the whole\nEAP identity handshake without locking your own NIC into quarantine VLAN 999.\n\nExtensible Authentication Protocol over LAN (`eapol`) carries IEEE 802.1X\nPort-Based Network Access Control signaling directly over Ethernet II (`0x888e`)\nbetween an endpoint Supplicant and a switch or wireless Authenticator (PAE\nmulticast group MAC `01:80:c2:00:00:03`).\n\nFrameAssembly models the complete 802.1X access-port lifecycle: `start`\n(`EAPOL-Start`), `eappacket` (`EAP-Request/Response/Success/Failure` with\n`identity` or EAP method codes), `key` (WPA2/MACsec EAPOL-Key descriptors), and\n`logoff` (`EAPOL-Logoff`)—and pairs naturally with `radius` frames on the upstream\nswitch-to-AAA leg.\n\n## Minimal Quickstart (`eapol_quickstart.frasm`)\n\n```frameassembly\nhost supplicant { mac 00:1b:21:cc:10:25 }\nhost switch_pae { mac 00:1c:73:aa:00:01 }\n\ncompile {\n    supplicant -> switch_pae eapol\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x888e` and defaults destination MAC to the IEEE\n  802.1X PAE group address `01:80:c2:00:00:03`.\n- Writes the 4-byte EAPOL header (`Protocol Version` default `2`, `Packet Type`,\n  and exact 16-bit `Packet Body Length`).\n- For `eappacket` (`type 0`), encodes the RFC 3748 EAP header (`Code`,\n  `Identifier`, 16-bit `Length`, `Type` such as `1` Identity or `13` EAP-TLS, and\n  `identity` bytes) or minimal 4-byte EAP-Success (`eapcode 3`) / EAP-Failure\n  (`eapcode 4`).\n\n## Practical Lab Example: Full IEEE 802.1X Supplicant Onboarding With Upstream RADIUS Verification (`eapol_8021x_nac.frasm`)\n\nTraces a workstation sending `EAPOL-Start`, answering an `EAP-Request/Identity`\nchallenge, triggering an upstream `RADIUS Access-Request/Accept` on the switch,\nand receiving `EAP-Success`.\n\n```frameassembly\nhost laptop    { mac 00:1b:21:55:66:77 }\nhost access_sw { ip 10.20.0.2  mac 00:1c:73:00:01:02 }\nhost radius_srv { ip 10.20.0.50 mac 00:50:56:00:00:50 }\n\ncompile {\n    // 1. Supplicant initiates 802.1X on physical switch port\n    laptop -> access_sw eapol start version 2 wait 2ms\n    // 2. Switch Authenticator requests EAP Identity (eapcode 1 = Request, eapmethod 1 = Identity)\n    access_sw -> laptop eapol eappacket version 2 eapcode 1 eapid 1 eapmethod 1 dstmac 00:1b:21:55:66:77 wait 3ms\n    // 3. Supplicant responds with corporate identity\n    laptop -> access_sw eapol eappacket version 2 eapcode 2 eapid 1 eapmethod 1 identity \"corp\\\\jdoe\" wait 2ms\n    // 4. Switch forwards authentication upstream to RADIUS AAA server\n    access_sw -> radius_srv radius accessrequest id 10 user \"corp\\\\jdoe\" nasip 10.20.0.2 wait 4ms\n    access_sw <- radius_srv radius accessaccept id 10 framedip 10.20.100.45 wait 2ms\n    // 5. Switch grants port access with EAP-Success (eapcode 3)\n    access_sw -> laptop eapol eappacket version 2 eapcode 3 eapid 1 dstmac 00:1b:21:55:66:77\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show eapol_8021x_nac.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly eapol_8021x_nac.frasm eapol_8021x_nac.pcap\nframeassembly eapol_8021x_nac.frasm eapol_8021x_nac.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse eapol_8021x_nac.pcap eapol_8021x_nac_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r eapol_8021x_nac.pcap -Y \"eapol || eap\"\n```\n\n## All `eapol` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host eapol [version <0..255>] [type\n<eappacket|start|logoff|key> | eappacket | start | logoff | key] [eapcode\n<0..255>] [eapid <0..255>] [eapmethod <0..255>] [identity \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `eappacket \\| start \\| logoff \\| key \\| type <...>` | EAPOL packet type keyword or u8 | `eappacket (type 0)` | Selects EAPOL Packet Type: `eappacket` (`0`), `start` (`1`, 0-byte body), `logoff` (`2`, 0-byte body), or `key` (`3`, EAPOL-Key descriptor). |\n| `version <0..255>` | Whole number (0..255) | `2 (802.1X-2004)` | Sets the 1-byte EAPOL Protocol Version (`1` = 2001, `2` = 2004, `3` = 2010/2020). |\n| `eapcode <1..4>` | 8-bit RFC 3748 EAP Code | `2 (Response)` | Sets the inner EAP Code when `eappacket` is active: `1` Request, `2` Response, `3` Success, `4` Failure. |\n| `eapid <0..255>` | 8-bit EAP Identifier | `1` | Matches an EAP Response (`eapcode 2`) to its corresponding EAP Request (`eapcode 1`). |\n| `eapmethod <0..255>` | 8-bit EAP Method Type | `1 (Identity)` | Sets EAP Method on Request/Response: `1` Identity, `4` MD5-Challenge, `13` EAP-TLS, `25` PEAP. |\n| `identity \"<text>\"` | UTF-8 string | `\"user\" (on Identity)` | Populates the EAP-Identity Type-Data string (escape backslashes as `\"corp\\\\alice\"`). |\n\n## Cross-Layer Options Valid with `eapol`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Escape Backslashes in Windows Domain Identities\n\n- **Avoid:** `laptop -> sw eapol identity \"corp\\alice\"`\n- **Valid v3.3.0 Syntax:** `laptop -> sw eapol identity \"corp\\\\alice\"`\n\nDouble-quoted `.frasm` strings support C-style escape sequences (`\\r`, `\\n`, `\\t`,\n`\\\\`). Write `\"corp\\\\alice\"` so the wire string contains a literal `\\` rather than\nan escape.\n\n### MAC-Only Supplicants Cannot Directly Send L3 RADIUS\n\n- **Avoid:** `laptop -> radius_srv radius accessrequest (when laptop has no ip)`\n- **Valid v3.3.0 Syntax:** `access_sw -> radius_srv radius accessrequest (switch\n  has ip + mac)`\n\n`eapol` supports MAC-only hosts, whereas `radius` is a Layer 7 UDP protocol\nrequiring IPv4 or IPv6 addresses on both endpoints.\n"}
{"id":"pretrain-proto-mpls","kind":"protocol_spec","title":"Multiprotocol Label Switching Unicast Shim (mpls) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/mpls","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["mpls"],"text":"# mpls — Repeatable 32-Bit RFC 3032 MPLS Label Stacks (0x8847) (`mpls`)\n\n> **FrameAssembly v3.3.0** · Protocol 8 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/mpls\n\n- **Full Protocol Name:** Multiprotocol Label Switching Unicast Shim\n- **Keyword:** `mpls`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x8847 (Label 16)\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** RFC 3032, RFC 5462\n- **Wireshark Display Filter:** `mpls`\n- **Wire Encapsulation:** `Ethernet II -> MPLS Shim Stack (0x8847)`\n\n## Overview\n\nNo need to boot four virtual provider-edge routers just to get a multi-label\n`0x8847` stack — chain `mpls 16001 mpls 24010 exp 6 mplsttl 64` onto any packet\nline and the compiler sets `bos 0 -> bos 1` automatically.\n\nMultiprotocol Label Switching (`mpls`) inserts one or more 32-bit shim headers\n(`EtherType 0x8847`) between Layer 2 Ethernet/VLAN headers and the inner Layer 2\nor Layer 3 payload. Each 4-byte shim packs a 20-bit Label (`0..1048575`), 3-bit\nTraffic Class / Experimental QoS field (`exp` or `tc`), 1-bit Bottom-of-Stack\nindicator (`bos`), and an 8-bit MPLS Time-To-Live (`mplsttl`).\n\nIn FrameAssembly v3.3.0, `mpls` is **repeatable** (`mpls 16001 mpls 24010`) both\nas a standalone Layer 2 protocol between MAC-only Label Switch Routers (LSRs) and\nas a cross-layer modifier ahead of EoMPLS Layer 2 or L3VPN / 6VPE IPv4/IPv6\npackets.\n\n## Minimal Quickstart (`mpls_quickstart.frasm`)\n\n```frameassembly\nhost pe_west { mac 00:1c:73:aa:00:01 }\nhost p_core  { mac 00:1c:73:bb:00:02 }\n\ncompile {\n    pe_west -> p_core mpls 16000 mpls 24010 exp 5 mplsttl 64 payload \"sr-l3vpn\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II (or inner VLAN/QinQ) EtherType to `0x8847` (MPLS Unicast).\n- Automatically sets `bos 0` on outer transit/transport labels and `bos 1` on the\n  innermost service label unless `bos` is explicitly overridden.\n- Places EoMPLS Layer 2 or checksummed IPv4/IPv6 + L4 + L7 payloads immediately\n  after the Bottom-of-Stack MPLS shim.\n\n## Practical Lab Example: SR-MPLS L3VPN Core Transit Over 802.1Q Sub-Interfaces (`mpls_sr_l3vpn.frasm`)\n\nModels two Provider Edge routers exchanging MPLS-labeled BGP control traffic, VoIP\nEF traffic (`exp 5`), and dual-stack IPv6 customer probes across VLAN 400.\n\n```frameassembly\nhost pe1_v4 { ip 10.100.1.10 mac 00:1c:73:10:01:01 }\nhost pe2_v4 { ip 10.100.2.20 mac 00:1c:73:20:02:02 }\nhost ce1_v6 { ip 2001:db8:50::10 mac 00:1c:73:10:01:01 }\nhost ce2_v6 { ip 2001:db8:60::20 mac 00:1c:73:20:02:02 }\n\ncompile {\n    // 1. Standalone 2-label SR-MPLS OAM probe over VLAN 400 (outer Node SID 16001, inner VPN label 24010)\n    pe1_v4 -> pe2_v4 mpls 16001 mpls 24010 exp 6 mplsttl 64 vlan 400 payload \"sr-oam-ping\" wait 2ms\n    // 2. L3VPN IPv4 HTTPS TLS ClientHello inside outer label 16002 + inner VPN label 24010\n    pe1_v4 -> pe2_v4 tcp syn srcport 52443 dstport 443 win 65535 mss 1440 vlan 400 mpls 16002 mpls 24010 exp 4 mplsttl 63 wait 1ms\n    pe1_v4 <- pe2_v4 tcp syn ack win 65535 mss 1440 vlan 400 mpls 16001 mpls 24020 exp 4 mplsttl 63 wait 1ms\n    pe1_v4 -> pe2_v4 tcp ack vlan 400 mpls 16002 mpls 24010 exp 4 mplsttl 63 wait 1ms\n    pe1_v4 -> pe2_v4 tls clienthello sni \"erp.vrf-prod.internal\" alpn \"h2\" vlan 400 mpls 16002 mpls 24010 exp 4 mplsttl 63 wait 2ms\n    // 3. 6VPE IPv6 ICMPv6 Echo inside MPLS label stack (16002 -> 24055)\n    ce1_v6 -> ce2_v6 icmp echorequest id 9 seq 1 vlan 400 mpls 16002 mpls 24055 tc 5 mplsttl 62\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show mpls_sr_l3vpn.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly mpls_sr_l3vpn.frasm mpls_sr_l3vpn.pcap\nframeassembly mpls_sr_l3vpn.frasm mpls_sr_l3vpn.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse mpls_sr_l3vpn.pcap mpls_sr_l3vpn_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r mpls_sr_l3vpn.pcap -Y \"mpls\"\n```\n\n## All `mpls` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host mpls [<0..1048575> | label\n<0..1048575>] [exp|tc <0..7>] [bos <0|1>] [mplsttl <0..255>] (repeatable)`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `mpls [<0..1048575>] \\| label <0..1048575>` | 20-bit unsigned integer (0..1048575) | `16` | Sets the 20-bit MPLS Label (`0..15` reserved special-purpose labels such as `0` IPv4 Explicit Null / `3` Implicit Null; `16..1048575` general labels). |\n| `exp <0..7> \\| tc <0..7>` | 3-bit unsigned integer (0..7) | `0` | Sets the 3-bit RFC 5462 Traffic Class (formerly Experimental `EXP`) QoS field (`tc` and `exp` are exact aliases). |\n| `bos <0\\|1>` | 1-bit flag (0 or 1) | `1` | Sets the Bottom-of-Stack bit (`1` marks the innermost label preceding the L3 payload). |\n| `mplsttl <0..255>` | Whole number (0..255) (0..255) | `64` | Sets the 8-bit MPLS shim TTL independently of the inner IPv4/IPv6 `ttl` modifier. |\n\n## Cross-Layer Options Valid with `mpls`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n\n## Common Mistakes & Quick Fixes\n\n### Repeat mpls <label> for Multi-Label Stacks (Auto Bottom-of-Stack)\n\n- **Avoid:** `pe1 -> pe2 icmp mpls [16001, 24010]`\n- **Valid v3.3.0 Syntax:** `pe1 -> pe2 icmp mpls 16001 mpls 24010`\n\nStack multiple MPLS labels in outer-to-inner wire order (`mpls 16001 mpls 24010`).\nFrameAssembly sets `bos 0` on outer labels and `bos 1` on the bottom label\nautomatically.\n\n### Use mplsttl for the Shim TTL vs ttl for Inner IP\n\n- **Avoid:** `Assuming ttl 255 changes the MPLS shim TTL`\n- **Valid v3.3.0 Syntax:** `pe1 -> pe2 icmp ttl 64 mpls 16000 mplsttl 255`\n\n`mplsttl` controls the 8-bit TTL inside the MPLS shim (`0x8847`), whereas `ttl`\ncontrols the inner IPv4 Time-To-Live or IPv6 Hop Limit.\n"}
{"id":"pretrain-proto-cdp","kind":"protocol_spec","title":"Cisco Discovery Protocol v2 (IEEE 802.3 LLC/SNAP) (cdp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/cdp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["cdp"],"text":"# cdp — Cisco Discovery Protocol v2 LLC/SNAP Neighbor Frames (`cdp`)\n\n> **FrameAssembly v3.3.0** · Protocol 9 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/cdp\n\n- **Full Protocol Name:** Cisco Discovery Protocol v2 (IEEE 802.3 LLC/SNAP)\n- **Keyword:** `cdp`\n- **OSI Layer & Transport:** Layer 2 · 802.3 SNAP 0x2000\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** Cisco CDP v2, IEEE 802.2 LLC/SNAP\n- **Wireshark Display Filter:** `cdp`\n- **Wire Encapsulation:** `Ethernet II -> Cisco CDP v2 (802.3 SNAP 0x2000)`\n\n## Overview\n\nBecause half the campus closet still speaks fluent Cisco `01:00:0c:cc:cc:cc` over\n802.3 LLC/SNAP `0x2000`: `cdp` packs Device ID, Port ID, Platform, and Native VLAN\nmismatch TLVs with exact big-endian checksums.\n\nCisco Discovery Protocol (`cdp`) advertises neighbor identity, hardware platform,\nIOS/NX-OS software version, management IP addresses, port capabilities, and native\nVLAN mismatches over IEEE 802.3 LLC/SNAP (`DSAP=0xaa, SSAP=0xaa, Ctrl=0x03`, Cisco\nOUI `00:00:0c`, Protocol ID `0x2000`) to multicast destination MAC\n`01:00:0c:cc:cc:cc`.\n\nFrameAssembly encodes complete CDP v2 TLV sequences (`0x0001` Device ID, `0x0002`\nAddresses, `0x0003` Port ID, `0x0004` Capabilities, `0x0005` Software Version,\n`0x0006` Platform, and `0x000a` Native VLAN) and computes the 16-bit RFC 1071 CDP\nheader checksum automatically over MAC-only or IP-enabled switch endpoints.\n\n## Minimal Quickstart (`cdp_quickstart.frasm`)\n\n```frameassembly\nhost access_sw { mac 00:1b:21:aa:00:01 }\nhost core_sw   { mac 00:1b:21:bb:00:02 }\n\ncompile {\n    access_sw -> core_sw cdp deviceid \"access-sw-01\" portid \"Gi1/0/48\" platform \"C9300-48P\" nativevlan 10\n}\n```\n\n### Automatic Wire Calculations\n\n- Encapsulates the frame in IEEE 802.3 length framing + 8-byte LLC/SNAP header\n  (`aa:aa:03:00:00:0c:20:00`) and targets Cisco multicast MAC `01:00:0c:cc:cc:cc`\n  when `dstmac` is omitted.\n- Serializes big-endian 16-bit Type + 16-bit Length TLV headers for every\n  configured attribute (`deviceid`, `addr`, `portid`, `capabilities`, `swversion`,\n  `platform`, `nativevlan`).\n- Calculates the 16-bit ones'-complement CDP checksum across the entire CDP header\n  and TLV payload.\n\n## Practical Lab Example: Bidirectional Catalyst-to-Nexus Trunk Discovery & Native VLAN Check (`cdp_trunk_neighbors.frasm`)\n\nCaptures two switches exchanging CDP v2 neighbor advertisements with management\nIPv4 addresses, Router/Switch capability flags, and a Native VLAN 99 trunk tag.\n\n```frameassembly\nhost dist_nxos { ip 10.20.0.1 mac 00:2a:6a:10:00:01 }\nhost edge_ios  { ip 10.20.0.2 mac 00:1c:73:20:00:02 }\n\ncompile {\n    // 1. Distribution Nexus switch advertises capabilities 0x29 (Router + Switch + IGMP)\n    dist_nxos -> edge_ios cdp version 2 ttl 180 deviceid \"dist-n9k-01.corp\" addr 10.20.0.1 portid \"Ethernet1/1\" capabilities 0x29 platform \"N9K-C93180YC-FX\" swversion \"NX-OS 10.4(2)\" nativevlan 99 wait 5ms\n    // 2. Access Catalyst switch replies with matching Native VLAN 99\n    edge_ios -> dist_nxos cdp version 2 ttl 180 deviceid \"edge-c9300-04.corp\" addr 10.20.0.2 portid \"TenGigabitEthernet1/1/1\" capabilities 0x28 platform \"C9300-48U\" swversion \"IOS-XE 17.12.3\" nativevlan 99\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show cdp_trunk_neighbors.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly cdp_trunk_neighbors.frasm cdp_trunk_neighbors.pcap\nframeassembly cdp_trunk_neighbors.frasm cdp_trunk_neighbors.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse cdp_trunk_neighbors.pcap cdp_trunk_neighbors_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r cdp_trunk_neighbors.pcap -Y \"cdp\"\n```\n\n## All `cdp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host cdp [version <0..255>] [ttl <0..255>]\n[deviceid \"<text>\"] [addr <ip>] [portid \"<text>\"] [capabilities <number>]\n[swversion \"<text>\"] [platform \"<text>\"] [nativevlan <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `version <0..255>` | Whole number (0..255) | `2` | Sets the 8-bit CDP Version byte (`2` for CDP v2 rapid TLV extensions; `1` for legacy CDPv1). |\n| `ttl <0..255>` | Holdtime in seconds (0..255) | `180` | Sets the 8-bit CDP Time-To-Live (neighbor holdtime in seconds) inside the 4-byte CDP header. |\n| `deviceid \"<text>\"` | Quoted text or identifier | `\"switch\"` | Encodes TLV `0x0001` (Device-ID hostname string). |\n| `addr <ip>` | IPv4 or IPv6 literal | `Source host IP when present` | Encodes TLV `0x0002` (Management Address list entry with NLPID protocol header). |\n| `portid \"<text>\"` | Quoted text or interface name | `\"GigabitEthernet0/1\"` | Encodes TLV `0x0003` (outgoing interface name such as `\"Gi1/0/48\"`). |\n| `capabilities <number>` | 32-bit capability bitmask | `0x00000028 (Switch + IGMP)` | Encodes TLV `0x0004` (`0x01` Router, `0x08` Switch, `0x10` Host, `0x20` IGMP, `0x80` VoIP Phone). |\n| `swversion \"<text>\"` | Quoted text | `Omitted unless set` | Encodes TLV `0x0005` (NOS release banner string). |\n| `platform \"<text>\"` | Quoted text | `\"Cisco\"` | Encodes TLV `0x0006` (hardware chassis model string such as `\"C9300\"`). |\n| `nativevlan <0..65535>` | VLAN ID (0..4095) | `Omitted unless set` | Encodes TLV `0x000a` (16-bit Native VLAN ID for trunk mismatch detection). |\n\n## Cross-Layer Options Valid with `cdp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Use nativevlan for the CDP TLV vs vlan for Outer 802.1Q Tagging\n\n- **Avoid:** `sw1 -> sw2 cdp native_vlan 10`\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 cdp nativevlan 10 vlan 10`\n\n`nativevlan 10` writes CDP TLV `0x000a` inside the CDP payload, whereas\ncross-layer `vlan 10` wraps the outer Ethernet frame in an IEEE 802.1Q tag.\n\n### CDP ttl Is an 8-Bit Holdtime (0..255 Seconds)\n\n- **Avoid:** `sw1 -> sw2 cdp ttl 600`\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 cdp ttl 180`\n\nUnlike `lldp` (which carries a 16-bit TTL TLV up to 65535), the CDP header\nHoldtime field is a single byte (`0..255` seconds, Cisco default `180`).\n"}
{"id":"pretrain-proto-isis","kind":"protocol_spec","title":"Intermediate System to Intermediate System (ISO/IEC 10589) (isis) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/isis","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["isis"],"text":"# isis — CLNS Link-State Routing (IIH, LSP, CSNP & PSNP Over L2) (`isis`)\n\n> **FrameAssembly v3.3.0** · Protocol 10 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/isis\n\n- **Full Protocol Name:** Intermediate System to Intermediate System (ISO/IEC\n  10589)\n- **Keyword:** `isis`\n- **OSI Layer & Transport:** Layer 2 · 802.3 LLC CLNS 0xfefe03\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** ISO/IEC 10589, RFC 1195, RFC 5301, RFC 5308\n- **Wireshark Display Filter:** `isis`\n- **Wire Encapsulation:** `Ethernet II -> IS-IS (802.3 LLC CLNS 0xfefe03)`\n\n## Overview\n\nCarrier and hyperscale backbones love IS-IS because it rides directly over Layer 2\n(`0xfefe03` CLNS) and doesn’t care whether IPv4 or IPv6 melted down — `isis`\nbuilds L1/L2 Hellos, LSPs, CSNPs, and PSNPs in one line.\n\nIntermediate System to Intermediate System (`isis`, ISO/IEC 10589 / RFC 1195) is\nthe Layer 2 CLNS link-state interior gateway protocol powering service-provider\nMPLS/SRv6 cores and large data-center underlays. Because IS-IS runs directly over\nIEEE 802.3 LLC (`DSAP=0xfe, SSAP=0xfe, Ctrl=0x03`, NLPID `0x83`) rather than IP,\nadjacencies stay independent of IPv4 or IPv6 address-family changes.\n\nFrameAssembly constructs all nine IS-IS PDU types (`l1iih`, `l2iih`, `p2piih`,\n`l1lsp`, `l2lsp`, `l1csnp`, `l2csnp`, `l1psnp`, `l2psnp`), selects the matching\nAllL1IS (`01:80:c2:00:00:14`) or AllL2IS (`01:80:c2:00:00:15`) multicast MAC\nautomatically, encodes Area Addresses (TLV `1`), Dynamic Hostname (TLV `137`, RFC\n5301), and Protocols Supported (TLV `129`), and computes Fletcher-16 LSP\nchecksums.\n\n## Minimal Quickstart (`isis_quickstart.frasm`)\n\n```frameassembly\nhost core_r1 { mac 00:1c:73:01:00:01 }\nhost core_r2 { mac 00:1c:73:01:00:02 }\n\ncompile {\n    core_r1 -> core_r2 isis l2iih sysid \"1921.6800.1001\" area \"49.0001\" holdtime 30 hostname \"core-rtr-01\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Frames packets with IEEE 802.3 length + LLC `fe:fe:03` + ISO 10589 Intradomain\n  Routing Protocol Discriminator `0x83` and sets `AllL1IS` (`01:80:c2:00:00:14`)\n  or `AllL2IS` (`01:80:c2:00:00:15`) multicast destination MACs.\n- Parses dotted hex `sysid` (`\"1921.6800.1001\"`) into the 6-byte System ID and\n  encodes NSAP `area` (`\"49.0001\"`) into Area Addresses TLV `1` plus RFC 5301\n  Dynamic Hostname TLV `137`.\n- Computes the ISO 8473 Fletcher-16 checksum across Link State PDUs (`l1lsp` /\n  `l2lsp`) from the Remaining Lifetime offset to end-of-PDU.\n\n## Practical Lab Example: Level-2 Broadcast Adjacency + LSP Flooding & CSNP/PSNP Acknowledgment (`isis_l2_lsdb_sync.frasm`)\n\nModels two service-provider core routers forming a Level-2 LAN adjacency over VLAN\n500, flooding an L2 LSP with sequence number 12, and synchronizing via CSNP and\nPSNP.\n\n```frameassembly\nhost p_west { mac 00:1c:73:aa:10:01 }\nhost p_east { mac 00:1c:73:aa:10:02 }\n\ncompile {\n    // 1. Bidirectional Level-2 LAN IIH Hellos on trunk VLAN 500\n    p_west -> p_east isis l2iih sysid \"1921.6801.0001\" area \"49.0001\" priority 64 holdtime 27 hostname \"p-west-01\" vlan 500 wait 2ms\n    p_east -> p_west isis l2iih sysid \"1921.6801.0002\" area \"49.0001\" priority 64 holdtime 27 hostname \"p-east-01\" vlan 500 wait 5ms\n    // 2. Link State PDU flood + CSNP summary + PSNP confirmation\n    p_west -> p_east isis l2lsp sysid \"1921.6801.0001\" lifetime 1199 seqnum 12 hostname \"p-west-01\" vlan 500 wait 2ms\n    p_east -> p_west isis l2csnp sysid \"1921.6801.0002\" vlan 500 wait 2ms\n    p_west -> p_east isis l2psnp sysid \"1921.6801.0001\" vlan 500\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show isis_l2_lsdb_sync.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly isis_l2_lsdb_sync.frasm isis_l2_lsdb_sync.pcap\nframeassembly isis_l2_lsdb_sync.frasm isis_l2_lsdb_sync.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse isis_l2_lsdb_sync.pcap isis_l2_lsdb_sync_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r isis_l2_lsdb_sync.pcap -Y \"isis\"\n```\n\n## All `isis` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host isis [l1iih | l2iih | p2piih | l1lsp |\nl2lsp | l1csnp | l2csnp | l1psnp | l2psnp] [sysid \"<text>\"] [area \"<text>\"]\n[holdtime <0..65535>] [priority <0..255>] [lanid \"<text>\"] [circuittype <0..255>]\n[lifetime <0..65535>] [seqnum <number>] [hostname \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `l1iih \\| l2iih \\| p2piih \\| l1lsp \\| l2lsp \\| l1csnp \\| l2csnp \\| l1psnp \\| l2psnp` | IS-IS PDU type keyword (or `type \"<pdu>\"`) | `l2iih (PDU Type 16)` | Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`). |\n| `sysid \"<text>\"` | 6-byte hex System ID (e.g. \"1921.6800.1001\") | `\"0000.0000.0001\"` | Writes the 6-octet originating System ID in the IIH, LSP, CSNP, or PSNP header. |\n| `area \"<text>\"` | Hex ISO Area Address (e.g. \"49.0001\") | `\"49.0001\"` | Encodes Area Addresses TLV `1` inside Hello and LSP PDUs. |\n| `holdtime <0..65535>` | Seconds (0..65535) | `30` | Sets the 16-bit Holding Timer inside `l1iih`, `l2iih`, and `p2piih` headers. |\n| `priority <0..255>` | DIS Priority (0..127) | `64` | Sets the 7-bit Designated Intermediate System (DIS) election priority in LAN IIH headers. |\n| `lanid \"<text>\"` | 7-byte LAN ID (System ID + Pseudonode) | `sysid + \".01\"` | Sets the 7-octet Designated IS LAN ID field inside `l1iih` and `l2iih` PDUs. |\n| `circuittype <0..255>` | Circuit Type (1=L1, 2=L2, 3=L1/L2) | `Matches PDU level (1, 2, or 3)` | Sets the 8-bit Circuit Type field inside IIH and LSP headers. |\n| `lifetime <0..65535>` | Remaining Lifetime in seconds | `1200` | Sets the 16-bit Remaining Lifetime inside `l1lsp` and `l2lsp` PDUs (`0` purges an LSP). |\n| `seqnum <number>` | Whole number (32-bit LSP sequence) | `1` | Sets the 32-bit Sequence Number in `l1lsp` and `l2lsp` headers and recalculates Fletcher-16. |\n| `hostname \"<text>\"` | Quoted router hostname | `Omitted unless set` | Appends RFC 5301 Dynamic Hostname TLV (`137`) so Wireshark resolves System IDs symbolically. |\n\n## Cross-Layer Options Valid with `isis`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### IS-IS Runs Directly Over Layer 2 (MAC-Only Hosts Are Valid)\n\n- **Avoid:** `isis_a -> isis_b isis l2_iih sys_id \"1921.6800.1001\"`\n- **Valid v3.3.0 Syntax:** `isis_a -> isis_b isis l2iih sysid \"1921.6800.1001\"`\n\nAll PDU type names and modifiers are strict lowercase alphanumeric (`l2iih`,\n`p2piih`, `l2lsp`, `l2csnp`, `sysid`, `holdtime`, `seqnum`) with zero underscores.\n\n### Quote Dotted Hex sysid and area Values\n\n- **Avoid:** `p1 -> p2 isis l2iih sysid 1921.6800.1001 area 49.0001`\n- **Valid v3.3.0 Syntax:** `p1 -> p2 isis l2iih sysid \"1921.6800.1001\" area\n  \"49.0001\"`\n\nWrap NSAP area strings (`\"49.0001\"`) and 6-byte System IDs (`\"1921.6800.1001\"`) in\ndouble quotes so the lexer does not parse them as malformed IPv4 literals or OIDs.\n"}
{"id":"pretrain-proto-macsec","kind":"protocol_spec","title":"IEEE 802.1AE Media Access Control Security (MACsec) (macsec) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/macsec","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["macsec"],"text":"# macsec — IEEE 802.1AE Line-Rate Hop-by-Hop SecTAG & ICV Frames (`macsec`)\n\n> **FrameAssembly v3.3.0** · Protocol 11 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/macsec\n\n- **Full Protocol Name:** IEEE 802.1AE Media Access Control Security (MACsec)\n- **Keyword:** `macsec`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x88e5\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEEE 802.1AE, IEEE 802.1AEbw\n- **Wireshark Display Filter:** `macsec`\n- **Wire Encapsulation:** `Ethernet II -> MACsec (802.1AE) (EtherType 0x88e5)`\n\n## Overview\n\nEncrypting dark-fiber metro trunks and campus switch uplinks at Layer 2\n(`0x88e5`): `macsec` packs the exact SecTAG (`tci`, `an`, `pn`, optional 8-byte\n`sci`) plus 16-byte AES-GCM `icv` trailer.\n\nIEEE 802.1AE Media Access Control Security (`macsec`) provides line-rate\nhop-by-hop Layer 2 encryption and replay protection across dark fiber\ninterconnects, metro WAN handoffs, and high-security campus access ports\n(`EtherType 0x88e5`). Every MACsec frame prepends an 8-byte or 16-byte Security\nTag (`SecTAG`) carrying Tag Control Information (`tci`), Association Number\n(`an`), Short Length (`sl`), 32-bit Packet Number (`pn`), and optional 64-bit\nSecure Channel Identifier (`sci`), followed by ciphertext and a 16-byte Integrity\nCheck Value (`icv`).\n\nFrameAssembly builds deterministic `0x88e5` SecTAG headers and AES-GCM-style ICV\ntrailers over MAC-only or IP switch endpoints, enabling replay-window,\nkey-rollover (`an 0..3`), and MTU overhead verification without hardware MACsec\nPHYs.\n\n## Minimal Quickstart (`macsec_quickstart.frasm`)\n\n```frameassembly\nhost dc_west { mac 00:1b:21:aa:00:01 }\nhost dc_east { mac 00:1b:21:bb:00:02 }\n\ncompile {\n    dc_west -> dc_east macsec tci 0x2c an 0 pn 1 sci 0x001b21aa00010001 icv \"0102030405060708090a0b0c0d0e0f10\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x88e5` (IEEE 802.1AE MACsec) and bit-packs upper\n  `tci` flags with the 2-bit Association Number (`an`).\n- Automatically sets the `SC` (Secure Channel) bit and appends the 8-byte\n  big-endian `sci` whenever `sci` is specified (emitting a 16-byte SecTAG vs.\n  8-byte compact SecTAG).\n- Appends the 16-byte Integrity Check Value (`icv`) trailer after the protected\n  payload bytes.\n\n## Practical Lab Example: MKA Key Establishment Followed by MACsec SAK Rollover Across a Metro Trunk (`macsec_sak_rollover.frasm`)\n\nSimulates an 802.1X MKA (`eapol key`) exchange between two data-center border\nswitches followed by encrypted `macsec` frames rolling cleanly from Association\nNumber 0 to Association Number 1.\n\n```frameassembly\nhost border_a { mac 00:1c:73:a0:00:01 }\nhost border_b { mac 00:1c:73:b0:00:02 }\n\ncompile {\n    // 1. MKA (MACsec Key Agreement) EAPOL-Key peer keepalive\n    border_a -> border_b eapol key version 3 wait 2ms\n    // 2. Encrypted MACsec frames on SAK Association Number 0 (with 8-byte SCI)\n    border_a -> border_b macsec tci 0x2c an 0 pn 100 sci 0x001c73a000010001 payload \"ciphertext-block-100\" icv \"a0a1a2a3a4a5a6a7a8a9aaabacadaeaf\" wait 1ms\n    border_a <- border_b macsec tci 0x2c an 0 pn 200 sci 0x001c73b000020001 payload \"ciphertext-block-200\" icv \"b0b1b2b3b4b5b6b7b8b9babbbcbdbebf\" wait 2ms\n    // 3. Hitless SAK key rollover onto Association Number 1 (pn resets to 1)\n    border_a -> border_b macsec tci 0x2c an 1 pn 1 sci 0x001c73a000010001 payload \"ciphertext-new-sak\" icv \"c0c1c2c3c4c5c6c7c8c9cacbcccdcecf\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show macsec_sak_rollover.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly macsec_sak_rollover.frasm macsec_sak_rollover.pcap\nframeassembly macsec_sak_rollover.frasm macsec_sak_rollover.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse macsec_sak_rollover.pcap macsec_sak_rollover_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r macsec_sak_rollover.pcap -Y \"macsec\"\n```\n\n## All `macsec` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host macsec [tci <0..255>] [an <0..3>] [sl\n<0..63>] [pn <number>] [sci <number>] [icv \"<hex>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `tci <0..255>` | Tag Control Information byte (0..255) | `0x08 (E=0, C=0) or 0x2c with SCI` | Sets SecTAG TCI flags (`0x20` SC present, `0x08` E encryption, `0x04` C changed text). |\n| `an <0..3>` | 2-bit Association Number (0..3) | `0` | Sets the active SAK Association Number in the low 2 bits of the TCI/AN byte. |\n| `sl <0..63>` | 6-bit Short Length (0..63) | `0` | Sets Short Length in byte 3 of SecTAG (`1..47` octets for short frames; `0` otherwise). |\n| `pn <number>` | 32-bit Packet Number (>= 1) | `1` | Sets the big-endian 32-bit replay-protection Packet Number in bytes 4..7 of SecTAG. |\n| `sci <number>` | 64-bit hex/decimal Secure Channel ID | `Omitted unless set (6-byte MAC + 2-byte port)` | Appends the 8-byte Secure Channel Identifier (`0x001b21aa00010001`) to SecTAG. |\n| `icv \"<hex>\"` | 16-byte hex string (32 hex digits) | `16-byte deterministic tag` | Appends the 128-bit AES-GCM Integrity Check Value trailer at the end of the frame. |\n\n## Cross-Layer Options Valid with `macsec`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Pass sci as a 64-Bit Hex Literal (0x...) and icv as a Quoted Hex String\n\n- **Avoid:** `sw1 -> sw2 macsec sci \"00:1b:21:aa:00:01:00:01\" icv 0x0102`\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 macsec sci 0x001b21aa00010001 icv\n  \"0102030405060708090a0b0c0d0e0f10\"`\n\n`sci` takes a Whole number (`0x001b21aa00010001`), while `icv` takes a quoted hex\nbyte string (`\"0102...0f10\"`).\n\n### Association Number an Is Bounded to 0..3\n\n- **Avoid:** `sw1 -> sw2 macsec an 4 pn 1`\n- **Valid v3.3.0 Syntax:** `sw1 -> sw2 macsec an 3 pn 1`\n\nPer IEEE 802.1AE, `an` occupies bits 0..1 of the TCI/AN octet and only accepts\nvalues `0`, `1`, `2`, or `3`.\n"}
{"id":"pretrain-proto-pfc","kind":"protocol_spec","title":"IEEE 802.1Qbb Priority-based Flow Control (Lossless Ethernet) (pfc) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/pfc","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["pfc"],"text":"# pfc — IEEE 802.1Qbb Per-Priority Pause Frames for Lossless RoCEv2 (`pfc`)\n\n> **FrameAssembly v3.3.0** · Protocol 12 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/pfc\n\n- **Full Protocol Name:** IEEE 802.1Qbb Priority-based Flow Control (Lossless\n  Ethernet)\n- **Keyword:** `pfc`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x8808 (Opcode 0x0101)\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEEE 802.1Qbb, IEEE 802.3x MAC Control\n- **Wireshark Display Filter:** `macc || eth.type == 0x8808`\n- **Wire Encapsulation:** `Ethernet II -> PFC (802.1Qbb) (EtherType 0x8808 (Opcode\n  0x0101))`\n\n## Overview\n\nWhen an AI GPU cluster’s RoCEv2 queue fills up, switches fire `0x8808` opcode\n`0x0101` Priority Flow Control frames on Priority `3` (`pfc q3 512`) so congested\nqueues pause without freezing the whole link.\n\nPriority-based Flow Control (`pfc`, IEEE 802.1Qbb) enables lossless Ethernet\nfabrics for **RoCEv2 AI/GPU training clusters** and Fibre Channel / NVMe storage\nnetworks without pausing unrelated best-effort traffic. Carried over Ethernet MAC\nControl (`EtherType 0x8808`, Opcode `0x0101`) to reserved link-local multicast MAC\n`01:80:c2:00:00:01`, each 60-byte PFC frame contains a 16-bit Class-Enable Vector\n(`enable`) followed by eight 16-bit pause timers (`q0`..`q7`, measured in\n512-bit-time quanta).\n\nFrameAssembly encodes exact 46-byte padded `0x8808` MAC Control payloads,\nautomatically enabling individual bits in the Class-Enable Vector when you set\n`q0`..`q7` (or letting you override `enable` and uniform `quanta` directly) for\nPFC watchdog and storm analysis.\n\n## Minimal Quickstart (`pfc_quickstart.frasm`)\n\n```frameassembly\nhost leaf_tor { mac 00:1c:73:dc:00:01 }\nhost gpu_nic  { mac 00:1c:73:dc:00:10 }\n\ncompile {\n    leaf_tor -> gpu_nic pfc q3 512\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x8808` (MAC Control), destination MAC to\n  `01:80:c2:00:00:01`, and MAC Control Opcode to `0x0101` (PFC).\n- Automatically sets bit `i` in the 16-bit Class-Enable Vector (`enable`) whenever\n  `q0`..`q7` is specified, unless `enable` is explicitly overridden.\n- Zero-pads trailing bytes to the mandatory 46-byte Ethernet MAC Control minimum\n  payload (`60` bytes before FCS; add `fcs` for full `64`-byte wire length).\n\n## Practical Lab Example: Microsecond RoCEv2 Priority-3 XOFF Pause & XON Resume Sequence (`pfc_xoff_xon_lossless.frasm`)\n\nModels a congested Top-of-Rack switch asserting IEEE 802.1Qbb XOFF backpressure\n(`q3 2000`) toward a GPU host NIC, draining its ingress buffer over `150us`, and\nsending an XON (`q3 0`) release.\n\n```frameassembly\nhost tor_sw  { ip 10.80.1.1  mac 00:1c:73:80:00:01 }\nhost gpu_srv { ip 10.80.1.11 mac 00:1c:73:80:00:11 }\n\ncompile {\n    // 1. Congested ToR asserts XOFF pause on lossless Priority 3 (512-bit quanta = 2000)\n    tor_sw -> gpu_srv pfc enable 0x0008 q3 2000 fcs wait 150us\n    // 2. Queue drains below watermark; ToR sends XON (quanta 0) to resume Priority 3\n    tor_sw -> gpu_srv pfc enable 0x0008 q3 0 fcs wait 50us\n    // 3. Multi-class pause across Priority 3 (RDMA) and Priority 4 (Storage)\n    tor_sw -> gpu_srv pfc enable 0x0018 q3 512 q4 256 fcs\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show pfc_xoff_xon_lossless.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly pfc_xoff_xon_lossless.frasm pfc_xoff_xon_lossless.pcap\nframeassembly pfc_xoff_xon_lossless.frasm pfc_xoff_xon_lossless.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse pfc_xoff_xon_lossless.pcap pfc_xoff_xon_lossless_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r pfc_xoff_xon_lossless.pcap -Y \"macc || eth.type == 0x8808\"\n```\n\n## All `pfc` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host pfc [enable <0..65535>] [quanta\n<0..65535>] [q0 <0..65535>] [q1 <0..65535>] [q2 <0..65535>] [q3 <0..65535>] [q4\n<0..65535>] [q5 <0..65535>] [q6 <0..65535>] [q7 <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `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). |\n| `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. |\n| `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). |\n\n## Cross-Layer Options Valid with `pfc`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Include Explicit enable When Sending Zero-Quanta XON Frames\n\n- **Avoid:** `tor_sw -> gpu_srv pfc`\n- **Valid v3.3.0 Syntax:** `tor_sw -> gpu_srv pfc enable 0x0008 q3 0`\n\nTo unpause Priority 3 (`q3 0`), set `enable 0x0008` explicitly so receivers know\nthe `0` timer applies to Traffic Class 3 rather than an ignored disabled bit.\n\n### Use .pcapng Output to Preserve Sub-Microsecond PFC Timing\n\n- **Avoid:** `Relying on microsecond .pcap when testing 250ns PFC bursts`\n- **Valid v3.3.0 Syntax:** `tor_sw -> gpu_srv pfc q3 512 wait 250ns`\n\nClassic `.pcap` truncates timestamps to microseconds; compile to `.pcapng`\n(`IfTsResol=9`) when modeling 100G/400G nanosecond pause intervals.\n"}
{"id":"pretrain-proto-pppoe","kind":"protocol_spec","title":"Point-to-Point Protocol over Ethernet (Discovery & Session) (pppoe) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/pppoe","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["pppoe"],"text":"# pppoe — Broadband PADI/PADO/PADR/PADS Discovery & Session Frames (`pppoe`)\n\n> **FrameAssembly v3.3.0** · Protocol 13 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/pppoe\n\n- **Full Protocol Name:** Point-to-Point Protocol over Ethernet (Discovery &\n  Session)\n- **Keyword:** `pppoe`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x8863 / 0x8864\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** RFC 2516, RFC 4638\n- **Wireshark Display Filter:** `pppoed || pppoes`\n- **Wire Encapsulation:** `Ethernet II -> PPPoE (EtherType 0x8863 / 0x8864)`\n\n## Overview\n\nStill powering tens of millions of FTTH fiber ONTs worldwide: `pppoe` steps\ncleanly through `0x8863` `padi -> pado -> padr -> pads` discovery tags and\n`0x8864` subscriber `session` data.\n\nPoint-to-Point Protocol over Ethernet (`pppoe`, RFC 2516) remains the primary\nresidential FTTH/GPON and wholesale broadband subscriber access encapsulation\nterminating on ISP Broadband Network Gateways (BNGs). PPPoE operates across two\ndistinct EtherTypes: **Discovery (`0x8863`)**—which negotiates a 16-bit Session ID\nvia `padi` (`0x09`), `pado` (`0x07`), `padr` (`0x19`), `pads` (`0x65`), and `padt`\n(`0xa7`)—and **Session (`0x8864`)**, which carries 2-byte PPP Protocol IDs\n(`0xc021` LCP, `0xc023` PAP, `0xc223` CHAP, `0x0021` IPv4, `0x0057` IPv6).\n\nFrameAssembly encodes Discovery TLV tags (`0x0101` Service-Name, `0x0102` AC-Name,\n`0x0103` Host-Uniq, `0x0104` AC-Cookie), broadcasts `padi` to `ff:ff:ff:ff:ff:ff`\nautomatically, and calculates exact 16-bit PPPoE payload lengths.\n\n## Minimal Quickstart (`pppoe_quickstart.frasm`)\n\n```frameassembly\nhost ont_cpe { mac 00:1b:21:c0:00:10 }\nhost isp_bng { mac 00:1c:73:b0:00:01 }\n\ncompile {\n    ont_cpe -> isp_bng pppoe padi servicename \"ftth-gigabit\" hostuniq \"01020304\" wait 2ms\n    ont_cpe <- isp_bng pppoe pado acname \"bng-edge-01\" servicename \"ftth-gigabit\" hostuniq \"01020304\" accookie \"deadbeefcafe\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Selects EtherType `0x8863` for Discovery (`padi`, `pado`, `padr`, `pads`,\n  `padt`) and `0x8864` for `session`, broadcasting `padi` to `ff:ff:ff:ff:ff:ff`\n  automatically.\n- Sets Version=1, Type=1 (`0x11`), writes `sessionid 0x0000` during Discovery\n  (until `pads` assigns a non-zero session), and calculates the 16-bit PPPoE\n  Length field.\n- Encodes RFC 2516 Discovery Tags (`Service-Name`, `AC-Name`, `Host-Uniq`,\n  `AC-Cookie`) or prepends the 16-bit `pppproto` header on `session` frames.\n\n## Practical Lab Example: QinQ FTTH Subscriber DORA-Equivalent: PADI/PADO/PADR/PADS + PPP Session + PADT (`pppoe_bng_lifecycle.frasm`)\n\nModels a residential ONT over QinQ (`S-VLAN 500`, `C-VLAN 101`) completing full\nPPPoE Discovery with an ISP BNG, exchanging a PPP session frame (`sessionid\n0x1a2b`), and closing cleanly via `padt`.\n\n```frameassembly\nhost cpe_ont { mac 00:1b:21:55:01:01 }\nhost bng_agg { mac 00:1c:73:99:00:01 }\n\ncompile {\n    // 1. 4-step RFC 2516 PPPoE Discovery over QinQ S-VLAN 500 / C-VLAN 101\n    cpe_ont -> bng_agg pppoe padi servicename \"isp-fiber\" hostuniq \"a1b2c3d4\" qinq 500 innervlan 101 wait 2ms\n    cpe_ont <- bng_agg pppoe pado acname \"bng-metro-01\" servicename \"isp-fiber\" hostuniq \"a1b2c3d4\" accookie \"aa55aa55\" qinq 500 innervlan 101 wait 2ms\n    cpe_ont -> bng_agg pppoe padr servicename \"isp-fiber\" hostuniq \"a1b2c3d4\" accookie \"aa55aa55\" qinq 500 innervlan 101 wait 2ms\n    cpe_ont <- bng_agg pppoe pads sessionid 0x1a2b servicename \"isp-fiber\" hostuniq \"a1b2c3d4\" qinq 500 innervlan 101 wait 5ms\n    // 2. Active PPPoE Session frame (EtherType 0x8864, PPP LCP 0xc021)\n    cpe_ont -> bng_agg pppoe session sessionid 0x1a2b pppproto 0xc021 hexpayload \"0901000812345678\" qinq 500 innervlan 101 wait 10ms\n    // 3. Session termination (PADT on EtherType 0x8863)\n    cpe_ont -> bng_agg pppoe padt sessionid 0x1a2b qinq 500 innervlan 101\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show pppoe_bng_lifecycle.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly pppoe_bng_lifecycle.frasm pppoe_bng_lifecycle.pcap\nframeassembly pppoe_bng_lifecycle.frasm pppoe_bng_lifecycle.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse pppoe_bng_lifecycle.pcap pppoe_bng_lifecycle_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r pppoe_bng_lifecycle.pcap -Y \"pppoed || pppoes\"\n```\n\n## All `pppoe` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host pppoe [padi | pado | padr | pads | padt\n| session] [sessionid <0..65535>] [servicename \"<text>\"] [acname \"<text>\"]\n[hostuniq \"<hex>\"] [accookie \"<hex>\"] [pppproto <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `padi \\| pado \\| padr \\| pads \\| padt \\| session` | PPPoE stage keyword (or `type <stage>`) | `padi (Discovery 0x09)` | Selects Discovery codes `0x09` (`padi`), `0x07` (`pado`), `0x19` (`padr`), `0x65` (`pads`), `0xa7` (`padt`) on `0x8863`, or `session` (`0x00`) on `0x8864`. |\n| `sessionid <0..65535>` | 16-bit PPPoE Session ID | `0 on PADI/PADO/PADR; 1 on PADS/Session` | Sets the big-endian 16-bit Session_ID in bytes 2..3 of the 6-byte PPPoE header. |\n| `servicename \"<text>\"` | Quoted ISP service string | `\"\" (empty wildcard Service-Name tag)` | Encodes Discovery Tag `0x0101` (`Service-Name`). |\n| `acname \"<text>\"` | Quoted Access Concentrator name | `Omitted unless set (or \"AC\" on PADO)` | Encodes Discovery Tag `0x0102` (`AC-Name` advertised by the BNG in `pado`). |\n| `hostuniq \"<hex>\"` | Quoted hex byte string | `Omitted unless set` | Encodes Discovery Tag `0x0103` (`Host-Uniq` client correlation token). |\n| `accookie \"<hex>\"` | Quoted hex byte string | `Omitted unless set` | Encodes Discovery Tag `0x0104` (`AC-Cookie` SYN-cookie-style anti-spoofing token). |\n| `pppproto <0..65535>` | 16-bit PPP Protocol ID (e.g. 0xc021, 0x0021, 0x0057) | `0x0021 (IPv4)` | Sets the 2-byte PPP Protocol field immediately following the `0x8864` PPPoE Session header. |\n\n## Cross-Layer Options Valid with `pppoe`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### hostuniq and accookie Expect Quoted Even-Length Hex Bytes\n\n- **Avoid:** `cpe -> bng pppoe padi hostuniq \"router-1\"`\n- **Valid v3.3.0 Syntax:** `cpe -> bng pppoe padi hostuniq \"6370653031\"`\n\n`hostuniq` and `accookie` are raw binary RFC 2516 TLV octets parsed as hex byte\nstrings (`\"a1b2c3d4\"` or `\"a1:b2:c3:d4\"`).\n\n### Discovery Uses sessionid 0 Until PADS Assigns the Session ID\n\n- **Avoid:** `cpe -> bng pppoe padi sessionid 42`\n- **Valid v3.3.0 Syntax:** `cpe <- bng pppoe pads sessionid 42`\n\nPer RFC 2516, `padi`, `pado`, and `padr` carry `SESSION_ID = 0x0000`; the BNG\nassigns the non-zero `sessionid` in `pads`, which both peers reuse in `session`\nand `padt`.\n"}
{"id":"pretrain-proto-nsh","kind":"protocol_spec","title":"Network Service Header (Service Function Chaining) (nsh) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/nsh","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["nsh"],"text":"# nsh — RFC 8300 Service Function Chaining (SPI, SI & Context) (`nsh`)\n\n> **FrameAssembly v3.3.0** · Protocol 14 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/nsh\n\n- **Full Protocol Name:** Network Service Header (Service Function Chaining)\n- **Keyword:** `nsh`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x894f\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** RFC 8300, RFC 7665\n- **Wireshark Display Filter:** `nsh`\n- **Wire Encapsulation:** `Ethernet II -> NSH (RFC 8300) (EtherType 0x894f)`\n\n## Overview\n\nSteer packets through NFV firewall and scrubber chains on `0x894f`: `nsh` packs\nthe 24-bit `spi`, hop-decrementing `si`, 16-byte `mdtype 1` context, and enforces\nthe 6-bit `ttl <= 63` rule at compile time.\n\nNetwork Service Header (`nsh`, RFC 8300, `EtherType 0x894f`) is the IETF\ndata-plane encapsulation for **Service Function Chaining (SFC)** across NFV\nfirewalls, DPI scrubbers, carrier NATs, and SD-WAN service appliances. An NSH\nheader combines a 4-byte Base Header (`version`, `oam` bit, 6-bit `ttl`, `length`,\n`mdtype`, `nextproto`), a 4-byte Service Path Header (24-bit Service Path\nIdentifier `spi` + 8-bit Service Index `si`), and fixed 16-byte (`mdtype 1`) or\nvariable TLV (`mdtype 2`) Context Headers.\n\nFrameAssembly validates the 6-bit NSH `ttl` bound (`0..63`) at compile time,\nauto-computes the 6-bit NSH Length field in 4-byte words (`0x06` for MD Type 1,\n`0x02+` for MD Type 2), and maps symbolic `nextproto` names (`\"ipv4\"`, `\"ipv6\"`,\n`\"ethernet\"`, `\"nsh\"`, `\"mpls\"`).\n\n## Minimal Quickstart (`nsh_quickstart.frasm`)\n\n```frameassembly\nhost sff_ingress { mac 00:1c:73:50:00:01 }\nhost sf_firewall { mac 00:1c:73:50:00:10 }\n\ncompile {\n    sff_ingress -> sf_firewall nsh spi 100 si 255 mdtype 1 nextproto \"ipv4\" context \"00000001000000020000000300000004\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x894f` and bit-packs the 2-bit `version`, `oam`\n  flag, 6-bit `ttl` (`default 63`), and 6-bit 32-bit-word `Length` field.\n- Packs the 24-bit Service Path Identifier (`spi`) and 8-bit Service Index (`si`)\n  into the 4-byte Service Path Header.\n- Pads or sizes the Context Header to 16 bytes for `mdtype 1` (`Length = 6`) or\n  4-byte-aligned variable octets for `mdtype 2`.\n\n## Practical Lab Example: Multi-Hop NFV Service Chain: Classifier -> Firewall SF -> IPS SF (SI 255 -> 253) (`nsh_sfc_chain.frasm`)\n\nTraces a packet classified onto Service Path `spi 420` stepping through two\nService Functions as `si` decrements from `255` to `254` to `253`, followed by an\n`oam` health check.\n\n```frameassembly\nhost classifier { mac 00:1c:73:01:00:01 }\nhost sff_core   { mac 00:1c:73:01:00:02 }\nhost sf_ngfw    { mac 00:1c:73:01:00:11 }\nhost sf_ips     { mac 00:1c:73:01:00:12 }\n\ncompile {\n    // 1. Classifier pushes NSH SPI 420, SI 255 with tenant ID in MD Type 1 context\n    classifier -> sff_core nsh spi 420 si 255 ttl 63 mdtype 1 nextproto \"ethernet\" context \"000001a4000000100000000000000000\" wait 1ms\n    // 2. SFF steers packet through NGFW (decrements SI -> 254) and IPS (SI -> 253)\n    sff_core -> sf_ngfw nsh spi 420 si 255 ttl 62 mdtype 1 nextproto \"ethernet\" context \"000001a4000000100000000000000000\" wait 1ms\n    sf_ngfw -> sff_core nsh spi 420 si 254 ttl 62 mdtype 1 nextproto \"ethernet\" context \"000001a4000000100000000100000000\" wait 1ms\n    sff_core -> sf_ips nsh spi 420 si 254 ttl 61 mdtype 1 nextproto \"ethernet\" context \"000001a4000000100000000100000000\" wait 1ms\n    sf_ips -> sff_core nsh spi 420 si 253 ttl 61 mdtype 1 nextproto \"ethernet\" context \"000001a4000000100000000300000000\" wait 2ms\n    // 3. SFC OAM probe on MD Type 2 (variable-length context omitted, Length = 2)\n    classifier -> sff_core nsh oam spi 420 si 255 ttl 63 mdtype 2 nextproto \"nsh\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show nsh_sfc_chain.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly nsh_sfc_chain.frasm nsh_sfc_chain.pcap\nframeassembly nsh_sfc_chain.frasm nsh_sfc_chain.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse nsh_sfc_chain.pcap nsh_sfc_chain_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r nsh_sfc_chain.pcap -Y \"nsh\"\n```\n\n## All `nsh` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host nsh [version <0..3>] [oam] [ttl\n<0..63>] [mdtype <1|2>] [nextproto <0..255 | \"ipv4\" | \"ipv6\" | \"ethernet\" | \"nsh\"\n| \"mpls\">] [spi <0..16777215>] [si <0..255>] [context \"<hex>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `version <0..3>` | 2-bit NSH version (0..3) | `0` | Sets the 2-bit RFC 8300 NSH Base Header Version (`0` standard). |\n| `oam` | Boolean flag | `Unset (0)` | Sets the `O` (Operations, Administration, and Maintenance) bit in the NSH Base Header. |\n| `ttl <0..63>` | 6-bit NSH Service Plane TTL (0..63) | `63` | Sets the 6-bit loop-prevention TTL inside the NSH Base Header (validated `<= 63` at compile time). |\n| `mdtype <1\\|2>` | Metadata Type (1 = Fixed 16B, 2 = Variable) | `1` | Selects Fixed 4x32-bit Context Header (`1`, `Length=6`) or Variable Context (`2`). |\n| `nextproto <\"ipv4\"\\|\"ipv6\"\\|\"ethernet\"\\|\"nsh\"\\|\"mpls\"\\|0..255>` | Protocol name or 8-bit code | `\"ipv4\" (0x01)` | Sets Next Protocol (`1`=IPv4, `2`=IPv6, `3`=Ethernet, `4`=NSH, `5`=MPLS). |\n| `spi <0..16777215>` | 24-bit Service Path Identifier | `1` | Writes the big-endian 24-bit Service Path ID in bytes 4..6 of the NSH header. |\n| `si <0..255>` | 8-bit Service Index | `255` | Writes the 8-bit Service Index hop counter in byte 7 of the NSH header. |\n| `context \"<hex>\"` | Quoted hex bytes (16B on mdtype 1) | `16 zero bytes on mdtype 1` | Populates the NSH Mandatory Context Header (`mdtype 1`) or variable metadata (`mdtype 2`). |\n\n## Cross-Layer Options Valid with `nsh`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### NSH ttl Is Strictly 6 Bits (0..63, Never 64 or 255)\n\n- **Avoid:** `sff1 -> sff2 nsh spi 100 ttl 64`\n- **Valid v3.3.0 Syntax:** `sff1 -> sff2 nsh spi 100 ttl 63`\n\nRFC 8300 allocates a 6-bit TTL field in the NSH Base Header (`max 63`), so `ttl\n64` or `ttl 255` fails compile-time semantic validation on `nsh` statements.\n\n### Use nextproto (Never nextheader) on NSH Frames\n\n- **Avoid:** `sff1 -> sff2 nsh spi 100 nextheader 1`\n- **Valid v3.3.0 Syntax:** `sff1 -> sff2 nsh spi 100 nextproto \"ipv4\"`\n\n`nextproto` sets the NSH Base Header Next Protocol field (`\"ipv4\"`, `\"ipv6\"`,\n`\"ethernet\"`, `\"nsh\"`, `\"mpls\"`).\n"}
{"id":"pretrain-proto-profinet","kind":"protocol_spec","title":"IEC 61158 PROFINET Real-Time & DCP (Ethernet 0x8892 / UDP 34964) (profinet) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/profinet","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["profinet"],"text":"# profinet — IEC 61158 Real-Time Cyclic IO & DCP (0x8892 / UDP 34964) (`profinet`)\n\n> **FrameAssembly v3.3.0** · Protocol 15 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/profinet\n\n- **Full Protocol Name:** IEC 61158 PROFINET Real-Time & DCP (Ethernet 0x8892 /\n  UDP 34964)\n- **Keyword:** `profinet`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x8892 (or UDP 34964)\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEC 61158, IEC 61784-2, PROFINET IO\n- **Wireshark Display Filter:** `pn_rt || pn_dcp`\n- **Wire Encapsulation:** `Ethernet II -> PROFINET RT (EtherType 0x8892 (or UDP\n  34964))`\n\n## Overview\n\nFactory-floor deterministic Ethernet on `0x8892` (or routed over UDP `34964` with\n`transport udp`): `profinet` stamps exact `frameid`, cyclic counters, and DCP\nidentify requests without touching a live Siemens line.\n\nPROFINET (`profinet`, IEC 61158) is the dominant real-time industrial Ethernet\nfieldbus across discrete manufacturing, robotics, and Siemens SIMATIC automation\ncells. Cyclic Real-Time (`RT_CLASS_1`/`RT_CLASS_3`) I/O data and Discovery and\nBasic Configuration Protocol (`DCP`) frames run directly over Layer 2 (`EtherType\n0x8892`) prepended with a 16-bit `FrameID` (`0x8000..0xfbff` RT cyclic,\n`0xfefe`/`0xfeff` DCP Identify) and suffixed with a 4-byte cyclic trailer\n(`CycleCounter`, `DataStatus`, `TransferStatus`).\n\nFrameAssembly emits native `0x8892` Layer 2 frames over MAC-only or IP hosts by\ndefault—and when you append `transport udp` over IP hosts, it automatically\nswitches to **PROFINET RT over UDP (`dstport 34964`)** for routed L3\nfactory-backbone conduits.\n\n## Minimal Quickstart (`profinet_quickstart.frasm`)\n\n```frameassembly\nhost io_controller { mac 00:0e:8c:aa:00:01 }\nhost io_device     { mac 00:0e:8c:bb:00:10 }\n\ncompile {\n    io_controller -> io_device profinet frameid 0x8000 cycle 100 datastatus 0x35 vlan 0 pcp 6\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x8892` on Layer 2 frames, or encapsulates inside\n  IPv4/IPv6 + UDP `dstport 34964` when `transport udp` is specified.\n- Encodes the 16-bit big-endian `FrameID`, pads cyclic RT payloads to minimum\n  length, and appends the 4-byte `CycleCounter` + `DataStatus` (`0x35`\n  Valid/Primary/Run/OK) + `TransferStatus` (`0x00`) trailer.\n- Constructs structured PROFINET DCP headers (`ServiceID`, `ServiceType`, `Xid`)\n  when `service` / `get` / `set` / `request` / `response` is selected.\n\n## Practical Lab Example: PROFINET DCP Station Discovery + Cyclic 802.1p Priority-Tagged I/O + Routed UDP (`profinet_dcp_and_rt_io.frasm`)\n\nCaptures a PLC IO-Controller discovering a field IO-Device via DCP, exchanging\ncyclic `0x8000` real-time frames on priority tag `vlan 0 pcp 6`, and sending a\nrouted `transport udp` frame.\n\n```frameassembly\nhost plc_s7_1500 { ip 10.110.1.10 mac 00:0e:8c:15:00:01 }\nhost et200sp_io  { ip 10.110.1.20 mac 00:0e:8c:20:00:02 }\n\ncompile {\n    // 1. DCP Identify request & response over Layer 2 (0x8892)\n    plc_s7_1500 -> et200sp_io profinet frameid 0xfefe service \"identify\" request xid 0x01020304 wait 2ms\n    plc_s7_1500 <- et200sp_io profinet frameid 0xfeff service \"identify\" response xid 0x01020304 wait 2ms\n    // 2. Priority-tagged (VLAN 0, PCP 6) cyclic RT_CLASS_1 I/O exchange\n    plc_s7_1500 -> et200sp_io profinet frameid 0x8000 cycle 3200 datastatus 0x35 vlan 0 pcp 6 wait 1ms\n    plc_s7_1500 <- et200sp_io profinet frameid 0x8001 cycle 3200 datastatus 0x35 vlan 0 pcp 6 wait 2ms\n    // 3. Routed PROFINET over UDP port 34964\n    plc_s7_1500 -> et200sp_io profinet frameid 0x8000 cycle 3232 datastatus 0x35 transport udp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show profinet_dcp_and_rt_io.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly profinet_dcp_and_rt_io.frasm profinet_dcp_and_rt_io.pcap\nframeassembly profinet_dcp_and_rt_io.frasm profinet_dcp_and_rt_io.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse profinet_dcp_and_rt_io.pcap profinet_dcp_and_rt_io_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r profinet_dcp_and_rt_io.pcap -Y \"pn_rt || pn_dcp\"\n```\n\n## All `profinet` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host profinet [frameid <0..65535>] [cycle\n<0..65535>] [datastatus <0..255>] [transferstatus <0..255>] [service \"<text>\"]\n[xid <number>] [request | response | read | write | get | set | connect | release]\n[transport udp]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `frameid <0..65535>` | 16-bit PROFINET FrameID (e.g. 0x8000, 0xfefe) | `0x8000 (RT_CLASS_1 cyclic)` | Writes the 2-byte PROFINET FrameID ahead of the RT or DCP payload. |\n| `cycle <0..65535>` | 16-bit 31.25us Cycle Counter | `0` | Sets the 16-bit CycleCounter in the 4-byte cyclic PROFINET RT trailer. |\n| `datastatus <0..255>` | 8-bit RT DataStatus flags | `0x35 (State=Primary, DataValid, ProviderRun, StationOK)` | Sets the DataStatus byte in the cyclic RT trailer (`0x35` healthy; clear bit `0x04` to simulate invalid I/O). |\n| `transferstatus <0..255>` | 8-bit TransferStatus byte | `0x00` | Sets the final TransferStatus byte of the cyclic PROFINET RT trailer. |\n| `service \"<text>\" \\| get \\| set \\| read \\| write \\| connect \\| release` | DCP / IO service selector | `Cyclic RT when omitted` | Selects DCP `get`/`set`/`identify` or IO `read`/`write`/`connect`/`release` PDU encoding. |\n| `request \\| response` | PDU direction role flag | `request` | Toggles DCP `ServiceType` (`0` Request vs `1` Response Success). |\n| `xid <number>` | 32-bit DCP Transaction ID | `1` | Sets the 4-byte `Xid` correlation field in PROFINET DCP frames. |\n| `transport udp` | Optional UDP encapsulation override (IP hosts required) | `Raw Ethernet 0x8892` | Encapsulates the PROFINET frame inside IPv4/IPv6 + UDP `dstport 34964`. |\n\n## Cross-Layer Options Valid with `profinet`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), EtherType 0x8892 (or UDP 34964)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport udp` | Optional UDP encapsulation override | `Ethernet 0x8892 (UDP 34964 when transport udp is set)` | Wraps the protocol frame inside an IPv4/IPv6 + UDP header instead of raw Ethernet or raw IP encapsulation. |\n\n## Common Mistakes & Quick Fixes\n\n### transport udp Requires IP Addresses on Both Endpoints\n\n- **Avoid:** `host io1 { mac 00:0e:8c:00:00:01 }\nio1 -> io2 profinet transport udp`\n- **Valid v3.3.0 Syntax:** `host io1 { ip 10.110.1.10 mac 00:0e:8c:00:00:01 }\nio1 -> io2 profinet transport udp`\n\nNative Layer 2 `profinet` (`0x8892`) works on MAC-only hosts, whereas `profinet\ntransport udp` builds an IP + UDP `34964` header and requires `ip` on both hosts.\n\n### PROFINET Supports transport udp Only (Never transport tcp)\n\n- **Avoid:** `plc -> io profinet transport tcp`\n- **Valid v3.3.0 Syntax:** `plc -> io profinet transport udp`\n\nPer IEC 61158, routed PROFINET Real-Time uses UDP port `34964`; TCP is not a valid\nPROFINET RT transport.\n"}
{"id":"pretrain-proto-goose","kind":"protocol_spec","title":"IEC 61850-8-1 Generic Object Oriented Substation Events (goose) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/goose","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["goose"],"text":"# goose — IEC 61850-8-1 Substation Protection Trip Events (0x88b8) (`goose`)\n\n> **FrameAssembly v3.3.0** · Protocol 16 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/goose\n\n- **Full Protocol Name:** IEC 61850-8-1 Generic Object Oriented Substation Events\n- **Keyword:** `goose`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x88b8\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEC 61850-8-1, IEEE 802.1Q\n- **Wireshark Display Filter:** `goose`\n- **Wire Encapsulation:** `Ethernet II -> IEC 61850 GOOSE (EtherType 0x88b8)`\n\n## Overview\n\nSubstation protection relays don’t wait for TCP handshakes when a 500 kV line\nfaults — `goose` fires ASN.1 BER `0x88b8` multicast trip events (`stnum`\nincrements, `sqnum` resets) in under 4 milliseconds.\n\nGeneric Object Oriented Substation Events (`goose`, IEC 61850-8-1) delivers\nsub-4-millisecond protective-relay trip commands, breaker status interlocks, and\nbusbar protection signals directly over Layer 2 Ethernet (`EtherType 0x88b8`) to\nIEC multicast MACs (`01:0c:cd:01:00:00..ff`). Every GOOSE frame carries an 8-byte\nheader (`APPID`, `Length`, `Reserved1`, `Reserved2`) wrapping an ASN.1 BER\n`goosePdu` (`0x61`) with `gocbRef`, `timeAllowedtoLive`, `datSet`, `goID`, `stNum`\n(state change counter), `sqNum` (retransmission sequence), `simulation`,\n`confRev`, `ndsCom`, and `allData`.\n\nFrameAssembly encodes valid ASN.1 BER tag-length-value trees and IEC multicast\ndestination MACs automatically—making it safe to validate substation NERC CIP IDS\nrules (`stNum` jump / spoofed trip injection) without touching energized 230kV\nswitchgear.\n\n## Minimal Quickstart (`goose_quickstart.frasm`)\n\n```frameassembly\nhost relay_ied1 { mac 00:1b:21:61:85:01 }\nhost breaker_mu { mac 01:0c:cd:01:00:01 }\n\ncompile {\n    relay_ied1 -> breaker_mu goose appid 0x1001 gocbref \"IED1PROT/LLN0$GO$gcbTrip\" datset \"IED1PROT/LLN0$TripSet\" stnum 1 sqnum 0 vlan 100 pcp 6\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x88b8` and targets IEC 61850 GOOSE multicast\n  `01:0c:cd:01:00:01` when `dstmac` / peer MAC is default.\n- Writes the 8-byte IEC 61850 header (`APPID`, total `Length`, `Reserved 0x0000\n  0x0000`) and constructs a complete ASN.1 BER `0x61` `goosePdu` sequence.\n- Computes exact BER definite lengths across nested context-specific tags\n  `[0]`..`[11]` so Wireshark `goose` dissects zero malformed-BER warnings.\n\n## Practical Lab Example: Substation Breaker Trip Event: Steady Heartbeat -> Fault Trip -> Fast Retransmit (`goose_breaker_trip_sequence.frasm`)\n\nCaptures steady-state `stnum 1` GOOSE heartbeats on Substation VLAN 200 (`pcp 6`),\nfollowed by an overcurrent trip (`stnum 2`, `sqnum 0..2`) at exponential sub-4ms\nintervals.\n\n```frameassembly\nhost feeder_ied { mac 00:1b:21:50:01:10 }\nhost bus_group  { mac 01:0c:cd:01:00:10 }\n\ncompile {\n    // 1. Steady-state heartbeat before fault (stNum=1, sqNum=42, TTL=2000ms)\n    feeder_ied -> bus_group goose appid 0x1010 gocbref \"BAY01_IED/LLN0$GO$BreakerTrip\" datset \"BAY01_IED/LLN0$ProtTrip\" goid \"BAY01_TRIP\" stnum 1 sqnum 42 timetolive 2000 confrev 1 numdatsetentries 2 vlan 200 pcp 6 wait 10ms\n    // 2. Overcurrent fault! State number increments (stNum=2), sequence resets (sqNum=0)\n    feeder_ied -> bus_group goose appid 0x1010 gocbref \"BAY01_IED/LLN0$GO$BreakerTrip\" datset \"BAY01_IED/LLN0$ProtTrip\" goid \"BAY01_TRIP\" stnum 2 sqnum 0 timetolive 4 confrev 1 numdatsetentries 2 vlan 200 pcp 6 wait 2ms\n    // 3. Fast IEC 61850 retransmission burst (sqNum=1, sqNum=2)\n    feeder_ied -> bus_group goose appid 0x1010 gocbref \"BAY01_IED/LLN0$GO$BreakerTrip\" datset \"BAY01_IED/LLN0$ProtTrip\" goid \"BAY01_TRIP\" stnum 2 sqnum 1 timetolive 8 confrev 1 numdatsetentries 2 vlan 200 pcp 6 wait 4ms\n    feeder_ied -> bus_group goose appid 0x1010 gocbref \"BAY01_IED/LLN0$GO$BreakerTrip\" datset \"BAY01_IED/LLN0$ProtTrip\" goid \"BAY01_TRIP\" stnum 2 sqnum 2 timetolive 16 confrev 1 numdatsetentries 2 vlan 200 pcp 6\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show goose_breaker_trip_sequence.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly goose_breaker_trip_sequence.frasm goose_breaker_trip_sequence.pcap\nframeassembly goose_breaker_trip_sequence.frasm goose_breaker_trip_sequence.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse goose_breaker_trip_sequence.pcap goose_breaker_trip_sequence_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r goose_breaker_trip_sequence.pcap -Y \"goose\"\n```\n\n## All `goose` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host goose [appid <0..65535>] [gocbref\n\"<text>\"] [timetolive <number>] [datset \"<text>\"] [goid \"<text>\"] [stnum <number>]\n[sqnum <number>] [simulation] [confrev <number>] [ndscom] [numdatsetentries\n<number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `appid <0..65535>` | 16-bit IEC 61850 APPID (typically 0x0000..0x3fff or 0x8000..0xbfff) | `0x1000` | Sets bytes 0..1 of the 8-byte GOOSE header. |\n| `gocbref \"<text>\"` | GOOSE Control Block Reference string | `\"IED1/LLN0$GO$gcb01\"` | Encodes BER context tag `[0]` (`gocbRef`). |\n| `timetolive <number>` | Milliseconds (timeAllowedtoLive) | `2000` | Encodes BER context tag `[1]` (`timeAllowedtoLive` in milliseconds). |\n| `datset \"<text>\"` | Dataset ObjectReference string | `\"IED1/LLN0$dataset01\"` | Encodes BER context tag `[2]` (`datSet`). |\n| `goid \"<text>\"` | GOOSE Identifier string | `\"GOOSE1\"` | Encodes BER context tag `[3]` (`goID`). |\n| `stnum <number>` | State Number counter (>= 1) | `1` | Encodes BER context tag `[5]` (`stNum`, increments on every dataset value transition). |\n| `sqnum <number>` | Sequence Number counter (>= 0) | `0` | Encodes BER context tag `[6]` (`sqNum`, increments on heartbeats; resets to `0` on state change). |\n| `simulation` | Boolean test-mode flag | `false (0x00)` | Sets BER context tag `[7]` (`simulation = true`) so live relays ignore test-bench GOOSE frames. |\n| `confrev <number>` | Configuration Revision counter | `1` | Encodes BER context tag `[8]` (`confRev` SCL configuration revision). |\n| `ndscom` | Needs Commissioning boolean flag | `false` | Sets BER context tag `[9]` (`ndsCom = true`). |\n| `numdatsetentries <number>` | Number of dataset members | `1` | Encodes BER context tag `[10]` (`numDatSetEntries`) and matching `allData` `[11]` entries. |\n\n## Cross-Layer Options Valid with `goose`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Use timetolive for GOOSE Hold Time (ttl Is Reserved for Layer 3 IP)\n\n- **Avoid:** `ied1 -> bus goose ttl 2000 st_num 1`\n- **Valid v3.3.0 Syntax:** `ied1 -> bus goose timetolive 2000 stnum 1`\n\nGOOSE runs directly over Layer 2 (`0x88b8`); use `timetolive` for the IEC 61850\n`timeAllowedtoLive` field and lowercase `stnum`/`sqnum`/`gocbref` without\nunderscores.\n\n### Quote IEC 61850 Strings Containing $ Object Separators\n\n- **Avoid:** `ied1 -> bus goose gocbref IED1/LLN0$GO$gcb01`\n- **Valid v3.3.0 Syntax:** `ied1 -> bus goose gocbref \"IED1/LLN0$GO$gcb01\"`\n\nIEC 61850 object references contain `/` and `$` characters and must always be\nenclosed in double quotes.\n"}
{"id":"pretrain-proto-sv","kind":"protocol_spec","title":"IEC 61850-9-2 Substation Sampled Values (Process Bus) (sv) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/sv","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["sv"],"text":"# sv — IEC 61850-9-2 Process-Bus Merging Unit Waveforms (0x88ba) (`sv`)\n\n> **FrameAssembly v3.3.0** · Protocol 17 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/sv\n\n- **Full Protocol Name:** IEC 61850-9-2 Substation Sampled Values (Process Bus)\n- **Keyword:** `sv`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x88ba\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEC 61850-9-2, IEC 61869-9 (9-2LE)\n- **Wireshark Display Filter:** `sv`\n- **Wire Encapsulation:** `Ethernet II -> IEC 61850 SV (EtherType 0x88ba)`\n\n## Overview\n\nPair `sv` (`0x88ba` Merging Unit voltage/current ASDU waveforms) with `wait 208us`\n(4,800 Hz) and `.pcapng` nanosecond output to test digital-substation process-bus\nsensors offline.\n\nSampled Values (`sv`, IEC 61850-9-2 / 9-2LE) streams digitized three-phase current\nand voltage waveforms from substation Merging Units (`MU`) to protective relays\nover the IEC 61850 Process Bus (`EtherType 0x88ba`, multicast\n`01:0c:cd:04:00:00..ff`) at 4,000 or 4,800 frames per second (`250us` / `208us`\nintervals). Each frame carries an 8-byte header (`APPID 0x4000..0x7fff`, `Length`,\n`Reserved1`, `Reserved2`) wrapping an ASN.1 BER `savPdu` (`0x60`) containing one\nor more `ASDU` (`0x30`) blocks with `svID`, `smpCnt`, `confRev`, `smpSynch`, and\n64-byte 9-2LE current/voltage sample arrays.\n\nCombined with FrameAssembly v3.3.0's `repeat` block, sub-millisecond `wait 250us`\ntiming, and nanosecond `.pcapng` output, `sv` generates precision process-bus\nwaveforms without physical Merging Units.\n\n## Minimal Quickstart (`sv_quickstart.frasm`)\n\n```frameassembly\nhost merging_unit { mac 00:1b:21:92:00:01 }\nhost process_bus  { mac 01:0c:cd:04:00:01 }\n\ncompile {\n    merging_unit -> process_bus sv appid 0x4001 svid \"BAY01_MU01\" smpcnt 0 confrev 1 smpsynch 2 vlan 300 pcp 4\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x88ba` (IEC 61850 Sampled Values), defaults\n  `APPID` to `0x4000`, and sets bit `0x8000` in `Reserved1` when `simulation` is\n  present.\n- Encodes the ASN.1 BER `savPdu` (`0x60`) -> `noASDU = 1` -> `seqASDU` (`0xa2`) ->\n  `ASDU` (`0x30`) with exact BER length tags and a 64-byte 4xI + 4xV 9-2LE sample\n  dataset.\n- Targets IEC 61850-9-2 multicast destination MAC `01:0c:cd:04:00:01`\n  automatically when `dstmac` is omitted on default hosts.\n\n## Practical Lab Example: 250-Microsecond Merging Unit Stream With PTP Sync Loss Transition (`sv_merging_unit_stream.frasm`)\n\nEmits 4 consecutive 50Hz 9-2LE Sampled Values frames (`wait 250us`) where the\nMerging Unit transitions from global PTP lock (`smpsynch 2`) to holdover\n(`smpsynch 0`) on sample 3.\n\n```frameassembly\nhost mu_bay01  { mac 00:1b:21:92:10:01 }\nhost sv_mcast  { mac 01:0c:cd:04:00:01 }\n\ncompile {\n    // 80 samples/cycle @ 50Hz = 250us inter-frame gap (compile to .pcapng for 1ns fidelity)\n    mu_bay01 -> sv_mcast sv appid 0x4001 svid \"SUB1_BAY01_MU\" smpcnt 0 confrev 1 smpsynch 2 smprate 80 vlan 300 pcp 4 wait 250us\n    mu_bay01 -> sv_mcast sv appid 0x4001 svid \"SUB1_BAY01_MU\" smpcnt 1 confrev 1 smpsynch 2 smprate 80 vlan 300 pcp 4 wait 250us\n    mu_bay01 -> sv_mcast sv appid 0x4001 svid \"SUB1_BAY01_MU\" smpcnt 2 confrev 1 smpsynch 2 smprate 80 vlan 300 pcp 4 wait 250us\n    // Merging Unit loses PTP grandmaster lock (smpsynch drops from 2 -> 0)\n    mu_bay01 -> sv_mcast sv appid 0x4001 svid \"SUB1_BAY01_MU\" smpcnt 3 confrev 1 smpsynch 0 smprate 80 vlan 300 pcp 4\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show sv_merging_unit_stream.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly sv_merging_unit_stream.frasm sv_merging_unit_stream.pcap\nframeassembly sv_merging_unit_stream.frasm sv_merging_unit_stream.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse sv_merging_unit_stream.pcap sv_merging_unit_stream_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r sv_merging_unit_stream.pcap -Y \"sv\"\n```\n\n## All `sv` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host sv [appid <0..65535>] [svid \"<text>\"]\n[datset \"<text>\"] [smpcnt <0..65535>] [confrev <number>] [smpsynch <0|1|2>]\n[smprate <0..65535>] [simulation]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `appid <0..65535>` | 16-bit IEC 61850 SV APPID (0x4000..0x7fff) | `0x4000` | Sets bytes 0..1 of the 8-byte Sampled Values header. |\n| `svid \"<text>\"` | Sampled Values Identifier string (10..34 chars typical) | `\"MU01\"` | Encodes ASDU context tag `[0]` (`svID`). |\n| `datset \"<text>\"` | Optional dataset reference string | `Omitted unless set (per 9-2LE)` | Encodes optional ASDU context tag `[1]` (`datSet`). |\n| `smpcnt <0..65535>` | 16-bit Sample Counter (0..3999 or 0..4799) | `0` | Encodes ASDU context tag `[2]` (`smpCnt`, resets to `0` on each 1-PPS second boundary). |\n| `confrev <number>` | 32-bit Configuration Revision | `1` | Encodes ASDU context tag `[3]` (`confRev`). |\n| `smpsynch <0\\|1\\|2>` | Clock sync state (0=None, 1=Local, 2=Global PTP) | `2 (Global synchronized)` | Encodes ASDU context tag `[5]` (`smpSynch` synchronization status byte). |\n| `smprate <0..65535>` | Samples per nominal period (e.g. 80 or 256) | `Omitted unless set` | Encodes optional ASDU context tag `[6]` (`smpRate`). |\n| `simulation` | Boolean test-mode flag | `Unset` | Sets bit 15 (`0x8000`) of `Reserved1` in the 8-byte IEC 61850 SV header. |\n\n## Cross-Layer Options Valid with `sv`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n\n## Common Mistakes & Quick Fixes\n\n### Standard SV APPID Range Is 0x4000..0x7fff (GOOSE Uses 0x0000..0x3fff)\n\n- **Avoid:** `mu1 -> bus sv app_id 0x1000 smp_cnt 1`\n- **Valid v3.3.0 Syntax:** `mu1 -> bus sv appid 0x4001 smpcnt 1`\n\nUse strict lowercase `appid`, `svid`, `smpcnt`, `smpsynch`, `smprate`, and\n`confrev` without underscores, and keep `appid` in `0x4000..0x7fff` so substation\nswitches classify SV traffic properly.\n\n### smpsynch Accepts 0, 1, or 2\n\n- **Avoid:** `mu1 -> bus sv smpsynch 5`\n- **Valid v3.3.0 Syntax:** `mu1 -> bus sv smpsynch 2`\n\nIEC 61850-9-2 defines `0` (not synchronized), `1` (synchronized by local area\nclock), and `2` (synchronized by global area clock).\n"}
{"id":"pretrain-proto-ethercat","kind":"protocol_spec","title":"IEC 61158 EtherCAT Industrial Ethernet Fieldbus (0x88a4 / UDP 34980) (ethercat) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ethercat","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ethercat"],"text":"# ethercat — On-the-Fly Industrial Fieldbus Datagrams (0x88a4) (`ethercat`)\n\n> **FrameAssembly v3.3.0** · Protocol 18 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ethercat\n\n- **Full Protocol Name:** IEC 61158 EtherCAT Industrial Ethernet Fieldbus (0x88a4\n  / UDP 34980)\n- **Keyword:** `ethercat`\n- **OSI Layer & Transport:** Layer 2 · EtherType 0x88a4 (or UDP 34980)\n- **Host Endpoint Rule:** MAC-Only or IP\n- **Standards:** IEC 61158 Type 12, ETG.1000.4\n- **Wireshark Display Filter:** `ecat`\n- **Wire Encapsulation:** `Ethernet II -> EtherCAT (EtherType 0x88a4 (or UDP\n  34980))`\n\n## Overview\n\nServo drives process `0x88a4` EtherCAT frames on the fly as the bits pass through\nthe ASIC, incrementing the Working Counter (`wkc`) on each slave — `ethercat`\npacks the little-endian header and `transport udp` (`34980`) mode cleanly.\n\nEtherCAT (`ethercat`, IEC 61158 Type 12 / ETG.1000.4) powers ultra-low-latency\nservo motion control, CNC machining, semiconductor wafer tools, and PLC I/O rings\nby processing Ethernet frames **on the fly** (`EtherType 0x88a4`). Every EtherCAT\nframe starts with a 2-byte little-endian EtherCAT Frame Header (`11-bit Length`,\n`Type = 1` DLPDU) followed by datagrams containing an 8-bit Command (`APRD`,\n`APWR`, `FPRD`, `FPWR`, `BRD`, `BWR`, `LRD`, `LWR`, `NOP`), 8-bit Index (`idx`),\n32-bit Position/Node/Logical Address (`adp`+`ado` or `addr`), Length/Round-Trip\nflags, 16-bit Interrupt (`irq`), data bytes, and a 16-bit **Working Counter\n(`wkc`)** incremented by each slave ASIC.\n\nFrameAssembly encodes native little-endian `0x88a4` frames over MAC-only or IP\nhosts—and switches to **EtherCAT over UDP (`dstport 34980`)** when `transport udp`\nis added.\n\n## Minimal Quickstart (`ethercat_quickstart.frasm`)\n\n```frameassembly\nhost twincat_master { mac 00:01:05:10:00:01 }\nhost servo_drive_01 { mac 00:01:05:10:00:02 }\n\ncompile {\n    twincat_master -> servo_drive_01 ethercat read idx 1 adp 0x0000 ado 0x0130 wkc 0 wait 125us\n    twincat_master <- servo_drive_01 ethercat read idx 1 adp 0x0001 ado 0x0130 wkc 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets Ethernet II EtherType to `0x88a4` (or IPv4/IPv6 + UDP `dstport 34980` when\n  `transport udp` is specified).\n- Packs the little-endian 16-bit EtherCAT Frame Header (`Length | (1 << 12)`) and\n  10-byte Datagram Header + trailing 16-bit little-endian `wkc`.\n- Writes little-endian 16-bit `adp` (`addr` alias, `0..=65535`) and 16-bit `ado`\n  (`offset` alias, `0..=65535`) into the 32-bit datagram address slot.\n\n## Practical Lab Example: 125us Isochronous Motion-Control Cycle: Broadcast AL Status + Logical Read/Write (`ethercat_servo_ring_cycle.frasm`)\n\nSimulates an EtherCAT master polling 4 servo drives for `SAFEOP`/`OP` status (`ado\n0x0130`), exchanging logical process-data (`LRW` at `addr 0x1000`), and sending an\nengineering mailbox check over `transport udp`.\n\n```frameassembly\nhost plc_master { ip 10.120.1.10 mac 00:01:05:aa:00:01 }\nhost drive_ring { ip 10.120.1.20 mac ff:ff:ff:ff:ff:ff }\n\ncompile {\n    // 1. Broadcast Read (BRD) of AL Status register 0x0130 outbound (wkc=0) and returning (wkc=4 drives)\n    plc_master -> drive_ring ethercat cmd \"BRD\" idx 10 adp 0x0000 ado 0x0130 wkc 0 wait 60us\n    plc_master <- drive_ring ethercat cmd \"BRD\" idx 10 adp 0x0004 ado 0x0130 wkc 4 wait 65us\n    // 2. Logical Read/Write (LRW) process data exchange at logical base address 0x1000\n    plc_master -> drive_ring ethercat cmd \"LRW\" idx 11 addr 0x1000 hexpayload \"0f00e80300000000\" wkc 0 wait 60us\n    plc_master <- drive_ring ethercat cmd \"LRW\" idx 11 addr 0x1000 hexpayload \"3702e80300000000\" wkc 12 wait 200us\n    // 3. Routed EtherCAT-over-UDP (port 34980) diagnostic read\n    plc_master -> drive_ring ethercat cmd \"FPRD\" idx 12 adp 0x03e9 offset 0x0000 wkc 0 transport udp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ethercat_servo_ring_cycle.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ethercat_servo_ring_cycle.frasm ethercat_servo_ring_cycle.pcap\nframeassembly ethercat_servo_ring_cycle.frasm ethercat_servo_ring_cycle.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ethercat_servo_ring_cycle.pcap ethercat_servo_ring_cycle_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ethercat_servo_ring_cycle.pcap -Y \"ecat\"\n```\n\n## All `ethercat` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ethercat [nop | read | write | cmd\n\"<text>\"] [idx <0..255>] [adp|addr <0..65535>] [ado|offset <0..65535>] [irq\n<0..65535>] [wkc <0..65535>] [transport udp]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `nop \\| read \\| write \\| cmd \"<text>\"` | Command keyword or ETG mnemonic (\"APRD\",\"APWR\",\"FPRD\",\"FPWR\",\"BRD\",\"BWR\",\"LRD\",\"LWR\",\"LRW\") | `read (APRD 0x01)` | Sets the 8-bit EtherCAT Datagram Command byte (`0x00` NOP, `0x01` APRD, `0x02` APWR, `0x04` FPRD, `0x05` FPWR, `0x07` BRD, `0x0a` LRD, `0x0b` LWR, `0x0c` LRW). |\n| `idx <0..255>` | 8-bit Datagram Index | `0` | Sets the 1-byte master correlation `Index` in byte 1 of the datagram header. |\n| `adp <0..65535> \\| addr <0..65535>` | 16-bit Slave Position / Configured / Logical Base Address | `0` | Sets the little-endian 16-bit `ADP` / low address word (`addr` is validated `0..=65535` at compile time). |\n| `ado <0..65535> \\| offset <0..65535>` | 16-bit ESC Register / High Word Offset (e.g. 0x0130) | `0` | Sets the little-endian 16-bit `ADO` physical memory/register offset (`offset` is an exact alias). |\n| `irq <0..65535>` | 16-bit EtherCAT Event Request mask | `0` | Sets the little-endian 16-bit `IRQ` field ahead of the datagram payload. |\n| `wkc <0..65535>` | 16-bit Working Counter | `0` | Writes the trailing 16-bit little-endian Working Counter incremented by slaves on the wire. |\n| `transport udp` | Optional UDP 34980 encapsulation (IP hosts required) | `Raw Ethernet 0x88a4` | Encapsulates the EtherCAT DLPDU inside IPv4/IPv6 + UDP `dstport 34980`. |\n\n## Cross-Layer Options Valid with `ethercat`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), EtherType 0x88a4 (or UDP 34980)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport udp` | Optional UDP encapsulation override | `Ethernet 0x88a4 (UDP 34980 when transport udp is set)` | Wraps the protocol frame inside an IPv4/IPv6 + UDP header instead of raw Ethernet or raw IP encapsulation. |\n\n## Common Mistakes & Quick Fixes\n\n### Declare IP Addresses on Hosts When Using ethercat transport udp\n\n- **Avoid:** `host m { mac 00:01:05:00:00:01 }\nm -> s ethercat read transport udp`\n- **Valid v3.3.0 Syntax:** `host m { ip 10.120.1.10 mac 00:01:05:00:00:01 }\nm -> s ethercat read transport udp`\n\nPure Layer 2 `ethercat` (`0x88a4`) compiles on MAC-only hosts, whereas `transport\nudp` builds an outer IP + UDP `34980` header and requires `ip` on both hosts.\n\n### Keep adp/addr and ado/offset Within 16-Bit Bounds (0..65535)\n\n- **Avoid:** `m -> s ethercat cmd \"LRW\" addr 0x10000 wkc 0`\n- **Valid v3.3.0 Syntax:** `m -> s ethercat cmd \"LRW\" addr 0x1000 offset 0x0001\n  wkc 0`\n\nSemantic validation enforces 16-bit bounds (`0..=65535`) on `adp`/`addr` and\n`ado`/`offset`; split upper 16-bit words into `ado` / `offset`.\n"}
{"id":"pretrain-proto-icmp","kind":"protocol_spec","title":"Internet Control Message Protocol v4 & Dual-Stack ICMPv6 (icmp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/icmp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["icmp"],"text":"# icmp — Dual-Stack ICMPv4 & ICMPv6 Echo and Error Frames (`icmp`)\n\n> **FrameAssembly v3.3.0** · Protocol 19 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/icmp\n\n- **Full Protocol Name:** Internet Control Message Protocol v4 & Dual-Stack ICMPv6\n- **Keyword:** `icmp`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 1 (v4) / NextHdr 58 (v6)\n- **Host Endpoint Rule:** Dual-Stack Morphing (v4/v6)\n- **Standards:** RFC 792, RFC 4443\n- **Wireshark Display Filter:** `icmp || icmpv6`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  ICMP / ICMPv6 (IP Proto 1 (v4) / NextHdr 58 (v6))`\n\n## Overview\n\nThe humble ping (`a -> b icmp echorequest` and `a <- b icmp echoreply`)\nautomatically emits ICMPv4 over IPv4 hosts or ICMPv6 with full pseudo-header\nchecksums over IPv6 hosts.\n\nInternet Control Message Protocol (`icmp`) handles network reachability\ndiagnostics, Path MTU Discovery signaling, and hop-limit expiration feedback. In\nFrameAssembly v3.2.0, `icmp` is **dual-stack morphing**: when invoked between IPv4\nhosts, it emits IPv4 Protocol `1` with an RFC 1071 header checksum; when invoked\nbetween IPv6 hosts, the exact same syntax automatically morphs into **ICMPv6**\n(Next Header `58`) with a full RFC 4443 IPv6 pseudo-header checksum.\n\nNamed shorthands (`echorequest`, `echoreply`, `destunreach`, `timeexceeded`,\n`redirect`) map transparently to their respective v4 (`8`, `0`, `3`, `11`, `5`)\nand v6 (`128`, `129`, `1`, `3`, `137`) wire Type codes.\n\n## Minimal Quickstart (`icmp_quickstart.frasm`)\n\n```frameassembly\nhost client { ip 10.0.0.10 }\nhost router { ip 10.0.0.1 }\n\ncompile {\n    client -> router icmp echorequest wait 2ms\n    client <- router icmp echoreply\n}\n```\n\n### Automatic Wire Calculations\n\n- Automatically selects IPv4 Protocol `1` (`0x0800`) over IPv4 endpoints or ICMPv6\n  Next Header `58` (`0x86dd`) over IPv6 endpoints.\n- Translates `echorequest` (`8` v4 / `128` v6), `echoreply` (`0` v4 / `129` v6),\n  `destunreach` (`3` v4 / `1` v6), `timeexceeded` (`11` v4 / `3` v6), and\n  `redirect` (`5` v4 / `137` v6).\n- Computes the RFC 1071 ones-complement checksum on IPv4 and the mandatory RFC\n  4443 40-byte IPv6 pseudo-header checksum on IPv6.\n\n## Practical Lab Example: Dual-Stack Echo Flow Plus IPv4 Fragmentation-Needed & Traceroute TTL Expiry (`icmp_dualstack_pmtud.frasm`)\n\nReuses a `ping_test(src, dst)` flow across IPv4 and IPv6 hosts, then sends a\nrouter Time Exceeded (`ttl 1`) and Fragmentation Needed (`destunreach code 4`)\nreply.\n\n```frameassembly\nhost app_v4  { ip 10.10.0.25 }\nhost edge_v4 { ip 10.10.0.1 }\nhost app_v6  { ip 2001:db8:10::25 }\nhost edge_v6 { ip 2001:db8:10::1 }\n\nflow ping_test(src, dst) {\n    src -> dst icmp echorequest id 0x2026 seq 1 payload \"healthcheck-probe\" wait 1ms\n    src <- dst icmp echoreply id 0x2026 seq 1 payload \"healthcheck-probe\" wait 2ms\n}\n\ncompile {\n    ping_test(app_v4, edge_v4)\n    ping_test(app_v6, edge_v6)\n    // Traceroute hop 1 expiry + PMTUD Fragmentation Needed (Type 3, Code 4)\n    app_v4 -> edge_v4 icmp echorequest id 0x2026 seq 2 ttl 1 df wait 1ms\n    app_v4 <- edge_v4 icmp timeexceeded code 0 wait 2ms\n    app_v4 <- edge_v4 icmp destunreach code 4\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show icmp_dualstack_pmtud.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly icmp_dualstack_pmtud.frasm icmp_dualstack_pmtud.pcap\nframeassembly icmp_dualstack_pmtud.frasm icmp_dualstack_pmtud.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse icmp_dualstack_pmtud.pcap icmp_dualstack_pmtud_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r icmp_dualstack_pmtud.pcap -Y \"icmp || icmpv6\"\n```\n\n## All `icmp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host icmp [echorequest | echoreply |\ndestunreach | timeexceeded | redirect] [type <0..255>] [code <0..255>] [id\n<0..65535>] [seq <0..65535>] [gateway <ipv4>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `echorequest \\| echoreply \\| destunreach \\| timeexceeded \\| redirect` | Named ICMP message shorthand | `echorequest` | Maps to IPv4/ICMPv6 Type codes: `8`/`128` (`echorequest`), `0`/`129` (`echoreply`), `3`/`1` (`destunreach`), `11`/`3` (`timeexceeded`), `5`/`137` (`redirect`). |\n| `type <0..255> \\| code <0..255>` | 8-bit unsigned integers | `Derived from shorthand (code 0)` | Explicitly overrides the 1-byte ICMP/ICMPv6 Type and Code fields (e.g., `type 2 code 0` for ICMPv6 Packet Too Big). |\n| `id <0..65535> \\| seq <0..65535>` | 16-bit unsigned integers | `id 1, seq 1` | Sets the 16-bit Echo Identifier and Echo Sequence Number in the 4-byte rest-of-header. |\n| `gateway <ipv4>` | IPv4 address literal | `0.0.0.0 (or source router IPv4)` | Sets the 4-byte Redirect Gateway Internet Address on IPv4 `icmp redirect` messages. |\n\n## Cross-Layer Options Valid with `icmp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n\n## Common Mistakes & Quick Fixes\n\n### Zero Underscores in ICMP Message Keywords\n\n- **Avoid:** `a -> b icmp echo_request`\n- **Valid v3.3.0 Syntax:** `a -> b icmp echorequest`\n\nWrite `echorequest`, `echoreply`, `destunreach`, and `timeexceeded` with zero\nunderscores.\n\n### Both Endpoints Must Share the Same IP Address Family\n\n- **Avoid:** `app_v4 -> edge_v6 icmp echorequest`\n- **Valid v3.3.0 Syntax:** `app_v6 -> edge_v6 icmp echorequest`\n\nBoth hosts on a single packet line must use IPv4 or both must use IPv6—you cannot\nsend a packet directly from an IPv4 host to an IPv6 host.\n"}
{"id":"pretrain-proto-ndp","kind":"protocol_spec","title":"IPv6 Neighbor Discovery Protocol (ndp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ndp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ndp"],"text":"# ndp — RFC 4861 IPv6 Neighbor Discovery & Router Advertisements (`ndp`)\n\n> **FrameAssembly v3.3.0** · Protocol 20 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ndp\n\n- **Full Protocol Name:** IPv6 Neighbor Discovery Protocol\n- **Keyword:** `ndp`\n- **OSI Layer & Transport:** Layer 3 · ICMPv6 NextHdr 58 (Hop Limit 255)\n- **Host Endpoint Rule:** IPv6-Only\n- **Standards:** RFC 4861\n- **Wireshark Display Filter:** `icmpv6.type >= 133 && icmpv6.type <= 137`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv6 -> IPv6\n  NDP (ICMPv6 NextHdr 58 (Hop Limit 255))`\n\n## Overview\n\nIPv6 threw ARP in the bin and replaced it with ICMPv6 Neighbor Discovery at Hop\nLimit `255`. `ndp` builds `neighborsolicit`, `neighboradvert`, and rogue\n`routeradvert` frames to test switch RA Guard.\n\nIPv6 Neighbor Discovery Protocol (`ndp`) replaces IPv4 ARP, ICMP Router Discovery,\nand ICMP Redirect with five ICMPv6 message types (`133..137`) carried over IPv6\nNext Header `58`. Per RFC 4861, routers and hosts validate that incoming NDP\npackets arrive with **IPv6 Hop Limit `255`** so off-link spoofing attempts are\ndropped immediately.\n\nFrameAssembly defaults `ndp` Hop Limit (`ttl`) to `255`, encodes Source and Target\nLink-Layer Address options (`slla` Type 1, `tlla` Type 2) padded to 8-octet\nboundaries, and computes the full IPv6 pseudo-header checksum automatically.\n\n## Minimal Quickstart (`ndp_quickstart.frasm`)\n\n```frameassembly\nhost host_v6   { ip 2001:db8:cafe::25 mac 00:1b:21:aa:00:25 }\nhost router_v6 { ip 2001:db8:cafe::1  mac 00:1c:73:bb:00:01 }\n\ncompile {\n    host_v6 -> router_v6 ndp neighborsolicit target 2001:db8:cafe::1 slla 00:1b:21:aa:00:25 wait 1ms\n    host_v6 <- router_v6 ndp neighboradvert target 2001:db8:cafe::1 tlla 00:1c:73:bb:00:01\n}\n```\n\n### Automatic Wire Calculations\n\n- Enforces IPv6 Hop Limit `255` (`ttl 255`) by default in accordance with RFC 4861\n  §6.1.2 / §7.1.1.\n- Encodes exact ICMPv6 message bodies for `routersolicit` (`133`), `routeradvert`\n  (`134`, `routerlifetime 1800`), `neighborsolicit` (`135`), `neighboradvert`\n  (`136`, Solicited + Override flags set), and `redirect` (`137`).\n- Appends 8-byte RFC 4861 Option TLV 1 (`slla`) or TLV 2 (`tlla`) when link-layer\n  MACs are provided and computes the IPv6 pseudo-header checksum.\n\n## Practical Lab Example: IPv6 SLAAC Router Discovery Followed by Neighbor Solicitation & Advertisement (`ndp_slaac_discovery.frasm`)\n\nModels a dual-interface IPv6 leaf node soliciting an upstream router\n(`routersolicit` -> `routeradvert`) before resolving next-hop MAC reachability\n(`neighborsolicit` -> `neighboradvert`).\n\n```frameassembly\nhost leaf_node { ip fe80::1b21:ff:feaa:10 mac 00:1b:21:aa:00:10 }\nhost core_rtr  { ip fe80::1c73:ff:febb:01 mac 00:1c:73:bb:00:01 }\n\ncompile {\n    // 1. Host sends Router Solicitation with Source Link-Layer Address (SLLA)\n    leaf_node -> core_rtr ndp routersolicit slla 00:1b:21:aa:00:10 vlan 100 wait 2ms\n    // 2. Router replies with Router Advertisement (30-minute router lifetime)\n    core_rtr -> leaf_node ndp routeradvert routerlifetime 1800 slla 00:1c:73:bb:00:01 vlan 100 wait 5ms\n    // 3. Neighbor Solicitation & Solicited+Override Neighbor Advertisement\n    leaf_node -> core_rtr ndp neighborsolicit target fe80::1c73:ff:febb:01 slla 00:1b:21:aa:00:10 vlan 100 wait 1ms\n    leaf_node <- core_rtr ndp neighboradvert target fe80::1c73:ff:febb:01 tlla 00:1c:73:bb:00:01 vlan 100\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ndp_slaac_discovery.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ndp_slaac_discovery.frasm ndp_slaac_discovery.pcap\nframeassembly ndp_slaac_discovery.frasm ndp_slaac_discovery.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ndp_slaac_discovery.pcap ndp_slaac_discovery_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ndp_slaac_discovery.pcap -Y \"icmpv6.type >= 133 && icmpv6.type <= 137\"\n```\n\n## All `ndp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ndp [routersolicit | routeradvert |\nneighborsolicit | neighboradvert | redirect] [target <ipv6>] [slla <mac>] [tlla\n<mac>] [routerlifetime <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `routersolicit \\| routeradvert \\| neighborsolicit \\| neighboradvert \\| redirect` | NDP message selector | `neighborsolicit (Type 135)` | Selects ICMPv6 Type `133` (`routersolicit`), `134` (`routeradvert`), `135` (`neighborsolicit`), `136` (`neighboradvert`), or `137` (`redirect`). |\n| `target <ipv6>` | 128-bit IPv6 address literal | `Destination host IPv6 address` | Populates the 16-byte Target Address field in Neighbor Solicitation, Neighbor Advertisement, and Redirect messages. |\n| `slla <mac> \\| tlla <mac>` | 48-bit MAC address | `Omitted unless set` | Appends 8-byte NDP Option Type `1` (Source Link-Layer Address, `slla`) or Option Type `2` (Target Link-Layer Address, `tlla`). |\n| `routerlifetime <0..65535>` | Whole number (0..65535) (seconds) | `1800` | Sets the 16-bit Router Lifetime in `routeradvert` (`0` indicates the router is not a default gateway). |\n\n## Cross-Layer Options Valid with `ndp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 255, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n\n## Common Mistakes & Quick Fixes\n\n### IPv6 Endpoints Are Mandatory on ndp\n\n- **Avoid:** `host v4_a { ip 10.0.0.1 }\nv4_a -> v4_b ndp neighborsolicit`\n- **Valid v3.3.0 Syntax:** `host v6_a { ip 2001:db8::1 }\nv6_a -> v6_b ndp neighborsolicit`\n\nNDP runs over ICMPv6, so both hosts on an `ndp` line must have IPv6 addresses. Use\n`arp` for IPv4 MAC resolution.\n\n### Strict Alphanumeric Message Names\n\n- **Avoid:** `v6_a -> v6_b ndp neighbor_solicit router_lifetime 900`\n- **Valid v3.3.0 Syntax:** `v6_a -> v6_b ndp routeradvert routerlifetime 900`\n\nSpell NDP sub-keywords without underscores: `routersolicit`, `routeradvert`,\n`neighborsolicit`, `neighboradvert`, `routerlifetime`.\n"}
{"id":"pretrain-proto-igmp","kind":"protocol_spec","title":"Internet Group Management Protocol v1, v2 & v3 (igmp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/igmp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["igmp"],"text":"# igmp — IPv4 IGMPv1/v2/v3 Multicast Queries, Joins & Leaves (`igmp`)\n\n> **FrameAssembly v3.3.0** · Protocol 21 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/igmp\n\n- **Full Protocol Name:** Internet Group Management Protocol v1, v2 & v3\n- **Keyword:** `igmp`\n- **OSI Layer & Transport:** Layer 3 · IPv4 Proto 2 (TTL 1)\n- **Host Endpoint Rule:** IPv4-Only\n- **Standards:** RFC 1112, RFC 2236, RFC 3376\n- **Wireshark Display Filter:** `igmp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 ->\n  IGMPv1/v2/v3 (IPv4 Proto 2 (TTL 1))`\n\n## Overview\n\nMulticast is great right up until IGMP snooping misbehaves and floods video onto\nevery desk phone in the building. `igmp` builds `query`, `report`, and `leave`\nframes at `ttl 1` with RFC 1112 multicast MACs.\n\nInternet Group Management Protocol (`igmp`) manages IPv4 multicast group\nmemberships between receivers and local multicast routers (and Layer 2 IGMP\nSnooping switches) over **IPv4 Protocol `2`** with `ttl 1`.\n\nFrameAssembly supports all three protocol generations—`v1` (RFC 1112), `v2` (RFC\n2236, default, adding fast `leave`), and `v3` (RFC 3376 source-specific Group\nRecord Membership Reports `0x22` and 12-byte Queries)—computing the RFC\nones-complement IGMP checksum automatically.\n\n## Minimal Quickstart (`igmp_quickstart.frasm`)\n\n```frameassembly\nhost querier  { ip 10.20.1.1 }\nhost receiver { ip 10.20.1.55 }\n\ncompile {\n    querier -> receiver igmp v2 query group 224.0.0.1 maxresp 100 wait 5ms\n    receiver -> querier igmp v2 report group 239.1.1.10\n}\n```\n\n### Automatic Wire Calculations\n\n- Encapsulates inside IPv4 Protocol `2` with link-local `ttl 1` by default.\n- Maps version + operation cleanly onto wire Type codes: `0x11` (`query`, 8B in\n  v1/v2 or 12B in v3), `0x12` (`v1 report`), `0x16` (`v2 report`), `0x17` (`v2\n  leave`), and `0x22` (`v3 report` with `MODE_IS_EXCLUDE` Group Record).\n- Derives RFC 1112 multicast destination MACs (`01:00:5e:xx:xx:xx`) automatically\n  when the destination host IP is in `224.0.0.0/4`.\n\n## Practical Lab Example: VLAN-Tagged IGMPv2 Query,IGMPv3 Receiver Join, and IGMPv2 Fast Leave (`igmp_snooping_vlan.frasm`)\n\nDemonstrates a multicast router polling VLAN 50, one receiver joining\n`239.255.10.1` via IGMPv3, and a second receiver joining and leaving via IGMPv2.\n\n```frameassembly\nhost mcast_rtr { ip 10.50.0.1 }\nhost all_hosts { ip 224.0.0.1 }\nhost decoder_1 { ip 10.50.0.21 }\nhost decoder_2 { ip 10.50.0.22 }\n\ncompile {\n    // 1. General Query to 224.0.0.1 (auto-derives MAC 01:00:5e:00:00:01)\n    mcast_rtr -> all_hosts igmp v2 query group 0.0.0.0 maxresp 100 vlan 50 wait 4ms\n    // 2. Receiver 1 sends IGMPv3 Membership Report for 239.255.10.1\n    decoder_1 -> mcast_rtr igmp v3 report group 239.255.10.1 vlan 50 wait 3ms\n    // 3. Receiver 2 joins and then leaves 239.255.10.2 via IGMPv2\n    decoder_2 -> mcast_rtr igmp v2 report group 239.255.10.2 vlan 50 wait 20ms\n    decoder_2 -> mcast_rtr igmp v2 leave group 239.255.10.2 vlan 50\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show igmp_snooping_vlan.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly igmp_snooping_vlan.frasm igmp_snooping_vlan.pcap\nframeassembly igmp_snooping_vlan.frasm igmp_snooping_vlan.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse igmp_snooping_vlan.pcap igmp_snooping_vlan_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r igmp_snooping_vlan.pcap -Y \"igmp\"\n```\n\n## All `igmp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host igmp [query | report | leave] [v1 | v2\n| v3 | version <1|2|3>] [group <ipv4>] [maxresp <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `query \\| report \\| leave` | IGMP message type | `query` | Selects Membership Query (`0x11`), Membership Report (`0x12` v1 / `0x16` v2 / `0x22` v3), or Leave Group (`0x17`). |\n| `v1 \\| v2 \\| v3 \\| version <1\\|2\\|3>` | Protocol version selector | `v2` | Selects RFC 1112 IGMPv1, RFC 2236 IGMPv2, or RFC 3376 IGMPv3 packet encoding. |\n| `group <ipv4>` | IPv4 multicast address | `224.0.0.1 (or 0.0.0.0 general query)` | Sets the 4-byte Group Address in v1/v2 headers or the Multicast Address inside the v3 Group Record. |\n| `maxresp <0..255>` | Whole number (0..255) (1/10th seconds) | `100 (10.0 seconds)` | Sets the Max Response Time byte in IGMPv2/v3 Queries (`0` in IGMPv1 and Reports). |\n\n## Cross-Layer Options Valid with `igmp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 1, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n\n## Common Mistakes & Quick Fixes\n\n### IPv4 Endpoints Are Required on igmp (Use mld for IPv6)\n\n- **Avoid:** `host6_a -> host6_b igmp v3 report`\n- **Valid v3.3.0 Syntax:** `host6_a -> host6_b mld report multicastaddr ff02::16`\n\nIGMP runs exclusively over IPv4, so IPv6 hosts are rejected on `igmp` lines. For\nIPv6 multicast group management, use `mld` (Multicast Listener Discovery).\n\n### maxresp Is Expressed in Tenths of a Second\n\n- **Valid v3.3.0 Syntax:** `rtr -> host1 igmp v2 query maxresp 100`\n\nPer RFC 2236, `maxresp 100` represents `10.0` seconds (`100 * 0.1s`), and `maxresp\n10` represents `1.0` second.\n"}
{"id":"pretrain-proto-mld","kind":"protocol_spec","title":"Multicast Listener Discovery v1 & v2 (IPv6) (mld) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/mld","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["mld"],"text":"# mld — IPv6 Multicast Listener Discovery (ICMPv6 130–132) (`mld`)\n\n> **FrameAssembly v3.3.0** · Protocol 22 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/mld\n\n- **Full Protocol Name:** Multicast Listener Discovery v1 & v2 (IPv6)\n- **Keyword:** `mld`\n- **OSI Layer & Transport:** Layer 3 · ICMPv6 NextHdr 58 (Hop Limit 1)\n- **Host Endpoint Rule:** IPv6-Only\n- **Standards:** RFC 2710, RFC 3810\n- **Wireshark Display Filter:** `icmpv6.type >= 130 && icmpv6.type <= 132`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv6 -> IPv6\n  MLD (ICMPv6 NextHdr 58 (Hop Limit 1))`\n\n## Overview\n\nWhat `igmp` does for IPv4, `mld` does for IPv6 (`ff02::/16 -> 33:33:xx:xx:xx:xx`\nEthernet MACs at Hop Limit `1`), making it easy to check whether your leaf\nswitches actually snoop IPv6 multicast.\n\nMulticast Listener Discovery (`mld`) is the IPv6 counterpart to IGMP, carried\ninside ICMPv6 (`Next Header 58`) with a link-local **Hop Limit of `1`**. IPv6\nnodes use MLD not only for streaming multicast applications, but also to join\nsolicited-node multicast groups (`ff02::1:ffxx:xxxx`) required by IPv6 Neighbor\nDiscovery.\n\nFrameAssembly constructs 24-byte MLD messages (`query` Type `130`, `report` Type\n`131`, and `done` Type `132`) with automatic RFC 2464 `33:33:xx:xx:xx:xx`\nmulticast Ethernet MAC derivation and IPv6 pseudo-header checksums.\n\n## Minimal Quickstart (`mld_quickstart.frasm`)\n\n```frameassembly\nhost rtr_v6  { ip fe80::1 }\nhost node_v6 { ip fe80::25 }\n\ncompile {\n    rtr_v6 -> node_v6 mld query maxrespdelay 10000 wait 3ms\n    node_v6 -> rtr_v6 mld report multicastaddr ff02::1:ff00:25\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets IPv6 Next Header to `58` (ICMPv6) and defaults Hop Limit (`ttl`) to `1` per\n  RFC 2710.\n- Encodes ICMPv6 Type `130` (`query`), `131` (`report`), or `132` (`done`), 16-bit\n  `Maximum Response Delay` (milliseconds), and 128-bit `Multicast Address`.\n- Derives RFC 2464 `33:33:xx:xx:xx:xx` destination MACs automatically when sending\n  to `ff00::/8` multicast hosts and computes the IPv6 pseudo-header checksum.\n\n## Practical Lab Example: Link-Local MLD General Query, Solicited-Node Join, and Listener Done (`mld_snooping_ipv6.frasm`)\n\nSimulates an IPv6 multicast router querying all link-local nodes (`ff02::1`), a\nsubscriber reporting membership in `ff05::100`, and cleanly departing with `mld\ndone`.\n\n```frameassembly\nhost querier_v6 { ip fe80::1c73:1 }\nhost all_nodes  { ip ff02::1 }\nhost all_rtrs   { ip ff02::2 }\nhost listener   { ip fe80::1b21:50 }\n\ncompile {\n    // 1. General MLD Query to ff02::1 (multicastaddr :: = all groups, 10000ms max delay)\n    querier_v6 -> all_nodes mld query multicastaddr :: maxrespdelay 10000 vlan 200 wait 4ms\n    // 2. Host joins site-local multicast stream ff05::100\n    listener -> querier_v6 mld report multicastaddr ff05::100 maxrespdelay 0 vlan 200 wait 25ms\n    // 3. Host sends MLD Done to all-routers multicast ff02::2 upon leaving\n    listener -> all_rtrs mld done multicastaddr ff05::100 vlan 200\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show mld_snooping_ipv6.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly mld_snooping_ipv6.frasm mld_snooping_ipv6.pcap\nframeassembly mld_snooping_ipv6.frasm mld_snooping_ipv6.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse mld_snooping_ipv6.pcap mld_snooping_ipv6_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r mld_snooping_ipv6.pcap -Y \"icmpv6.type >= 130 && icmpv6.type <= 132\"\n```\n\n## All `mld` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host mld [query | report | done]\n[multicastaddr <ipv6>] [maxrespdelay <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `query \\| report \\| done` | MLD message selector | `query (Type 130)` | Selects MLD Multicast Listener Query (`130`), Multicast Listener Report (`131`), or Multicast Listener Done (`132`). |\n| `multicastaddr <ipv6>` | 128-bit IPv6 multicast address (or ::) | `:: (General Query)` | Sets the 16-byte Multicast Address field (`::` in General Queries, specific `ffxx::` group in Group-Specific Queries, Reports, and Done messages). |\n| `maxrespdelay <0..65535>` | Whole number (0..65535) (milliseconds) | `10000 (10 seconds)` | Sets the Maximum Response Delay in milliseconds on MLD Queries (`0` on Reports and Done messages). |\n\n## Cross-Layer Options Valid with `mld`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 1, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n\n## Common Mistakes & Quick Fixes\n\n### IPv6 Endpoints Are Mandatory on mld\n\n- **Avoid:** `host4_a -> host4_b mld query`\n- **Valid v3.3.0 Syntax:** `host6_a -> host6_b mld query multicastaddr ::`\n\nMLD runs inside ICMPv6, so both hosts must have IPv6 addresses. Use `igmp` for\nIPv4 multicast group management.\n\n### Use multicastaddr (Not group) and maxrespdelay in Milliseconds\n\n- **Avoid:** `node_v6 -> rtr_v6 mld report group ff05::100 maxresp 100`\n- **Valid v3.3.0 Syntax:** `node_v6 -> rtr_v6 mld report multicastaddr ff05::100\n  maxrespdelay 1000`\n\nMLD uses `multicastaddr <ipv6>` and millisecond-granularity `maxrespdelay\n<0..65535>`, whereas IPv4 `igmp` uses `group <ipv4>` and `1/10`s `maxresp\n<0..255>`.\n"}
{"id":"pretrain-proto-gre","kind":"protocol_spec","title":"Generic Routing Encapsulation (GRE, GRETAP & NVGRE) (gre) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/gre","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["gre"],"text":"# gre — RFC 2784 / 2890 GRE Tunnel Wrappers & Key/Seq Flags (`gre`)\n\n> **FrameAssembly v3.3.0** · Protocol 23 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/gre\n\n- **Full Protocol Name:** Generic Routing Encapsulation (GRE, GRETAP & NVGRE)\n- **Keyword:** `gre`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 47\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 2784, RFC 2890, RFC 7637\n- **Wireshark Display Filter:** `gre`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  GRE / NVGRE (IP Proto 47)`\n\n## Overview\n\nBefore everything became UDP overlays, engineers duct-taped continents together\nwith IP Protocol `47`. `gre` toggles RFC 2890 Key, Sequence, and Checksum bits\nautomatically as you add fields.\n\nGeneric Routing Encapsulation (`gre`) tunnels arbitrary Layer 2 or Layer 3\npayloads inside outer IPv4 or IPv6 packets using **IP Protocol `47`**. The\nvariable-length GRE header begins with a 16-bit Flags/Version word (`C` Checksum\nbit 15, `K` Key bit 13, `S` Sequence bit 12) and a 16-bit encapsulated EtherType\n(`greproto`, such as `0x0800` IPv4, `0x86dd` IPv6, `0x6558` Transparent Ethernet\nBridging, or `0x88be` ERSPAN).\n\nFrameAssembly automatically sets the exact `C`, `K`, and `S` flag bits based on\nwhich modifiers (`checksum`, `grekey`, `greseq`) you include, sizing the header\nbetween 4 and 16 bytes and computing the RFC 2784 GRE checksum when requested.\n\n## Minimal Quickstart (`gre_quickstart.frasm`)\n\n```frameassembly\nhost branch_wan { ip 203.0.113.10 }\nhost hub_wan    { ip 198.51.100.1 }\n\ncompile {\n    branch_wan -> hub_wan gre grekey 1001 greseq 1 checksum payload \"gre-keepalive\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets outer IPv4 Protocol or IPv6 Next Header to `47` and defaults `greproto` to\n  `0x0800` (IPv4) with an inner probe header when `payload` is omitted.\n- Dynamically toggles GRE header flag bits (`0x8000` for `checksum`, `0x2000` for\n  `grekey`/`key`, `0x1000` for `greseq`) and inserts only the active 32-bit\n  extension words in RFC 2890 order (`Checksum+Reserved1`, `Key`, `Sequence`).\n- Computes the 16-bit ones-complement RFC 2784 GRE checksum across the GRE header\n  and payload whenever `checksum` is present.\n\n## Practical Lab Example: Keyed Dual-Stack GRE Tunnel Sequence & Transparent Ethernet Bridging (GRETAP) (`gre_overlay_lab.frasm`)\n\nDemonstrates an RFC 2890 keyed + checksummed GRE tunnel exchange over IPv4\nfollowed by an IPv6 outer GRETAP (`greproto 0x6558`) overlay frame.\n\n```frameassembly\nhost edge_a_v4 { ip 172.16.100.1 }\nhost edge_b_v4 { ip 172.16.100.2 }\nhost vtep_a_v6 { ip 2001:db8:47::1 }\nhost vtep_b_v6 { ip 2001:db8:47::2 }\n\ncompile {\n    // 1. Minimal 4-byte RFC 2784 GRE keepalive\n    edge_a_v4 -> edge_b_v4 gre payload \"keepalive-1\" wait 2ms\n    // 2. Full 16-byte GRE header (C=1, K=1, S=1) with tunnel key 5000\n    edge_a_v4 -> edge_b_v4 gre grekey 5000 greseq 10 checksum dscp 46 payload \"wan-voice-tunnel\" wait 2ms\n    edge_a_v4 <- edge_b_v4 gre grekey 5000 greseq 1 checksum dscp 46 payload \"wan-voice-reply\" wait 3ms\n    // 3. GRE over IPv6 carrying Transparent Ethernet Bridging (0x6558)\n    vtep_a_v6 -> vtep_b_v6 gre grekey 0x00102000 greproto 0x6558 hexpayload \"ffffffffffff001b21aa00010806\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show gre_overlay_lab.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly gre_overlay_lab.frasm gre_overlay_lab.pcap\nframeassembly gre_overlay_lab.frasm gre_overlay_lab.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse gre_overlay_lab.pcap gre_overlay_lab_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r gre_overlay_lab.pcap -Y \"gre\"\n```\n\n## All `gre` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host gre [grekey|key <number>] [greseq\n<number>] [greproto <0..65535>] [checksum]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `grekey <number> \\| key <number>` | Whole number | `Omitted (K=0)` | Sets Key Present bit (`0x2000`) and inserts the 4-byte RFC 2890 Tunnel Key (or 24-bit NVGRE VSID + 8-bit FlowID). |\n| `greseq <number>` | Whole number | `Omitted (S=0)` | Sets Sequence Number Present bit (`0x1000`) and inserts the 4-byte GRE Sequence Number. |\n| `greproto <0..65535>` | 16-bit EtherType (decimal or 0x hex) | `0x0800` | Sets the 2-byte GRE Protocol Type (`0x0800` IPv4, `0x86dd` IPv6, `0x6558` TEB/GRETAP, `0x88be` ERSPAN). |\n| `checksum` | Bare boolean flag | `Omitted (C=0)` | Sets Checksum Present bit (`0x8000`) and inserts the computed 2-byte GRE Checksum + 2-byte Reserved1 (`0x0000`). |\n\n## Cross-Layer Options Valid with `gre`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### Use greseq (Not seq) for the GRE Sequence Number\n\n- **Avoid:** `a -> b gre seq 10`\n- **Valid v3.3.0 Syntax:** `a -> b gre greseq 10`\n\nBare `seq` is the TCP sequence number modifier and is rejected on non-TCP\nprotocols like `gre`. Always write `greseq <number>` for RFC 2890 GRE sequence\nnumbers.\n\n### GRE Uses IP Protocol 47 (No L4 Ports)\n\n- **Avoid:** `a -> b gre dstport 4789`\n- **Valid v3.3.0 Syntax:** `a -> b vxlan vni 100 (or gre grekey 100)`\n\nStandard GRE runs directly atop IP Protocol `47` without UDP/TCP headers. For\nUDP-encapsulated overlays, use `vxlan` (`4789`) or `geneve` (`6081`).\n"}
{"id":"pretrain-proto-vxlan","kind":"protocol_spec","title":"Virtual eXtensible Local Area Network Overlay (vxlan) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/vxlan","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vxlan"],"text":"# vxlan — 24-Bit Data-Center VXLAN Overlays on UDP 4789 (`vxlan`)\n\n> **FrameAssembly v3.3.0** · Protocol 24 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/vxlan\n\n- **Full Protocol Name:** Virtual eXtensible Local Area Network Overlay\n- **Keyword:** `vxlan`\n- **OSI Layer & Transport:** Layer 3 · UDP 4789 (VNI 1)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 7348\n- **Wireshark Display Filter:** `vxlan`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  VXLAN (UDP 4789 (VNI 1))`\n\n## Overview\n\nWhen 4,094 VLANs stopped being enough, data centers wrapped Layer 2 inside UDP\n`4789` and got 16 million VNIs. `vxlan vni 10050` stamps the exact 8-byte `0x08`\nVXLAN shim.\n\nVirtual eXtensible Local Area Network (`vxlan`) stretches Layer 2 broadcast\ndomains across routed Layer 3 leaf-spine fabrics by encapsulating inner Ethernet\nframes inside UDP datagrams on **`dstport 4789`**. The 8-byte RFC 7348 VXLAN\nheader sets the `I` flag (`0x08`) and carries a 24-bit VXLAN Network Identifier\n(`vni` / `vnid`, supporting up to 16.7 million tenant segments `0..16777215`).\n\nFrameAssembly emits the outer Ethernet + IPv4/IPv6 + UDP (`4789`) + 8-byte VXLAN\nheader plus an encapsulated inner Ethernet/IPv4 frame automatically—making\nEVPN-VXLAN data-plane testing immediate.\n\n## Minimal Quickstart (`vxlan_quickstart.frasm`)\n\n```frameassembly\nhost vtep_leaf1 { ip 172.16.0.11 }\nhost vtep_leaf2 { ip 172.16.0.12 }\n\ncompile {\n    vtep_leaf1 -> vtep_leaf2 vxlan vni 10100\n}\n```\n\n### Automatic Wire Calculations\n\n- Wraps the packet in UDP `dstport 4789` with ephemeral outer `srcport` and\n  computes the outer IPv4/IPv6 + UDP checksums.\n- Writes the 8-byte RFC 7348 VXLAN header (`08 00 00 00 <24-bit VNI> 00`) with the\n  mandatory `I` bit (`0x08`) set.\n- Appends a valid inner Ethernet II + IPv4 frame when `payload`/`hexpayload` is\n  omitted, and validates `vni` bounds (`0..=16777215`).\n\n## Practical Lab Example: Multi-Tenant EVPN-VXLAN Underlay Carrying L2VNI 10100 & L3VNI 50000 (`vxlan_evpn_fabric.frasm`)\n\nSimulates leaf VTEPs exchanging multi-tenant VXLAN traffic across ECMP UDP source\nports, plus an IPv6 underlay VXLAN encapsulation.\n\n```frameassembly\nhost leaf1_vtep { ip 10.255.0.11 mac 00:1c:73:aa:00:11 }\nhost leaf2_vtep { ip 10.255.0.12 mac 00:1c:73:aa:00:12 }\nhost vtep6_a    { ip 2001:db8:255::11 }\nhost vtep6_b    { ip 2001:db8:255::12 }\n\ncompile {\n    // Tenant A L2VNI 10100 with outer UDP entropy port 52101 and underlay VLAN 4090\n    leaf1_vtep -> leaf2_vtep vxlan vni 10100 srcport 52101 vlan 4090 dscp 26 wait 1ms\n    // Tenant B Symmetric IRB L3VNI 50000 with different ECMP hash port 58420\n    leaf2_vtep -> leaf1_vtep vxlan vnid 50000 srcport 58420 vlan 4090 dscp 46 wait 2ms\n    // IPv6 underlay VXLAN on legacy Linux port 8472\n    vtep6_a -> vtep6_b vxlan vni 20200 dstport 8472 flowlabel 0x33445\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show vxlan_evpn_fabric.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly vxlan_evpn_fabric.frasm vxlan_evpn_fabric.pcap\nframeassembly vxlan_evpn_fabric.frasm vxlan_evpn_fabric.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse vxlan_evpn_fabric.pcap vxlan_evpn_fabric_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r vxlan_evpn_fabric.pcap -Y \"vxlan\"\n```\n\n## All `vxlan` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host vxlan [vni|vnid <0..16777215>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `vni <0..16777215> \\| vnid <0..16777215>` | 24-bit unsigned integer (0..16777215) | `1` | Sets the 24-bit VXLAN Network Identifier in bytes 4..6 of the 8-byte VXLAN header (`vnid` is an exact alias for `vni`). |\n| `srcport <0..65535> \\| dstport <0..65535>` | 16-bit UDP ports | `srcport 49152, dstport 4789` | Controls outer UDP entropy `srcport` for spine ECMP hashing or overrides `dstport` (e.g., `8472` for Flannel / early Linux VXLAN). |\n\n## Cross-Layer Options Valid with `vxlan`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 4789 (VNI 1)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### 24-Bit VNI Upper Bound (16,777,215)\n\n- **Avoid:** `leaf1 -> leaf2 vxlan vni 20000000`\n- **Valid v3.3.0 Syntax:** `leaf1 -> leaf2 vxlan vni 16777215`\n\nVXLAN VNIs occupy 24 bits (`0..=16777215` / `0xffffff`). Values exceeding\n`16777215` are rejected by semantic validation.\n\n### VXLAN Runs Exclusively Over UDP (No transport tcp)\n\n- **Avoid:** `leaf1 -> leaf2 vxlan vni 100 transport tcp`\n- **Valid v3.3.0 Syntax:** `leaf1 -> leaf2 vxlan vni 100`\n\nPer RFC 7348, VXLAN is strictly UDP-encapsulated and is not in the 9-protocol\n`transport` whitelist.\n"}
{"id":"pretrain-proto-geneve","kind":"protocol_spec","title":"Generic Network Virtualization Encapsulation (geneve) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/geneve","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["geneve"],"text":"# geneve — Extensible SDN & Cloud GWLB Overlays on UDP 6081 (`geneve`)\n\n> **FrameAssembly v3.3.0** · Protocol 25 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/geneve\n\n- **Full Protocol Name:** Generic Network Virtualization Encapsulation\n- **Keyword:** `geneve`\n- **OSI Layer & Transport:** Layer 3 · UDP 6081 (Proto 0x6558)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 8926\n- **Wireshark Display Filter:** `geneve`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  GENEVE (UDP 6081 (Proto 0x6558))`\n\n## Overview\n\nVXLAN’s extensible cousin powering OVN, Cilium, and AWS Gateway Load Balancers on\nUDP `6081`: `geneve` packs a 24-bit `vni` plus variable-length TLV option headers\nwithout manual `optlen` math.\n\nGeneric Network Virtualization Encapsulation (`geneve`, RFC 8926) is the\nextensible cloud and Kubernetes CNI overlay protocol (used by OVN-Kubernetes,\nCilium, NSX-T, and AWS Gateway Load Balancer) running over **UDP `dstport 6081`**.\nUnlike fixed-header VXLAN, GENEVE includes a 6-bit `OptLen` field (`4-byte`\nmultiples) allowing SDN controllers and cloud load balancers to attach\nvariable-length Type-Length-Value (TLV) security metadata (`optclass` +\n`opttype`).\n\nFrameAssembly generates the RFC 8926 base header (`Protocol Type 0x6558`\nTransparent Ethernet Bridging by default), encodes optional 4-byte aligned TLV\noptions when `optclass` or `opttype` is supplied, and updates `OptLen`\nautomatically.\n\n## Minimal Quickstart (`geneve_quickstart.frasm`)\n\n```frameassembly\nhost k8s_worker1 { ip 10.240.0.11 }\nhost k8s_worker2 { ip 10.240.0.12 }\n\ncompile {\n    k8s_worker1 -> k8s_worker2 geneve vni 20200 optclass 0x0102 opttype 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Encapsulates over UDP `dstport 6081` with computed IPv4/IPv6 and UDP\n  pseudo-header checksums.\n- Writes the 8-byte RFC 8926 GENEVE base header (`Ver=0`, dynamic `OptLen` in\n  4-byte words, `Protocol Type=0x6558` TEB, and 24-bit `VNI`).\n- When `optclass` or `opttype` is set, appends a 4-byte padded GENEVE TLV option\n  header + value and sets `OptLen` so Wireshark dissects both the TLV and inner\n  frame cleanly.\n\n## Practical Lab Example: Kubernetes OVN & Cilium GENEVE Overlay With Security Identity TLVs (`geneve_cni_tlvs.frasm`)\n\nModels pod-to-pod overlay packets carrying OVN (`0x0102`) and Cilium (`0x0104`)\noption classes, plus a Layer 3 IPv6 inner payload (`protocoltype 0x86dd`).\n\n```frameassembly\nhost node_az1 { ip 10.128.1.10 }\nhost node_az2 { ip 10.128.2.20 }\n\ncompile {\n    // 1. OVN-Kubernetes pod egress carrying Option Class 0x0102\n    node_az1 -> node_az2 geneve vni 4010 optclass 0x0102 opttype 1 srcport 55100 wait 1ms\n    // 2. Cilium return packet carrying Option Class 0x0104\n    node_az1 <- node_az2 geneve vni 4010 optclass 0x0104 opttype 2 srcport 59200 wait 2ms\n    // 3. Direct L3 IPv4 payload inside GENEVE (protocoltype 0x0800) for GWLB appliance test\n    node_az1 -> node_az2 geneve vni 100 optclass 0x0108 opttype 1 protocoltype 0x0800\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show geneve_cni_tlvs.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly geneve_cni_tlvs.frasm geneve_cni_tlvs.pcap\nframeassembly geneve_cni_tlvs.frasm geneve_cni_tlvs.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse geneve_cni_tlvs.pcap geneve_cni_tlvs_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r geneve_cni_tlvs.pcap -Y \"geneve\"\n```\n\n## All `geneve` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host geneve [vni|vnid <0..16777215>]\n[optclass <0..65535>] [opttype <0..255>] [protocoltype <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `vni <0..16777215> \\| vnid <0..16777215>` | 24-bit unsigned integer (0..16777215) | `1` | Sets the 24-bit Virtual Network Identifier (`vnid` is an alias for `vni`). |\n| `optclass <0..65535>` | 16-bit IANA Option Class (hex or decimal) | `Omitted (OptLen 0 unless set)` | Appends a GENEVE TLV Option with the given namespace (`0x0102` OVN, `0x0104` Cilium, `0x0108` AWS) and increments `OptLen`. |\n| `opttype <0..255>` | 8-bit Option Type (bit 7 = Critical bit) | `1 (when optclass set)` | Sets the 8-bit Option Type inside the GENEVE TLV (`>= 0x80` marks a Critical option per RFC 8926 §3.5). |\n| `protocoltype <0..65535>` | 16-bit IEEE EtherType | `0x6558 (Transparent Ethernet Bridging)` | Sets the inner encapsulated EtherType (`0x6558` Ethernet L2 frame, `0x0800` raw IPv4, `0x86dd` raw IPv6). |\n\n## Cross-Layer Options Valid with `geneve`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 6081 (Proto 0x6558)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Spell optclass, opttype, and protocoltype Without Underscores\n\n- **Avoid:** `a -> b geneve opt_class 0x0102 opt_type 1 protocol_type 0x6558`\n- **Valid v3.3.0 Syntax:** `a -> b geneve optclass 0x0102 opttype 1 protocoltype\n  0x6558`\n\nAll GENEVE sub-keywords are strict lowercase alphanumeric tokens with zero\nunderscores.\n\n### Critical Option Bit Semantics (opttype >= 0x80)\n\n- **Valid v3.3.0 Syntax:** `a -> b geneve vni 10 optclass 0x0102 opttype 0x81`\n\nSetting bit 7 (`0x80`) in `opttype` sets the GENEVE header `C` (Critical Options\nPresent) flag; tunnel endpoints that do not recognize a critical option must drop\nthe packet.\n"}
{"id":"pretrain-proto-ipip","kind":"protocol_spec","title":"IP-in-IP & IPv6-in-IPv4 Tunneling (ipip) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ipip","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ipip"],"text":"# ipip — RFC 2003 IP-in-IP (Proto 4) & 6in4 (Proto 41) Tunnels (`ipip`)\n\n> **FrameAssembly v3.3.0** · Protocol 26 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ipip\n\n- **Full Protocol Name:** IP-in-IP & IPv6-in-IPv4 Tunneling\n- **Keyword:** `ipip`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 4 (IPv4) / 41 (IPv6)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 2003, RFC 4213, RFC 2473\n- **Wireshark Display Filter:** `ip.proto == 4 || ip.proto == 41`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  IP-in-IP (RFC 2003 / 4213) (IP Proto 4 (IPv4) / 41 (IPv6))`\n\n## Overview\n\nZero GRE shim, zero UDP ports — `ipip` wraps an inner IPv4 (`Proto 4`) or IPv6\n(`Proto 41`) header straight inside outer IP for Kubernetes Calico pod overlays\nand Katran L4 DSR load balancers.\n\nIP-in-IP (`ipip`, RFC 2003 / RFC 4213 / RFC 2473) encapsulates a complete inner\nIPv4 (`IP Protocol 4`) or IPv6 (`IP Protocol 41`) header directly inside an outer\nIPv4 or IPv6 delivery packet with zero GRE or UDP shim overhead. It underpins\n**Kubernetes Calico IPIP** pod networking, **Katran / Maglev L4 Direct Server\nReturn (DSR)** load balancers, **6in4 / 4in6** dual-stack transition tunnels, and\nDDoS scrubbing return pipes.\n\nFrameAssembly automatically sets the outer IP Protocol / Next Header to `4` for\ninner IPv4 (`v4`) or `41` for inner IPv6 (`v6`), formats the 20-byte inner IPv4\nheader (with valid RFC 1071 inner header checksum) or 40-byte inner IPv6 header,\nand lets you control `srcip`, `dstip`, `innerttl`, `innerdscp`, and inner `proto`\nindependently of the outer tunnel header.\n\n## Minimal Quickstart (`ipip_quickstart.frasm`)\n\n```frameassembly\nhost k8s_node_a { ip 172.16.10.11 }\nhost k8s_node_b { ip 172.16.20.22 }\n\ncompile {\n    k8s_node_a -> k8s_node_b ipip v4 srcip 10.244.1.15 dstip 10.244.2.40 innerttl 63 proto 6 payload \"calico-pod-probe\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets outer IPv4 Protocol / IPv6 Next Header to `4` (`IPIP`) when the inner\n  header is IPv4 or `41` (`IPv6` encapsulation) when `v6` / `version 6` or IPv6\n  `srcip`/`dstip` is selected.\n- Computes both the inner IPv4 RFC 1071 header checksum (`innerttl`, `innerdscp`,\n  `proto`, inner total length) and the outer delivery IPv4 checksum automatically.\n- Supports cross-family encapsulation—such as inner IPv6 (`v6`) carried over outer\n  IPv4 hosts (`6in4`) or inner IPv4 (`v4`) carried over outer IPv6 hosts (`4in6`).\n\n## Practical Lab Example: L4 Load Balancer Direct Server Return (4in4) & 6in4 Transition Tunnel (`ipip_dsr_and_6in4.frasm`)\n\nCaptures a Katran L4 edge director forwarding an encapsulated IPv4 client request\n(`IP Proto 4`) to a real server, followed by an RFC 4213 `6in4` (`IP Proto 41`)\ntunnel packet over the same IPv4 fabric.\n\n```frameassembly\nhost lb_director { ip 192.0.2.10 mac 00:1c:73:aa:00:01 }\nhost real_srv_01 { ip 192.0.2.55 mac 00:1c:73:bb:00:55 }\n\ncompile {\n    // 1. Katran 4in4 DSR: outer lb_director -> real_srv_01 (IP Proto 4), inner client -> anycast VIP\n    lb_director -> real_srv_01 ipip v4 srcip 198.51.100.42 dstip 203.0.113.10 innerttl 60 innerdscp 34 proto 6 ttl 64 df payload \"VIP-SYN-PROBE\" wait 2ms\n    // 2. RFC 4213 6in4 tunnel: outer IPv4 (IP Proto 41) carrying inner IPv6 2001:db8:: endpoints\n    lb_director -> real_srv_01 ipip v6 srcip 2001:db8:cafe::42 dstip 2001:db8:beef::10 innerttl 62 innerdscp 46 proto 58 payload \"ICMPv6-INSIDE-IPV4\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ipip_dsr_and_6in4.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ipip_dsr_and_6in4.frasm ipip_dsr_and_6in4.pcap\nframeassembly ipip_dsr_and_6in4.frasm ipip_dsr_and_6in4.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ipip_dsr_and_6in4.pcap ipip_dsr_and_6in4_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ipip_dsr_and_6in4.pcap -Y \"ip.proto == 4 || ip.proto == 41\"\n```\n\n## All `ipip` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ipip [v4 | v6 | version <4|6>] [srcip\n<ip>] [dstip <ip>] [innerttl <0..255>] [innerdscp <0..63>] [proto <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `v4 \\| v6 \\| version <4\\|6>` | Inner IP version selector (4 or 6) | `Matches inner srcip/dstip or outer host family (v4)` | Selects a 20-byte inner IPv4 header (outer proto `4`) or 40-byte inner IPv6 header (outer proto `41`). |\n| `srcip <ip> \\| dstip <ip>` | IPv4 or IPv6 literal matching inner version | `10.0.0.1 -> 10.0.0.2 (v4) or 2001:db8::1 -> 2001:db8::2 (v6)` | Writes the inner encapsulated source and destination IP addresses. |\n| `innerttl <0..255>` | 8-bit inner TTL / Hop Limit (0..255) | `64` | Sets the inner IPv4 TTL or inner IPv6 Hop Limit independently of outer `ttl`. |\n| `innerdscp <0..63>` | 6-bit inner DiffServ codepoint (0..63) | `0` | Sets the upper 6 bits of the inner IPv4 TOS byte or inner IPv6 Traffic Class. |\n| `proto <0..255>` | 8-bit IANA protocol number (0..255) | `59 (No Next Header on v6) / 6 or 17 / raw payload` | Sets the inner IPv4 Protocol or inner IPv6 Next Header byte (`1`=ICMP, `6`=TCP, `17`=UDP, `58`=ICMPv6). |\n\n## Cross-Layer Options Valid with `ipip`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### Use innerttl and innerdscp for the Encapsulated Header\n\n- **Avoid:** `node1 -> node2 ipip v4 srcip 10.1.0.1 dstip 10.2.0.1 ttl 63`\n- **Valid v3.3.0 Syntax:** `node1 -> node2 ipip v4 srcip 10.1.0.1 dstip 10.2.0.1\n  innerttl 63 ttl 255`\n\nBare `ttl` and `dscp` control the outer delivery IP header, while `innerttl` and\n`innerdscp` control the encapsulated inner IP header.\n\n### Keep Inner srcip and dstip in the Same Address Family\n\n- **Avoid:** `node1 -> node2 ipip v6 srcip 10.1.0.1 dstip 2001:db8::2`\n- **Valid v3.3.0 Syntax:** `node1 -> node2 ipip v6 srcip 2001:db8::1 dstip\n  2001:db8::2`\n\nWhile outer hosts can be IPv4 and inner addresses IPv6 (`6in4`), both inner\n`srcip` and `dstip` must belong to the selected inner IP version (`v4` or `v6`).\n"}
{"id":"pretrain-proto-srv6","kind":"protocol_spec","title":"Segment Routing over IPv6 — Segment Routing Header (srv6) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/srv6","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["srv6"],"text":"# srv6 — IPv6 Segment Routing Header (SRH Type 4) SID Stacks (`srv6`)\n\n> **FrameAssembly v3.3.0** · Protocol 27 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/srv6\n\n- **Full Protocol Name:** Segment Routing over IPv6 — Segment Routing Header\n- **Keyword:** `srv6`\n- **OSI Layer & Transport:** Layer 3 · IPv6 NextHdr 43 (Routing Type 4)\n- **Host Endpoint Rule:** IPv6-Only\n- **Standards:** RFC 8754, RFC 8986, RFC 9252\n- **Wireshark Display Filter:** `ipv6.routing.type == 4`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv6 -> SRv6\n  SRH (RFC 8754) (IPv6 NextHdr 43 (Routing Type 4))`\n\n## Overview\n\nWho needs MPLS label distribution when 128-bit IPv6 addresses carry the entire\nprogram? Repeat `sid <ipv6>` as many times as you want on `srv6` and the compiler\ncalculates `Hdr Ext Len` and `Last Entry` automatically.\n\nSegment Routing over IPv6 (`srv6`, RFC 8754 / RFC 8986) encodes explicit\nsource-routed paths, L3VPN/EVPN service functions (`End.DT4`, `End.DX2`), and 5G\ntransport slicing directly into the IPv6 data plane using the **Segment Routing\nHeader (SRH, IPv6 Extension Header `43`, Routing Type `4`)**. Each SRH carries an\nordered vector of 128-bit IPv6 Segment Identifiers (`sid`), a `Segments Left`\npointer (`segleft`), `Last Entry` index, `Flags`, and a 16-bit packet `Tag`.\n\nFrameAssembly enforces IPv6-only endpoints on `srv6` at compile time, supports\n**repeatable `sid <ipv6>` modifiers** to build multi-hop segment lists of any\nlength, and auto-computes both `Hdr Ext Len` (`2 * num_sids` in 8-octet units) and\n`Last Entry` (`num_sids - 1`).\n\n## Minimal Quickstart (`srv6_quickstart.frasm`)\n\n```frameassembly\nhost pe_ingress { ip 2001:db8:c0ca::1 }\nhost p_transit  { ip 2001:db8:c0ca::2 }\n\ncompile {\n    pe_ingress -> p_transit srv6 segleft 1 sid 2001:db8:100::1 sid 2001:db8:200::1 nextheader 59\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets the outer IPv6 Next Header field to `43` (Routing Header) and initializes\n  the SRH fixed 8-byte header with `Routing Type = 4` (SRH).\n- Calculates `Hdr Ext Len` (`num_sids * 2`) and `Last Entry` (`num_sids - 1`)\n  automatically from your repeatable `sid <ipv6>` list (inserting a default SID\n  when omitted).\n- Validates at compile time that both endpoints declare IPv6 addresses, preventing\n  accidental IPv4 SRH framing.\n\n## Practical Lab Example: 3-Segment SRv6 L3VPN Path Progression Across Ingress PE, Transit P & Egress PE (`srv6_te_path.frasm`)\n\nTraces a packet traversing an SRv6 Traffic-Engineered path as `segleft` decrements\nfrom `2` to `1` across transit hops, carrying a VRF classification `tag` and ECMP\n`flowlabel`.\n\n```frameassembly\nhost pe1_v6 { ip 2001:db8:fab::11 mac 00:1c:73:01:00:11 }\nhost p1_v6  { ip 2001:db8:fab::22 mac 00:1c:73:02:00:22 }\nhost pe2_v6 { ip 2001:db8:fab::33 mac 00:1c:73:03:00:33 }\n\ncompile {\n    // 1. Hop 1 (PE1 -> P1): 3 SIDs in SRH (End.DT4 VPN SID at index 0, transit SIDs at 1 & 2), segleft = 2\n    pe1_v6 -> p1_v6 srv6 segleft 2 tag 100 nextheader 4 sid 2001:db8:33::d4 sid 2001:db8:22::e1 sid 2001:db8:11::e1 dscp 46 flowlabel 0x4a100 payload \"inner-vrf-frame\" wait 1ms\n    // 2. Hop 2 (P1 -> PE2): Transit node decrements segleft -> 1 and Hop Limit -> 63\n    p1_v6 -> pe2_v6 srv6 segleft 1 tag 100 nextheader 4 sid 2001:db8:33::d4 sid 2001:db8:22::e1 sid 2001:db8:11::e1 ttl 63 dscp 46 flowlabel 0x4a100 payload \"inner-vrf-frame\" wait 2ms\n    // 3. SRv6 OAM probe with No-Next-Header (59) and O-flag (0x20)\n    pe1_v6 -> pe2_v6 srv6 segleft 0 flags 0x20 tag 999 nextheader 59 sid 2001:db8:33::e1\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show srv6_te_path.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly srv6_te_path.frasm srv6_te_path.pcap\nframeassembly srv6_te_path.frasm srv6_te_path.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse srv6_te_path.pcap srv6_te_path_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r srv6_te_path.pcap -Y \"ipv6.routing.type == 4\"\n```\n\n## All `srv6` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host srv6 [nextheader <0..255>] [segleft\n<0..255>] [flags <0..255>] [tag <0..65535>] [sid <ipv6>]...`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `sid <ipv6> (repeatable)` | 128-bit IPv6 Segment Identifier (repeatable) | `Single default SID (2001:db8::1)` | Appends each 16-byte IPv6 SID into `Segment List[0..n]` and updates `Hdr Ext Len` and `Last Entry`. |\n| `segleft <0..255>` | 8-bit Segments Left index (0..255) | `0 (or SidCount - 1)` | Sets the active segment index pointer in byte 3 of the SRH. |\n| `nextheader <0..255>` | 8-bit IANA protocol number (0..255) | `59 (IPv6 No Next Header)` | Sets byte 0 of the SRH (`4`=IPv4-in-SRv6, `41`=IPv6-in-SRv6, `58`=ICMPv6, `59`=No Next Header, `143`=Ethernet L2VPN). |\n| `flags <0..255>` | 8-bit SRH Flags bitmask (0..255) | `0` | Sets byte 5 of the SRH (such as RFC 9259 OAM `O-flag = 0x20`). |\n| `tag <0..65535>` | 16-bit unsigned packet group tag (0..65535) | `0` | Writes the big-endian 16-bit Tag in bytes 6..7 of the SRH. |\n\n## Cross-Layer Options Valid with `srv6`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### srv6 Requires IPv6 Endpoints on Both Hosts\n\n- **Avoid:** `host r1 { ip 10.0.0.1 }\nhost r2 { ip 10.0.0.2 }\ncompile { r1 -> r2 srv6 }`\n- **Valid v3.3.0 Syntax:** `host r1 { ip 2001:db8::1 }\nhost r2 { ip 2001:db8::2 }\ncompile { r1 -> r2 srv6 sid 2001:db8:1::1 }`\n\nBecause SRv6 is an IPv6 Routing Extension Header (`Next Header 43`),\n`validate_semantics` rejects IPv4 or MAC-only endpoints on `srv6` frames.\n\n### Repeat sid <ipv6> for Each Hop (Never Comma-Separated Arrays)\n\n- **Avoid:** `r1 -> r2 srv6 sid [2001:db8:1::1, 2001:db8:2::1]`\n- **Valid v3.3.0 Syntax:** `r1 -> r2 srv6 sid 2001:db8:1::1 sid 2001:db8:2::1`\n\nPass each 128-bit Segment ID as its own `sid <ipv6>` modifier clause on the same\nframe line.\n"}
{"id":"pretrain-proto-erspan","kind":"protocol_spec","title":"Cisco Encapsulated Remote SPAN Port Mirroring (Type II & Type III) (erspan) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/erspan","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["erspan"],"text":"# erspan — Cisco ERSPAN Type II (0x88be) & III (0x22eb) Mirrors (`erspan`)\n\n> **FrameAssembly v3.3.0** · Protocol 28 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/erspan\n\n- **Full Protocol Name:** Cisco Encapsulated Remote SPAN Port Mirroring (Type II &\n  Type III)\n- **Keyword:** `erspan`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 47 (GRE 0x88be v2 / 0x22eb v3)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** IETF draft-foschiano-erspan, RFC 2784\n- **Wireshark Display Filter:** `erspan`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  ERSPAN II & III (IP Proto 47 (GRE 0x88be v2 / 0x22eb v3))`\n\n## Overview\n\nShip mirrored switch traffic across Layer 3 to Zeek or Suricata: `erspan` wraps\nGRE `0x88be` (`v2`) or hardware-timestamped `0x22eb` (`v3`) headers complete with\n`sessionid`, `vid`, and ingress/egress `direction`.\n\nEncapsulated Remote SPAN (`erspan`, `IP Protocol 47` GRE) transports mirrored\nswitch and virtual-machine Ethernet traffic across Layer 3 IPv4 or IPv6 networks\nto NDR sensors (Suricata, Zeek, Corelight, ExtraHop, Darktrace) and packet\nbrokers. **ERSPAN Type II (`v2`)** uses GRE Protocol Type `0x88be` with an 8-byte\nmetadata header carrying 10-bit `sessionid`, 12-bit mirrored `vid`, `cos`, and\n`index`; **ERSPAN Type III (`v3`)** uses GRE Protocol Type `0x22eb` with a 12-byte\nheader adding sub-microsecond hardware `timestamp` and ingress/egress `direction`.\n\nFrameAssembly sets the GRE Sequence Number bit (`S=1`), switches the GRE Protocol\nEtherType automatically between `0x88be` (`v2`) and `0x22eb` (`v3`), and packs the\nexact bitfields plus an inner mirrored Ethernet frame so NDR decapsulators dissect\nevery header cleanly.\n\n## Minimal Quickstart (`erspan_quickstart.frasm`)\n\n```frameassembly\nhost leaf_sw   { ip 10.20.0.11 }\nhost zeek_tap  { ip 10.99.0.50 }\n\ncompile {\n    leaf_sw -> zeek_tap erspan v3 sessionid 10 vid 120 cos 5 greseq 1 timestamp 50000 direction 0\n}\n```\n\n### Automatic Wire Calculations\n\n- Encapsulates inside IP Protocol `47` (GRE with `S=1` 32-bit `greseq`) using GRE\n  Protocol `0x88be` for Type II (`v2`, default) or `0x22eb` for Type III (`v3`).\n- Bit-packs Version (`0x1` for Type II, `0x2` for Type III wire format), 12-bit\n  `vid`, 3-bit `cos`, 10-bit `sessionid`, port `index`, and Type III 32-bit\n  `timestamp` + `direction`.\n- Includes a well-formed inner mirrored Ethernet frame (or custom `payload` /\n  `hexpayload` bytes) after the ERSPAN header so Wireshark `erspan` never flags\n  truncated capture errors.\n\n## Practical Lab Example: Leaf Switch Bidirectional ERSPAN Type II & Type III Feed to NDR Collector (`erspan_ndr_mirror.frasm`)\n\nStreams an ERSPAN Type II (`0x88be`) ingress capture from Session 10 and a\nhardware-timestamped ERSPAN Type III (`0x22eb`) ingress/egress pair (`direction 0`\n-> `direction 1`) from Session 20.\n\n```frameassembly\nhost tor_leaf_01 { ip 172.18.1.10 mac 00:1c:73:10:00:01 }\nhost ndr_sensor  { ip 172.18.99.20 mac 00:50:56:99:00:20 }\n\ncompile {\n    // 1. ERSPAN Type II (GRE 0x88be) mirroring VLAN 100 port index 48\n    tor_leaf_01 -> ndr_sensor erspan v2 sessionid 10 vid 100 cos 0 greseq 101 index 48 payload \"mirrored-vlan100-ingress\" wait 1ms\n    // 2. ERSPAN Type III (GRE 0x22eb) ingress frame (direction 0) + egress reply (direction 1)\n    tor_leaf_01 -> ndr_sensor erspan v3 sessionid 20 vid 200 cos 5 greseq 1 timestamp 100000 index 12 direction 0 payload \"mirrored-rx-pdu\" wait 250us\n    tor_leaf_01 -> ndr_sensor erspan v3 sessionid 20 vid 200 cos 5 greseq 2 timestamp 100250 index 12 direction 1 payload \"mirrored-tx-pdu\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show erspan_ndr_mirror.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly erspan_ndr_mirror.frasm erspan_ndr_mirror.pcap\nframeassembly erspan_ndr_mirror.frasm erspan_ndr_mirror.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse erspan_ndr_mirror.pcap erspan_ndr_mirror_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r erspan_ndr_mirror.pcap -Y \"erspan\"\n```\n\n## All `erspan` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host erspan [v2 | v3 | version <2|3>]\n[sessionid <0..1023>] [vid <0..4095>] [cos <0..7>] [greseq <number>] [index\n<number>] [timestamp <number>] [direction <0|1>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `v2 \\| v3 \\| version <2\\|3>` | ERSPAN version (Type II = 2, Type III = 3) | `v2 (Type II, GRE 0x88be)` | Selects 8-byte ERSPAN Type II (`0x88be`) or 12-byte hardware-timestamped ERSPAN Type III (`0x22eb`). |\n| `sessionid <0..1023>` | 10-bit ERSPAN Session ID (0..1023) | `1` | Writes the 10-bit ERSPAN Session ID used by packet brokers and switches to separate mirror sessions. |\n| `vid <0..4095>` | 12-bit mirrored VLAN ID (0..4095) | `1` | Records the original 802.1Q VLAN ID of the mirrored frame inside the ERSPAN metadata header. |\n| `cos <0..7>` | 3-bit mirrored Class of Service (0..7) | `0` | Records the original 802.1p CoS priority bits inside the ERSPAN metadata header. |\n| `greseq <number>` | 32-bit GRE Sequence Number | `1` | Writes the 32-bit GRE sequence counter ahead of the ERSPAN header to detect dropped mirror packets. |\n| `index <number>` | 20-bit switch port index | `1` | Identifies the source/destination physical switch port index in the ERSPAN header. |\n| `timestamp <number>` | 32-bit ASIC timestamp (Type III) | `0` | Writes the 32-bit lower timestamp word in ERSPAN Type III (`v3`) headers (`100us` / `1ns` granularity). |\n| `direction <0\\|1>` | 1-bit mirror direction (0 = Ingress, 1 = Egress) | `0 (Ingress)` | Sets the `T` / Direction bit in ERSPAN (`0` incoming to port, `1` outgoing from port). |\n\n## Cross-Layer Options Valid with `erspan`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### Use vid on ERSPAN for Mirrored Metadata vs vlan for Outer Underlay Tagging\n\n- **Avoid:** `Assuming vlan 200 sets the inner ERSPAN metadata VLAN field`\n- **Valid v3.3.0 Syntax:** `leaf -> tap erspan v3 sessionid 10 vid 200 vlan 99`\n\n`vid 200` sets the mirrored VLAN ID inside the ERSPAN header, whereas `vlan 99`\nwraps the outer delivery Ethernet frame in an 802.1Q underlay tag.\n\n### timestamp Applies to ERSPAN Type III (v3)\n\n- **Avoid:** `leaf -> tap erspan v2 timestamp 50000`\n- **Valid v3.3.0 Syntax:** `leaf -> tap erspan v3 sessionid 10 timestamp 50000`\n\nERSPAN Type II (`0x88be`) is a fixed 8-byte header without a 32-bit timestamp\nfield; add `v3` (`0x22eb`) when testing hardware timestamps.\n"}
{"id":"pretrain-proto-ipsec","kind":"protocol_spec","title":"IPsec Encapsulating Security Payload (Protocol Alias) (ipsec) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ipsec","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ipsec"],"text":"# ipsec — IP Protocol 50 ESP Tunnel Frames & SPI Headers (`ipsec`)\n\n> **FrameAssembly v3.3.0** · Protocol 29 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ipsec\n\n- **Full Protocol Name:** IPsec Encapsulating Security Payload (Protocol Alias)\n- **Keyword:** `ipsec`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 50 (ESP)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 4303, RFC 4301\n- **Wireshark Display Filter:** `esp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  IPsec (ESP Alias) (IP Proto 50 (ESP))`\n\n## Overview\n\nEdge firewalls love dropping IP Protocol `50` when someone only opened UDP `500`.\n`ipsec` emits clean ESP headers (`spi`, `seq`, `iv`, `icv`) so you can prove\nwhether the tunnel pipe is open.\n\nThe `ipsec` keyword in FrameAssembly v3.2.2 is a convenient shorthand alias for\n**`esp`** (RFC 4303 Encapsulating Security Payload, **IP Protocol `50`**). Both\n`ipsec` and `esp` write the exact same ESP wire layout: 32-bit Security Parameters\nIndex (`spi`), 32-bit Sequence Number (`seq`), Initialization Vector (`iv`),\npadded payload + trailer (`Pad Length` + `nextheader`), and Integrity Check Value\n(`icv`).\n\nWhen reversing existing `.pcap` files containing IP Protocol `50`, `frameassembly\nreverse` emits the explicit `esp` keyword, while both `ipsec` and `esp` build\nbyte-identical wire packets.\n\n## Minimal Quickstart (`ipsec_quickstart.frasm`)\n\n```frameassembly\nhost vpn_branch { ip 198.51.100.10 }\nhost vpn_hq     { ip 203.0.113.20 }\n\ncompile {\n    vpn_branch -> vpn_hq ipsec spi 0x00001001 seq 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets outer IPv4 Protocol or IPv6 Next Header to `50` (ESP).\n- Encodes the 4-byte `spi` (default `0x00000100`), 4-byte ESP `seq` (default `1`),\n  8-byte `iv`, block-aligned ciphertext + 2-byte ESP trailer (`Pad Length` +\n  `nextheader`), and 12-byte `icv` authentication tag.\n- Parses `iv` and `icv` hex strings cleanly whether formatted continuously\n  (`\"0102030405060708\"`), colon-separated, or space-separated.\n\n## Practical Lab Example: IKEv2 Tunnel Bring-Up Followed by Bidirectional IPsec Data Frames (`ipsec_site_to_site.frasm`)\n\nPairs an `ikev2` `SA_INIT` + `IKE_AUTH` negotiation on UDP 500 with encrypted\n`ipsec` tunnel-mode (`nextheader 4`) data packets in both directions.\n\n```frameassembly\nhost gw_west { ip 198.51.100.10 }\nhost gw_east { ip 203.0.113.20 }\n\ncompile {\n    // 1. IKEv2 SA_INIT and IKE_AUTH key exchange on UDP 500\n    gw_west -> gw_east ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 msgid 0 nextheader 33 wait 3ms\n    gw_west <- gw_east ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 flags 0x20 wait 3ms\n    gw_west -> gw_east ikev2 auth initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 msgid 1 nextheader 46 wait 4ms\n    // 2. Bidirectional IPsec ESP tunnel frames (outbound SPI 0x1001, inbound SPI 0x2002)\n    gw_west -> gw_east ipsec spi 0x00001001 seq 1 iv \"0102030405060708\" icv \"aabbccddeeff001122334455\" nextheader 4 wait 1ms\n    gw_west -> gw_east ipsec spi 0x00001001 seq 2 iv \"090a0b0c0d0e0f10\" icv \"112233445566778899aabbcc\" nextheader 4 wait 2ms\n    gw_west <- gw_east ipsec spi 0x00002002 seq 1 iv \"f1f2f3f4f5f6f7f8\" icv \"99887766554433221100ffaa\" nextheader 4\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ipsec_site_to_site.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ipsec_site_to_site.frasm ipsec_site_to_site.pcap\nframeassembly ipsec_site_to_site.frasm ipsec_site_to_site.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ipsec_site_to_site.pcap ipsec_site_to_site_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ipsec_site_to_site.pcap -Y \"esp\"\n```\n\n## All `ipsec` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ipsec [spi <number>] [seq <number>] [iv\n\"<hex>\"] [icv \"<hex>\"] [nextheader <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `spi <number>` | Whole number (decimal or 0x hex) | `0x00000100` | Sets the 4-byte Security Parameters Index identifying the unidirectional IPsec Security Association. |\n| `seq <number>` | Whole number | `1` | Sets the 4-byte RFC 4303 ESP anti-replay Sequence Number (contextual to IPsec rather than TCP). |\n| `iv \"<hex>\"` | Double-quoted even-length hex octets | `8-byte deterministic IV` | Writes the explicit Initialization Vector octets immediately after `spi` + `seq`. |\n| `icv \"<hex>\"` | Double-quoted even-length hex octets | `12-byte (96-bit) authenticator` | Appends the trailing Integrity Check Value authentication tag. |\n| `nextheader <0..255>` | 8-bit IP protocol number | `4 (IPv4-in-IP tunnel mode)` | Sets the ESP trailer Next Header byte (`4` IPv4-in-IP, `41` IPv6-in-IP, `6` TCP transport mode). |\n\n## Cross-Layer Options Valid with `ipsec`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### ipsec vs esp vs ah Keyword Selection\n\n- **Valid v3.3.0 Syntax:** `gw_a -> gw_b esp spi 0x1001 seq 1 // or ah spi 0x2001\n  seq 1`\n\n`ipsec` and `esp` both emit IP Protocol `50` (ESP). If you need IP Protocol `51`\n(RFC 4302 Authentication Header without encryption), use the `ah` keyword.\n\n### Hex Strings Must Be Double-Quoted\n\n- **Avoid:** `gw_a -> gw_b ipsec iv 0102030405060708`\n- **Valid v3.3.0 Syntax:** `gw_a -> gw_b ipsec iv \"0102030405060708\"`\n\nPass `iv` and `icv` byte arrays as double-quoted hex strings (`\"0102030405060708\"`\nor `\"01:02:03:04:05:06:07:08\"`).\n"}
{"id":"pretrain-proto-esp","kind":"protocol_spec","title":"IPsec Encapsulating Security Payload (esp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/esp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["esp"],"text":"# esp — Canonical RFC 4303 ESP Headers & Reverse Scrubbing (`esp`)\n\n> **FrameAssembly v3.3.0** · Protocol 30 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/esp\n\n- **Full Protocol Name:** IPsec Encapsulating Security Payload\n- **Keyword:** `esp`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 50\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 4303\n- **Wireshark Display Filter:** `esp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  IPsec ESP (IP Proto 50)`\n\n## Overview\n\n`esp` is the canonical keyword emitted when `frameassembly reverse` decompiles IP\nProtocol `50` captures, making it trivial to scrub customer VPN gateway IPs before\nemailing a trace to vendor TAC.\n\nEncapsulating Security Payload (`esp`, RFC 4303) provides confidentiality,\ndata-origin authentication, connectionless integrity, and anti-replay protection\nover **IP Protocol `50`** (and IPv6 Extension / Next Header `50`).\n\n`esp` is the canonical protocol keyword emitted by `frameassembly reverse`\nwhenever decompiling IP Protocol `50` packets from `.pcap` or `.pcapng` traces,\nand accepts the exact same modifiers (`spi`, `seq`, `iv`, `icv`, `nextheader`) as\nits `ipsec` alias.\n\n## Minimal Quickstart (`esp_quickstart.frasm`)\n\n```frameassembly\nhost peer_a { ip 172.16.50.1 }\nhost peer_b { ip 172.16.50.2 }\n\ncompile {\n    peer_a -> peer_b esp spi 0xdead0001 seq 1 iv \"0102030405060708\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Emits IPv4 Protocol `50` or IPv6 Next Header `50` with computed outer IPv4\n  header checksum and exact payload length.\n- Aligns ciphertext + padding + 2-byte trailer (`Pad Length`, `Next Header`)\n  cleanly to cipher block boundaries before appending the `icv`.\n- Round-trips cleanly through `frameassembly reverse` preserving `spi` and `seq`.\n\n## Practical Lab Example: Dual-Stack IPv4 & IPv6 ESP Security Associations With DiffServ QoS (`esp_dualstack_vpn.frasm`)\n\nEmits unidirectional outbound and inbound ESP Security Associations across both\nIPv4 and IPv6 WAN endpoints with preserved DiffServ markings.\n\n```frameassembly\nhost hub_v4    { ip 198.51.100.1 }\nhost spoke_v4  { ip 203.0.113.50 }\nhost hub_v6    { ip 2001:db8:100::1 }\nhost spoke_v6  { ip 2001:db8:200::50 }\n\ncompile {\n    // IPv4 ESP tunnel (SPI 0x1010 -> 0x2020) with Expedited Forwarding (dscp 46)\n    spoke_v4 -> hub_v4 esp spi 0x00001010 seq 101 iv \"1011121314151617\" icv \"a1a2a3a4a5a6a7a8a9aaabac\" nextheader 4 dscp 46 df wait 1ms\n    spoke_v4 <- hub_v4 esp spi 0x00002020 seq 88 iv \"2021222324252627\" icv \"b1b2b3b4b5b6b7b8b9babbbc\" nextheader 4 dscp 46 df wait 3ms\n    // IPv6 ESP tunnel (Next Header 50, inner Next Header 41 = IPv6-in-IPv6)\n    spoke_v6 -> hub_v6 esp spi 0x00061010 seq 1 iv \"3031323334353637\" icv \"c1c2c3c4c5c6c7c8c9cacbcc\" nextheader 41 flowlabel 0x50001\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show esp_dualstack_vpn.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly esp_dualstack_vpn.frasm esp_dualstack_vpn.pcap\nframeassembly esp_dualstack_vpn.frasm esp_dualstack_vpn.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse esp_dualstack_vpn.pcap esp_dualstack_vpn_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r esp_dualstack_vpn.pcap -Y \"esp\"\n```\n\n## All `esp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host esp [spi <number>] [seq <number>] [iv\n\"<hex>\"] [icv \"<hex>\"] [nextheader <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `spi <number>` | Whole number (decimal or 0x hex) | `0x00000100` | Sets the 4-byte ESP Security Parameters Index (`0..255` reserved by IANA; `>= 256` assigned by IKE). |\n| `seq <number>` | Whole number | `1` | Sets the 4-byte ESP Sequence Number field. |\n| `iv \"<hex>\"` | Double-quoted even-length hex string | `8-byte IV` | Sets the explicit Initialization Vector bytes (`8B` AES-GCM/CBC or `16B` AES-CBC). |\n| `icv \"<hex>\"` | Double-quoted even-length hex string | `12-byte ICV` | Appends the Integrity Check Value trailer (`12B` HMAC-SHA1-96 / `16B` AES-GCM-128). |\n| `nextheader <0..255>` | 8-bit IP protocol number | `4 (IPv4)` | Sets the inner protocol number inside the encrypted ESP trailer. |\n\n## Cross-Layer Options Valid with `esp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### NAT-Traversal ESP-in-UDP vs Native Protocol 50\n\n- **Valid v3.3.0 Syntax:** `spoke -> hub esp spi 0x1010 seq 1 // Native IP\n  Protocol 50`\n\n`esp` emits native IP Protocol `50` (not UDP `4500` NAT-T encapsulation). To\nsimulate UDP `4500` NAT-T packets, use `ikev2 srcport 4500 dstport 4500` or `udp\nsrcport 4500 dstport 4500 hexpayload \"...\"`.\n\n### Even-Length Hex Octets in iv and icv\n\n- **Avoid:** `spoke -> hub esp iv \"abc\"`\n- **Valid v3.3.0 Syntax:** `spoke -> hub esp iv \"0a0b0c0d0e0f1011\"`\n\nHex byte literals must contain an even number of hexadecimal digits (`0-9`, `a-f`,\n`A-F`) representing complete 8-bit octets.\n"}
{"id":"pretrain-proto-ah","kind":"protocol_spec","title":"IPsec Authentication Header (ah) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ah","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ah"],"text":"# ah — RFC 4302 IPsec Authentication Header (IP Proto 51) (`ah`)\n\n> **FrameAssembly v3.3.0** · Protocol 31 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ah\n\n- **Full Protocol Name:** IPsec Authentication Header\n- **Keyword:** `ah`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 51\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 4302\n- **Wireshark Display Filter:** `ah`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  IPsec AH (IP Proto 51)`\n\n## Overview\n\nRare in the wild because NAT breaks it on sight, yet still lurking in compliance\nchecklists and OSPFv3 auth: `ah` builds IP Protocol `51` headers with aligned\n32-bit `Payload Len` math.\n\nIPsec Authentication Header (`ah`, RFC 4302) provides connectionless integrity,\ndata-origin authentication, and anti-replay protection across the outer IP header\nand upper-layer payload **without encrypting the payload** (**IP Protocol `51`** /\nIPv6 Extension Header `51`).\n\nRFC 4302 has a subtle wire length formula: `Payload Len` is encoded in **32-bit\nwords minus `2`**, while the total AH header must be padded to a multiple of 32\nbits on IPv4 or 64 bits on IPv6. FrameAssembly computes `Payload Len` and aligns\nthe `icv` field automatically across both IPv4 and IPv6.\n\n## Minimal Quickstart (`ah_quickstart.frasm`)\n\n```frameassembly\nhost rtr_core1 { ip 10.0.51.1 }\nhost rtr_core2 { ip 10.0.51.2 }\n\ncompile {\n    rtr_core1 -> rtr_core2 ah spi 0x00002001 seq 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets outer IPv4 Protocol or IPv6 Next Header to `51` (Authentication Header).\n- Computes RFC 4302 `Payload Len = (total_ah_bytes / 4) - 2` automatically and\n  zero-pads `icv` to 4-byte (IPv4) or 8-byte (IPv6) alignment.\n- Populates 16-bit Reserved (`0x0000`), 32-bit `spi` (default `0x00000200`),\n  32-bit `seq` (default `1`), and 96-bit default `icv`.\n\n## Practical Lab Example: Authenticated Dual-Stack Router Peering Using IPsec AH (Protocol 51) (`ah_authenticated_peering.frasm`)\n\nEmits bidirectional IPv4 and IPv6 RFC 4302 Authentication Header packets\ndemonstrating 32-bit vs 64-bit ICV alignment.\n\n```frameassembly\nhost core_a_v4 { ip 172.16.51.1 }\nhost core_b_v4 { ip 172.16.51.2 }\nhost core_a_v6 { ip 2001:db8:51::1 }\nhost core_b_v6 { ip 2001:db8:51::2 }\n\ncompile {\n    // IPv4 AH (24-byte header: Payload Len = 4, 12-byte 96-bit ICV)\n    core_a_v4 -> core_b_v4 ah spi 0x00002001 seq 1 nextheader 59 icv \"00112233445566778899aabb\" payload \"cleartext-signed-v4\" wait 2ms\n    core_a_v4 <- core_b_v4 ah spi 0x00002002 seq 1 nextheader 59 icv \"aabbccddeeff001122334455\" payload \"cleartext-ack-v4\" wait 3ms\n    // IPv6 AH (aligned to 8-octet boundary per RFC 4302 §2.2)\n    core_a_v6 -> core_b_v6 ah spi 0x00062001 seq 1 nextheader 59 icv \"0102030405060708090a0b0c\" payload \"cleartext-signed-v6\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ah_authenticated_peering.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ah_authenticated_peering.frasm ah_authenticated_peering.pcap\nframeassembly ah_authenticated_peering.frasm ah_authenticated_peering.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ah_authenticated_peering.pcap ah_authenticated_peering_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ah_authenticated_peering.pcap -Y \"ah\"\n```\n\n## All `ah` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ah [spi <number>] [seq <number>] [icv\n\"<hex>\"] [nextheader <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `spi <number>` | Whole number (decimal or 0x hex) | `0x00000200` | Sets the 4-byte Security Parameters Index. |\n| `seq <number>` | Whole number | `1` | Sets the 4-byte RFC 4302 Sequence Number. |\n| `icv \"<hex>\"` | Double-quoted even-length hex string | `12-byte (96-bit) ICV` | Sets the Integrity Check Value bytes (padded automatically to 32-bit alignment on IPv4 or 64-bit alignment on IPv6). |\n| `nextheader <0..255>` | 8-bit IP protocol number | `6 (TCP) or 59 (No Next Header)` | Sets the first byte of the AH header identifying the payload immediately following the ICV. |\n\n## Cross-Layer Options Valid with `ah`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### ah Does Not Take an iv (Initialization Vector) Modifier\n\n- **Avoid:** `a -> b ah spi 0x2001 iv \"0102030405060708\"`\n- **Valid v3.3.0 Syntax:** `a -> b ah spi 0x2001 seq 1 icv\n  \"00112233445566778899aabb\"`\n\nAuthentication Header (`ah`) signs packets in cleartext without cipher encryption,\nso there is no Initialization Vector on the wire (`iv` applies to `esp`/`ipsec`).\n\n### Choose Valid Inner nextheader Codes for Wireshark Dissection\n\n- **Valid v3.3.0 Syntax:** `a -> b ah spi 0x2001 nextheader 59 payload \"raw-test\"`\n\nIf you attach an arbitrary ASCII `payload`, set `nextheader 59` (IPv6 No Next\nHeader / raw data) so Wireshark does not try to dissect the ASCII text as a\ntruncated TCP (`6`) header.\n"}
{"id":"pretrain-proto-ikev2","kind":"protocol_spec","title":"Internet Key Exchange Protocol Version 2 (ikev2) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ikev2","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ikev2"],"text":"# ikev2 — RFC 7296 VPN Key Negotiation on UDP 500 & 4500 (`ikev2`)\n\n> **FrameAssembly v3.3.0** · Protocol 32 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ikev2\n\n- **Full Protocol Name:** Internet Key Exchange Protocol Version 2\n- **Keyword:** `ikev2`\n- **OSI Layer & Transport:** Layer 3 · UDP 500 -> 500 (NAT-T 4500)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 7296, RFC 3948\n- **Wireshark Display Filter:** `isakmp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  IKEv2 (UDP 500 -> 500 (NAT-T 4500))`\n\n## Overview\n\nBefore a single `esp` packet flows, two VPN concentrators argue about crypto\nproposals over UDP `500`. `ikev2` scripts `sainit <-> auth` handshakes and NAT-T\n`dstport 4500` checks.\n\nInternet Key Exchange Version 2 (`ikev2`, RFC 7296) performs mutual authentication\nand establishes IPsec Security Associations over **UDP `500 -> 500`** (or **UDP\n`4500 -> 4500`** when NAT-Traversal is detected). Every IKEv2 packet starts with a\n28-byte header containing 64-bit Initiator and Responder SPIs (`initiatorspi`,\n`responderspi`), Next Payload type (`nextpayload` / `nextheader`), Version `0x20`\n(2.0), Exchange Type (`34..37`), Flags (`0x08` Initiator, `0x20` Response),\nMessage ID (`msgid`), and 32-bit total Length.\n\nFrameAssembly encodes valid IKEv2 headers and chained payload structures across\nall four RFC 7296 exchange modes (`sainit`, `auth`, `createchildsa`,\n`informational`).\n\n## Minimal Quickstart (`ikev2_quickstart.frasm`)\n\n```frameassembly\nhost initiator { ip 198.51.100.10 }\nhost responder { ip 203.0.113.20 }\n\ncompile {\n    initiator -> responder ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 msgid 0 wait 3ms\n    initiator <- responder ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 flags 0x20 msgid 0\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults both `srcport` and `dstport` to IANA IKE port `500` (avoiding ephemeral\n  `49152` source ports blocked by strict VPN ACLs).\n- Writes the 28-byte RFC 7296 IKEv2 header (`Version 0x20`, exact 32-bit `Length`,\n  64-bit SPIs) and defaults `responderspi` to `0` on `sainit` requests.\n- Accepts exchange modes either bare (`ikev2 auth`) or prefixed (`ikev2 exchange\n  auth`), and treats `nextheader` and `nextpayload` as exact synonyms.\n\n## Practical Lab Example: IKEv2 SA_INIT on UDP 500 Floating to NAT-Traversal UDP 4500 + DPD Check (`ikev2_natt_dpd.frasm`)\n\nTraces a complete IKEv2 phase: `SA_INIT` on UDP `500`, NAT-T port float to UDP\n`4500` for encrypted `IKE_AUTH` (`nextpayload 46`), and an `INFORMATIONAL` Dead\nPeer Detection exchange.\n\n```frameassembly\nhost branch_fw { ip 198.51.100.15 }\nhost cloud_vpn { ip 203.0.113.99 }\n\ncompile {\n    // 1. IKE_SA_INIT on UDP 500 -> 500 (Next Payload 33 = Security Association)\n    branch_fw -> cloud_vpn ikev2 sainit initiatorspi 0x9080706050403020 responderspi 0 msgid 0 flags 0x08 nextpayload 33 wait 4ms\n    branch_fw <- cloud_vpn ikev2 sainit initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 0 flags 0x20 nextpayload 33 wait 4ms\n    // 2. Float to UDP 4500 for IKE_AUTH (Next Payload 46 = Encrypted & Authenticated SK)\n    branch_fw -> cloud_vpn ikev2 auth srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 1 flags 0x08 nextpayload 46 wait 5ms\n    branch_fw <- cloud_vpn ikev2 auth srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 1 flags 0x20 nextpayload 46 wait 50ms\n    // 3. INFORMATIONAL Dead Peer Detection (DPD) liveness check\n    branch_fw -> cloud_vpn ikev2 informational srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 2 flags 0x08 nextpayload 46 wait 3ms\n    branch_fw <- cloud_vpn ikev2 informational srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 2 flags 0x20 nextpayload 46\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ikev2_natt_dpd.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ikev2_natt_dpd.frasm ikev2_natt_dpd.pcap\nframeassembly ikev2_natt_dpd.frasm ikev2_natt_dpd.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ikev2_natt_dpd.pcap ikev2_natt_dpd_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ikev2_natt_dpd.pcap -Y \"isakmp\"\n```\n\n## All `ikev2` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ikev2 [exchange\n<sainit|auth|createchildsa|informational> | sainit | auth | createchildsa |\ninformational] [initiatorspi <u64|\"hex\">] [responderspi <u64|\"hex\">] [msgid\n<number>] [flags <0..255>] [nextpayload|nextheader <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `sainit \\| auth \\| createchildsa \\| informational \\| exchange <...>` | RFC 7296 Exchange Type keyword or u8 | `sainit (34)` | Sets Exchange Type: `sainit` (`34` IKE_SA_INIT), `auth` (`35` IKE_AUTH), `createchildsa` (`36` CREATE_CHILD_SA), `informational` (`37` INFORMATIONAL). |\n| `initiatorspi <u64\\|\"hex\"> \\| responderspi <u64\\|\"hex\">` | 64-bit integer or hex string | `Deterministic initiator SPI; responderspi 0 on sainit` | Populates the 8-byte Initiator SPI and 8-byte Responder SPI in the IKEv2 header. |\n| `msgid <number>` | Whole number | `0` | Sets the 4-byte IKEv2 Message ID (`0` for `sainit`, `1` for initial `auth`, incrementing per request/response pair). |\n| `flags <0..255>` | 8-bit bitmask | `0x08 (Initiator)` | Sets RFC 7296 Flags (`0x08` = Initiator `I`, `0x10` = Version `V`, `0x20` = Response `R`; responder replies to initiator typically use `0x20`). |\n| `nextpayload <0..255> \\| nextheader <0..255>` | 8-bit IKEv2 Payload Type | `33 (SA) or 0 (None)` | Sets the first chained IKEv2 Payload Type (`33` SA, `34` KE, `40` Nonce, `46` Encrypted SK, `0` None). |\n\n## Cross-Layer Options Valid with `ikev2`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 500 -> 500 (NAT-T 4500)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Zero Underscores in Exchange Modes\n\n- **Avoid:** `a -> b ikev2 sa_init   // or create_child_sa`\n- **Valid v3.3.0 Syntax:** `a -> b ikev2 sainit    // or createchildsa`\n\nExchange modes follow the strict lowercase alphanumeric rule: `sainit`, `auth`,\n`createchildsa`, `informational`.\n\n### Set flags 0x20 on Responder Replies\n\n- **Valid v3.3.0 Syntax:** `a <- b ikev2 sainit initiatorspi 0x1122 responderspi\n  0x3344 flags 0x20`\n\nOn responder replies (`<-`), setting `flags 0x20` sets the RFC 7296 Response (`R`)\nbit and clears the Initiator (`I`) bit so Wireshark labels the packet\n`(Response)`.\n"}
{"id":"pretrain-proto-wireguard","kind":"protocol_spec","title":"WireGuard Noise_IK Secure Network Tunnel (wireguard) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/wireguard","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["wireguard"],"text":"# wireguard — Noise_IK VPN Handshakes & Data on UDP 51820 (`wireguard`)\n\n> **FrameAssembly v3.3.0** · Protocol 33 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/wireguard\n\n- **Full Protocol Name:** WireGuard Noise_IK Secure Network Tunnel\n- **Keyword:** `wireguard`\n- **OSI Layer & Transport:** Layer 3 · UDP 51820\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** WireGuard Whitepaper (NDSS 2017)\n- **Wireshark Display Filter:** `wg`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  WireGuard (UDP 51820)`\n\n## Overview\n\nFour clean message types on UDP `51820` (`initiation`, `response`, `cookie`,\n`data`) with little-endian sender/receiver indices — `wireguard` lets you test\negress VPN policies in four lines.\n\nWireGuard (`wireguard`) is a modern cryptographic VPN tunnel built on the\nNoise_IKpsk2 handshake, ChaCha20-Poly1305 AEAD, BLAKE2s, and Curve25519 over **UDP\n`dstport 51820`**. WireGuard packets are famously fixed-size during the\nhandshake—`148` bytes for Type `1` Handshake Initiation, `92` bytes for Type `2`\nHandshake Response, and `64` bytes for Type `3` Cookie Reply—plus variable-length\n16-byte padded Type `4` Transport Data packets.\n\nFrameAssembly encodes the exact little-endian WireGuard header fields (`Message\nType` + 3 zero reserved bytes, 32-bit `sender` / `receiver` session indices, and\n64-bit AEAD `counter`) and enforces exact protocol wire lengths so stateful DPI\nengines and Wireshark recognize every message type immediately.\n\n## Minimal Quickstart (`wireguard_quickstart.frasm`)\n\n```frameassembly\nhost wg_laptop { ip 198.51.100.42 }\nhost wg_relay  { ip 203.0.113.10 }\n\ncompile {\n    wg_laptop -> wg_relay wireguard initiation sender 0x01020304 wait 2ms\n    wg_laptop <- wg_relay wireguard response sender 0x0a0b0c0d receiver 0x01020304\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults UDP `dstport` to `51820` and writes the 4-byte WireGuard message header\n  (`Type` `1..4` followed by three mandatory `0x00` reserved bytes).\n- Emits exact-length handshake structures: `148` bytes for `initiation` (`Type\n  1`), `92` bytes for `response` (`Type 2`), and `64` bytes for `cookie` (`Type\n  3`).\n- Encodes `sender`, `receiver`, and 64-bit `counter` in WireGuard little-endian\n  byte order per the WireGuard specification.\n\n## Practical Lab Example: Full 1-RTT Noise_IK Handshake, Transport Data Stream, and Under-Load Cookie (`wireguard_handshake_data.frasm`)\n\nCaptures a WireGuard initiator completing a 1-RTT handshake (`initiation` +\n`response`), exchanging encrypted `data` frames with incrementing counters, and\nhandling a `cookie` challenge.\n\n```frameassembly\nhost roadwarrior { ip 198.51.100.88 }\nhost corp_wg_gw  { ip 203.0.113.5 }\n\ncompile {\n    // 1. Optional DoS Cookie Reply challenge (64 bytes, Type 3)\n    roadwarrior -> corp_wg_gw wireguard initiation sender 0x11112222 wait 2ms\n    roadwarrior <- corp_wg_gw wireguard cookie receiver 0x11112222 wait 3ms\n    // 2. Full 1-RTT Noise_IKpsk2 Handshake (148B Initiation -> 92B Response)\n    roadwarrior -> corp_wg_gw wireguard initiation sender 0x33334444 wait 2ms\n    roadwarrior <- corp_wg_gw wireguard response sender 0xaaaabbbb receiver 0x33334444 wait 2ms\n    // 3. Encrypted Transport Data packets (Type 4) swapping receiver indices\n    roadwarrior -> corp_wg_gw wireguard data receiver 0xaaaabbbb counter 0 payload \"inner-ipv4-syn\" wait 1ms\n    roadwarrior <- corp_wg_gw wireguard data receiver 0x33334444 counter 0 payload \"inner-ipv4-synack\" wait 1ms\n    roadwarrior -> corp_wg_gw wireguard data receiver 0xaaaabbbb counter 1 payload \"inner-ipv4-ack\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show wireguard_handshake_data.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly wireguard_handshake_data.frasm wireguard_handshake_data.pcap\nframeassembly wireguard_handshake_data.frasm wireguard_handshake_data.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse wireguard_handshake_data.pcap wireguard_handshake_data_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r wireguard_handshake_data.pcap -Y \"wg\"\n```\n\n## All `wireguard` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host wireguard [type\n<initiation|response|cookie|data> | initiation | response | cookie | data] [sender\n<number>] [receiver <number>] [counter <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `initiation \\| response \\| cookie \\| data \\| type <...>` | WireGuard message type keyword | `initiation (Type 1)` | Selects Type `1` Handshake Initiation (`148B`), Type `2` Handshake Response (`92B`), Type `3` Cookie Reply (`64B`), or Type `4` Transport Data (`>= 32B`). |\n| `sender <number>` | Whole number | `1` | Sets the 32-bit Sender Index in `initiation` and `response` messages identifying the local session slot. |\n| `receiver <number>` | Whole number | `2` | Sets the 32-bit Receiver Index in `response`, `cookie`, and `data` messages referencing the peer Sender Index. |\n| `counter <number>` | Whole number | `0` | Sets the 64-bit ChaCha20-Poly1305 AEAD nonce counter in Type `4` `data` packets. |\n\n## Cross-Layer Options Valid with `wireguard`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 51820` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Match receiver on Data Frames to the Peer sender Index\n\n- **Valid v3.3.0 Syntax:** `a -> b wireguard response sender 0x99 receiver 0x11\na <- b wireguard data receiver 0x99 counter 0`\n\nWireGuard Transport Data (`data`) frames only carry the destination peer\n`receiver` index (not `sender`), which must match the `sender` index advertised by\nthat peer during the handshake.\n\n### Use counter (Not seq) for AEAD Packet Nonces\n\n- **Avoid:** `a -> b wireguard data seq 1`\n- **Valid v3.3.0 Syntax:** `a -> b wireguard data receiver 0x99 counter 1`\n\nBecause WireGuard runs over UDP rather than TCP, TCP `seq` is not valid here. Use\n`counter` for the 64-bit WireGuard packet counter.\n"}
{"id":"pretrain-proto-ospf","kind":"protocol_spec","title":"Open Shortest Path First — OSPFv2 & Dual-Stack OSPFv3 (ospf) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ospf","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ospf"],"text":"# ospf — Dual-Stack OSPFv2 & OSPFv3 Link-State Adjacencies (`ospf`)\n\n> **FrameAssembly v3.3.0** · Protocol 34 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ospf\n\n- **Full Protocol Name:** Open Shortest Path First — OSPFv2 & Dual-Stack OSPFv3\n- **Keyword:** `ospf`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 89 (TTL 1)\n- **Host Endpoint Rule:** Dual-Stack Morphing (v4/v6)\n- **Standards:** RFC 2328, RFC 5340\n- **Wireshark Display Filter:** `ospf`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  OSPFv2 / OSPFv3 (IP Proto 89 (TTL 1))`\n\n## Overview\n\nMismatched hello/dead timers have caused more silent routing blackholes than fiber\nbackhoes. `ospf` builds IPv4 OSPFv2 (Fletcher-16 checksum) and IPv6 OSPFv3\n(ICMPv6-style pseudo-header checksum) automatically.\n\nOpen Shortest Path First (`ospf`) is the enterprise and service-provider\nlink-state Interior Gateway Protocol running directly over **IP Protocol `89`**\nwith link-local `ttl 1`. In FrameAssembly v3.2.0, `ospf` is **dual-stack\nmorphing**: over IPv4 hosts, it emits **OSPFv2** (RFC 2328, 24-byte header, RFC\n1071 checksum omitting the 64-bit authentication field); over IPv6 hosts, the\nexact same syntax emits **OSPFv3** (RFC 5340, Version `3`, 16-byte header,\nInstance ID `0`, and full IPv6 pseudo-header checksum).\n\nAll five OSPF packet types (`hello`, `dbd`, `lsr`, `lsu`, `lsack`) are natively\ngenerated, including valid **Fletcher-16 (`ISO 8473`) LSA checksums** on Link\nState Update and Acknowledgment records.\n\n## Minimal Quickstart (`ospf_quickstart.frasm`)\n\n```frameassembly\nhost rtr_a { ip 10.0.0.1 }\nhost rtr_b { ip 10.0.0.2 }\n\ncompile {\n    rtr_a -> rtr_b ospf hello routerid 1.1.1.1 areaid 0\n}\n```\n\n### Automatic Wire Calculations\n\n- Selects OSPFv2 (24B header, IPv4 Proto `89`) over IPv4 hosts or OSPFv3 (16B\n  header, IPv6 Next Header `89`, IPv6 pseudo-header checksum) over IPv6 hosts.\n- Defaults IP `ttl` / Hop Limit to `1` and derives multicast destination MACs\n  automatically when sending to `224.0.0.5` / `224.0.0.6` or `ff02::5` /\n  `ff02::6`.\n- Computes both the outer OSPF packet checksum and inner ISO 8473 Fletcher-16 LSA\n  checksums on `lsu` and `lsack` packets.\n\n## Practical Lab Example: Full OSPF Adjacency Synchronization Plus OSPFv3 IPv6 Backbone Hello (`ospf_adjacency_v2_v3.frasm`)\n\nWalks two core routers through OSPFv2 `hello`, `dbd`, `lsr`, `lsu`, and `lsack`\nexchange on Area 0, followed by an OSPFv3 IPv6 Hello using 32-bit `routerid`.\n\n```frameassembly\nhost core_1_v4 { ip 172.16.0.1 }\nhost core_2_v4 { ip 172.16.0.2 }\nhost allspf_v6 { ip ff02::5 }\nhost core_1_v6 { ip fe80::1c73:1 }\n\ncompile {\n    // 1. OSPFv2 Area 0 adjacency bring-up and LSA exchange\n    core_1_v4 -> core_2_v4 ospf hello routerid 1.1.1.1 areaid 0 hellointerval 10 deadinterval 40 priority 100 dscp 48 wait 2ms\n    core_1_v4 <- core_2_v4 ospf hello routerid 2.2.2.2 areaid 0 hellointerval 10 deadinterval 40 priority 1 dscp 48 wait 2ms\n    core_1_v4 -> core_2_v4 ospf dbd routerid 1.1.1.1 areaid 0 dscp 48 wait 1ms\n    core_1_v4 <- core_2_v4 ospf lsr routerid 2.2.2.2 areaid 0 dscp 48 wait 1ms\n    core_1_v4 -> core_2_v4 ospf lsu routerid 1.1.1.1 areaid 0 dscp 48 wait 1ms\n    core_1_v4 <- core_2_v4 ospf lsack routerid 2.2.2.2 areaid 0 dscp 48 wait 4ms\n    // 2. OSPFv3 over IPv6 multicast ff02::5 (routerid stays 32-bit dotted-quad!)\n    core_1_v6 -> allspf_v6 ospf hello routerid 1.1.1.1 areaid 0.0.0.0 hellointerval 10 deadinterval 40\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ospf_adjacency_v2_v3.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ospf_adjacency_v2_v3.frasm ospf_adjacency_v2_v3.pcap\nframeassembly ospf_adjacency_v2_v3.frasm ospf_adjacency_v2_v3.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ospf_adjacency_v2_v3.pcap ospf_adjacency_v2_v3_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ospf_adjacency_v2_v3.pcap -Y \"ospf\"\n```\n\n## All `ospf` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ospf [hello | dbd | lsr | lsu | lsack]\n[routerid <ipv4>] [areaid <u32|ipv4>] [hellointerval <0..65535>] [deadinterval\n<number>] [priority <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `hello \\| dbd \\| lsr \\| lsu \\| lsack` | OSPF Packet Type keyword | `hello (Type 1)` | Selects Type `1` Hello, Type `2` Database Description (`dbd`), Type `3` Link State Request (`lsr`), Type `4` Link State Update (`lsu`), or Type `5` Link State Acknowledgment (`lsack`). |\n| `routerid <ipv4>` | 32-bit dotted-quad IPv4 format (e.g. 1.1.1.1) | `Source IPv4 (or 1.1.1.1 on IPv6)` | Sets the 32-bit OSPF Router ID in both OSPFv2 and OSPFv3 headers. |\n| `areaid <u32\\|ipv4>` | u32 integer (0) or dotted-quad (0.0.0.0) | `0 (Backbone Area 0.0.0.0)` | Sets the 32-bit OSPF Area ID. |\n| `hellointerval <0..65535> \\| deadinterval <number>` | Timers in seconds | `hellointerval 10, deadinterval 40` | Sets the Hello Interval (`u16` seconds) and Router Dead Interval (`u32` OSPFv2 / `u16` OSPFv3) in `hello` packets. |\n| `priority <0..255>` | Whole number (0..255) | `1` | Sets the Designated Router (DR) Election Priority (`0` = ineligible to become DR/BDR). |\n\n## Cross-Layer Options Valid with `ospf`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 1, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### OSPFv3 routerid Always Remains 32-Bit Dotted-Quad (RFC 5340)\n\n- **Avoid:** `core_1_v6 -> core_2_v6 ospf hello routerid 2001:db8::1`\n- **Valid v3.3.0 Syntax:** `core_1_v6 -> core_2_v6 ospf hello routerid 1.1.1.1`\n\nPer RFC 5340 §2.11, OSPFv3 retains 32-bit Router IDs and Area IDs formatted in\ndotted-quad notation (`1.1.1.1`) even when running over 128-bit IPv6 endpoints.\n\n### Zero Underscores in Timer Modifiers\n\n- **Avoid:** `r1 -> r2 ospf hello router_id 1.1.1.1 hello_interval 10`\n- **Valid v3.3.0 Syntax:** `r1 -> r2 ospf hello routerid 1.1.1.1 hellointerval 10\n  deadinterval 40`\n\nUse `routerid`, `areaid`, `hellointerval`, and `deadinterval` with zero\nunderscores.\n"}
{"id":"pretrain-proto-bgp","kind":"protocol_spec","title":"Border Gateway Protocol 4 & 4-Byte ASN Capability (bgp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/bgp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["bgp"],"text":"# bgp — Stateful TCP 179 Peering, NLRI & 4-Byte ASN Magic (`bgp`)\n\n> **FrameAssembly v3.3.0** · Protocol 35 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/bgp\n\n- **Full Protocol Name:** Border Gateway Protocol 4 & 4-Byte ASN Capability\n- **Keyword:** `bgp`\n- **OSI Layer & Transport:** Layer 3 · TCP 179\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 4271, RFC 6793\n- **Wireshark Display Filter:** `bgp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  BGP-4 / 4-Byte ASN (TCP 179)`\n\n## Overview\n\nPass `asn 4200000001` on `bgp open` and the compiler automatically drops\n`AS_TRANS` (`23456`) into the legacy 16-bit slot plus RFC 6793 Capability `65`,\nriding right on top of stateful TCP port `179`.\n\nBorder Gateway Protocol 4 (`bgp`, RFC 4271) exchanges inter-domain and data-center\nleaf-spine routes over **TCP port `179`**. Every BGP message starts with a 16-byte\nall-ones (`ff..ff`) marker, 16-bit Message Length (`19..4096`), and 8-bit Type\n(`1` `open`, `2` `update`, `3` `notification`, `4` `keepalive`).\n\nFrameAssembly tracks TCP sequence and acknowledgment numbers automatically across\n`tcp` and `bgp` packets—and when you pass a **4-byte ASN (`asn > 65535`, e.g.\n`4200000001`)** on `bgp open`, it automatically sets `AS_TRANS` (`23456`) in the\n16-bit header field and adds **RFC 6793 Capability Code `65`** with the full\n4-byte ASN.\n\n## Minimal Quickstart (`bgp_quickstart.frasm`)\n\n```frameassembly\nhost spine_01 { ip 10.255.0.1 }\nhost leaf_01  { ip 10.255.0.2 }\n\ncompile {\n    spine_01 -> leaf_01 bgp open asn 65001 holdtime 90 bgpid 10.255.0.1 wait 2ms\n    spine_01 <- leaf_01 bgp open asn 65101 holdtime 90 bgpid 10.255.0.2 wait 2ms\n    spine_01 -> leaf_01 bgp keepalive\n}\n```\n\n### Automatic Wire Calculations\n\n- Tracks TCP sequence and acknowledgment numbers automatically on port `179` (`psh\n  ack` flags set by default) and prepends the 16-byte `ff..ff` BGP marker.\n- On `bgp open` with `asn > 65535`, writes `AS_TRANS` (`23456`) in the 16-bit My\n  AS field and encodes Optional Parameter `2` (Capabilities) -> Capability `65`\n  (4-octet AS) with the full 32-bit `asn`.\n- On `bgp update`, encodes well-known mandatory Path Attributes (`ORIGIN = IGP`,\n  `AS_PATH`, `NEXT_HOP`) and bit-packed CIDR `NLRI` (`prefix` / `nlri`).\n\n## Practical Lab Example: Stateful TCP Handshake + 4-Byte ASN eBGP Peering & Route Advertisement (`bgp_4byte_asn_session.frasm`)\n\nEstablishes a GTSM-protected (`ttl 255`) TCP 179 session between two 4-byte ASN\nswitches (`4200000001` and `4200000101`), exchanges `OPEN` + `KEEPALIVE`, and\nadvertises `10.100.0.0/16`.\n\n```frameassembly\nhost leaf_tor  { ip 172.16.255.1 }\nhost spine_agg { ip 172.16.255.2 }\n\ncompile {\n    // 1. Stateful TCP 3-way handshake on port 179 with GTSM (ttl 255) and CS6 (dscp 48)\n    leaf_tor -> spine_agg tcp syn srcport 53179 dstport 179 win 65535 mss 1460 ttl 255 dscp 48 wait 1ms\n    leaf_tor <- spine_agg tcp syn ack win 65535 mss 1460 ttl 255 dscp 48 wait 1ms\n    leaf_tor -> spine_agg tcp ack ttl 255 dscp 48 wait 1ms\n    // 2. 4-Byte ASN OPEN negotiation (auto-encodes AS_TRANS 23456 + Capability 65)\n    leaf_tor -> spine_agg bgp open asn 4200000101 holdtime 90 bgpid 10.0.1.1 ttl 255 dscp 48 wait 2ms\n    leaf_tor <- spine_agg bgp open asn 4200000001 holdtime 90 bgpid 10.0.0.1 ttl 255 dscp 48 wait 2ms\n    leaf_tor -> spine_agg bgp keepalive ttl 255 dscp 48 wait 1ms\n    leaf_tor <- spine_agg bgp keepalive ttl 255 dscp 48 wait 2ms\n    // 3. Advertise tenant CIDR 10.100.0.0/16 via BGP UPDATE\n    leaf_tor -> spine_agg bgp update asn 4200000101 prefix \"10.100.0.0/16\" nexthop 172.16.255.1 ttl 255 dscp 48\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show bgp_4byte_asn_session.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly bgp_4byte_asn_session.frasm bgp_4byte_asn_session.pcap\nframeassembly bgp_4byte_asn_session.frasm bgp_4byte_asn_session.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse bgp_4byte_asn_session.pcap bgp_4byte_asn_session_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r bgp_4byte_asn_session.pcap -Y \"bgp\"\n```\n\n## All `bgp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host bgp [open | update | notification |\nkeepalive] [asn <number>] [holdtime <0..65535>] [bgpid <ipv4>] [prefix|nlri\n<str|ip>] [nexthop <ip>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `open \\| update \\| notification \\| keepalive` | BGP message type keyword | `keepalive (Type 4)` | Selects Type `1` OPEN, Type `2` UPDATE, Type `3` NOTIFICATION (Cease error), or Type `4` 19-byte KEEPALIVE. |\n| `asn <number>` | 16-bit or 32-bit Autonomous System Number | `65001` | Sets the Autonomous System in `open` (`<= 65535` direct; `> 65535` `AS_TRANS` `23456` + Capability `65`) and `AS_PATH` in `update`. |\n| `holdtime <0..65535>` | Whole number (0..65535) (seconds) | `180` | Sets the BGP Hold Time in `open` (`0` or `>= 3` seconds per RFC 4271). |\n| `bgpid <ipv4>` | 32-bit dotted-quad identifier | `Source IPv4 (or 1.1.1.1 on IPv6)` | Sets the 4-byte BGP Identifier in `open` messages (always 32-bit dotted-quad on both v4 and v6). |\n| `prefix <str\\|ip> \\| nlri <str\\|ip>` | CIDR string (\"10.20.0.0/16\") or IP literal | `\"10.0.0.0/24\"` | Encodes Network Layer Reachability Information (`nlri` is an exact alias for `prefix`) in `update` messages. |\n| `nexthop <ip>` | IPv4 or IPv6 address literal | `Source host IP` | Sets the `NEXT_HOP` path attribute inside `bgp update` messages. |\n\n## Cross-Layer Options Valid with `bgp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 179` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Quote CIDR Prefixes in bgp update (Never Put /24 in host Blocks)\n\n- **Avoid:** `host r1 { ip 10.0.0.1/24 }\nr1 -> r2 bgp update prefix 10.20.0.0/16`\n- **Valid v3.3.0 Syntax:** `host r1 { ip 10.0.0.1 }\nr1 -> r2 bgp update prefix \"10.20.0.0/16\"`\n\n`host` declarations take plain IP literals without CIDR slashes, while CIDR\nstrings in `bgp update prefix \"10.20.0.0/16\"` must be wrapped in double quotes.\n\n### bgpid Is Always 32-Bit Dotted-Quad Even Over IPv6 eBGP\n\n- **Avoid:** `r6_a -> r6_b bgp open asn 65001 bgpid 2001:db8::1`\n- **Valid v3.3.0 Syntax:** `r6_a -> r6_b bgp open asn 65001 bgpid 10.0.0.1`\n\nPer RFC 4271 and RFC 6286, the BGP Identifier is always a 4-octet 32-bit\ndotted-quad (`10.0.0.1`) regardless of whether TCP 179 runs over IPv4 or IPv6.\n"}
{"id":"pretrain-proto-rip","kind":"protocol_spec","title":"Routing Information Protocol — RIPv2 & Dual-Stack RIPng (rip) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/rip","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["rip"],"text":"# rip — RIPv2 (UDP 520) & IPv6 RIPng (UDP 521) Route Updates (`rip`)\n\n> **FrameAssembly v3.3.0** · Protocol 36 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/rip\n\n- **Full Protocol Name:** Routing Information Protocol — RIPv2 & Dual-Stack RIPng\n- **Keyword:** `rip`\n- **OSI Layer & Transport:** Layer 3 · UDP 520 (RIPv2) / UDP 521 (RIPng)\n- **Host Endpoint Rule:** Dual-Stack Morphing (v4/v6)\n- **Standards:** RFC 2453, RFC 2080\n- **Wireshark Display Filter:** `rip || ripng`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  RIPv2 / RIPng (UDP 520 (RIPv2) / UDP 521 (RIPng))`\n\n## Overview\n\nEvery textbook swears RIP died in 1998, right up until you inherit a branch router\nrunning it. `rip` builds RIPv2 (`520`) over IPv4 and RIPng (`521`) over IPv6,\nright up to `metric 16` poison reverse.\n\nRouting Information Protocol (`rip`) is a distance-vector routing protocol limited\nto a maximum hop count of `15` (`metric 16` = infinity / route poison). In\nFrameAssembly v3.2.0, `rip` morphs automatically by address family: between IPv4\nhosts, it emits **RIPv2** (RFC 2453, **UDP `520 -> 520`**, 20-byte Route Table\nEntry with Route Tag, Subnet Mask, Next Hop, and 32-bit Metric); between IPv6\nhosts, it emits **RIPng** (RFC 2080, **UDP `521 -> 521`**, Version `1`, 20-byte\nIPv6 Prefix RTE).\n\nBoth `request` (`command 1`) and `response`/`reply` (`command 2`) messages compile\ncleanly with zero boilerplate.\n\n## Minimal Quickstart (`rip_quickstart.frasm`)\n\n```frameassembly\nhost branch_rtr { ip 10.10.0.1 }\nhost edge_rtr   { ip 10.10.0.2 }\n\ncompile {\n    branch_rtr -> edge_rtr rip request wait 2ms\n    branch_rtr <- edge_rtr rip response prefix 10.200.0.0 metric 2 tag 100\n}\n```\n\n### Automatic Wire Calculations\n\n- Selects RIPv2 on UDP `520 -> 520` over IPv4 hosts or RIPng on UDP `521 -> 521`\n  over IPv6 hosts.\n- Populates Address Family Identifier `2` (`AF_INET`), `255.255.255.0` default\n  mask, Route Tag, Next Hop, and Metric in RIPv2—or 128-bit IPv6 prefix +\n  prefix-length + 8-bit metric in RIPng.\n- Derives RFC multicast Ethernet MACs automatically when sending to `224.0.0.9`\n  (RIPv2) or `ff02::9` (RIPng).\n\n## Practical Lab Example: RIPv2 Multicast Update, Route Poisoning (Metric 16), and IPv6 RIPng (`rip_v2_ripng.frasm`)\n\nShows a branch router advertising `10.50.10.0` (`metric 2`), subsequently\npoisoning the route (`metric 16`) upon link loss, and advertising an IPv6 prefix\nover RIPng (`ff02::9`).\n\n```frameassembly\nhost rtr_branch { ip 172.16.10.2 }\nhost rip_mcast  { ip 224.0.0.9 }\nhost rtr6_a     { ip fe80::10:1 }\nhost ripng_all  { ip ff02::9 }\n\ncompile {\n    // 1. Periodic RIPv2 multicast advertisement (metric 2, route tag 65010)\n    rtr_branch -> rip_mcast rip response prefix 10.50.10.0 nexthop 0.0.0.0 metric 2 tag 65010 ttl 2 wait 10ms\n    // 2. Triggered route-poison update (metric 16 = infinity / unreachable)\n    rtr_branch -> rip_mcast rip response prefix 10.50.10.0 nexthop 0.0.0.0 metric 16 tag 65010 ttl 2 wait 5ms\n    // 3. IPv6 RIPng advertisement on UDP 521 -> 521 to ff02::9\n    rtr6_a -> ripng_all rip response prefix 2001:db8:50:: metric 1 tag 100 ttl 255\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show rip_v2_ripng.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly rip_v2_ripng.frasm rip_v2_ripng.pcap\nframeassembly rip_v2_ripng.frasm rip_v2_ripng.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse rip_v2_ripng.pcap rip_v2_ripng_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r rip_v2_ripng.pcap -Y \"rip || ripng\"\n```\n\n## All `rip` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host rip [request | response | reply]\n[prefix <ip>] [metric <1..16>] [nexthop <ip>] [tag <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `request \\| response \\| reply \\| command <1\\|2>` | RIP Command selector | `response (Command 2)` | Selects Command `1` (`request`) or Command `2` (`response` / `reply`). |\n| `prefix <ip>` | IPv4 or IPv6 address literal (no /CIDR slash) | `10.0.0.0 (v4) / 2001:db8:: (v6)` | Sets the advertised destination network address in the Route Table Entry. |\n| `metric <1..16>` | Hop count integer (1..16) | `1` | Sets the route hop-count metric (`1..15` reachable hops, `16` infinity / unreachable). |\n| `nexthop <ip>` | IPv4 address literal | `0.0.0.0 (advertising router)` | Sets the immediate Next Hop IP in RIPv2 (`0.0.0.0` means use the UDP packet source IP). |\n| `tag <0..65535>` | Whole number (0..65535) | `0` | Sets the 16-bit external Route Tag (often carrying redistributed BGP ASN). |\n\n## Cross-Layer Options Valid with `rip`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 520 (RIPv2) / UDP 521 (RIPng)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Pass Plain IP Literals to rip prefix (No /24 Suffix)\n\n- **Avoid:** `r1 -> r2 rip response prefix \"10.50.10.0/24\"`\n- **Valid v3.3.0 Syntax:** `r1 -> r2 rip response prefix 10.50.10.0 metric 2`\n\nUnlike `bgp update prefix \"10.20.0.0/16\"`, `rip prefix <ip>` expects an unquoted\nIPv4 or IPv6 address literal (`10.50.10.0` or `2001:db8:50::`).\n\n### Valid Hop-Count Metric Bounds (1..16)\n\n- **Avoid:** `r1 -> r2 rip response metric 255`\n- **Valid v3.3.0 Syntax:** `r1 -> r2 rip response metric 16`\n\nPer RFC 2453, RIP metrics range from `1` to `16` (`16` = infinity).\n"}
{"id":"pretrain-proto-pim","kind":"protocol_spec","title":"Protocol Independent Multicast — Sparse Mode (pim) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/pim","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["pim"],"text":"# pim — RFC 7761 Sparse-Mode Multicast Hellos, Joins & RP (`pim`)\n\n> **FrameAssembly v3.3.0** · Protocol 37 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/pim\n\n- **Full Protocol Name:** Protocol Independent Multicast — Sparse Mode\n- **Keyword:** `pim`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 103\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 7761\n- **Wireshark Display Filter:** `pim`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  PIM-SM (IP Proto 103)`\n\n## Overview\n\nDebug Rendezvous Points (`rp`) without a 6-router multicast lab: `pim` emits IP\nProtocol `103` `hello`, `joinprune`, and `register` frames with proper RFC 7761\nencoded unicast/group addresses.\n\nProtocol Independent Multicast — Sparse Mode (`pim`, RFC 7761) builds shared\n(`*,G`) and shortest-path (`S,G`) multicast distribution trees across Layer 3\nrouters over **IP Protocol `103`** (`PIMv2`, header byte `0x20`).\n\nFrameAssembly encodes PIMv2 `hello` neighbor discovery (`Type 0`, carrying\nHoldtime TLV 1 and DR Priority TLV 19), unicast First-Hop Router `register` (`Type\n1` to the Rendezvous Point, checksumming **only the 8-byte PIMv2 header**\nexcluding encapsulated multicast data per RFC 7761 §4.9), and `joinprune` (`Type\n3` carrying Encoded-Group and Encoded-Source addresses) across both IPv4 and IPv6.\n\n## Minimal Quickstart (`pim_quickstart.frasm`)\n\n```frameassembly\nhost fhr_leaf { ip 172.16.20.1 }\nhost core_rp  { ip 172.16.0.1 }\n\ncompile {\n    fhr_leaf -> core_rp pim hello holdtime 105 drpriority 100 wait 3ms\n    fhr_leaf -> core_rp pim register group 239.10.10.1 source 10.10.1.50 rp 172.16.0.1\n}\n```\n\n### Automatic Wire Calculations\n\n- Encapsulates over IPv4 Protocol `103` or IPv6 Next Header `103` with PIM Version\n  `2` (`0x20`).\n- Computes full-message checksums (including IPv6 pseudo-header on v6) for `hello`\n  and `joinprune`, while restricting `register` checksums to the 8-byte PIMv2\n  header per RFC 7761 §4.9.\n- Derives multicast Ethernet MACs automatically when targeting `224.0.0.13`\n  (`ALL-PIM-ROUTERS`) or `ff02::d`.\n\n## Practical Lab Example: End-to-End Multicast Control Plane: IGMPv3 Join + PIM Hello, Join/Prune & Register (`pim_multicast_tree.frasm`)\n\nCombines a receiver `igmp v3 report` with upstream `pim hello`, `(S,G)`\n`joinprune`, and First-Hop `pim register` signaling to the Rendezvous Point.\n\n```frameassembly\nhost receiver_01 { ip 10.40.1.50 }\nhost lhr_router  { ip 10.40.1.1 }\nhost pim_mcast   { ip 224.0.0.13 }\nhost core_rp     { ip 172.16.255.1 }\n\ncompile {\n    // 1. PIMv2 Hello on multicast 224.0.0.13 electing DR (drpriority 200)\n    lhr_router -> pim_mcast pim hello holdtime 105 drpriority 200 ttl 1 dscp 48 wait 2ms\n    // 2. Receiver joins SSM channel 232.10.10.5 on LAN\n    receiver_01 -> lhr_router igmp v3 report group 232.10.10.5 wait 2ms\n    // 3. Last-Hop Router sends PIM Join/Prune upstream toward source 10.10.5.100\n    lhr_router -> core_rp pim joinprune group 232.10.10.5 source 10.10.5.100 holdtime 210 dscp 48 wait 3ms\n    // 4. Unicast PIM Register encapsulated to Rendezvous Point\n    lhr_router -> core_rp pim register group 239.20.20.1 source 10.40.1.50 rp 172.16.255.1 ttl 64 dscp 48\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show pim_multicast_tree.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly pim_multicast_tree.frasm pim_multicast_tree.pcap\nframeassembly pim_multicast_tree.frasm pim_multicast_tree.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse pim_multicast_tree.pcap pim_multicast_tree_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r pim_multicast_tree.pcap -Y \"pim\"\n```\n\n## All `pim` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host pim [hello | joinprune | register]\n[holdtime <0..65535>] [drpriority <number>] [group <ip>] [source <ip>] [rp <ip>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `hello \\| joinprune \\| register` | PIMv2 Message Type keyword | `hello (Type 0)` | Selects Type `0` Hello, Type `1` unicast Register (to RP), or Type `3` Join/Prune. |\n| `holdtime <0..65535>` | Whole number (0..65535) (seconds) | `105 (3.5x 30s Hello)` | Encodes Holdtime Option TLV `1` in `hello` or Holdtime field in `joinprune` (`0xffff` = never expire). |\n| `drpriority <number>` | Whole number | `1` | Encodes Designated Router Priority Option TLV `19` in `pim hello` messages. |\n| `group <ip> \\| source <ip> \\| rp <ip>` | IPv4 or IPv6 address literals | `239.1.1.1 / endpoint IPs` | Sets the multicast Group, unicast Source `(S,G)`, and Rendezvous Point addresses in `joinprune` and `register` packets. |\n\n## Cross-Layer Options Valid with `pim`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### Spell joinprune and drpriority Without Underscores or Slashes\n\n- **Avoid:** `r1 -> r2 pim join_prune dr_priority 100`\n- **Valid v3.3.0 Syntax:** `r1 -> r2 pim joinprune drpriority 100`\n\nAll built-in PIM tokens are strictly lowercase alphanumeric (`joinprune`,\n`drpriority`, `holdtime`).\n\n### Match Address Families Across group, source, and Endpoints\n\n- **Avoid:** `rtr6_a -> rtr6_b pim joinprune group 239.1.1.1`\n- **Valid v3.3.0 Syntax:** `rtr6_a -> rtr6_b pim joinprune group ff05::100 source\n  2001:db8::10`\n\nWhen running `pim` over IPv6 routers, pass IPv6 multicast `group` (`ffxx::`) and\nIPv6 `source` literals.\n"}
{"id":"pretrain-proto-vrrp","kind":"protocol_spec","title":"Virtual Router Redundancy Protocol v2 & v3 (vrrp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/vrrp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vrrp"],"text":"# vrrp — VRRPv2 & VRRPv3 First-Hop Gateway Heartbeats (`vrrp`)\n\n> **FrameAssembly v3.3.0** · Protocol 38 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/vrrp\n\n- **Full Protocol Name:** Virtual Router Redundancy Protocol v2 & v3\n- **Keyword:** `vrrp`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 112 (TTL 255)\n- **Host Endpoint Rule:** Dual-Stack Morphing (v4/v6)\n- **Standards:** RFC 3768, RFC 5798\n- **Wireshark Display Filter:** `vrrp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  VRRPv2 / VRRPv3 (IP Proto 112 (TTL 255))`\n\n## Overview\n\nWhen two routers both claim Priority `255` because a trunk VLAN blocked IP\nProtocol `112`, chaos ensues. `vrrp` emits `ttl 255` advertisements for both\nVRRPv2 and VRRPv3 (`00:00:5e:00:01:<vrid>`).\n\nVirtual Router Redundancy Protocol (`vrrp`) provides standards-based First-Hop\nRedundancy (FHRP) over **IP Protocol `112`** with mandatory **TTL / Hop Limit\n`255`** (routers discard any VRRP packet arriving with `TTL != 255`).\n\nFrameAssembly defaults to **VRRPv2** (`version 2`, RFC 3768, `advint` in whole\nseconds, ones-complement checksum) over IPv4 endpoints and automatically upgrades\nto **VRRPv3** (`version 3`, RFC 5798, 12-bit `Max Advver Int` in centiseconds,\npseudo-header checksum) over IPv6 endpoints—or when `version 3` is explicitly\nrequested on IPv4.\n\n## Minimal Quickstart (`vrrp_quickstart.frasm`)\n\n```frameassembly\nhost gw_master { ip 10.10.1.2 mac 00:00:5e:00:01:0a }\nhost vrrp_all  { ip 224.0.0.18 }\n\ncompile {\n    gw_master -> vrrp_all vrrp vrid 10 priority 150 advint 1 vip 10.10.1.1\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets IPv4 Protocol / IPv6 Next Header to `112` and defaults `ttl` / Hop Limit to\n  `255` per RFC 3768 / RFC 5798.\n- Selects VRRPv2 (`version 2`) over IPv4 and VRRPv3 (`version 3`, 12-bit\n  centisecond `Max Adver Int` + pseudo-header checksum) over IPv6 automatically.\n- Derives multicast Ethernet MAC `01:00:5e:00:00:12` (`224.0.0.18`) or\n  `33:33:00:00:00:12` (`ff02::12`) automatically.\n\n## Practical Lab Example: Graceful VRRP Master Shutdown (Priority 0), Backup Takeover & VRRPv3 IPv6 (`vrrp_failover_v2_v3.frasm`)\n\nTraces VRID 10 on VLAN 10 where the primary router sends a `priority 0` release,\nthe backup router assumes mastership + sends GARP, alongside an IPv6 VRRPv3\nadvertisement.\n\n```frameassembly\nhost rtr_pri   { ip 10.10.10.2 mac 00:00:5e:00:01:0a }\nhost rtr_bkp   { ip 10.10.10.3 mac 00:00:5e:00:01:0a }\nhost vrrp_v4   { ip 224.0.0.18 }\nhost rtr6_pri  { ip fe80::10:2 mac 00:00:5e:00:02:0a }\nhost vrrp_v6   { ip ff02::12 }\n\ncompile {\n    // 1. Primary router steady-state VRRPv2 heartbeat (VRID 10, Priority 150)\n    rtr_pri -> vrrp_v4 vrrp vrid 10 priority 150 advint 1 vip 10.10.10.1 vlan 10 pcp 6 wait 5ms\n    // 2. Primary router initiates graceful shutdown (Priority 0 triggers immediate takeover)\n    rtr_pri -> vrrp_v4 vrrp vrid 10 priority 0 advint 1 vip 10.10.10.1 vlan 10 pcp 6 wait 2ms\n    // 3. Backup router promotes to Master (Priority 120) and broadcasts GARP for VIP\n    rtr_bkp -> vrrp_v4 vrrp vrid 10 priority 120 advint 1 vip 10.10.10.1 vlan 10 pcp 6 wait 1ms\n    rtr_bkp -> vrrp_v4 arp gratuitous sendermac 00:00:5e:00:01:0a senderip 10.10.10.1 vlan 10 wait 3ms\n    // 4. Dual-stack VRRPv3 over IPv6 (advint 100 = 100 centiseconds = 1.00s)\n    rtr6_pri -> vrrp_v6 vrrp version 3 vrid 10 priority 150 advint 100 vip fe80::10:1 vlan 10\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show vrrp_failover_v2_v3.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly vrrp_failover_v2_v3.frasm vrrp_failover_v2_v3.pcap\nframeassembly vrrp_failover_v2_v3.frasm vrrp_failover_v2_v3.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse vrrp_failover_v2_v3.pcap vrrp_failover_v2_v3_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r vrrp_failover_v2_v3.pcap -Y \"vrrp\"\n```\n\n## All `vrrp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host vrrp [vrid <1..255>] [priority\n<0..255>] [advint <0..65535>] [vip <ip>] [version <2|3>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `vrid <1..255>` | 8-bit Virtual Router Identifier (1..255) | `1` | Sets the VRID (matches standard virtual MAC `00:00:5e:00:01:<vrid_hex>` on v4 or `00:00:5e:00:02:<vrid_hex>` on v6). |\n| `priority <0..255>` | 8-bit election priority (0..255) | `100` | Sets router election priority (`255` = IP address owner, `100` = default backup, `0` = current Master releasing virtual router). |\n| `advint <0..65535>` | u8 seconds (v2) or 12-bit centiseconds (v3) | `1 (v2) / 100 (v3)` | Sets Advertisement Interval (`1` second in VRRPv2; `100` centiseconds = `1.00s` in VRRPv3). |\n| `vip <ip>` | IPv4 or IPv6 Virtual IP address | `Source host IP` | Populates the Virtual Router IPv4/IPv6 Address field (`Count IPvX Addr = 1`). |\n| `version <2\\|3>` | 2 or 3 | `2 (IPv4) / 3 (IPv6)` | Selects RFC 3768 VRRPv2 or RFC 5798 VRRPv3 header & pseudo-header checksum rules. |\n\n## Cross-Layer Options Valid with `vrrp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 255, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### vrid Starts at 1 (1..255)\n\n- **Avoid:** `r1 -> vrrp_v4 vrrp vrid 0`\n- **Valid v3.3.0 Syntax:** `r1 -> vrrp_v4 vrrp vrid 1 priority 120`\n\nPer RFC 3768 / RFC 5798, valid Virtual Router Identifiers are `1..=255` (`0` is\ninvalid). Note that `priority 0` *is* valid and signals Master release.\n\n### VRRPv3 Uses Centiseconds (100 = 1s) Instead of Whole Seconds\n\n- **Valid v3.3.0 Syntax:** `r6 -> vrrp_v6 vrrp version 3 vrid 10 advint 100`\n\nIn VRRPv2 `advint 1` is `1` second, whereas in VRRPv3 `advint` is encoded in\ncentiseconds (`100` = `1.00` second, enabling sub-second `advint 10` = `100ms`\nfailovers).\n"}
{"id":"pretrain-proto-hsrp","kind":"protocol_spec","title":"Cisco Hot Standby Router Protocol v1 & v2 (hsrp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/hsrp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["hsrp"],"text":"# hsrp — Cisco HSRPv1 (1985) & HSRPv2 (2029) Standby Frames (`hsrp`)\n\n> **FrameAssembly v3.3.0** · Protocol 39 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/hsrp\n\n- **Full Protocol Name:** Cisco Hot Standby Router Protocol v1 & v2\n- **Keyword:** `hsrp`\n- **OSI Layer & Transport:** Layer 3 · UDP 1985 (v1) / UDP 2029 (v2)\n- **Host Endpoint Rule:** Dual-Stack Morphing (v4/v6)\n- **Standards:** RFC 2281\n- **Wireshark Display Filter:** `hsrp || hsrp2`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  HSRPv1 / HSRPv2 (UDP 1985 (v1) / UDP 2029 (v2))`\n\n## Overview\n\nCisco’s classic gateway protocol: `hsrp` writes HSRPv1 (`UDP 1985`) on IPv4 and\nautomatically upgrades to TLV-formatted HSRPv2 (`UDP 2029`) on IPv6 endpoints.\n\nHot Standby Router Protocol (`hsrp`, RFC 2281) is Cisco’s First-Hop Redundancy\nProtocol. Between IPv4 hosts, FrameAssembly builds 20-byte **HSRPv1** Hellos on\n**UDP `1985 -> 1985`** (Opcode `0` Hello, State, `hellotime`, `holdtime`,\nPriority, Group, 8-byte cleartext `auth` string, and Virtual IP `vip`). Between\nIPv6 hosts, `hsrp` automatically switches to **HSRPv2** TLV format on **UDP `2029\n-> 2029`**.\n\nFields `group`, `priority`, `state`, `hellotime`, and `holdtime` each take a\n1-byte value (`0..255`).\n\n## Minimal Quickstart (`hsrp_quickstart.frasm`)\n\n```frameassembly\nhost dist_sw1 { ip 10.20.10.2 mac 00:00:0c:07:ac:0a }\nhost all_rtrs { ip 224.0.0.2 }\n\ncompile {\n    dist_sw1 -> all_rtrs hsrp group 10 priority 110 state 16 vip 10.20.10.1\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults UDP source and destination ports to `1985 -> 1985` on IPv4 (HSRPv1) or\n  `2029 -> 2029` on IPv6 (HSRPv2 TLV).\n- Zero-pads or truncates `auth` cleanly into the fixed 8-byte RFC 2281\n  Authentication Data field (default `\"cisco\\0\\0\\0\"`).\n- Validates `hellotime` and `holdtime` within `0..=255` (`u8`) at compile time and\n  derives `01:00:5e:00:00:02` (`224.0.0.2`) multicast MACs automatically.\n\n## Practical Lab Example: Campus VLAN 20 Active/Standby HSRP Pair Plus HSRPv2 IPv6 Gateway (`hsrp_active_standby.frasm`)\n\nModels two distribution switches exchanging Active (`state 16`, `priority 110`)\nand Standby (`state 8`, `priority 100`) HSRPv1 Hellos on VLAN 20 alongside an IPv6\nHSRPv2 Active router.\n\n```frameassembly\nhost dist_a   { ip 10.20.20.2 mac 00:00:0c:07:ac:14 }\nhost dist_b   { ip 10.20.20.3 mac 00:1c:73:20:00:03 }\nhost hsrp_v4  { ip 224.0.0.2 }\nhost dist6_a  { ip fe80::20:2 mac 00:05:73:a0:00:14 }\nhost hsrp_v6  { ip ff02::66 }\n\ncompile {\n    // 1. Active router (state 16, priority 110, virtual MAC 00:00:0c:07:ac:14 for group 20)\n    dist_a -> hsrp_v4 hsrp group 20 priority 110 state 16 hellotime 3 holdtime 10 auth \"corpkey1\" vip 10.20.20.1 vlan 20 ttl 1 dscp 48 wait 3ms\n    // 2. Standby router (state 8, priority 100) monitoring Active peer\n    dist_b -> hsrp_v4 hsrp group 20 priority 100 state 8 hellotime 3 holdtime 10 auth \"corpkey1\" vip 10.20.20.1 vlan 20 ttl 1 dscp 48 wait 5ms\n    // 3. HSRPv2 over IPv6 on UDP 2029 -> ff02::66\n    dist6_a -> hsrp_v6 hsrp group 20 priority 110 state 16 hellotime 3 holdtime 10 vip 2001:db8:20::1 vlan 20 ttl 255\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show hsrp_active_standby.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly hsrp_active_standby.frasm hsrp_active_standby.pcap\nframeassembly hsrp_active_standby.frasm hsrp_active_standby.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse hsrp_active_standby.pcap hsrp_active_standby_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r hsrp_active_standby.pcap -Y \"hsrp || hsrp2\"\n```\n\n## All `hsrp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host hsrp [group <0..255>] [priority\n<0..255>] [state <0..255>] [hellotime <0..255>] [holdtime <0..255>] [auth\n\"<text>\"] [vip <ip>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `group <0..255>` | Whole number (0..255) (0..255) | `1` | Sets the Standby Group number (HSRPv1 virtual MACs follow `00:00:0c:07:ac:<group_hex>`). |\n| `priority <0..255>` | Whole number (0..255) (0..255) | `100` | Sets router election priority (higher value wins when preemption is enabled). |\n| `state <0..255>` | 8-bit RFC 2281 HSRP state code | `16 (Active)` | Sets router state: `0` Initial, `1` Learn, `2` Listen, `4` Speak, `8` Standby, `16` Active. |\n| `hellotime <0..255> \\| holdtime <0..255>` | 8-bit unsigned integers (seconds) | `hellotime 3, holdtime 10` | Sets the 1-byte Hello Time and Hold Time fields in seconds. |\n| `auth \"<text>\"` | ASCII string (up to 8 bytes in v1) | `\"cisco\"` | Populates the 8-byte Authentication Data field in HSRPv1 packets. |\n| `vip <ip>` | IPv4 or IPv6 Virtual IP address | `Source host IP` | Sets the shared Virtual IP address served by the HSRP group. |\n\n## Cross-Layer Options Valid with `hsrp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 1985 (v1) / UDP 2029 (v2)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### hellotime and holdtime Must Be Between 0 and 255 Seconds\n\n- **Avoid:** `dist_a -> hsrp_v4 hsrp hellotime 300`\n- **Valid v3.3.0 Syntax:** `dist_a -> hsrp_v4 hsrp hellotime 3 holdtime 10`\n\nRFC 2281 stores `hellotime` and `holdtime` as 1-byte fields in seconds, so values\nabove `255` are rejected.\n\n### Numeric State Codes (16 = Active, 8 = Standby)\n\n- **Avoid:** `dist_a -> hsrp_v4 hsrp state \"active\"`\n- **Valid v3.3.0 Syntax:** `dist_a -> hsrp_v4 hsrp state 16`\n\n`state` takes its numeric RFC 2281 bit value (`16` Active, `8` Standby, `4` Speak,\n`2` Listen).\n"}
{"id":"pretrain-proto-glbp","kind":"protocol_spec","title":"Cisco Gateway Load Balancing Protocol (glbp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/glbp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["glbp"],"text":"# glbp — Active-Active Cisco GLBP AVG & AVF Load-Share Frames (`glbp`)\n\n> **FrameAssembly v3.3.0** · Protocol 40 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/glbp\n\n- **Full Protocol Name:** Cisco Gateway Load Balancing Protocol\n- **Keyword:** `glbp`\n- **OSI Layer & Transport:** Layer 3 · UDP 3222 (Multicast 224.0.0.102, TTL 1)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** Cisco GLBP Specification\n- **Wireshark Display Filter:** `glbp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  Cisco GLBP (3222) (UDP 3222 (Multicast 224.0.0.102, TTL 1))`\n\n## Overview\n\nWhy let standby routers sit idle? `glbp` runs on UDP `3222` (`224.0.0.102`, `ttl\n1`) so an Active Virtual Gateway can hand out `00:07:b4` virtual MACs across up to\nfour forwarding routers.\n\nGateway Load Balancing Protocol (`glbp`, **UDP `3222`** to link-local multicast\n`224.0.0.102` / `ff02::66` at `ttl 1`) extends first-hop gateway redundancy beyond\nactive/standby HSRP and VRRP by electing one **Active Virtual Gateway (AVG)** and\nup to four **Active Virtual Forwarders (AVFs)** sharing traffic across virtual\nMACs (`00:07:b4:00:xx:yy`).\n\nFrameAssembly encodes the 12-byte GLBP base header (`version`, `group 0..1023`,\n`ownerid` MAC) followed by structured **Hello (`type 1`)**, **Request/Response\n(`type 2`)**, and **Plaintext Authentication (`type 3`)** TLVs—including\n`priority`, `weight`, `hellotime`, `holdtime`, `redirect`, `timeout`, `vip`, and\nvirtual forwarder `vmac`.\n\n## Minimal Quickstart (`glbp_quickstart.frasm`)\n\n```frameassembly\nhost dist_rtr_a { ip 172.16.10.2 mac 00:50:56:01:00:01 }\nhost dist_rtr_b { ip 172.16.10.3 mac 00:50:56:01:00:02 }\n\ncompile {\n    dist_rtr_a -> dist_rtr_b glbp hello group 10 priority 150 weight 100 vip 172.16.10.1 ownerid 00:50:56:01:00:01 vmac 00:07:b4:00:0a:01\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults UDP source and destination ports to `3222`, sets IPv4 TTL / IPv6 Hop\n  Limit to `1`, and targets `224.0.0.102` (`01:00:5e:00:00:66`) over IPv4 or\n  `ff02::66` over IPv6 unless overridden.\n- Encodes the 10-bit `group` ID (`0..1023`), 6-byte `ownerid`, Hello TLV (state,\n  priority, timers, `vip`), Request/Response Forwarder TLV (`forwarder`, `weight`,\n  `vmac`), and optional Auth TLV.\n- Validates at compile time that `group <= 1023` to match the 10-bit GLBP wire\n  header specification.\n\n## Practical Lab Example: Dual-Distribution Router GLBP Group 10 AVG Election & AVF Assignment (`glbp_avg_avf_lab.frasm`)\n\nCaptures two distribution routers exchanging authenticated GLBP Hellos on Group 10\n(`vip 10.10.20.1`), followed by AVF forwarder slot request and virtual MAC\n(`00:07:b4:00:0a:02`) assignment.\n\n```frameassembly\nhost core_dist_1 { ip 10.10.20.2 mac 00:1c:73:a1:00:01 }\nhost core_dist_2 { ip 10.10.20.3 mac 00:1c:73:a2:00:02 }\n\ncompile {\n    // 1. AVG (core_dist_1, priority 150) & Standby AVG (core_dist_2, priority 120) exchange Hellos\n    core_dist_1 -> core_dist_2 glbp hello group 10 state 32 priority 150 hellotime 3000 holdtime 10000 vip 10.10.20.1 ownerid 00:1c:73:a1:00:01 auth \"corp-fhrp\" wait 2ms\n    core_dist_1 <- core_dist_2 glbp hello group 10 state 16 priority 120 hellotime 3000 holdtime 10000 vip 10.10.20.1 ownerid 00:1c:73:a2:00:02 auth \"corp-fhrp\" wait 2ms\n    // 2. AVF 2 Request from core_dist_2 and Response assigning virtual MAC 00:07:b4:00:0a:02\n    core_dist_1 <- core_dist_2 glbp request group 10 forwarder 2 weight 100 ownerid 00:1c:73:a2:00:02 auth \"corp-fhrp\" wait 1ms\n    core_dist_1 -> core_dist_2 glbp response group 10 forwarder 2 state 32 weight 100 redirect 600 timeout 14400 vmac 00:07:b4:00:0a:02 ownerid 00:1c:73:a1:00:01 auth \"corp-fhrp\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show glbp_avg_avf_lab.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly glbp_avg_avf_lab.frasm glbp_avg_avf_lab.pcap\nframeassembly glbp_avg_avf_lab.frasm glbp_avg_avf_lab.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse glbp_avg_avf_lab.pcap glbp_avg_avf_lab_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r glbp_avg_avf_lab.pcap -Y \"glbp\"\n```\n\n## All `glbp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host glbp [hello | request | response]\n[version <0..255>] [group <0..1023>] [ownerid <mac>] [state <0..255>] [priority\n<0..255>] [weight <0..255>] [forwarder <0..255>] [hellotime <number>] [holdtime\n<number>] [redirect <0..65535>] [timeout <0..65535>] [vip <ip>] [vmac <mac>] [auth\n\"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `hello \\| request \\| response` | GLBP TLV message mode | `hello` | Selects Hello TLV (`1`) or Forwarder Request / Response TLV (`2`). |\n| `group <0..1023>` | 10-bit GLBP group number (0..1023) | `1` | Packs the 10-bit GLBP virtual router group into bytes 2..3 of the GLBP header. |\n| `priority <0..255> \\| weight <0..255>` | 8-bit AVG priority and AVF weight | `priority 100, weight 100` | `priority` governs AVG election; `weight` governs AVF load-sharing eligibility. |\n| `state <0..255> \\| forwarder <0..255>` | GLBP state code and AVF slot index (1..4) | `state 32 (Active), forwarder 1` | Sets gateway/forwarder state (`4`=Speak, `8`=Standby, `16`=Listen, `32`=Active) and AVF index. |\n| `vip <ip> \\| vmac <mac> \\| ownerid <mac>` | Virtual IP, Virtual Forwarder MAC & Owner MAC | `Host IP / 00:07:b4:00:01:01 / source MAC` | Populates the Virtual IP in Hello TLVs, the `00:07:b4` AVF MAC, and the 6-byte Owner ID. |\n| `hellotime <number> \\| holdtime <number>` | 32-bit timers in milliseconds | `hellotime 3000, holdtime 10000` | Sets the 4-byte millisecond Hello Interval (`3000` = 3s) and Hold Time (`10000` = 10s). |\n| `redirect <0..65535> \\| timeout <0..65535>` | 16-bit timers in seconds | `redirect 600, timeout 14400` | Sets the AVG ARP redirect timer (`600s`) and secondary AVF forwarder timeout (`14400s` = 4h). |\n| `auth \"<text>\"` | Quoted plaintext authentication key | `Omitted (no Auth TLV)` | Appends a GLBP Type `3` Plaintext Authentication TLV. |\n\n## Cross-Layer Options Valid with `glbp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 1, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 3222 (Multicast 224.0.0.102, TTL 1)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### GLBP Group Numbers Are 10-Bit (0..1023)\n\n- **Avoid:** `r1 -> r2 glbp hello group 2048 vip 10.0.0.1`\n- **Valid v3.3.0 Syntax:** `r1 -> r2 glbp hello group 1023 vip 10.0.0.1`\n\nUnlike HSRPv2 (12-bit `0..4095`), GLBP allocates 10 bits for the Group ID\n(`0..1023`).\n\n### GLBP hellotime Is in Milliseconds (u32), Unlike HSRP Seconds (u8)\n\n- **Avoid:** `Assuming hellotime 3000 overflows like HSRP`\n- **Valid v3.3.0 Syntax:** `r1 -> r2 glbp hello group 10 hellotime 3000 holdtime\n  10000`\n\nGLBP encodes 32-bit millisecond timers (`3000` = 3 seconds) to support sub-second\ntuning, whereas HSRPv1 uses 8-bit second timers.\n"}
{"id":"pretrain-proto-bfd","kind":"protocol_spec","title":"Bidirectional Forwarding Detection Control Packet (bfd) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/bfd","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["bfd"],"text":"# bfd — Sub-Second RFC 5880 Link Liveness on UDP 3784 (`bfd`)\n\n> **FrameAssembly v3.3.0** · Protocol 41 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/bfd\n\n- **Full Protocol Name:** Bidirectional Forwarding Detection Control Packet\n- **Keyword:** `bfd`\n- **OSI Layer & Transport:** Layer 3 · UDP 3784 (Multihop 4784, TTL 255)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 5880, RFC 5881, RFC 5883\n- **Wireshark Display Filter:** `bfd`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  BFD (UDP 3784 (Multihop 4784, TTL 255))`\n\n## Overview\n\nWaiting 180 seconds for BGP Hold Time to notice a dead fiber is painful — `bfd`\nfires `ttl 255` UDP `3784` control packets with microsecond `mintx`/`minrx` timers\nand discriminator handshakes.\n\nBidirectional Forwarding Detection (`bfd`, RFC 5880) provides sub-50ms\nforwarding-plane failure detection for BGP, OSPF, IS-IS, VRRP, and MPLS/VXLAN\ntunnels. Single-hop BFD (RFC 5881) runs over **UDP `dstport 3784`** with `srcport\n>= 49152` and mandatory **TTL / Hop Limit `255`**, while multihop BFD (RFC 5883)\nuses `dstport 4784` and Seamless BFD uses `dstport 7784`.\n\nFrameAssembly constructs the exact 24-byte BFD v1 Control header—packing Version\n`1`, 5-bit Diagnostic (`diag`), 2-bit State (`state`), Detect Multiplier (`mult`),\n32-bit `mydisc` / `yourdisc` session discriminators, and microsecond `mintx` /\n`minrx` intervals.\n\n## Minimal Quickstart (`bfd_quickstart.frasm`)\n\n```frameassembly\nhost rtr_leaf  { ip 172.16.0.1 }\nhost rtr_spine { ip 172.16.0.2 }\n\ncompile {\n    rtr_leaf -> rtr_spine bfd state 3 mydisc 101 yourdisc 202 mintx 50000 minrx 50000 mult 3 wait 50ms\n    rtr_leaf <- rtr_spine bfd state 3 mydisc 202 yourdisc 101 mintx 50000 minrx 50000 mult 3\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults UDP `srcport` to RFC 5881 range (`49152+`), `dstport` to `3784`, and IP\n  `ttl` / Hop Limit to `255`.\n- Bit-packs Version (`1`), `diag` (`0..31`), `state` (`0..3`), `mult` (default\n  `3`), `Length = 24`, `mydisc`, `yourdisc`, `mintx` (`100000` us), `minrx`\n  (`100000` us), and Echo RX interval.\n- Validates `state` (`0..=3`) and `diag` (`0..=31`) bounds at compile time.\n\n## Practical Lab Example: BFD 3-Way Session Bring-Up (Down -> Init -> Up) & Detection Timeout (`bfd_state_machine.frasm`)\n\nTraces two routers negotiating a 50ms (`50000` us * `mult 3` = `150ms` detection)\nBFD session from `Down` (`1`) through `Init` (`2`) to `Up` (`3`), followed by a\n`diag 1` timeout.\n\n```frameassembly\nhost pe_north { ip 10.255.1.1 }\nhost pe_south { ip 10.255.1.2 }\n\ncompile {\n    // 1. Initial Down packet (state 1, yourdisc 0 = peer unknown, slow 1s timer)\n    pe_north -> pe_south bfd state 1 diag 0 mydisc 0x1001 yourdisc 0 mintx 1000000 minrx 1000000 mult 3 dscp 48 wait 2ms\n    // 2. Peer sees 0x1001 and transitions to Init (state 2)\n    pe_north <- pe_south bfd state 2 diag 0 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 mult 3 dscp 48 wait 2ms\n    // 3. Both peers reach Up (state 3) at 50ms (50,000 us) intervals\n    pe_north -> pe_south bfd state 3 diag 0 mydisc 0x1001 yourdisc 0x2002 mintx 50000 minrx 50000 mult 3 dscp 48 wait 50ms\n    pe_north <- pe_south bfd state 3 diag 0 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 mult 3 dscp 48 wait 150ms\n    // 4. Link failure detected: state 1 (Down), diag 1 (Control Detection Time Expired)\n    pe_north -> pe_south bfd state 1 diag 1 mydisc 0x1001 yourdisc 0x2002 mintx 1000000 minrx 1000000 mult 3 dscp 48\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show bfd_state_machine.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly bfd_state_machine.frasm bfd_state_machine.pcap\nframeassembly bfd_state_machine.frasm bfd_state_machine.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse bfd_state_machine.pcap bfd_state_machine_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r bfd_state_machine.pcap -Y \"bfd\"\n```\n\n## All `bfd` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host bfd [state <0..3>] [diag <0..31>]\n[mydisc <number>] [yourdisc <number>] [mintx <number>] [minrx <number>] [mult\n<0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `state <0..3>` | 2-bit BFD session state (0..3) | `3 (Up)` | Sets session state: `0` = AdminDown, `1` = Down, `2` = Init, `3` = Up. |\n| `diag <0..31>` | 5-bit RFC 5880 Diagnostic code (0..31) | `0 (No Diagnostic)` | Sets failure reason (`0` None, `1` Control Detection Time Expired, `3` Neighbor Signaled Session Down, `7` Administratively Down). |\n| `mydisc <number> \\| yourdisc <number>` | 32-bit non-zero / peer session discriminators | `mydisc 1, yourdisc 0` | Sets My Discriminator and Your Discriminator (`0` until learned from peer). |\n| `mintx <number> \\| minrx <number>` | Whole number (microseconds) | `100000 (100 ms)` | Sets Desired Min TX Interval and Required Min RX Interval in **microseconds** (`50000` = `50ms`, `1000000` = `1s`). |\n| `mult <1..255>` | 8-bit Detect Multiplier | `3` | Sets the missed-packet multiplier (`Detection Time = mult * max(minrx, peer_mintx)`). |\n\n## Cross-Layer Options Valid with `bfd`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 255, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 3784 (Multihop 4784, TTL 255)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### mintx and minrx Are Expressed in Microseconds (Not Milliseconds)\n\n- **Avoid:** `r1 -> r2 bfd mintx 50 minrx 50   // 50 microseconds!`\n- **Valid v3.3.0 Syntax:** `r1 -> r2 bfd mintx 50000 minrx 50000 // 50\n  milliseconds`\n\nPer RFC 5880 §4.1, BFD timer fields are encoded in microseconds (`50000` = `50\nms`, `300000` = `300 ms`).\n\n### Use dstport 4784 for Multihop BFD (RFC 5883)\n\n- **Valid v3.3.0 Syntax:** `r1 -> r2 bfd dstport 4784 ttl 64 state 3 mydisc 10\n  yourdisc 20`\n\nSingle-hop BFD uses UDP `3784` with `ttl 255`; for multihop eBGP loopback BFD\nsessions, override `dstport 4784` and set an appropriate `ttl`.\n"}
{"id":"pretrain-proto-openflow","kind":"protocol_spec","title":"OpenFlow SDN Control Channel (OpenFlow 1.3 / 1.4) (openflow) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/openflow","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["openflow"],"text":"# openflow — OpenFlow 1.3 SDN Controller <-> Switch Messages (`openflow`)\n\n> **FrameAssembly v3.3.0** · Protocol 42 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/openflow\n\n- **Full Protocol Name:** OpenFlow SDN Control Channel (OpenFlow 1.3 / 1.4)\n- **Keyword:** `openflow`\n- **OSI Layer & Transport:** Layer 3 · TCP 6653\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** ONF OpenFlow 1.3 (TS-023), OpenFlow 1.4\n- **Wireshark Display Filter:** `openflow_v4 || openflow`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  OpenFlow SDN (TCP 6653)`\n\n## Overview\n\nSpeak directly to virtual switches and SDN controllers over TCP `6653`: `openflow`\nbuilds `hello`, `featuresreply` (`dpid`), `packetin`, and `flowmod` headers\nwithout booting an entire controller stack.\n\nOpenFlow (`openflow`) is the Software-Defined Networking (SDN) southbound control\nprotocol used between controllers (ONOS, Ryu, OpenDaylight, OVN `ovs-vswitchd`)\nand OpenFlow switches over **TCP `dstport 6653`** (legacy `6633`). Every OpenFlow\nmessage starts with an 8-byte header (`version`, `type`, 16-bit `length`, and\n32-bit Transaction ID `xid`).\n\nFrameAssembly defaults to **OpenFlow 1.3 (`version 4`)**, shares 4-tuple TCP\nsequence tracking with `tcp`, and encodes structured payloads for `hello`,\n`echoreq`/`echoreply`, `featuresreq`/`featuresreply` (with 64-bit Datapath ID\n`dpid`), `packetin`, `packetout`, and `flowmod` (`tableid` + `priority`).\n\n## Minimal Quickstart (`openflow_quickstart.frasm`)\n\n```frameassembly\nhost sdn_ctrl { ip 10.90.0.10 }\nhost ovs_br0  { ip 10.90.0.21 }\n\ncompile {\n    sdn_ctrl -> ovs_br0 openflow hello xid 1 wait 1ms\n    sdn_ctrl <- ovs_br0 openflow hello xid 1 wait 1ms\n    sdn_ctrl -> ovs_br0 openflow featuresreq xid 2 wait 1ms\n    sdn_ctrl <- ovs_br0 openflow featuresreply xid 2 dpid 0x0000001c73000001\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to IANA OpenFlow port TCP `6653`, Version `4` (`0x04` = OpenFlow 1.3),\n  and shares stateful 4-tuple TCP `seq`/`acknum` progression.\n- Computes the exact 16-bit big-endian OpenFlow `length` field across both 8-byte\n  header-only messages (`hello`, `featuresreq`, `echoreq`) and structured bodies\n  (`32B` `featuresreply`, `56B` `flowmod`).\n- Encodes the 64-bit switch Datapath ID (`dpid`) inside `OFPT_FEATURES_REPLY`\n  (`type 6`) and `tableid` + `priority` inside `OFPT_FLOW_MOD` (`type 14`).\n\n## Practical Lab Example: Complete OpenFlow 1.3 Switch Onboarding, Packet-In Miss & FlowMod Programming (`openflow_sdn_pipeline.frasm`)\n\nWalks through TCP 6653 connection establishment, OpenFlow 1.3 `HELLO` +\n`FEATURES_REPLY`, a switch table-miss `PACKET_IN`, controller `FLOW_MOD`\ninstallation in Table 0, and `ECHO` heartbeat.\n\n```frameassembly\nhost controller { ip 10.90.0.10 }\nhost leaf_ovs   { ip 10.90.0.51 }\n\ncompile {\n    // 1. TCP handshake on port 6653\n    leaf_ovs -> controller tcp syn srcport 54653 dstport 6653 win 65535 mss 1460 wait 1ms\n    leaf_ovs <- controller tcp syn ack win 65535 mss 1460 wait 1ms\n    leaf_ovs -> controller tcp ack wait 1ms\n    // 2. OpenFlow 1.3 (version 4) Hello & Features negotiation\n    leaf_ovs -> controller openflow hello version 4 xid 10 wait 1ms\n    leaf_ovs <- controller openflow hello version 4 xid 10 wait 1ms\n    leaf_ovs <- controller openflow featuresreq version 4 xid 11 wait 1ms\n    leaf_ovs -> controller openflow featuresreply version 4 xid 11 dpid 0x0000001c73aa0051 wait 3ms\n    // 3. Table-miss PacketIn triggers FlowMod rule installation + PacketOut\n    leaf_ovs -> controller openflow packetin version 4 xid 0 tableid 0 wait 2ms\n    leaf_ovs <- controller openflow flowmod version 4 xid 12 tableid 0 priority 1000 wait 1ms\n    leaf_ovs <- controller openflow packetout version 4 xid 13 wait 5ms\n    // 4. Liveness Echo Request / Reply\n    leaf_ovs <- controller openflow echoreq version 4 xid 99 wait 1ms\n    leaf_ovs -> controller openflow echoreply version 4 xid 99\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show openflow_sdn_pipeline.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly openflow_sdn_pipeline.frasm openflow_sdn_pipeline.pcap\nframeassembly openflow_sdn_pipeline.frasm openflow_sdn_pipeline.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse openflow_sdn_pipeline.pcap openflow_sdn_pipeline_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r openflow_sdn_pipeline.pcap -Y \"openflow_v4 || openflow\"\n```\n\n## All `openflow` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host openflow [hello | echoreq | echorequest\n| echoreply | featuresreq | featuresreply | packetin | packetout | flowmod | type\n<0..255>] [version <0..255>] [xid <number>] [dpid <number>] [tableid <0..255>]\n[priority <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `hello \\| echoreq \\| echorequest \\| echoreply \\| featuresreq \\| featuresreply \\| packetin \\| packetout \\| flowmod \\| type <0..255>` | OpenFlow message type keyword or u8 | `hello (Type 0)` | Maps to OpenFlow 1.3 types: `hello` (`0`), `echoreq`/`echorequest` (`2`), `echoreply` (`3`), `featuresreq` (`5`), `featuresreply` (`6`), `packetin` (`10`), `packetout` (`13`), `flowmod` (`14`). |\n| `version <0..255>` | 8-bit wire version code | `4 (OpenFlow 1.3)` | Sets wire protocol version (`1` = OF 1.0, `4` = OF 1.3, `5` = OF 1.4, `6` = OF 1.5). |\n| `xid <number>` | 32-bit Transaction ID | `1` | Correlates controller requests (`featuresreq`, `echoreq`) with switch replies. |\n| `dpid <number>` | Whole number (0x hex recommended) | `1` | Sets the 8-byte Datapath ID in `featuresreply` (`upper 16 bits` vendor/ID + `lower 48 bits` switch MAC). |\n| `tableid <0..255> \\| priority <0..65535>` | 8-bit Table ID, 16-bit Flow Priority | `tableid 0, priority 100` | Populates pipeline Table ID (`flowmod` / `packetin`) and rule match Priority (`flowmod`). |\n\n## Cross-Layer Options Valid with `openflow`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 6653` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Wire Version Numbers Differ From Marketing Version Strings\n\n- **Avoid:** `ctrl -> sw openflow hello version \"1.3\"`\n- **Valid v3.3.0 Syntax:** `ctrl -> sw openflow hello version 4 // 0x04 = OpenFlow\n  1.3`\n\nOn the wire, OpenFlow 1.0 is `version 1`, OpenFlow 1.3 is `version 4`, and\nOpenFlow 1.4 is `version 5`.\n\n### Legacy Port 6633 vs IANA Standardized Port 6653\n\n- **Valid v3.3.0 Syntax:** `ctrl -> sw openflow hello dstport 6633`\n\nFrameAssembly defaults to IANA port `6653`; add `dstport 6633` when testing older\nOpenFlow 1.0 controllers.\n"}
{"id":"pretrain-proto-rsvp","kind":"protocol_spec","title":"Resource Reservation Protocol — Traffic Engineering (rsvp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/rsvp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["rsvp"],"text":"# rsvp — IP Protocol 46 MPLS RSVP-TE Path & Resv LSP Signaling (`rsvp`)\n\n> **FrameAssembly v3.3.0** · Protocol 43 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/rsvp\n\n- **Full Protocol Name:** Resource Reservation Protocol — Traffic Engineering\n- **Keyword:** `rsvp`\n- **OSI Layer & Transport:** Layer 3 · IP Proto 46 (Router Alert Optional)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 2205, RFC 3209, RFC 4090\n- **Wireshark Display Filter:** `rsvp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  RSVP-TE (RFC 3209) (IP Proto 46 (Router Alert Optional))`\n\n## Overview\n\nSignal bandwidth-guaranteed MPLS-TE tunnels on IP Protocol `46`: pair `rsvp path`\n+ `routeralert` downstream with `rsvp resv label 24010` upstream and watch\nWireshark dissect every Class-Num object.\n\nResource Reservation Protocol — Traffic Engineering (`rsvp`, **IP Protocol `46`**,\nRFC 2205 / RFC 3209) signals bandwidth-guaranteed **MPLS Traffic Engineering Label\nSwitched Paths (TE-LSPs)** and RFC 4090 Fast Reroute (FRR) bypass tunnels across\ncarrier and financial WAN backbones. Headend routers transmit downstream `Path`\nmessages carrying `LSP_TUNNEL_IPV4/IPV6` `SESSION`, `RSVP_HOP`, `TIME_VALUES`,\n`LABEL_REQUEST`, and `SENDER_TEMPLATE` objects, and tailend/transit LSRs reply\nupstream with `Resv` messages carrying allocated `LABEL` objects.\n\nFrameAssembly encodes the 8-byte RFC 2205 common header (Version `1`, Message\nType, ones'-complement RSVP checksum, Send_TTL, Total Length) plus properly\naligned 4-byte RSVP Object headers (`Length`, `Class-Num`, `C-Type`), and pairs\nseamlessly with the `routeralert` IPv4 modifier (`IP Option 20`).\n\n## Minimal Quickstart (`rsvp_quickstart.frasm`)\n\n```frameassembly\nhost pe_headend { ip 172.16.0.1 }\nhost pe_tailend { ip 172.16.0.2 }\n\ncompile {\n    pe_headend -> pe_tailend rsvp path tunnelid 100 lspid 1 srcip 172.16.0.1 dstip 172.16.0.2 routeralert wait 2ms\n    pe_headend <- pe_tailend rsvp resv tunnelid 100 lspid 1 label 24100\n}\n```\n\n### Automatic Wire Calculations\n\n- Sets outer IPv4 Protocol / IPv6 Next Header to `46` (`RSVP`) and computes the\n  16-bit ones'-complement RSVP message checksum over all appended Class-Num /\n  C-Type objects.\n- Builds RFC 3209 `SESSION` (Class `1`, C-Type `7` IPv4 / `8` IPv6 LSP_TUNNEL),\n  `RSVP_HOP` (`3`), `TIME_VALUES` (`5`), `LABEL_REQUEST` (`19`) on `path`, `LABEL`\n  (`16`) on `resv`, `ERROR_SPEC` (`6`) on `patherr`/`resverr`, and `HELLO` (`22`)\n  on `hello`.\n- Combines cleanly with `routeralert` on IPv4 endpoints to insert the 4-byte RFC\n  2113 Router Alert IP option (`0x94 0x04 0x00 0x00`) expected by transit LSRs.\n\n## Practical Lab Example: MPLS-TE Tunnel Lifecycle: RSVP Hello, Path/Resv Setup, MPLS Data & Make-Before-Break Re-Opt (`rsvp_te_lifecycle.frasm`)\n\nWalks through LSR neighbor `hello`, `lspid 1` signaling (`label 24010`), labeled\ntraffic forwarding, make-before-break `lspid 2` (`label 24020`) re-optimization,\nand graceful `pathtear` of `lspid 1`.\n\n```frameassembly\nhost headend_pe { ip 10.0.12.1 mac 00:1c:73:01:00:01 }\nhost tailend_pe { ip 10.0.12.2 mac 00:1c:73:02:00:02 }\n\ncompile {\n    // 1. RSVP Node Hello adjacency check\n    headend_pe -> tailend_pe rsvp hello srcip 10.0.12.1 dstip 10.0.12.2 wait 1ms\n    // 2. Signal Tunnel 500, LSP 1 with IPv4 Router Alert -> Tailend allocates Label 24010\n    headend_pe -> tailend_pe rsvp path tunnelid 500 lspid 1 refresh 30000 srcip 10.0.12.1 dstip 10.0.12.2 routeralert wait 2ms\n    headend_pe <- tailend_pe rsvp resv tunnelid 500 lspid 1 label 24010 refresh 30000 srcip 10.0.12.1 dstip 10.0.12.2 wait 2ms\n    // 3. Forward traffic over allocated TE Label 24010\n    headend_pe -> tailend_pe icmp echorequest id 50 seq 1 mpls 24010 exp 5 wait 2ms\n    // 4. Make-before-break LSP 2 (Label 24020), then tear down old LSP 1\n    headend_pe -> tailend_pe rsvp path tunnelid 500 lspid 2 srcip 10.0.12.1 dstip 10.0.12.2 routeralert wait 1ms\n    headend_pe <- tailend_pe rsvp resv tunnelid 500 lspid 2 label 24020 srcip 10.0.12.1 dstip 10.0.12.2 wait 1ms\n    headend_pe -> tailend_pe rsvp pathtear tunnelid 500 lspid 1 srcip 10.0.12.1 dstip 10.0.12.2 routeralert\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show rsvp_te_lifecycle.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly rsvp_te_lifecycle.frasm rsvp_te_lifecycle.pcap\nframeassembly rsvp_te_lifecycle.frasm rsvp_te_lifecycle.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse rsvp_te_lifecycle.pcap rsvp_te_lifecycle_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r rsvp_te_lifecycle.pcap -Y \"rsvp\"\n```\n\n## All `rsvp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host rsvp [path | resv | patherr | resverr |\npathtear | resvtear | resvconf | hello] [tunnelid <0..65535>] [lspid <0..65535>]\n[label <number>] [refresh <number>] [srcip <ip>] [dstip <ip>] [errcode <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `path \\| resv \\| patherr \\| resverr \\| pathtear \\| resvtear \\| resvconf \\| hello` | RSVP-TE message type keyword | `path (Type 1)` | Selects RSVP Message Type (`1`=Path, `2`=Resv, `3`=PathErr, `4`=ResvErr, `5`=PathTear, `6`=ResvTear, `7`=ResvConf, `20`=Hello). |\n| `tunnelid <0..65535> \\| lspid <0..65535>` | 16-bit TE Tunnel ID and 16-bit LSP ID | `tunnelid 1, lspid 1` | Populates the RFC 3209 `SESSION` Tunnel ID and `SENDER_TEMPLATE` / `FILTER_SPEC` LSP ID. |\n| `label <0..1048575>` | MPLS label value in Resv LABEL object | `16` | Encodes the downstream-assigned MPLS label inside the Class `16` `RSVP LABEL` object on `resv` messages. |\n| `refresh <number>` | 32-bit refresh period R in milliseconds | `30000 (30s)` | Sets the refresh interval inside the `TIME_VALUES` object (`Class 5`). |\n| `srcip <ip> \\| dstip <ip>` | Tunnel sender and endpoint IPv4/IPv6 addresses | `Outer frame source and destination host IPs` | Populates the tunnel headend (`SENDER_TEMPLATE`) and tailend (`SESSION` Endpoint) addresses. |\n| `errcode <0..255>` | 8-bit RSVP Error Code | `24 (Routing Problem)` | Sets the Error Code inside `ERROR_SPEC` (`Class 6`) on `patherr` and `resverr` frames. |\n\n## Cross-Layer Options Valid with `rsvp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n\n## Common Mistakes & Quick Fixes\n\n### RSVP Runs Directly on IP Protocol 46 (Never TCP or UDP)\n\n- **Avoid:** `pe1 -> pe2 rsvp path tunnelid 10 dstport 3455`\n- **Valid v3.3.0 Syntax:** `pe1 -> pe2 rsvp path tunnelid 10 routeralert`\n\nStandard RFC 2205 / RFC 3209 RSVP is a native Layer 3 IP protocol (`46`), so\nTCP/UDP ports and `transport` overrides are rejected.\n\n### Attach routeralert When Simulating Hop-by-Hop IPv4 Path Inspection\n\n- **Avoid:** `Forgetting Router Alert when testing transit LSR punt rules`\n- **Valid v3.3.0 Syntax:** `pe1 -> pe2 rsvp path tunnelid 10 lspid 1 routeralert`\n\nAdding the cross-layer `routeralert` flag injects IPv4 Option `20` (`0x94 0x04\n0x00 0x00`), matching how production Juniper and Cisco routers punt `Path` and\n`PathTear` messages.\n"}
{"id":"pretrain-proto-ldp","kind":"protocol_spec","title":"Label Distribution Protocol (ldp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ldp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ldp"],"text":"# ldp — Port 646 MPLS Label Distribution (UDP Hello & TCP Session) (`ldp`)\n\n> **FrameAssembly v3.3.0** · Protocol 44 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ldp\n\n- **Full Protocol Name:** Label Distribution Protocol\n- **Keyword:** `ldp`\n- **OSI Layer & Transport:** Layer 3 · TCP 646 (Session) / UDP 646 (transport udp\n  Hello)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 5036, RFC 7552\n- **Wireshark Display Filter:** `ldp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  MPLS LDP (Port 646) (TCP 646 (Session) / UDP 646 (transport udp Hello))`\n\n## Overview\n\nDiscover neighbors with `ldp hello ... transport udp` on port `646`, then flip\nstraight onto stateful TCP `646` to trade `init`, `keepalive`, and `labelmapping`\nFEC bindings.\n\nLabel Distribution Protocol (`ldp`, RFC 5036 / RFC 7552) distributes MPLS\nforwarding labels for IGP prefixes across service-provider and enterprise MPLS\ncores without manual tunnel engineering. LDP operates across **both UDP and TCP\nport `646`**: routers multicast link `hello` discovery messages over **UDP `646`**\n(`transport udp`), then establish a stateful **TCP `646`** session (the default\ntransport) to exchange `init`, `keepalive`, `labelmapping`, `labelrequest`,\n`labelwithdraw`, `labelrelease`, and `notification` PDUs.\n\nFrameAssembly encodes the 10-byte RFC 5036 LDP PDU header (`Version = 1`, `PDU\nLength`, 4-byte `LSR ID` + 2-byte `Label Space ID`) and nested TLV messages\n(`Common Hello Parameters`, `Common Session Parameters`, `FEC Prefix TLV`,\n`Generic Label TLV`, and `Status TLV`).\n\n## Minimal Quickstart (`ldp_quickstart.frasm`)\n\n```frameassembly\nhost lsr_pe1 { ip 10.0.0.1 }\nhost lsr_p1  { ip 10.0.0.2 }\n\ncompile {\n    lsr_pe1 -> lsr_p1 ldp hello lsrid 1.1.1.1 holdtime 15 transport udp wait 2ms\n    lsr_pe1 -> lsr_p1 ldp labelmapping lsrid 1.1.1.1 msgid 10 prefix \"192.0.2.0/24\" label 24001\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `646` for session messages and switches seamlessly\n  to UDP port `646` when `transport udp` is added for link/targeted `hello`\n  discovery.\n- Computes exact nested RFC 5036 `PDU Length` (excluding Version + Length) and\n  `Message Length` across `FEC`, `Generic Label`, `Common Hello`, `Common\n  Session`, and `Status` TLVs.\n- Parses IPv4 or IPv6 CIDR strings in `prefix \"<cidr>\"` (`\"10.20.0.0/16\"` or\n  `\"2001:db8:10::/48\"`) into compact Address Family + Prefix-Length bit-aligned\n  octets inside the FEC Element.\n\n## Practical Lab Example: End-to-End MPLS LDP Session: UDP 646 Discovery, TCP-MD5 Session & Label Mapping (`ldp_session_and_labels.frasm`)\n\nCaptures bidirectional UDP `646` Hellos, a 3-way TCP `646` handshake, `init` +\n`keepalive` negotiation, and FEC `labelmapping` exchanges between two core LSRs.\n\n```frameassembly\nhost lsr_west { ip 172.16.1.1 mac 00:1c:73:11:00:01 }\nhost lsr_east { ip 172.16.1.2 mac 00:1c:73:22:00:02 }\n\ncompile {\n    // 1. Link Hello discovery over UDP port 646\n    lsr_west -> lsr_east ldp hello lsrid 10.255.0.1 holdtime 15 transport udp wait 1ms\n    lsr_west <- lsr_east ldp hello lsrid 10.255.0.2 holdtime 15 transport udp wait 2ms\n    // 2. Active LSR (higher IP 172.16.1.2 -> 172.16.1.1) opens TCP 646 session\n    lsr_east -> lsr_west tcp syn srcport 51646 dstport 646 win 65535 mss 1460 wait 1ms\n    lsr_east <- lsr_west tcp syn ack win 65535 mss 1460 wait 1ms\n    lsr_east -> lsr_west tcp ack wait 1ms\n    // 3. LDP Initialization, KeepAlive, and Loopback FEC Label Mapping (Implicit Null 3 & 24010)\n    lsr_east -> lsr_west ldp init lsrid 10.255.0.2 msgid 1 holdtime 180 wait 1ms\n    lsr_east <- lsr_west ldp init lsrid 10.255.0.1 msgid 1 holdtime 180 wait 1ms\n    lsr_east -> lsr_west ldp keepalive lsrid 10.255.0.2 msgid 2 wait 1ms\n    lsr_east <- lsr_west ldp keepalive lsrid 10.255.0.1 msgid 2 wait 2ms\n    lsr_east -> lsr_west ldp labelmapping lsrid 10.255.0.2 msgid 3 prefix \"10.255.0.2/32\" label 3 wait 1ms\n    lsr_east <- lsr_west ldp labelmapping lsrid 10.255.0.1 msgid 3 prefix \"10.100.20.0/24\" label 24010\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ldp_session_and_labels.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ldp_session_and_labels.frasm ldp_session_and_labels.pcap\nframeassembly ldp_session_and_labels.frasm ldp_session_and_labels.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ldp_session_and_labels.pcap ldp_session_and_labels_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ldp_session_and_labels.pcap -Y \"ldp\"\n```\n\n## All `ldp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ldp [hello | init | keepalive |\nnotification | labelmapping | labelrequest | labelwithdraw | labelrelease] [lsrid\n<ipv4>] [labelspace <0..65535>] [msgid <number>] [holdtime <0..65535>] [label\n<number>] [prefix \"<cidr>\"] [status <number>] [transport <tcp|udp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `hello \\| init \\| keepalive \\| notification \\| labelmapping \\| labelrequest \\| labelwithdraw \\| labelrelease` | LDP message type keyword | `hello (0x0100) or labelmapping` | Selects RFC 5036 Message Type (`0x0001`=Notification, `0x0100`=Hello, `0x0200`=Initialization, `0x0201`=KeepAlive, `0x0400`=Label Mapping, `0x0401`=Request, `0x0402`=Withdraw, `0x0403`=Release). |\n| `lsrid <ipv4> [labelspace <0..65535>]` | 32-bit dotted-quad LSR Router ID & 16-bit Label Space | `Source IPv4 (or 1.1.1.1 on IPv6), labelspace 0` | Writes the 6-byte LDP Identifier (`4B LSR ID : 2B Label Space`) in the 10-byte LDP PDU header. |\n| `msgid <number>` | 32-bit LDP Message ID | `1` | Sets the 32-bit correlation Message ID inside the LDP message header. |\n| `holdtime <0..65535>` | 16-bit Hold Time in seconds | `15 on hello, 180 on init` | Sets Hello Hold Time (`Common Hello Parameters`) or KeepAlive Time (`Common Session Parameters`). |\n| `prefix \"<cidr>\" \\| label <0..1048575>` | Quoted CIDR string & 20-bit MPLS label | `\"10.0.0.0/24\", label 16` | Encodes the `FEC TLV` (`0x0100` Prefix element) and `Generic Label TLV` (`0x0200`) on label distribution messages. |\n| `status <number>` | 32-bit RFC 5036 Status Code | `0` | Sets the Status Code inside the `Status TLV` (`0x0300`) on `notification` messages. |\n| `transport <tcp\\|udp>` | Layer 4 transport selector | `tcp (port 646)` | Use `transport udp` for UDP `646` Discovery Hellos; omit or use `transport tcp` for TCP `646` session PDUs. |\n\n## Cross-Layer Options Valid with `ldp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 646 (Session) / UDP 646 (transport udp Hello)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp>` | `tcp` or `udp` (LDP discovery UDP 646 vs session TCP 646) | `transport tcp` | Switches Layer 4 transport between stateful TCP (`psh ack`) and UDP. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Add transport udp on LDP Link Hellos for Authentic Wire Captures\n\n- **Avoid:** `Assuming ldp hello automatically switches away from TCP 646`\n- **Valid v3.3.0 Syntax:** `lsr1 -> lsr2 ldp hello lsrid 1.1.1.1 holdtime 15\n  transport udp`\n\n`ldp` defaults to `transport tcp` (`646`) because 7 of its 8 message types run\nover TCP; add `transport udp` on `ldp hello` so Wireshark dissects UDP `646` Link\nDiscovery.\n\n### lsrid Is Always a 32-Bit Dotted-Quad ID (Even Over IPv6 LDP)\n\n- **Avoid:** `lsr1 -> lsr2 ldp init lsrid 2001:db8::1`\n- **Valid v3.3.0 Syntax:** `lsr1 -> lsr2 ldp init lsrid 10.255.0.1`\n\nPer RFC 5036 and RFC 7552 (IPv6 LDP), the LDP Identifier always uses a 4-byte\nRouter ID (`10.255.0.1`) rather than a 128-bit IPv6 address.\n"}
{"id":"pretrain-proto-bmp","kind":"protocol_spec","title":"BGP Monitoring Protocol v3 (bmp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/bmp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["bmp"],"text":"# bmp — TCP 1790 Real-Time BGP Adj-RIB-In Collector Streams (`bmp`)\n\n> **FrameAssembly v3.3.0** · Protocol 45 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/bmp\n\n- **Full Protocol Name:** BGP Monitoring Protocol v3\n- **Keyword:** `bmp`\n- **OSI Layer & Transport:** Layer 3 · TCP 1790\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 7854, RFC 8671, RFC 9069\n- **Wireshark Display Filter:** `bmp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  BMP v3 (RFC 7854) (TCP 1790)`\n\n## Overview\n\nFeed live-looking BGP `Adj-RIB-In` telemetry into `pmacct`, `GoBMP`, or `Akvorado`\nover TCP `1790` without touching production peering routers — `bmp` packs the\n42-byte Per-Peer Header and embedded BGP PDUs automatically.\n\nBGP Monitoring Protocol (`bmp`, **TCP `1790`**, RFC 7854) streams real-time\npre-policy and post-policy `Adj-RIB-In` route updates, peer session state\ntransitions, and prefix-drop counters from core/edge routers to route collectors\nsuch as **pmacct**, **GoBMP**, **OpenBMP**, **Akvorado**, and **Kentik**. Every\nBMP frame begins with a 6-byte Common Header (`Version = 3`, 32-bit `Message\nLength`, `Message Type 0..6`), followed by a 42-byte **Per-Peer Header** on\npeer-scoped messages (`routemon`, `statsreport`, `peerdown`, `peerup`) or\nInformation TLVs on session-scoped messages (`initiation`, `termination`).\n\nFrameAssembly tracks TCP port `1790` sequence numbers automatically, formats\nIPv4-mapped or native 16-byte IPv6 peer addresses inside the 42-byte Per-Peer\nHeader, and embeds valid BGP `OPEN` / `UPDATE` frames inside `peerup` and\n`routemon` messages so Wireshark `bmp` dissects the full hierarchy.\n\n## Minimal Quickstart (`bmp_quickstart.frasm`)\n\n```frameassembly\nhost edge_rtr     { ip 192.0.2.1 }\nhost bmp_collector { ip 192.0.2.100 }\n\ncompile {\n    edge_rtr -> bmp_collector tcp syn srcport 51790 dstport 1790 win 65535 mss 1460 wait 1ms\n    edge_rtr <- bmp_collector tcp syn ack win 65535 mss 1460 wait 1ms\n    edge_rtr -> bmp_collector tcp ack wait 1ms\n    edge_rtr -> bmp_collector bmp initiation sysname \"edge-rtr-01\" sysdesc \"FRRouting 10.1\" wait 2ms\n    edge_rtr -> bmp_collector bmp peerup peerip 198.51.100.2 asn 64512 bgpid 198.51.100.2\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP `dstport 1790` and computes the 32-bit big-endian BMP\n  `Message Length` across the 6-byte Common Header, 42-byte Per-Peer Header, and\n  embedded BGP PDU or TLVs.\n- Sets the `V` flag (`0x80`) automatically in the Per-Peer Header when `peerip` is\n  an IPv6 address, or encodes an IPv4 address in the lower 4 bytes of the 16-byte\n  Peer Address field.\n- Populates Type `1` (`sysDescr`) and Type `2` (`sysName`) Information TLVs on\n  `initiation` frames and embeds valid RFC 4271 BGP framing inside `peerup` and\n  `routemon`.\n\n## Practical Lab Example: Full BMP v3 Telemetry Export: Initiation, eBGP Peer-Up, Route Monitoring & Peer-Down (`bmp_collector_stream.frasm`)\n\nModels a border router opening a TCP `1790` session to an OpenBMP/pmacct\ncollector, reporting `initiation` metadata, bringing up eBGP peer `AS 65100`,\nexporting a `routemon` RIB update plus `statsreport`, and logging a `peerdown`\nevent.\n\n```frameassembly\nhost border_pe { ip 10.250.0.11 }\nhost pmacct_rx { ip 10.250.0.90 }\n\ncompile {\n    // 1. Router initiates TCP 1790 connection to BMP collector\n    border_pe -> pmacct_rx tcp syn srcport 53790 dstport 1790 win 65535 mss 1460 wait 1ms\n    border_pe <- pmacct_rx tcp syn ack win 65535 mss 1460 wait 1ms\n    border_pe -> pmacct_rx tcp ack wait 1ms\n    // 2. Session Initiation TLVs (sysName + sysDescr)\n    border_pe -> pmacct_rx bmp initiation sysname \"border-pe-fra01\" sysdesc \"Arista EOS 4.32\" wait 2ms\n    // 3. Per-peer telemetry: Peer Up -> Route Monitoring -> Stats Report -> Peer Down\n    border_pe -> pmacct_rx bmp peerup peertype 0 peerip 203.0.113.9 asn 65100 bgpid 203.0.113.9 wait 2ms\n    border_pe -> pmacct_rx bmp routemon peertype 0 flags 0x00 peerip 203.0.113.9 asn 65100 bgpid 203.0.113.9 wait 2ms\n    border_pe -> pmacct_rx bmp statsreport peerip 203.0.113.9 asn 65100 bgpid 203.0.113.9 wait 5ms\n    border_pe -> pmacct_rx bmp peerdown peerip 203.0.113.9 asn 65100 bgpid 203.0.113.9 reason 1\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show bmp_collector_stream.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly bmp_collector_stream.frasm bmp_collector_stream.pcap\nframeassembly bmp_collector_stream.frasm bmp_collector_stream.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse bmp_collector_stream.pcap bmp_collector_stream_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r bmp_collector_stream.pcap -Y \"bmp\"\n```\n\n## All `bmp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host bmp [routemon | statsreport | peerdown\n| peerup | initiation | termination] [version <0..255>] [peertype <0..255>] [flags\n<0..255>] [peerip <ip>] [asn <number>] [bgpid <ipv4>] [sysname \"<text>\"] [sysdesc\n\"<text>\"] [reason <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `routemon \\| statsreport \\| peerdown \\| peerup \\| initiation \\| termination` | BMP v3 message type keyword | `initiation (Type 4) or routemon (Type 0)` | Selects RFC 7854 Message Type (`0`=Route Monitoring, `1`=Stats Report, `2`=Peer Down, `3`=Peer Up, `4`=Initiation, `5`=Termination). |\n| `version <0..255>` | 8-bit BMP protocol version | `3 (RFC 7854)` | Writes byte 0 of the 6-byte BMP Common Header (`3` for standard BMPv3). |\n| `peertype <0..255> \\| flags <0..255>` | Per-Peer Header Type & Flags | `peertype 0 (Global), flags auto (0x80 if IPv6 peerip)` | `peertype` selects Global (`0`), RD Instance (`1`), Local (`2`), or Loc-RIB (`3`); `flags` sets `V`/`L`/`A` bits (`0x40` = Post-Policy). |\n| `peerip <ip> \\| asn <number> \\| bgpid <ipv4>` | Monitored BGP neighbor IP, 32-bit ASN & 4-byte BGP ID | `192.0.2.2, asn 65001, bgpid 192.0.2.2` | Populates the 16-byte Peer Address, 4-byte Peer AS, and 4-byte Peer BGP ID inside the 42-byte Per-Peer Header. |\n| `sysname \"<text>\" \\| sysdesc \"<text>\"` | Quoted UTF-8 strings | `\"router\", \"FrameAssembly BMP\"` | Encodes Information TLV Type `2` (`sysName`) and Type `1` (`sysDescr`) on `initiation` frames. |\n| `reason <0..65535>` | Reason code on peerdown or termination | `1` | Sets the Peer Down Reason byte (`1..5`) on `peerdown` or 16-bit Termination Reason TLV on `termination`. |\n\n## Cross-Layer Options Valid with `bmp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 1790` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### BMP Runs Unidirectionally From Router to Collector Over TCP 1790\n\n- **Avoid:** `Expecting BMP request/response queries from the collector`\n- **Valid v3.3.0 Syntax:** `router -> collector bmp initiation sysname \"rtr-01\"`\n\nPer RFC 7854 Section 3.2, the monitored router sends BMP messages\nunidirectionally; the collector only acknowledges at the TCP layer (`tcp syn ack`\n/ `tcp ack`) and never transmits BMP PDUs.\n\n### bgpid Is Always a 4-Byte Dotted-Quad Identifier\n\n- **Avoid:** `router -> collector bmp peerup peerip 2001:db8::2 bgpid 2001:db8::2`\n- **Valid v3.3.0 Syntax:** `router -> collector bmp peerup peerip 2001:db8::2\n  bgpid 192.0.2.2`\n\nEven when `peerip` is an IPv6 neighbor (`2001:db8::2`), RFC 4271 / RFC 6286 BGP\nIdentifiers (`bgpid`) are always 32-bit dotted-quad values.\n"}
{"id":"pretrain-proto-rpkirtr","kind":"protocol_spec","title":"RPKI-Router Origin Validation Protocol (rpkirtr) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/rpkirtr","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["rpkirtr"],"text":"# rpkirtr — TCP 323 RPKI Route Origin Validation ROA Cache Sync (`rpkirtr`)\n\n> **FrameAssembly v3.3.0** · Protocol 46 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/rpkirtr\n\n- **Full Protocol Name:** RPKI-Router Origin Validation Protocol\n- **Keyword:** `rpkirtr`\n- **OSI Layer & Transport:** Layer 3 · TCP 323\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 6810, RFC 8210\n- **Wireshark Display Filter:** `rpki-rtr`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  RPKI-RTR (TCP 323) (TCP 323)`\n\n## Overview\n\nStop fat-fingered BGP route leaks at the border: `rpkirtr` streams RFC 8210\n`ipv4prefix` and `ipv6prefix` Validated ROA Payloads (`prefix`, `maxlen`, `asn`)\nover TCP `323` just like Routinator.\n\nRPKI-Router Protocol (`rpkirtr`, **TCP `323`**, RFC 6810 v0 / RFC 8210 v1)\ndelivers cryptographically validated **Route Origin Authorization (ROA)**\nprefix-to-ASN bindings (Validated ROA Payloads, VRPs) from local RPKI\nrelying-party caches (**Routinator**, **Cloudflare OctoRPKI**, **Fort**,\n**stayrtr**) to border BGP routers performing **Route Origin Validation (ROV)**.\nRouters send `resetquery` or `serialquery` PDUs, and the cache streams back\n`cacheresponse`, `ipv4prefix` / `ipv6prefix` announcements or withdrawals\n(`prefix`, `maxlen`, `asn`), and `endofdata`.\n\nFrameAssembly builds exact binary RFC 8210 v1 (default) or RFC 6810 v0\nPDUs—including 20-byte IPv4 Prefix PDUs, 32-byte IPv6 Prefix PDUs, 24-byte v1 `End\nof Data` timing headers (`refresh`, `retry`, `expire`), and structured\n`errorreport` diagnostics—over stateful TCP port `323`.\n\n## Minimal Quickstart (`rpkirtr_quickstart.frasm`)\n\n```frameassembly\nhost edge_bgp   { ip 192.0.2.10 }\nhost routinator { ip 192.0.2.53 }\n\ncompile {\n    edge_bgp -> routinator rpkirtr resetquery version 1 wait 1ms\n    edge_bgp <- routinator rpkirtr cacheresponse version 1 sessionid 42 wait 1ms\n    edge_bgp <- routinator rpkirtr ipv4prefix version 1 announce prefix \"203.0.113.0/24\" maxlen 24 asn 64500 wait 1ms\n    edge_bgp <- routinator rpkirtr endofdata version 1 sessionid 42 serial 100 refresh 3600 retry 600 expire 7200\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP `dstport 323` and RFC 8210 `version 1` (including the\n  12 extra refresh/retry/expire interval bytes on v1 `endofdata` vs 12-byte v0\n  `endofdata`).\n- Parses `prefix \"<cidr>\"` (`\"203.0.113.0/24\"` or `\"2001:db8::/32\"`) into Prefix\n  Length, Max Length (`defaults to prefix_len` if `maxlen` is omitted), and binary\n  IPv4 (4B) or IPv6 (16B) octets.\n- Sets Flags byte `1` for `announce` (default) or `0` for `withdraw` on\n  `ipv4prefix` and `ipv6prefix` PDUs.\n\n## Practical Lab Example: Full RFC 8210 RPKI-RTR v1 Bootstrap & Incremental ROA Withdrawal Cycle (`rpkirtr_roa_sync.frasm`)\n\nModels a border router establishing TCP `323` with a Routinator cache, executing a\n`resetquery` full table sync (IPv4 + IPv6 VRPs + `endofdata`), and later receiving\na `serialnotify` incremental ROA `withdraw`.\n\n```frameassembly\nhost peering_rtr { ip 10.30.0.1 }\nhost rpki_cache  { ip 10.30.0.20 }\n\ncompile {\n    // 1. TCP 323 handshake between BGP router and Routinator validator\n    peering_rtr -> rpki_cache tcp syn srcport 52323 dstport 323 win 65535 mss 1460 wait 1ms\n    peering_rtr <- rpki_cache tcp syn ack win 65535 mss 1460 wait 1ms\n    peering_rtr -> rpki_cache tcp ack wait 1ms\n    // 2. Initial Reset Query -> Cache Response + IPv4/IPv6 VRPs + End of Data (serial 500)\n    peering_rtr -> rpki_cache rpkirtr resetquery version 1 wait 1ms\n    peering_rtr <- rpki_cache rpkirtr cacheresponse version 1 sessionid 7 wait 1ms\n    peering_rtr <- rpki_cache rpkirtr ipv4prefix version 1 announce prefix \"198.51.100.0/24\" maxlen 24 asn 65010 wait 1ms\n    peering_rtr <- rpki_cache rpkirtr ipv6prefix version 1 announce prefix \"2001:db8:40::/48\" maxlen 48 asn 65010 wait 1ms\n    peering_rtr <- rpki_cache rpkirtr endofdata version 1 sessionid 7 serial 500 refresh 1800 retry 600 expire 7200 wait 5ms\n    // 3. Cache bumps serial to 501 and withdraws stale ROA\n    peering_rtr <- rpki_cache rpkirtr serialnotify version 1 sessionid 7 serial 501 wait 1ms\n    peering_rtr -> rpki_cache rpkirtr serialquery version 1 sessionid 7 serial 500 wait 1ms\n    peering_rtr <- rpki_cache rpkirtr cacheresponse version 1 sessionid 7 wait 1ms\n    peering_rtr <- rpki_cache rpkirtr ipv4prefix version 1 withdraw prefix \"198.51.100.0/24\" maxlen 24 asn 65010 wait 1ms\n    peering_rtr <- rpki_cache rpkirtr endofdata version 1 sessionid 7 serial 501 refresh 1800 retry 600 expire 7200\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show rpkirtr_roa_sync.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly rpkirtr_roa_sync.frasm rpkirtr_roa_sync.pcap\nframeassembly rpkirtr_roa_sync.frasm rpkirtr_roa_sync.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse rpkirtr_roa_sync.pcap rpkirtr_roa_sync_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r rpkirtr_roa_sync.pcap -Y \"rpki-rtr\"\n```\n\n## All `rpkirtr` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host rpkirtr [serialnotify | serialquery |\nresetquery | cacheresponse | ipv4prefix | ipv6prefix | endofdata | cachereset |\nerrorreport] [version <0|1>] [sessionid <0..65535>] [serial <number>] [announce |\nwithdraw | flags <0..255>] [prefix \"<cidr>\"] [maxlen <0..255>] [asn <number>]\n[refresh <number>] [retry <number>] [expire <number>] [errcode <0..65535>] [errmsg\n\"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `serialnotify \\| serialquery \\| resetquery \\| cacheresponse \\| ipv4prefix \\| ipv6prefix \\| endofdata \\| cachereset \\| errorreport` | RPKI-RTR PDU type keyword | `ipv4prefix (Type 4)` | Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data, `8`=Cache Reset, `10`=Error Report). |\n| `version <0\\|1>` | Protocol version (0 = RFC 6810, 1 = RFC 8210) | `1 (RFC 8210)` | Sets Protocol Version in byte 0 (`1` adds `refresh`, `retry`, and `expire` timers to `endofdata`). |\n| `sessionid <0..65535> \\| serial <number>` | 16-bit Cache Session ID & 32-bit Serial Number | `sessionid 1, serial 1` | Tracks cache epoch (`sessionid`) and monotonic serial state across `serialnotify`, `serialquery`, `cacheresponse`, and `endofdata`. |\n| `announce \\| withdraw \\| flags <0..255>` | ROA announcement flag (`1`) or withdrawal (`0`) | `announce (flags 1)` | Sets the `Flags` byte in `ipv4prefix` / `ipv6prefix` PDUs (`1` announce VRP, `0` withdraw VRP). |\n| `prefix \"<cidr>\" \\| maxlen <0..128> \\| asn <number>` | Quoted IPv4/IPv6 CIDR, Max Length & 32-bit Origin ASN | `\"192.0.2.0/24\", maxlen = prefix_len, asn 65001` | Writes the Prefix Length, Max Length, IPv4/IPv6 prefix bytes, and 4-byte Origin AS Number. |\n| `refresh <number> \\| retry <number> \\| expire <number>` | 32-bit intervals in seconds (v1 endofdata) | `refresh 3600, retry 600, expire 7200` | Populates the three RFC 8210 timing parameters at the end of `version 1` `endofdata` PDUs. |\n| `errcode <0..65535> \\| errmsg \"<text>\"` | 16-bit error code & UTF-8 diagnostic text | `errcode 0, \"\"` | Populates Error Code (`0..8`) and length-prefixed UTF-8 Error Text inside `errorreport` (`Type 10`) PDUs. |\n\n## Cross-Layer Options Valid with `rpkirtr`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 323` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Match ipv4prefix vs ipv6prefix to Your CIDR Address Family\n\n- **Avoid:** `rtr <- cache rpkirtr ipv4prefix prefix \"2001:db8::/32\" maxlen 48 asn\n  65001`\n- **Valid v3.3.0 Syntax:** `rtr <- cache rpkirtr ipv6prefix prefix \"2001:db8::/32\"\n  maxlen 48 asn 65001`\n\n`ipv4prefix` (`PDU Type 4`, 20 bytes) carries a 4-byte IPv4 prefix, whereas\n`ipv6prefix` (`PDU Type 6`, 32 bytes) carries a 16-byte IPv6 prefix.\n\n### Keep maxlen >= CIDR Prefix Length\n\n- **Avoid:** `rtr <- cache rpkirtr ipv4prefix prefix \"203.0.113.0/24\" maxlen 16\n  asn 64500`\n- **Valid v3.3.0 Syntax:** `rtr <- cache rpkirtr ipv4prefix prefix\n  \"203.0.113.0/24\" maxlen 24 asn 64500`\n\nPer RFC 8210 Section 5.6, `Max-Length` must be greater than or equal to\n`Prefix-Length` (`<= 32` for IPv4, `<= 128` for IPv6) or routers reject the VRP as\ncorrupt.\n"}
{"id":"pretrain-proto-l2tp","kind":"protocol_spec","title":"Layer Two Tunneling Protocol v2 & v3 (l2tp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/l2tp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["l2tp"],"text":"# l2tp — UDP 1701 Broadband L2TPv2 & IP Proto 115 L2TPv3 Tunnels (`l2tp`)\n\n> **FrameAssembly v3.3.0** · Protocol 47 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/l2tp\n\n- **Full Protocol Name:** Layer Two Tunneling Protocol v2 & v3\n- **Keyword:** `l2tp`\n- **OSI Layer & Transport:** Layer 3 · UDP 1701 (v2) / IP Proto 115 or transport\n  udp (v3)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 2661, RFC 3931\n- **Wireshark Display Filter:** `l2tp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  L2TPv2 & L2TPv3 (UDP 1701 (v2) / IP Proto 115 or transport udp (v3))`\n\n## Overview\n\nWhether you are debugging an ISP LAC <-> LNS `sccrq/sccrp/scccn` tunnel on UDP\n`1701` (`v2`) or a carrier L2TPv3 Ethernet pseudowire on IP Protocol `115` (`v3`\nor `transport udp`), `l2tp` builds both cleanly.\n\nLayer Two Tunneling Protocol (`l2tp`, RFC 2661 **L2TPv2** / RFC 3931 **L2TPv3**)\npowers ISP broadband subscriber wholesale handoffs (PPPoE LAC <-> LNS over **UDP\n`1701`**), L2TP/IPsec remote-access VPNs, and carrier Layer 2 Ethernet pseudowires\n(**L2TPv3** directly over **IP Protocol `115`** or over UDP `1701` when `transport\nudp` is added).\n\nFrameAssembly encodes both **L2TPv2 (`v2`, default)** with 16-bit Tunnel ID /\nSession ID headers on UDP `1701` and **L2TPv3 (`v3`)** with 32-bit Control\nConnection ID / Session ID headers on IP Protocol `115` (or UDP `1701` via\n`transport udp`), packing mandatory AVP TLVs (`Message Type` AVP 0, `Protocol\nVersion`, `Host Name`, `Assigned Tunnel ID`) on `sccrq`, `sccrp`, `scccn`,\n`hello`, and `stopccn` control frames.\n\n## Minimal Quickstart (`l2tp_quickstart.frasm`)\n\n```frameassembly\nhost lac_bng { ip 172.16.50.10 }\nhost lns_isp { ip 172.16.50.20 }\n\ncompile {\n    lac_bng -> lns_isp l2tp v2 sccrq tunnelid 0 ns 0 nr 0 wait 2ms\n    lac_bng <- lns_isp l2tp v2 sccrp tunnelid 100 ns 0 nr 1 wait 2ms\n    lac_bng -> lns_isp l2tp v2 scccn tunnelid 100 ns 1 nr 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Uses UDP `1701` automatically for `v2` (RFC 2661, 16-bit IDs) and switches to\n  raw IP Protocol `115` for `v3` (RFC 3931, 32-bit IDs) unless `transport udp` is\n  specified.\n- Sets the `T=1, L=1, S=1` control bits and appends mandatory `M=1` IETF AVP 0\n  (`Message Type`: `1`=SCCRQ, `2`=SCCRP, `3`=SCCCN, `4`=StopCCN, `6`=Hello) on\n  control packets, or `T=0` header framing on `data` packets.\n- Computes exact L2TP header `Length` and AVP 10-bit length fields across both v2\n  and v3.\n\n## Practical Lab Example: ISP LAC <-> LNS L2TPv2 Control Handshake + L2TPv3 IP Proto 115 Pseudowire (`l2tp_v2_and_v3_pseudowire.frasm`)\n\nEstablishes an L2TPv2 tunnel (`tunnelid 500`, `sessionid 1`) over UDP `1701`,\ntransmits subscriber `data`, and sends an L2TPv3 pseudowire frame over raw IP\nProtocol `115`.\n\n```frameassembly\nhost access_lac { ip 10.80.1.10 }\nhost core_lns   { ip 10.80.1.20 }\n\ncompile {\n    // 1. L2TPv2 3-way control connection setup on UDP 1701\n    access_lac -> core_lns l2tp v2 sccrq tunnelid 0 sessionid 0 ns 0 nr 0 wait 1ms\n    access_lac <- core_lns l2tp v2 sccrp tunnelid 500 sessionid 0 ns 0 nr 1 wait 1ms\n    access_lac -> core_lns l2tp v2 scccn tunnelid 500 sessionid 0 ns 1 nr 1 wait 2ms\n    // 2. Subscriber PPP session data frame + tunnel Hello keepalive\n    access_lac -> core_lns l2tp v2 data tunnelid 500 sessionid 1 payload \"ppp-lcp-echo\" wait 2ms\n    access_lac <- core_lns l2tp v2 hello tunnelid 500 sessionid 0 ns 1 nr 2 wait 2ms\n    // 3. L2TPv3 pseudowire data frame directly over IP Protocol 115 (32-bit sessionid)\n    access_lac -> core_lns l2tp v3 data sessionid 0x00010055 payload \"l2tpv3-eth-pw\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show l2tp_v2_and_v3_pseudowire.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly l2tp_v2_and_v3_pseudowire.frasm l2tp_v2_and_v3_pseudowire.pcap\nframeassembly l2tp_v2_and_v3_pseudowire.frasm l2tp_v2_and_v3_pseudowire.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse l2tp_v2_and_v3_pseudowire.pcap l2tp_v2_and_v3_pseudowire_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r l2tp_v2_and_v3_pseudowire.pcap -Y \"l2tp\"\n```\n\n## All `l2tp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host l2tp [v2 | v3 | version <2|3>] [hello |\nsccrq | sccrp | scccn | stopccn | data | msgtype \"<text>\" | msgtype <0..65535>]\n[tunnelid <number>] [sessionid <number>] [ns <0..65535>] [nr <0..65535>] [flags\n<0..65535>] [transport udp]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `v2 \\| v3 \\| version <2\\|3>` | L2TP protocol version (2 or 3) | `v2 (RFC 2661, UDP 1701)` | `v2` emits 16-bit Tunnel/Session IDs over UDP `1701`; `v3` emits 32-bit Connection/Session IDs over IP Protocol `115` (or UDP `1701` with `transport udp`). |\n| `sccrq \\| sccrp \\| scccn \\| stopccn \\| hello \\| data \\| msgtype <0..65535\\|\"<text>\">` | Control AVP message type or data mode | `sccrq (Control Type 1) or data` | Selects L2TP control AVP 0 (`1`=SCCRQ, `2`=SCCRP, `3`=SCCCN, `4`=StopCCN, `6`=Hello) or `T=0` `data` encapsulation. |\n| `tunnelid <number> \\| sessionid <number>` | 16-bit (v2) or 32-bit (v3) identifiers | `tunnelid 1, sessionid 1` | Sets the Tunnel / Control Connection ID and Session ID in the L2TP header. |\n| `ns <0..65535> \\| nr <0..65535>` | 16-bit Send (Ns) and Next Expected (Nr) sequence counters | `ns 0, nr 0` | Writes the 16-bit `Ns` and `Nr` reliable control-channel sequence numbers. |\n| `flags <0..65535>` | 16-bit L2TP header flags/version word override | `Auto (0xc802 control / 0x4002 data on v2)` | Explicitly overrides the 16-bit `T/L/S/O/P/Ver` flags bitmask. |\n| `transport udp` | Optional UDP encapsulation override for L2TPv3 | `UDP 1701 on v2; IP Proto 115 on v3` | Encapsulates `l2tp v3` frames inside UDP port `1701` instead of raw IP Protocol `115` (RFC 3931 UDP mode). |\n\n## Cross-Layer Options Valid with `l2tp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 1701 (v2) / IP Proto 115 or transport udp (v3)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport udp` | Optional UDP encapsulation override | `L2TPv2 UDP 1701 / L2TPv3 IP Proto 115 (UDP 1701 when transport udp is set)` | Wraps the protocol frame inside an IPv4/IPv6 + UDP header instead of raw Ethernet or raw IP encapsulation. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### L2TPv3 Defaults to IP Protocol 115 Unless You Add transport udp\n\n- **Avoid:** `pe1 -> pe2 l2tp v3 data sessionid 100 dstport 1701`\n- **Valid v3.3.0 Syntax:** `pe1 -> pe2 l2tp v3 data sessionid 100 transport udp\n  dstport 1701`\n\nRaw `l2tp v3` runs directly over IP Protocol `115` (no UDP header); add `transport\nudp` whenever you want UDP-encapsulated L2TPv3 or custom UDP ports.\n\n### TCP Transport Is Invalid on L2TP\n\n- **Avoid:** `lac -> lns l2tp v2 sccrq transport tcp`\n- **Valid v3.3.0 Syntax:** `lac -> lns l2tp v2 sccrq`\n\nL2TP runs strictly over UDP (`1701`) or IP Protocol `115`—never TCP.\n"}
{"id":"pretrain-proto-lisp","kind":"protocol_spec","title":"Locator/ID Separation Protocol (Data & Control Plane) (lisp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/lisp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["lisp"],"text":"# lisp — UDP 4341/4342 EID-to-RLOC Mapping & SD-Access Overlays (`lisp`)\n\n> **FrameAssembly v3.3.0** · Protocol 48 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/lisp\n\n- **Full Protocol Name:** Locator/ID Separation Protocol (Data & Control Plane)\n- **Keyword:** `lisp`\n- **OSI Layer & Transport:** Layer 3 · UDP 4341 (Data) / UDP 4342 (Control)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 9300, RFC 9301, RFC 8060\n- **Wireshark Display Filter:** `lisp || lisp-data`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  LISP (RFC 9300 / 9301) (UDP 4341 (Data) / UDP 4342 (Control))`\n\n## Overview\n\nUnder the hood of every Cisco SD-Access campus fabric sits LISP: `lisp` routes\ncontrol lookups (`maprequest`, `mapreply`, `mapregister`) to UDP `4342` and\nInstance-ID data packets (`lisp data`) to UDP `4341` automatically.\n\nLocator/ID Separation Protocol (`lisp`, RFC 9300 / RFC 9301) decouples endpoint\nidentities (**EIDs**) from underlay routing locators (**RLOCs**), serving as the\ncontrol-plane backbone for **Cisco SD-Access (SDA)** campus fabrics (paired with\nVXLAN-GPO data planes) and multi-site VM mobility overlays. LISP splits across two\nIANA UDP ports: **UDP `4341`** for data-plane encapsulation (`data`, carrying a\n24-bit Instance ID `iid`) and **UDP `4342`** for Map-Server / Map-Resolver control\nmessages (`maprequest`, `mapreply`, `mapregister`, `mapnotify`, and `ecm`\nEncapsulated Control Messages).\n\nFrameAssembly automatically selects UDP `4341` for `lisp data` and UDP `4342` for\ncontrol messages, encodes 64-bit echo `nonce` values, sets the Instance-ID bit\n(`I=1`) when `iid` is specified, and packs AFI-prefixed EID CIDR prefixes and RLOC\nlocator records (`priority`, `weight`).\n\n## Minimal Quickstart (`lisp_quickstart.frasm`)\n\n```frameassembly\nhost sda_edge { ip 172.16.100.11 }\nhost map_srv  { ip 172.16.100.2 }\n\ncompile {\n    sda_edge -> map_srv lisp maprequest iid 4099 nonce 0x1122334455667788 eid \"10.50.10.25/32\" rloc 172.16.100.11 wait 2ms\n    sda_edge <- map_srv lisp mapreply iid 4099 nonce 0x1122334455667788 eid \"10.50.10.25/32\" rloc 172.16.100.22 priority 1 weight 100\n}\n```\n\n### Automatic Wire Calculations\n\n- Selects UDP `dstport 4341` automatically for `lisp data` (`lisp-data` dissector)\n  and UDP `dstport 4342` for `maprequest`, `mapreply`, `mapregister`, `mapnotify`,\n  and `ecm` (`lisp` dissector).\n- Encodes IANA Address Family Identifiers (`AFI 1` IPv4, `AFI 2` IPv6, plus LCAF\n  Instance ID `Type 2` when `iid` is set) across EID-Prefix and RLOC Locator\n  records.\n- Writes the 8-byte RFC 9300 LISP data shim (`N/L/E/V/I` flags + 24-bit `iid`)\n  plus an inner IPv4/IPv6 probe header on `lisp data` frames.\n\n## Practical Lab Example: Campus SD-Access Host Registration, EID Resolution & LISP Data-Plane Forwarding (`lisp_sda_fabric_flow.frasm`)\n\nTraces Edge ETR-B registering host `10.200.5.40/32` with a Map-Server\n(`mapregister` -> `mapnotify`), Edge ITR-A resolving that EID (`maprequest` ->\n`mapreply`), and ITR-A encapsulating data to ETR-B on UDP `4341`.\n\n```frameassembly\nhost itr_edge_a { ip 172.20.0.11 }\nhost etr_edge_b { ip 172.20.0.22 }\nhost ms_mr_node { ip 172.20.0.2 }\n\ncompile {\n    // 1. ETR-B registers mobile endpoint 10.200.5.40/32 in VN Instance 4100 on Map-Server (UDP 4342)\n    etr_edge_b -> ms_mr_node lisp mapregister iid 4100 nonce 0xaabbccdd00112233 eid \"10.200.5.40/32\" rloc 172.20.0.22 priority 1 weight 100 wait 1ms\n    etr_edge_b <- ms_mr_node lisp mapnotify iid 4100 nonce 0xaabbccdd00112233 eid \"10.200.5.40/32\" rloc 172.20.0.22 priority 1 weight 100 wait 2ms\n    // 2. ITR-A queries Map-Resolver for 10.200.5.40/32 and receives RLOC 172.20.0.22\n    itr_edge_a -> ms_mr_node lisp maprequest iid 4100 nonce 0x9988776655443322 eid \"10.200.5.40/32\" rloc 172.20.0.11 wait 1ms\n    itr_edge_a <- ms_mr_node lisp mapreply iid 4100 nonce 0x9988776655443322 eid \"10.200.5.40/32\" rloc 172.20.0.22 priority 1 weight 100 wait 2ms\n    // 3. ITR-A encapsulates tenant traffic directly to ETR-B over LISP Data Plane (UDP 4341)\n    itr_edge_a -> etr_edge_b lisp data iid 4100 eid \"10.200.5.40/32\" dscp 34 df payload \"sda-vn4100-payload\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show lisp_sda_fabric_flow.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly lisp_sda_fabric_flow.frasm lisp_sda_fabric_flow.pcap\nframeassembly lisp_sda_fabric_flow.frasm lisp_sda_fabric_flow.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse lisp_sda_fabric_flow.pcap lisp_sda_fabric_flow_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r lisp_sda_fabric_flow.pcap -Y \"lisp || lisp-data\"\n```\n\n## All `lisp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host lisp [data | maprequest | mapreply |\nmapregister | mapnotify | ecm] [flags <0..255>] [iid <0..16777215>] [nonce\n<number>] [eid \"<cidr>\"] [rloc <ip>] [priority <0..255>] [weight <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `data \\| maprequest \\| mapreply \\| mapregister \\| mapnotify \\| ecm` | LISP data or control message mode | `maprequest (UDP 4342)` | Selects UDP `4341` Data encapsulation or UDP `4342` Control Type (`1`=Map-Request, `2`=Map-Reply, `3`=Map-Register, `4`=Map-Notify, `8`=Encapsulated Control Message). |\n| `iid <0..16777215>` | 24-bit LISP Instance ID / Virtual Network ID | `0 (omitted unless specified)` | Sets the 24-bit Instance ID (`I=1` bit on `data` shim, or LCAF Type `2` Instance-ID wrapper on control EIDs). |\n| `eid \"<cidr>\" \\| rloc <ip>` | Quoted IPv4/IPv6 EID prefix & RLOC locator IP | `\"10.0.0.0/24\", source/dest host IP` | Populates the Endpoint ID prefix record and Routing Locator address in Map-Request/Reply/Register/Notify records. |\n| `nonce <number>` | 64-bit unsigned echo/replay nonce | `0x0102030405060708` | Writes the 8-byte Nonce field correlating Map-Request <-> Map-Reply and Map-Register <-> Map-Notify. |\n| `priority <0..255> \\| weight <0..255>` | 8-bit RLOC locator preference & load-share weight | `priority 1, weight 100` | Sets RLOC Priority (`lower = preferred`, `255 = do not use`) and Weight (`0..100` equal-priority split). |\n| `flags <0..255>` | 8-bit LISP flags override | `Auto per message type` | Overrides the upper flag bits in the LISP control or data header. |\n\n## Cross-Layer Options Valid with `lisp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 4341 (Data) / UDP 4342 (Control)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Quote CIDR Prefixes Passed to eid \"<cidr>\"\n\n- **Avoid:** `itr -> mr lisp maprequest eid 10.200.0.0/16 rloc 172.16.0.1`\n- **Valid v3.3.0 Syntax:** `itr -> mr lisp maprequest eid \"10.200.0.0/16\" rloc\n  172.16.0.1`\n\nIn `.frasm`, CIDR prefixes containing `/` (`\"10.200.0.0/16\"` or `\"2001:db8::/48\"`)\nare always double-quoted strings, whereas bare IP literals (`rloc 172.16.0.1`) are\nunquoted.\n\n### Remember Data Uses UDP 4341 While Control Uses UDP 4342\n\n- **Avoid:** `Filtering Wireshark with udp.port == 4342 when inspecting lisp data`\n- **Valid v3.3.0 Syntax:** `Use Wireshark filter lisp || lisp-data (ports 4342 and\n  4341)`\n\nWireshark separates `lisp` (UDP `4342` control plane) from `lisp-data` (UDP `4341`\ndata plane).\n"}
{"id":"pretrain-proto-gtpu","kind":"protocol_spec","title":"GPRS Tunneling Protocol User Plane (4G S1-U & 5G N3/N9) (gtpu) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/gtpu","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["gtpu"],"text":"# gtpu — UDP 2152 4G S1-U & 5G N3 User-Plane Tunnels (TEID + QFI) (`gtpu`)\n\n> **FrameAssembly v3.3.0** · Protocol 49 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/gtpu\n\n- **Full Protocol Name:** GPRS Tunneling Protocol User Plane (4G S1-U & 5G N3/N9)\n- **Keyword:** `gtpu`\n- **OSI Layer & Transport:** Layer 3 · UDP 2152\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** 3GPP TS 29.281, 3GPP TS 38.415\n- **Wireshark Display Filter:** `gtp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  GTPv1-U (UDP 2152) (UDP 2152)`\n\n## Overview\n\nEvery byte your phone downloads over 4G LTE (`S1-U`) or 5G NR (`N3`) rides inside\nUDP `2152` `gtpu`: pass `qfi 9` on `gtpu gpdu` and the compiler automatically\nattaches the `0x85` 5G NR PDU Session Container extension header!\n\nGPRS Tunneling Protocol User Plane (`gtpu`, **UDP `2152`**, 3GPP TS 29.281 / TS\n38.415) carries subscriber user-plane IP packets across **4G LTE S1-U / S5 / S8\n(`eNB <-> SGW <-> PGW`)** and **5G NR N3 / N9 (`gNB <-> I-UPF <-> PSA-UPF`)**\nmobile core interfaces. Every GTPv1-U packet starts with an 8-byte mandatory\nheader (`Version = 1`, `PT = 1`, `E/S/PN` extension flags, `Message Type`,\n`Length`, and 32-bit **Tunnel Endpoint Identifier `teid`**), optionally followed\nby Sequence Number (`seqnum`), N-PDU (`npdu`), and the **5G NR PDU Session\nContainer Extension Header (`0x85`)** carrying the 6-bit **QoS Flow Identifier\n(`qfi 0..63`)**.\n\nFrameAssembly automatically sets the `E` (`0x04`) Next Extension Header bit and\nbuilds the 3GPP TS 38.415 `0x85` PDU Session Container whenever `qfi` is\nspecified, sets `S` (`0x02`) when `seqnum` is present (or on `echorequest` /\n`echoreply`), and encapsulates a clean inner subscriber IPv4/IPv6 packet on `gpdu`\n(`Message Type 0xff`).\n\n## Minimal Quickstart (`gtpu_quickstart.frasm`)\n\n```frameassembly\nhost gnb_du  { ip 172.22.10.11 }\nhost core_upf { ip 172.22.20.50 }\n\ncompile {\n    gnb_du -> core_upf gtpu echorequest teid 0 seqnum 1 wait 1ms\n    gnb_du <- core_upf gtpu echoreply teid 0 seqnum 1 wait 1ms\n    gnb_du -> core_upf gtpu gpdu teid 0x10002001 qfi 9 payload \"ue-uplink-pdu\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults UDP `dstport` to `2152` and computes the 16-bit GTPv1-U `Length` field\n  (bytes following the mandatory 8-byte header, including extension headers and\n  inner G-PDU payload).\n- Automatically sets `E=1` (`0x34` header flags) and appends the 4-byte aligned\n  **PDU Session Container (`0x85`)** Extension Header whenever `qfi <0..63>` is\n  provided.\n- Validates at compile time that `qfi` fits in 6 bits (`0..63`) per 3GPP TS\n  38.415.\n\n## Practical Lab Example: 5G N3 gNB <-> UPF Path Liveness, VoNR QFI=1 + Data QFI=9 Bearers & Xn Handover End-Marker (`gtpu_5g_n3_upf.frasm`)\n\nSimulates GTP-U Echo path verification (`teid 0`), uplink/downlink 5G NR `gpdu`\nframes carrying `qfi 9` (data) and `qfi 1` (VoNR voice), and an inter-gNB handover\n`endmarker`.\n\n```frameassembly\nhost gnb_cell_01 { ip 10.45.1.11 mac 00:1c:73:45:01:11 }\nhost upf_psa_01  { ip 10.45.9.50 mac 00:1c:73:45:09:50 }\n\ncompile {\n    // 1. 3GPP TS 29.281 Path Management Echo Request / Reply (TEID must be 0)\n    gnb_cell_01 -> upf_psa_01 gtpu echorequest teid 0 seqnum 100 wait 1ms\n    gnb_cell_01 <- upf_psa_01 gtpu echoreply teid 0 seqnum 100 wait 2ms\n    // 2. 5G N3 Uplink & Downlink G-PDUs with PDU Session Container (0x85) QFI=9 & VoNR QFI=1\n    gnb_cell_01 -> upf_psa_01 gtpu gpdu teid 0x20000101 qfi 9 dscp 18 payload \"ue-https-uplink\" wait 1ms\n    gnb_cell_01 <- upf_psa_01 gtpu gpdu teid 0x10000101 qfi 9 dscp 18 payload \"ue-https-downlink\" wait 1ms\n    gnb_cell_01 -> upf_psa_01 gtpu gpdu teid 0x20000101 qfi 1 seqnum 101 dscp 46 payload \"ue-vonr-rtp-frame\" wait 2ms\n    // 3. UPF sends End Marker (0xfe) toward source gNB during Xn handover\n    gnb_cell_01 <- upf_psa_01 gtpu endmarker teid 0x10000101\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show gtpu_5g_n3_upf.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly gtpu_5g_n3_upf.frasm gtpu_5g_n3_upf.pcap\nframeassembly gtpu_5g_n3_upf.frasm gtpu_5g_n3_upf.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse gtpu_5g_n3_upf.pcap gtpu_5g_n3_upf_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r gtpu_5g_n3_upf.pcap -Y \"gtp\"\n```\n\n## All `gtpu` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host gtpu [gpdu | echorequest | echoreply |\nerrorindication | endmarker] [teid <number>] [flags <0..255>] [seqnum <0..65535>]\n[npdu <0..255>] [qfi <0..63>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `gpdu \\| echorequest \\| echoreply \\| errorindication \\| endmarker` | GTPv1-U message type keyword | `gpdu (0xff)` | Selects 3GPP TS 29.281 Message Type (`1`=Echo Request, `2`=Echo Response, `26`=Error Indication, `254`=End Marker, `255`=T-PDU / G-PDU). |\n| `teid <number>` | 32-bit Tunnel Endpoint Identifier | `0 on echo, 1 on gpdu` | Writes the big-endian 32-bit TEID in bytes 4..7 of the GTPv1-U header. |\n| `qfi <0..63>` | 6-bit 5G QoS Flow Identifier (0..63) | `Omitted (4G S1-U mode)` | Sets `E=1` and appends Next Extension Header `0x85` (5G NR PDU Session Container) carrying the 6-bit QFI. |\n| `seqnum <0..65535> \\| npdu <0..255>` | 16-bit GTP-U Sequence Number & 8-bit N-PDU Number | `Omitted on gpdu (seqnum 1 on echo)` | Enables the 4-byte optional GTPv1-U header extension (`S=1` / `PN=1`) and writes Sequence / N-PDU fields. |\n| `flags <0..255>` | 8-bit GTPv1-U header byte 0 override | `0x30 (or 0x32/0x34 with seqnum/qfi)` | Overrides Version (`1`), Protocol Type (`PT=1`), and `E/S/PN` flag bits. |\n\n## Cross-Layer Options Valid with `gtpu`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 2152` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### qfi Is a 6-Bit 5G QoS Flow ID (0..63)\n\n- **Avoid:** `gnb -> upf gtpu gpdu teid 0x1001 qfi 64`\n- **Valid v3.3.0 Syntax:** `gnb -> upf gtpu gpdu teid 0x1001 qfi 9`\n\n3GPP TS 38.415 allocates 6 bits (`0..63`) for QoS Flow Identifier inside the PDU\nSession Container; `qfi > 63` fails compile-time validation.\n\n### GTPv1-U Runs on UDP 2152 (GTPv2-C Control Signaling Uses gtpc on UDP 2123)\n\n- **Avoid:** `gnb -> mme gtpu createsessionrequest teid 0`\n- **Valid v3.3.0 Syntax:** `gnb -> upf gtpu gpdu teid 0x10002001 qfi 9`\n\nUse `gtpu` (UDP `2152`) for user-plane `gpdu`, `echorequest`, `echoreply`,\n`errorindication`, and `endmarker`; session creation signaling belongs to\ncontrol-plane GTPv2-C.\n"}
{"id":"pretrain-proto-tcp","kind":"protocol_spec","title":"Transmission Control Protocol & RFC 7323 Options (tcp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/tcp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp"],"text":"# tcp — Automatic 4-Tuple Handshakes, RFC 7323 Options & Chaos (`tcp`)\n\n> **FrameAssembly v3.3.0** · Protocol 50 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/tcp\n\n- **Full Protocol Name:** Transmission Control Protocol & RFC 7323 Options\n- **Keyword:** `tcp`\n- **OSI Layer & Transport:** Layer 4 · IP Proto 6 (Default dstport 80)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 9293, RFC 7323, RFC 2018, RFC 2385, RFC 7413\n- **Wireshark Display Filter:** `tcp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP & RFC 7323 (IP Proto 6 (Default dstport 80))`\n\n## Overview\n\nThe crown jewel of the compiler: declare `srcport` and `dstport` once on `tcp\nsyn`, and FrameAssembly tracks `seq` and `acknum` across `->`, `<-`, and every TCP\nLayer 7 protocol (unless you override `seq` to inject chaos on purpose).\n\nTransmission Control Protocol (`tcp`, IP protocol `6`, RFC 9293) is the\nconnection-oriented Layer 4 transport powering HTTP, TLS, BGP, SSH, databases, and\nindustrial protocols. FrameAssembly includes a **built-in stateful 4-tuple TCP\nsequence tracker** shared automatically across raw `tcp` frames and every\nTCP-carried Layer 7 protocol.\n\nOnce you open a connection with `srcport` and `dstport` on `tcp syn`, subsequent\n`<-` and `->` statements inherit the reversed port pair, advance `seq` and\n`acknum` by `+1` on `syn`/`fin` and `+payload.len()` on data segments, pad RFC\n7323 options (`mss`, `wscale`, `sackperm`, `tsval`, `tsecr`) to 32-bit boundaries\nwith `NOP`/`EOL` bytes, and compute the exact IPv4 or IPv6 pseudo-header checksum.\n\n## Minimal Quickstart (`tcp_quickstart.frasm`)\n\n```frameassembly\nhost client { ip 10.10.1.15 }\nhost server { ip 10.10.1.80 }\n\ncompile {\n    client -> server tcp syn srcport 52400 dstport 443 win 65535 mss 1460 wscale 7 sackperm wait 1ms\n    client <- server tcp syn ack win 65535 mss 1460 wscale 7 sackperm wait 1ms\n    client -> server tcp ack\n}\n```\n\n### Automatic Wire Calculations\n\n- Tracks 4-tuple `(src_ip, dst_ip, src_port, dst_port)` sequence state starting at\n  `seq 1000`—advancing `seq` by `+1` for `syn`/`fin` and `+payload_len` for data\n  without manual arithmetic.\n- Remembers `srcport 52400` and `dstport 443` from the opening `syn` so `<-` and\n  `->` follow-up frames swap `443 <-> 52400` automatically.\n- Aligns variable-length TCP options (`mss` 4B, `sackperm` 2B, `tsval`/`tsecr`\n  10B, `wscale` 3B) to 4-byte multiples with RFC 9293 `NOP` (`0x01`) padding and\n  updates Data Offset.\n\n## Practical Lab Example: Full Lifecycle: RFC 7323 Handshake, ECN-Capable Data Exchange & Graceful FIN Close (`tcp_rfc7323_lifecycle.frasm`)\n\nCaptures a complete 7-packet TCP lifecycle with RFC 7323 timestamps\n(`tsval`/`tsecr`), selective ACK permission (`sackperm`), payload push (`psh\nack`), and 4-way `fin ack` teardown.\n\n```frameassembly\nhost app_client { ip 172.16.20.10 }\nhost api_origin { ip 172.16.20.90 }\n\ncompile {\n    // 1. 3-way handshake negotiating MSS 1460, Window Scale 7, SACK, and Timestamps\n    app_client -> api_origin tcp syn srcport 54110 dstport 8443 win 65535 mss 1460 wscale 7 sackperm tsval 1000 tsecr 0 wait 1ms\n    app_client <- api_origin tcp syn ack win 65535 mss 1460 wscale 7 sackperm tsval 5000 tsecr 1000 wait 1ms\n    app_client -> api_origin tcp ack tsval 1001 tsecr 5000 wait 2ms\n    // 2. Bidirectional application payload (seq/acknum advance automatically by byte length)\n    app_client -> api_origin tcp psh ack tsval 1003 tsecr 5000 payload \"PING /healthz\\r\\n\" wait 2ms\n    app_client <- api_origin tcp psh ack tsval 5002 tsecr 1003 payload \"200 OK\\r\\n\" wait 3ms\n    // 3. Clean 3-packet FIN/ACK session close\n    app_client -> api_origin tcp fin ack tsval 1006 tsecr 5002 wait 1ms\n    app_client <- api_origin tcp fin ack tsval 5003 tsecr 1007 wait 1ms\n    app_client -> api_origin tcp ack tsval 1007 tsecr 5004\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show tcp_rfc7323_lifecycle.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly tcp_rfc7323_lifecycle.frasm tcp_rfc7323_lifecycle.pcap\nframeassembly tcp_rfc7323_lifecycle.frasm tcp_rfc7323_lifecycle.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse tcp_rfc7323_lifecycle.pcap tcp_rfc7323_lifecycle_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r tcp_rfc7323_lifecycle.pcap -Y \"tcp\"\n```\n\n## All `tcp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host tcp [syn] [ack] [fin] [rst] [psh] [urg]\n[ece] [cwr] [srcport <0..65535>] [dstport <0..65535>] [seq <number>] [acknum\n<number>] [win|window <0..65535>] [urgent <0..65535>] [mss <0..65535>] [wscale\n<0..255>] [sackperm] [sackblock <number> <number>] [tsval <number>] [tsecr\n<number>] [tcpmd5 \"<hex>\"] [tfo \"<hex>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `syn \\| ack \\| fin \\| rst \\| psh \\| urg \\| ece \\| cwr` | Bare lowercase flag keywords (combinable) | `ack (or psh ack when payload present)` | Sets individual control bits in byte 13 of the 20-byte TCP header. |\n| `srcport <0..65535> \\| dstport <0..65535>` | Whole number (0..65535) | `srcport 49152, dstport 80 (or inherited)` | Sets TCP source and destination ports and anchors bidirectional pair port memory. |\n| `seq <number> \\| acknum <number>` | Whole number | `Tracked 4-tuple state (initial seq 1000)` | Explicitly overrides the 32-bit Sequence Number or Acknowledgment Number (`acknum`) and updates tracker state. |\n| `win <0..65535> \\| window <0..65535>` | Whole number (0..65535) | `65535` | Sets the 16-bit Receive Window field (`window` is an exact alias for `win`). |\n| `urgent <0..65535>` | Whole number (0..65535) | `0` | Sets the 16-bit Urgent Pointer field (pair with the `urg` flag). |\n| `mss <0..65535>` | Whole number (0..65535) (bytes) | `Omitted` | Appends TCP Option Kind `2` (Maximum Segment Size, 4 bytes, e.g. `1460` IPv4 or `1440` IPv6). |\n| `wscale <0..255>` | 8-bit shift count (RFC 7323 <= 14) | `Omitted` | Appends TCP Option Kind `3` (Window Scale, 3 bytes + 1-byte alignment NOP). |\n| `sackperm` | Boolean flag keyword | `Omitted` | Appends TCP Option Kind `4` (SACK Permitted, 2 bytes) per RFC 2018. |\n| `sackblock <left> <right>` | Two 32-bit sequence edge integers | `Omitted` | Appends TCP Option Kind `5` (RFC 2018 Selective Acknowledgment block `[left_edge, right_edge)`). |\n| `tsval <number> [tsecr <number>]` | Whole number | `Omitted (tsecr 0 when only tsval set)` | Appends TCP Option Kind `8` (RFC 7323 Timestamps, 10 bytes + 2-byte alignment NOPs). |\n| `tcpmd5 \"<hex>\"` | 16-byte hex digest (\"0102...0f10\") | `Omitted` | Appends TCP Option Kind `19` (RFC 2385 BGP/LDP MD5 Signature, 18 bytes + 2-byte NOP alignment). |\n| `tfo \"<hex>\"` | Quoted hex cookie (\"\" for TFO request or 4..16B cookie) | `Omitted` | Appends TCP Option Kind `34` (RFC 7413 TCP Fast Open cookie). |\n\n## Cross-Layer Options Valid with `tcp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n\n## Common Mistakes & Quick Fixes\n\n### Use acknum <number> for the Acknowledgment Number (Bare ack Is the Flag)\n\n- **Avoid:** `client -> server tcp syn ack 1001 sport 50000 dport 443`\n- **Valid v3.3.0 Syntax:** `client -> server tcp syn ack acknum 1001 srcport 50000\n  dstport 443`\n\nBare `ack` sets the 1-bit `ACK` flag in the TCP header. Use `acknum <number>` to\nset the 32-bit Acknowledgment Number, and always spell out `srcport` / `dstport`.\n\n### Never Add Underscores to sackperm, sackblock, or TCP Flags\n\n- **Avoid:** `client -> server tcp flags [SYN] sack_perm`\n- **Valid v3.3.0 Syntax:** `client -> server tcp syn sackperm`\n\nEvery FrameAssembly v3.3.0 built-in keyword is strictly lowercase alphanumeric\n(`syn`, `ack`, `psh`, `sackperm`, `sackblock`, `tcpmd5`, `tfo`, `wscale`, `tsval`,\n`tsecr`) without brackets or underscores.\n"}
{"id":"pretrain-proto-udp","kind":"protocol_spec","title":"User Datagram Protocol (udp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/udp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["udp"],"text":"# udp — Custom Datagrams, Port Memory & Mandatory Checksums (`udp`)\n\n> **FrameAssembly v3.3.0** · Protocol 51 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/udp\n\n- **Full Protocol Name:** User Datagram Protocol\n- **Keyword:** `udp`\n- **OSI Layer & Transport:** Layer 4 · IP Proto 17 (Default dstport 80)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 768, RFC 8200\n- **Wireshark Display Filter:** `udp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP (IP Proto 17 (Default dstport 80))`\n\n## Overview\n\nNo `syn`, no `fin`, no regrets: `udp` fires arbitrary string or hex bytes at any\nport, remembers the port pair on `<-` replies, and nails the mandatory IPv6 UDP\nchecksum every time.\n\nUser Datagram Protocol (`udp`, IP protocol `17`, RFC 768) provides stateless,\nminimal-overhead 8-byte Layer 4 framing (`Source Port`, `Destination Port`,\n`Length`, and `Checksum`) over both IPv4 and IPv6. It is the ideal building block\nfor custom binary protocols, proprietary game/financial market-data feeds,\nfirewall ACL probes, and IPv4 fragmentation tests.\n\nFrameAssembly computes the exact UDP Length (`8 + payload.len()`) and non-zero RFC\n768 / RFC 8200 pseudo-header checksum (mapping computed `0x0000` to `0xffff` as\nrequired on IPv6), while remembering `(srcport, dstport)` across `->` and `<-`\nframes on the same host pair.\n\n## Minimal Quickstart (`udp_quickstart.frasm`)\n\n```frameassembly\nhost sensor  { ip 10.20.0.15 }\nhost gateway { ip 10.20.0.1 }\n\ncompile {\n    sensor -> gateway udp srcport 53100 dstport 9000 payload \"ping:seq=1\" wait 2ms\n    sensor <- gateway udp payload \"pong:seq=1\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Computes the 16-bit UDP Length (`8 + payload bytes`) and outer IPv4 Total Length\n  / IPv6 Payload Length automatically.\n- Calculates the ones'-complement pseudo-header checksum over IPv4 or IPv6\n  addresses, converting `0x0000` to `0xffff` per RFC 768 / RFC 8200.\n- Remembers `srcport 53100` and `dstport 9000` on the `(sensor, gateway)` pair so\n  the `<-` reply automatically emits `9000 -> 53100`.\n\n## Practical Lab Example: Dual-Stack Custom Binary Telemetry Feed with QoS Marking (`udp_dualstack_binary.frasm`)\n\nUses a reusable `flow(tx, rx)` template to emit identical hex-encoded binary UDP\nframes marked `dscp 46` (EF) over both IPv4 and IPv6 endpoints.\n\n```frameassembly\nhost feed_v4 { ip 192.0.2.10 }\nhost recv_v4 { ip 192.0.2.20 }\nhost feed_v6 { ip 2001:db8:feed::10 }\nhost recv_v6 { ip 2001:db8:feed::20 }\n\nflow telemetry_burst(tx, rx) {\n    tx -> rx udp srcport 55100 dstport 19500 dscp 46 hexpayload \"cafebabe00010008deadbeef\" wait 500us\n    tx -> rx udp dscp 46 hexpayload \"cafebabe0002000801020304\" wait 1ms\n    tx <- rx udp dscp 46 payload \"ACK:2\"\n}\n\ncompile {\n    telemetry_burst(feed_v4, recv_v4)\n    telemetry_burst(feed_v6, recv_v6)\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show udp_dualstack_binary.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly udp_dualstack_binary.frasm udp_dualstack_binary.pcap\nframeassembly udp_dualstack_binary.frasm udp_dualstack_binary.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse udp_dualstack_binary.pcap udp_dualstack_binary_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r udp_dualstack_binary.pcap -Y \"udp\"\n```\n\n## All `udp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host udp [srcport <0..65535>] [dstport\n<0..65535>] [nochecksum] [payload \"<text>\" | hexpayload \"<hex>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `srcport <0..65535>` | Whole number (0..65535) | `49152 (or inherited pair port)` | Sets the 16-bit UDP Source Port in bytes 0..1 of the UDP header. |\n| `dstport <0..65535>` | Whole number (0..65535) | `80 (or inherited pair port)` | Sets the 16-bit UDP Destination Port in bytes 2..3 of the UDP header. |\n| `nochecksum` | Boolean zero-checksum flag | `Unset (valid RFC checksum)` | Writes `0x0000` into the 16-bit UDP Checksum field (commonly used for IPv4 VXLAN/tunnel offloads and RFC 6935 IPv6 tunnel tests). |\n| `payload \"<text>\"` | Quoted text | `Empty (0 bytes)` | Appends UTF-8 bytes after the 8-byte UDP header (mutually exclusive with `hexpayload`). |\n| `hexpayload \"<hex>\"` | Even-length hex octets (\"deadbeef\" or \"de:ad:be:ef\") | `Empty (0 bytes)` | Appends raw decoded bytes after the 8-byte UDP header (mutually exclusive with `payload`). |\n\n## Cross-Layer Options Valid with `udp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### TCP Flags and Options Are Rejected on UDP Frames\n\n- **Avoid:** `sensor -> gateway udp dstport 9000 syn seq 100`\n- **Valid v3.3.0 Syntax:** `sensor -> gateway udp dstport 9000 hexpayload\n  \"00000064\"`\n\nTCP-only flags and options (`syn`, `ack`, `psh`, `seq`, `acknum`, `win`, `mss`,\n`sackperm`) cannot be used on UDP packets.\n\n### Never Combine payload and hexpayload on One Frame\n\n- **Avoid:** `sensor -> gateway udp dstport 9000 payload \"hdr\" hexpayload\n  \"deadbeef\"`\n- **Valid v3.3.0 Syntax:** `sensor -> gateway udp dstport 9000 hexpayload\n  \"686472deadbeef\"`\n\nA single frame statement accepts either `payload \"<utf8>\"` or `hexpayload\n\"<hex>\"`, never both simultaneously.\n"}
{"id":"pretrain-proto-sctp","kind":"protocol_spec","title":"Stream Control Transmission Protocol (sctp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/sctp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["sctp"],"text":"# sctp — 4-Way Telecom Handshakes, Multi-Stream & CRC-32c (`sctp`)\n\n> **FrameAssembly v3.3.0** · Protocol 52 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/sctp\n\n- **Full Protocol Name:** Stream Control Transmission Protocol\n- **Keyword:** `sctp`\n- **OSI Layer & Transport:** Layer 4 · IP Proto 132 (38412 NGAP / 36412 S1AP)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 9260, RFC 4960, 3GPP TS 38.412\n- **Wireshark Display Filter:** `sctp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  SCTP (CRC-32c) (IP Proto 132 (38412 NGAP / 36412 S1AP))`\n\n## Overview\n\nPowering 4G S1AP and 5G NGAP telecom cores on IP Protocol `132`, `sctp` packs\n32-bit padded chunks (`init`, `data`, `sack`, `heartbeat`) and computes the\ninfamous reflected Castagnoli **CRC-32c** automatically.\n\nStream Control Transmission Protocol (`sctp`, IP protocol `132`, RFC 9260) is the\nmessage-oriented, multi-stream Layer 4 transport underpinning **5G Core NGAP\n(`38412`)**, **4G LTE S1AP (`36412`)**, **Diameter (`3868`)**, **SS7 SIGTRAN M3UA\n(`2905`)**, and WebRTC DataChannels. Every SCTP packet carries a 12-byte Common\nHeader (`Source Port`, `Destination Port`, 32-bit `Verification Tag`, and 32-bit\nchecksum) followed by chunk TLVs.\n\nUnlike TCP and UDP, SCTP mandates the **Castagnoli CRC-32c** polynomial rather\nthan an ones'-complement sum. FrameAssembly computes the exact hardware-table\nCastagnoli CRC-32c across the Common Header and 4-byte-padded chunks automatically\nso Wireshark and telecom core stacks validate every packet cleanly.\n\n## Minimal Quickstart (`sctp_quickstart.frasm`)\n\n```frameassembly\nhost gnb_01 { ip 10.50.1.10 }\nhost amf_01 { ip 10.50.1.20 }\n\ncompile {\n    gnb_01 -> amf_01 sctp init srcport 38412 dstport 38412 vtag 0 tsn 1000 wait 1ms\n    gnb_01 <- amf_01 sctp initack vtag 0x11223344 tsn 2000 wait 1ms\n    gnb_01 -> amf_01 sctp data vtag 0x22334455 tsn 1001 stream 0 ssn 0 ppid 60 hexpayload \"0015000900000100\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Computes the 32-bit reflected Castagnoli CRC-32c checksum across the 12-byte\n  SCTP Common Header and all padded chunk bytes.\n- Pads chunk payloads to 4-byte alignment per RFC 9260 while recording the exact\n  unpadded length inside the Chunk Length field.\n- Inherits bidirectional ports (`38412 <-> 38412`) across `->` and `<-` statements\n  after the initial `init` packet.\n\n## Practical Lab Example: Complete 5G N2 NGAP SCTP 4-Way Handshake, Data Transfer & Heartbeat (`sctp_5g_ngap_association.frasm`)\n\nModels a 5G gNodeB establishing a full 4-way cookie handshake with an AMF on port\n38412, transmitting an NGAP Setup Request (`ppid 60`), receiving `sack`, and\nexchanging `heartbeat` / `heartbeatack`.\n\n```frameassembly\nhost gnb_du { ip 172.20.10.11 }\nhost core_amf { ip 172.20.10.50 }\n\ncompile {\n    // 1. RFC 9260 4-way association handshake (INIT must carry vtag 0)\n    gnb_du -> core_amf sctp init srcport 38412 dstport 38412 vtag 0 tsn 1000 dscp 46 wait 1ms\n    gnb_du <- core_amf sctp initack vtag 0xa1b2c3d4 tsn 5000 dscp 46 wait 1ms\n    gnb_du -> core_amf sctp cookieecho vtag 0x55667788 dscp 46 wait 1ms\n    gnb_du <- core_amf sctp cookieack vtag 0xa1b2c3d4 dscp 46 wait 2ms\n    // 2. NGAP payload over Stream 0 (PPID 60 = 3GPP NGAP) + SACK acknowledgment\n    gnb_du -> core_amf sctp data vtag 0x55667788 tsn 1000 stream 0 ssn 0 ppid 60 dscp 46 hexpayload \"00150014000002001b00080000f110000001\" wait 1ms\n    gnb_du <- core_amf sctp sack vtag 0xa1b2c3d4 tsn 1000 dscp 46 wait 5ms\n    // 3. Path liveness probe\n    gnb_du -> core_amf sctp heartbeat vtag 0x55667788 wait 1ms\n    gnb_du <- core_amf sctp heartbeatack vtag 0xa1b2c3d4\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show sctp_5g_ngap_association.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly sctp_5g_ngap_association.frasm sctp_5g_ngap_association.pcap\nframeassembly sctp_5g_ngap_association.frasm sctp_5g_ngap_association.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse sctp_5g_ngap_association.pcap sctp_5g_ngap_association_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r sctp_5g_ngap_association.pcap -Y \"sctp\"\n```\n\n## All `sctp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host sctp [chunk <type> | data | init |\ninitack | sack | heartbeat | heartbeatack | abort | shutdown | shutdownack |\nshutdowncomplete | cookieecho | cookieack] [vtag <number>] [tsn <number>] [stream\n<0..65535>] [ssn <0..65535>] [ppid <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `data \\| init \\| initack \\| sack \\| heartbeat \\| heartbeatack \\| abort \\| shutdown \\| shutdownack \\| shutdowncomplete \\| cookieecho \\| cookieack` | Bare chunk keyword (or `chunk <type>`) | `data (Chunk Type 0)` | Selects the RFC 9260 SCTP chunk type (`0`=DATA, `1`=INIT, `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT, `5`=HEARTBEAT_ACK, `6`=ABORT, `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO, `11`=COOKIE_ACK, `14`=SHUTDOWN_COMPLETE). |\n| `vtag <number>` | Whole number | `0 on init, 1 otherwise` | Sets the 32-bit Verification Tag in bytes 4..7 of the SCTP Common Header (`0` mandatory on `init`). |\n| `tsn <number>` | Whole number | `1` | Sets Initial TSN in `init`/`initack`, Cumulative TSN Ack in `sack`, or chunk TSN in `data`. |\n| `stream <0..65535>` | Whole number (0..65535) | `0` | Sets the Stream Identifier S field inside `data` chunks. |\n| `ssn <0..65535>` | Whole number (0..65535) | `0` | Sets the 16-bit Stream Sequence Number inside `data` chunks. |\n| `ppid <number>` | 32-bit IANA Payload Protocol Identifier | `0` | Sets the big-endian Payload Protocol ID in `data` chunks (`60`=NGAP, `18`=S1AP, `46`=Diameter, `3`=M3UA) so Wireshark auto-dissects upper layers. |\n\n## Cross-Layer Options Valid with `sctp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), IP Proto 132 (38412 NGAP / 36412 S1AP)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n\n## Common Mistakes & Quick Fixes\n\n### Chunk Names Have Zero Underscores (initack, cookieecho, heartbeatack)\n\n- **Avoid:** `gnb_du <- core_amf sctp init_ack vtag 0x11223344`\n- **Valid v3.3.0 Syntax:** `gnb_du <- core_amf sctp initack vtag 0x11223344`\n\nAll SCTP chunk keywords follow FrameAssembly's `[a-z0-9]+` rule: `initack`,\n`cookieecho`, `cookieack`, `heartbeatack`, and `shutdownack`.\n\n### Use tsn Instead of TCP seq on SCTP Frames\n\n- **Avoid:** `gnb_du -> core_amf sctp data seq 1001 ppid 60`\n- **Valid v3.3.0 Syntax:** `gnb_du -> core_amf sctp data tsn 1001 ppid 60`\n\n`seq` is a TCP-only option and cannot be used on SCTP packets; use `tsn` for\nTransmission Sequence Numbers and `ssn` for Stream Sequence Numbers.\n"}
{"id":"pretrain-proto-snmp1","kind":"protocol_spec","title":"Simple Network Management Protocol v1 (snmp1) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/snmp1","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["snmp1"],"text":"# snmp1 — MIB-Free RFC 1157 Traps, Enterprise OIDs & Polls (`snmp1`)\n\n> **FrameAssembly v3.3.0** · Protocol 53 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/snmp1\n\n- **Full Protocol Name:** Simple Network Management Protocol v1\n- **Keyword:** `snmp1`\n- **OSI Layer & Transport:** Layer 7 · UDP/TCP 162 (trap) / 161 (get/set)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 1157, RFC 1155, RFC 3584\n- **Wireshark Display Filter:** `snmp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP/TCP 162 (trap) / 161 (get/set) (transport tcp|udp) -> SNMPv1`\n\n## Overview\n\nThat 22-year-old UPS in the basement closet still only speaks RFC 1157 `Trap-PDU`.\n`snmp1` encodes `enterprise`, `agentip`, `gentrap 0..6`, and BER `varbind` chains\nwith zero MIB files.\n\nSimple Network Management Protocol v1 (`snmp1`, RFC 1157) encodes ASN.1 BER\n`version = 0` management PDUs (`get`, `getnext`, `set`, `response` on **UDP\n`161`**) and legacy v1 `Trap-PDU` (`0xa4` on **UDP `162`**) carrying dedicated\n`enterprise`, `agent-addr` (`agentip`), `generic-trap` (`gentrap 0..6`),\n`specific-trap` (`spectrap`), and `time-stamp` (`sysuptime`) header fields.\n\nFrameAssembly compiles valid ASN.1 BER lengths, base-128 variable-length OID\nsub-identifiers (`40 * arc1 + arc2`), and repeatable typed `varbind` sequences\ncompletely offline—zero external MIB files or Net-SNMP libraries required.\n\n## Minimal Quickstart (`snmp1_quickstart.frasm`)\n\n```frameassembly\nhost ups_01 { ip 10.10.50.12 }\nhost nms_rx { ip 10.10.50.100 }\n\ncompile {\n    ups_01 -> nms_rx snmp1 trap community \"public\" enterprise 1.3.6.1.4.1.318 gentrap 6 spectrap 5 sysuptime 120500 varbind 1.3.6.1.2.1.1.5.0 string \"ups-dc1-row4\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Selects UDP `dstport 162` automatically for `trap` (the default PDU) and UDP\n  `161` (with `161 -> ephemeral` port reversal on `<- response`) for `get`,\n  `getnext`, `set`, and `response`.\n- Encodes dotted numeric OIDs (`1.3.6.1.4.1.318` or `.1.3.6.1...`) into compact\n  ASN.1 BER base-128 VLQ octets (`0x2b 0x06 0x01 ...`) and computes nested\n  SEQUENCE lengths.\n- Supports repeatable `varbind <oid> <type_val>` entries across `string`, `int`,\n  `oidval`, `ipval`, `counter32`, `gauge32`, `timeticks`, `counter64`, and `null`\n  (or `nullval`).\n\n## Practical Lab Example: SNMPv1 System MIB Poll (`sysDescr.0` / `sysName.0`) + ColdStart & Enterprise Traps (`snmp1_poll_and_traps.frasm`)\n\nPolls `sysDescr.0` on UDP 161, returns a multi-varbind `response`, and emits both\na standard `gentrap 0` (`coldStart`) and an `enterpriseSpecific` (`gentrap 6`)\nhardware alarm trap on UDP 162.\n\n```frameassembly\nhost poller   { ip 172.16.40.10 }\nhost legacy_sw { ip 172.16.40.25 }\n\ncompile {\n    // 1. Poll sysDescr.0 (1.3.6.1.2.1.1.1.0) on UDP 161\n    poller -> legacy_sw snmp1 get community \"ops-ro\" reqid 1001 oid 1.3.6.1.2.1.1.1.0 wait 2ms\n    poller <- legacy_sw snmp1 response community \"ops-ro\" reqid 1001 varbind 1.3.6.1.2.1.1.1.0 string \"Managed L2 Switch v4.2\" varbind 1.3.6.1.2.1.1.3.0 timeticks 8640000 wait 5ms\n    // 2. Generic coldStart trap (gentrap 0, spectrap 0) on UDP 162\n    legacy_sw -> poller snmp1 trap community \"ops-ro\" enterprise 1.3.6.1.4.1.9.1.516 agentip 172.16.40.25 gentrap 0 spectrap 0 sysuptime 120 wait 2ms\n    // 3. Enterprise-specific PSU fault trap (gentrap 6, spectrap 42) with typed varbinds\n    legacy_sw -> poller snmp1 trap community \"ops-ro\" enterprise 1.3.6.1.4.1.9.9.13 gentrap 6 spectrap 42 sysuptime 45000 varbind 1.3.6.1.2.1.1.5.0 string \"sw-idf-03\" varbind 1.3.6.1.4.1.9.9.13.1.5.1.3.1 int 4\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show snmp1_poll_and_traps.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly snmp1_poll_and_traps.frasm snmp1_poll_and_traps.pcap\nframeassembly snmp1_poll_and_traps.frasm snmp1_poll_and_traps.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse snmp1_poll_and_traps.pcap snmp1_poll_and_traps_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r snmp1_poll_and_traps.pcap -Y \"snmp\"\n```\n\n## All `snmp1` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host snmp1 [trap | get | getnext | set |\nresponse] [community \"<text>\"] [enterprise <oid>] [agentip <ipv4>] [gentrap\n<0..6>] [spectrap <number>] [sysuptime <number>] [reqid <number>] [oid <oid>]\n[varbind <oid> <type_val> ...]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `trap \\| get \\| getnext \\| set \\| response` | SNMPv1 PDU type keyword | `trap (PDU 0xa4 on UDP 162)` | Selects ASN.1 BER PDU context tag (`0xa0` GetRequest, `0xa1` GetNextRequest, `0xa2` GetResponse, `0xa3` SetRequest, `0xa4` v1 Trap). |\n| `community \"<text>\"` | Double-quoted OCTET STRING | `\"public\"` | Sets the cleartext SNMPv1 community string. |\n| `enterprise <oid>` | Dotted numeric OID (>= 2 arcs) | `1.3.6.1.4.1.8072.3.2.10` | Sets the `enterprise` OBJECT IDENTIFIER inside SNMPv1 `trap` PDUs. |\n| `agentip <ipv4>` | IPv4 dotted-quad literal | `Source IPv4 (or 0.0.0.0 on IPv6)` | Sets the 4-byte `NetworkAddress` (`agent-addr`) inside SNMPv1 `trap` PDUs. |\n| `gentrap <0..6> \\| spectrap <number>` | gentrap: 0..6, spectrap: u32 | `gentrap 6, spectrap 1` | Sets `generic-trap` (`0`=coldStart, `1`=warmStart, `2`=linkDown, `3`=linkUp, `4`=authFailure, `5`=egpNeighborLoss, `6`=enterpriseSpecific) and `specific-trap`. |\n| `sysuptime <number> \\| reqid <number>` | Whole number | `sysuptime 1000, reqid 1` | Sets `time-stamp` (`TimeTicks` hundredths of a second) on `trap` or `request-id` on `get`/`getnext`/`set`/`response`. |\n| `oid <oid>` | Dotted numeric OID | `1.3.6.1.2.1.1.1.0` | Shorthand that appends a `NULL`-valued varbind (`<oid> = NULL`) for `get` / `getnext` requests. |\n| `varbind <oid> string \"<text>\" \\| int <number> \\| oidval <oid> \\| ipval <ipv4> \\| counter32 <number> \\| gauge32 <number> \\| timeticks <number> \\| counter64 <number> \\| null \\| nullval` | Repeatable OID + SMI value keyword | `Omitted` | Appends an ASN.1 BER `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and `nullval` are interchangeable aliases). |\n\n## Cross-Layer Options Valid with `snmp1`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP/TCP 162 (trap) / 161 (get/set)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Always Spell Out varbind <oid> string \"<val>\" (Never str)\n\n- **Avoid:** `ups_01 -> nms_rx snmp1 trap varbind 1.3.6.1.2.1.1.5.0 str \"ups-01\"`\n- **Valid v3.3.0 Syntax:** `ups_01 -> nms_rx snmp1 trap varbind 1.3.6.1.2.1.1.5.0\n  string \"ups-01\"`\n\nThe SMI OCTET STRING varbind type keyword in FrameAssembly v3.2.0 is strictly\n`string` (never `str`).\n\n### getbulk and inform Require snmp2 or snmp3\n\n- **Avoid:** `poller -> legacy_sw snmp1 getbulk maxrepetitions 10 oid\n  1.3.6.1.2.1.2.2.1`\n- **Valid v3.3.0 Syntax:** `poller -> legacy_sw snmp2 getbulk maxrepetitions 10\n  oid 1.3.6.1.2.1.2.2.1`\n\nRFC 1157 SNMPv1 predates `GetBulkRequest` (`0xa5`) and `InformRequest` (`0xa6`);\nswitch the protocol keyword to `snmp2` or `snmp3` for bulk table walks.\n"}
{"id":"pretrain-proto-snmp2","kind":"protocol_spec","title":"Simple Network Management Protocol v2c (snmp2) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/snmp2","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["snmp2"],"text":"# snmp2 — MIB-Free SNMPv2c Traps, Informs & GetBulk Sweeps (`snmp2`)\n\n> **FrameAssembly v3.3.0** · Protocol 54 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/snmp2\n\n- **Full Protocol Name:** Simple Network Management Protocol v2c\n- **Keyword:** `snmp2`\n- **OSI Layer & Transport:** Layer 7 · UDP/TCP 162 (trap/inform) / 161\n  (get/getbulk)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 3416, RFC 3418, RFC 2863\n- **Wireshark Display Filter:** `snmp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP/TCP 162 (trap/inform) / 161 (get/getbulk) (transport tcp|udp) -> SNMPv2c`\n\n## Overview\n\nTesting a Zabbix, PRTG, or Prometheus alert rule from your desk? `snmp2 trap` and\n`snmp2 inform` pack `sysUpTime.0`, `snmpTrapOID.0`, and 64-bit `counter64`\nvarbinds straight from numeric OIDs.\n\nSimple Network Management Protocol v2c (`snmp2`, RFC 3416) upgrades SNMPv1\n(`version = 1`) with high-throughput **`getbulk`** table retrieval (`0xa5` using\n`nonrepeaters` and `maxrepetitions`), 64-bit **`counter64`** `ifXTable` interface\ncounters, acknowledged **`inform`** notifications (`0xa6`), and unified\nvarbind-based **`SNMPv2-Trap`** (`0xa7`) framing.\n\nWhen `sysuptime` is provided on `snmp2 trap`, `inform`, or `report`, FrameAssembly\nautomatically prepends the mandatory RFC 3416 `sysUpTime.0` (`1.3.6.1.2.1.1.3.0`)\nvarbind ahead of your `snmpTrapOID.0` (`1.3.6.1.6.3.1.1.4.1.0`) and payload\nvarbinds.\n\n## Minimal Quickstart (`snmp2_quickstart.frasm`)\n\n```frameassembly\nhost core_sw { ip 10.20.1.1 }\nhost nms_srv { ip 10.20.1.50 }\n\ncompile {\n    nms_srv -> core_sw snmp2 getbulk community \"ops-ro\" reqid 501 nonrepeaters 0 maxrepetitions 10 oid 1.3.6.1.2.1.31.1.1.1.6 wait 2ms\n    nms_srv <- core_sw snmp2 response community \"ops-ro\" reqid 501 varbind 1.3.6.1.2.1.31.1.1.1.6.1 counter64 98765432100\n}\n```\n\n### Automatic Wire Calculations\n\n- Encodes `GetBulkRequest` (`0xa5`) overloading the BER error-status and\n  error-index slots with `nonrepeaters` (default `0`) and `maxrepetitions`\n  (default `10`) per RFC 3416.\n- Automatically prepends `1.3.6.1.2.1.1.3.0` (`sysUpTime.0` `TimeTicks`) on `trap`\n  (`0xa7`), `inform` (`0xa6`), and `report` (`0xa8`) when `sysuptime` is\n  specified.\n- Routes `trap`, `inform`, and `report` to UDP `162` and\n  `get`/`getnext`/`getbulk`/`set` to UDP `161`, reversing ports automatically on\n  `<- response`.\n\n## Practical Lab Example: ifXTable 64-Bit Counter Walk + Acknowledged SNMPv2c LinkDown Inform (`snmp2_getbulk_and_inform.frasm`)\n\nWalks 64-bit high-capacity interface counters via `getbulk` on UDP 161, then\ndelivers a reliable `snmp2 inform` (`linkDown` `1.3.6.1.6.3.1.1.5.3`) on UDP 162\nwith manager `response` acknowledgment.\n\n```frameassembly\nhost nms_poller { ip 10.30.10.20 }\nhost dist_sw    { ip 10.30.10.1 }\n\ncompile {\n    // 1. High-capacity 64-bit interface counter bulk poll on UDP 161\n    nms_poller -> dist_sw snmp2 getbulk community \"infra-ro\" reqid 2001 nonrepeaters 1 maxrepetitions 5 varbind 1.3.6.1.2.1.1.3.0 null varbind 1.3.6.1.2.1.31.1.1.1.6 null wait 2ms\n    nms_poller <- dist_sw snmp2 response community \"infra-ro\" reqid 2001 varbind 1.3.6.1.2.1.1.3.0 timeticks 43200000 varbind 1.3.6.1.2.1.31.1.1.1.6.101 counter64 184502910440 varbind 1.3.6.1.2.1.31.1.1.1.1.101 string \"TenGigabitEthernet1/0/1\" wait 5ms\n    // 2. Acknowledged SNMPv2c InformRequest for linkDown (1.3.6.1.6.3.1.1.5.3) on UDP 162\n    dist_sw -> nms_poller snmp2 inform community \"infra-trap\" reqid 9001 sysuptime 43200500 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.2.2.1.1.101 int 101 varbind 1.3.6.1.2.1.2.2.1.8.101 int 2 wait 1ms\n    dist_sw <- nms_poller snmp2 response community \"infra-trap\" reqid 9001 varbind 1.3.6.1.2.1.1.3.0 timeticks 43200500 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show snmp2_getbulk_and_inform.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly snmp2_getbulk_and_inform.frasm snmp2_getbulk_and_inform.pcap\nframeassembly snmp2_getbulk_and_inform.frasm snmp2_getbulk_and_inform.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse snmp2_getbulk_and_inform.pcap snmp2_getbulk_and_inform_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r snmp2_getbulk_and_inform.pcap -Y \"snmp\"\n```\n\n## All `snmp2` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host snmp2 [trap | inform | report | get |\ngetnext | getbulk | set | response] [community \"<text>\"] [reqid <number>]\n[nonrepeaters <number>] [maxrepetitions <number>] [sysuptime <number>] [oid <oid>]\n[varbind <oid> <type_val> ...]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `trap \\| inform \\| report \\| get \\| getnext \\| getbulk \\| set \\| response` | SNMPv2c PDU type keyword | `trap (PDU 0xa7 on UDP 162)` | Selects RFC 3416 BER PDU tag (`0xa0`..`0xa3` or `0xa5` GetBulk, `0xa6` Inform, `0xa7` SNMPv2-Trap, `0xa8` Report). |\n| `community \"<text>\"` | Double-quoted OCTET STRING | `\"public\"` | Sets the SNMPv2c community string. |\n| `nonrepeaters <number> \\| maxrepetitions <number>` | Whole number | `nonrepeaters 0, maxrepetitions 10` | Sets scalar `non-repeaters` count and tabular `max-repetitions` row count on `getbulk` PDUs. |\n| `sysuptime <number>` | 32-bit TimeTicks (1/100s) | `Omitted (or auto-prepended when set)` | Prepends `1.3.6.1.2.1.1.3.0 = TimeTicks(<sysuptime>)` as the first varbind on `trap`, `inform`, and `report`. |\n| `reqid <number> \\| oid <oid>` | u32 request ID, dotted OID | `reqid 1, oid 1.3.6.1.2.1.1.1.0` | Sets 32-bit `request-id` and appends a `NULL`-valued query OID. |\n| `varbind <oid> string \"<text>\" \\| int <number> \\| oidval <oid> \\| ipval <ipv4> \\| counter32 <number> \\| gauge32 <number> \\| timeticks <number> \\| counter64 <number> \\| null \\| nullval` | Repeatable OID + SMIv2 value keyword | `Omitted` | Appends typed SMIv2 `VarBind` entries (`null` and `nullval` are interchangeable aliases; use `1.3.6.1.6.3.1.1.4.1.0 oidval <oid>` for `snmpTrapOID.0`). |\n\n## Cross-Layer Options Valid with `snmp2`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP/TCP 162 (trap/inform) / 161 (get/getbulk)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Pass snmpTrapOID.0 via varbind 1.3.6.1.6.3.1.1.4.1.0 oidval <oid> (Never trapoid)\n\n- **Avoid:** `dist_sw -> nms_poller snmp2 trap trapoid 1.3.6.1.6.3.1.1.5.3`\n- **Valid v3.3.0 Syntax:** `dist_sw -> nms_poller snmp2 trap sysuptime 5000\n  varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3`\n\nIn RFC 3416 SNMPv2c/v3, trap OIDs are regular varbinds rather than dedicated v1\nheader slots. Pass `1.3.6.1.6.3.1.1.4.1.0` (`snmpTrapOID.0`) with the `oidval`\ntype keyword.\n\n### Use string (Not str) for Text Varbinds\n\n- **Avoid:** `dist_sw -> nms_poller snmp2 response varbind 1.3.6.1.2.1.1.5.0 str\n  \"core-sw\"`\n- **Valid v3.3.0 Syntax:** `dist_sw -> nms_poller snmp2 response varbind\n  1.3.6.1.2.1.1.5.0 string \"core-sw\"`\n\nAlways write `string \"<value>\"` for OCTET STRING varbinds across `snmp1`, `snmp2`,\nand `snmp3`.\n"}
{"id":"pretrain-proto-snmp3","kind":"protocol_spec","title":"Simple Network Management Protocol v3 with USM Auth & Privacy (snmp3) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/snmp3","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["snmp3"],"text":"# snmp3 — Real SHA-256 + AES-128 Encrypted USM Traps & Polls (`snmp3`)\n\n> **FrameAssembly v3.3.0** · Protocol 55 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/snmp3\n\n- **Full Protocol Name:** Simple Network Management Protocol v3 with USM Auth &\n  Privacy\n- **Keyword:** `snmp3`\n- **OSI Layer & Transport:** Layer 7 · UDP/TCP 162 (trap/inform/report) / 161\n  (get/getbulk)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 3414, RFC 3826, RFC 7860\n- **Wireshark Display Filter:** `snmp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP/TCP 162 (trap/inform/report) / 161 (get/getbulk) (transport tcp|udp) ->\n  SNMPv3 USM (authPriv)`\n\n## Overview\n\nZero fake placeholder bytes here: `snmp3` runs full RFC 3414/7860 `Ku -> Kul` key\nlocalization against `engineid`, encrypts the `ScopedPDU` with AES-128-CFB or DES,\nand signs the live HMAC so Wireshark and `snmptrapd` decrypt it on the first try.\n\nSimple Network Management Protocol v3 (`snmp3`, RFC 3414 / RFC 3826 / RFC 7860)\nsecures network monitoring with the User-based Security Model (**USM**). Unlike\nmock packet generators that emit zeroed dummy bytes, FrameAssembly executes **full\ncryptographic key localization (`Ku -> Kul`)** against `msgAuthoritativeEngineID`\n(`engineid`), computes live truncated **HMAC (`md5`, `sha`, `sha256`, `sha384`,\n`sha512`)** over the entire SNMPv3 message, and encrypts the ASN.1 `ScopedPDU`\nusing **AES-128-CFB (`priv aes`)** or **CBC-DES (`priv des`)**.\n\nThat means you can enter your exact `user`, `auth`, and `priv` passphrases into\n**Wireshark -> Preferences -> Protocols -> SNMP -> Users Table** (or Checkmk /\n`snmptrapd`) and decrypt every FrameAssembly-generated `.pcap` on the first try.\n\n## Minimal Quickstart (`snmp3_quickstart.frasm`)\n\n```frameassembly\nhost poller { ip 10.40.1.10 }\nhost router { ip 10.40.1.1 }\n\ncompile {\n    poller -> router snmp3 get user \"secops\" engineid \"80001f888001020304\" engineboots 3 enginetime 1200 auth sha256 \"AuthPassPhrase99!\" priv aes \"PrivPassPhrase99!\" reqid 101 oid 1.3.6.1.2.1.1.1.0 wait 2ms\n    poller <- router snmp3 response user \"secops\" engineid \"80001f888001020304\" engineboots 3 enginetime 1200 auth sha256 \"AuthPassPhrase99!\" priv aes \"PrivPassPhrase99!\" reqid 101 varbind 1.3.6.1.2.1.1.1.0 string \"Core-RTR OS 17.9\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Derives `msgFlags` automatically from provided credentials: `noAuthNoPriv`\n  (neither set), `authNoPriv` (`auth` only), or `authPriv` (`auth` + `priv`,\n  setting `0x03`, plus `0x04` Reportable on requests/informs).\n- Runs RFC 3414 / RFC 7860 password-to-key (`Ku`, 1 MiB expansion) and\n  engine-localized (`Kul`) derivation for `md5`, `sha` (SHA-1), `sha256`,\n  `sha384`, and `sha512`.\n- Encrypts the `ScopedPDU` with `aes` (AES-128-CFB using `engineboots ||\n  enginetime || salt` IV per RFC 3826) or `des`, then writes the exact HMAC digest\n  into `msgAuthenticationParameters`.\n\n## Practical Lab Example: Full RFC 3414 Engine Discovery (`report`) + SHA-256/AES-128 `authPriv` Poll & Trap (`snmp3_usm_discovery_and_authpriv.frasm`)\n\nWalks through RFC 3414 USM engine discovery (`usmStatsUnknownEngineIDs.0`),\nauthenticated/encrypted `get` + `response` on UDP 161, and an `authPriv` encrypted\n`snmp3 trap` on UDP 162.\n\n```frameassembly\nhost zabbix_srv { ip 172.18.10.50 }\nhost core_rtr   { ip 172.18.10.1 }\n\ncompile {\n    // 1. Unauthenticated USM EngineID discovery probe -> Agent replies with Report PDU\n    zabbix_srv -> core_rtr snmp3 get user \"\" reqid 100 wait 1ms\n    zabbix_srv <- core_rtr snmp3 report user \"\" engineid \"80001f8880aabbccdd\" engineboots 5 enginetime 8420 reqid 100 varbind 1.3.6.1.6.3.15.1.1.4.0 counter32 1 wait 3ms\n    // 2. Encrypted authPriv (HMAC-SHA-256 + AES-128-CFB) GET & RESPONSE on UDP 161\n    zabbix_srv -> core_rtr snmp3 get user \"nms-v3-prod\" engineid \"80001f8880aabbccdd\" engineboots 5 enginetime 8420 auth sha256 \"StrongAuthKey2026!\" priv aes \"StrongPrivKey2026!\" reqid 101 oid 1.3.6.1.2.1.1.5.0 wait 2ms\n    zabbix_srv <- core_rtr snmp3 response user \"nms-v3-prod\" engineid \"80001f8880aabbccdd\" engineboots 5 enginetime 8420 auth sha256 \"StrongAuthKey2026!\" priv aes \"StrongPrivKey2026!\" reqid 101 varbind 1.3.6.1.2.1.1.5.0 string \"core-rtr-fra1.internal\" wait 5ms\n    // 3. Encrypted authPriv SNMPv3 Trap on UDP 162 (authoritative sender = core_rtr)\n    core_rtr -> zabbix_srv snmp3 trap user \"nms-v3-prod\" engineid \"80001f8880aabbccdd\" engineboots 5 enginetime 8425 auth sha256 \"StrongAuthKey2026!\" priv aes \"StrongPrivKey2026!\" sysuptime 842500 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.4 varbind 1.3.6.1.2.1.2.2.1.2.1 string \"HundredGigE0/0/0/1\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show snmp3_usm_discovery_and_authpriv.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly snmp3_usm_discovery_and_authpriv.frasm snmp3_usm_discovery_and_authpriv.pcap\nframeassembly snmp3_usm_discovery_and_authpriv.frasm snmp3_usm_discovery_and_authpriv.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse snmp3_usm_discovery_and_authpriv.pcap snmp3_usm_discovery_and_authpriv_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r snmp3_usm_discovery_and_authpriv.pcap -Y \"snmp\"\n```\n\n## All `snmp3` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host snmp3 [trap | inform | report | get |\ngetnext | getbulk | set | response] [user \"<text>\"] [engineid \"<even_hex>\"]\n[engineboots <number>] [enginetime <number>] [contextname \"<text>\"] [auth\n<md5|sha|sha256|sha384|sha512> \"<password>\"] [priv <des|aes> \"<password>\"] [reqid\n<number>] [nonrepeaters <number>] [maxrepetitions <number>] [sysuptime <number>]\n[oid <oid>] [varbind <oid> <type_val> ...]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `trap \\| inform \\| report \\| get \\| getnext \\| getbulk \\| set \\| response` | SNMPv3 ScopedPDU type keyword | `trap (UDP 162)` | Selects the inner BER PDU tag inside the plaintext or encrypted `ScopedPDU`. |\n| `user \"<text>\"` | Double-quoted USM securityName | `\"initial\"` | Sets `msgUserName` in the USM security parameters header. |\n| `engineid \"<even_hex>\"` | Even-length ASCII hex string (e.g. \"80001f880431\") | `\"80001f888000000001\"` | Sets `msgAuthoritativeEngineID` and `contextEngineID` and localizes `Ku -> Kul` USM keys. |\n| `engineboots <number> \\| enginetime <number>` | Whole number | `engineboots 1, enginetime 100` | Sets `msgAuthoritativeEngineBoots` and `msgAuthoritativeEngineTime` (also used in the AES-128-CFB IV). |\n| `contextname \"<text>\"` | Quoted text | `\"\" (default context)` | Sets `contextName` inside the `ScopedPDU` (e.g. `\"vlan-10\"` per-VLAN bridge MIB contexts). |\n| `auth md5 \\| sha \\| sha256 \\| sha384 \\| sha512 \"<password>\"` | HMAC algorithm keyword + passphrase string | `Omitted (noAuthNoPriv)` | Enables USM authentication (`authNoPriv` or `authPriv`) and writes the live RFC 3414 / RFC 7860 HMAC digest. |\n| `priv des \\| aes \"<password>\"` | `des` (CBC-DES) or `aes` (AES-128-CFB) + passphrase | `Omitted` | Encrypts the `ScopedPDU` (`authPriv`, requires `auth`) and populates the 8-byte `msgPrivacyParameters` salt/IV. |\n| `reqid <number> \\| nonrepeaters <number> \\| maxrepetitions <number> \\| sysuptime <number> \\| oid <oid>` | ScopedPDU request/bulk/trap fields | `reqid 1, nonrepeaters 0, maxrepetitions 10` | Sets inner `ScopedPDU` request ID, `getbulk` bounds, prepended `sysUpTime.0` varbind, or `NULL`-valued query OID. |\n| `varbind <oid> string \"<text>\" \\| int <number> \\| oidval <oid> \\| ipval <ipv4> \\| counter32 <number> \\| gauge32 <number> \\| timeticks <number> \\| counter64 <number> \\| null \\| nullval` | Repeatable SMIv2 OID + typed value keyword | `Omitted` | Appends `VarBind` entries (`string`, `int`, `oidval`, `ipval`, `counter32`, `gauge32`, `timeticks`, `counter64`, `null` \\| `nullval`) prior to encryption. |\n\n## Cross-Layer Options Valid with `snmp3`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP/TCP 162 (trap/inform/report) / 161 (get/getbulk)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### engineid Must Be Non-Empty Even-Length Hex Octets\n\n- **Avoid:** `poller -> router snmp3 get user \"ops\" engineid \"router-01\"`\n- **Valid v3.3.0 Syntax:** `poller -> router snmp3 get user \"ops\" engineid\n  \"80001f8804726f75746572\"`\n\n`engineid` must contain a non-empty even number of hexadecimal characters\n(`0-9a-fA-F`, with optional colons or spaces). Omit `engineid` on initial\ndiscovery probes rather than passing `engineid \"\"`.\n\n### SHA-1 Is Spelled sha (Not sha1)\n\n- **Avoid:** `poller -> router snmp3 get user \"ops\" auth sha1 \"SecretPass123!\"`\n- **Valid v3.3.0 Syntax:** `poller -> router snmp3 get user \"ops\" auth sha\n  \"SecretPass123!\"`\n\nAccepted USM HMAC keywords are `md5`, `sha` (RFC 3414 HMAC-SHA-1-96), `sha256`,\n`sha384`, and `sha512` (RFC 7860).\n"}
{"id":"pretrain-proto-dns","kind":"protocol_spec","title":"Domain Name System over UDP or TCP (dns) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/dns","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["dns"],"text":"# dns — RFC 1035 Queries, RCODEs & UDP/TCP Port 53 Captures (`dns`)\n\n> **FrameAssembly v3.3.0** · Protocol 56 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/dns\n\n- **Full Protocol Name:** Domain Name System over UDP or TCP\n- **Keyword:** `dns`\n- **OSI Layer & Transport:** Layer 7 · UDP 53 (or TCP 53 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 1035, RFC 3596, RFC 2782\n- **Wireshark Display Filter:** `dns`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 53 (or TCP 53 via transport tcp) (transport tcp|udp) -> DNS (UDP/TCP)`\n\n## Overview\n\nWhether you are testing a sinkhole rule, an Active Directory `SRV` lookup, or\nswitching to `transport tcp` (which auto-prepends the 2-byte RFC 1035 TCP length\nprefix!), `dns` encodes wire labels and compressed answers cleanly.\n\nDomain Name System (`dns`, RFC 1035 / RFC 3596) resolves domain names into IPv4\n(`A`), IPv6 (`AAAA`), service (`SRV`), mail (`MX`), and policy (`TXT`) records on\nport `53`. `dns` defaults to **UDP port `53`**, and adding `transport tcp`\nswitches to **TCP port `53`** with the required 2-byte RFC 1035 TCP length prefix.\n\nFrameAssembly formats RFC 1035 domain labels automatically, checks the RFC\n63-character label limit and 253-character total hostname limit before building\nyour `.pcap`, and writes compressed Answer records (`A`, `AAAA`, `CNAME`, `TXT`,\n`PTR`, `NS`, `MX`, `SRV`) on `response` packets.\n\n## Minimal Quickstart (`dns_quickstart.frasm`)\n\n```frameassembly\nhost stub_client { ip 10.10.0.25 }\nhost dns_resolv  { ip 10.10.0.53 }\n\ncompile {\n    stub_client -> dns_resolv dns query txid 0x4a12 qname \"api.frameassembly.internal\" qtype \"A\" wait 2ms\n    stub_client <- dns_resolv dns response txid 0x4a12 qname \"api.frameassembly.internal\" qtype \"A\" rdata \"10.10.50.80\" ansttl 300\n}\n```\n\n### Automatic Wire Calculations\n\n- Encodes dotted `qname` strings into RFC 1035 length-prefixed labels\n  (`\\x03api...\\x00`) and validates RFC label (`<= 63`B) and total length (`<=\n  253`B) limits at compile time.\n- Sets DNS flags (`QR=0, RD=1` `0x0100` on `query`; `QR=1, RD=1, RA=1` `0x8180 |\n  rcode` on `response`) and appends compressed `0xc00c` Answer RRs when `rdata` is\n  provided.\n- Prepends the 2-byte big-endian message length header automatically whenever\n  `transport tcp` is specified.\n\n## Practical Lab Example: UDP A/AAAA + NXDOMAIN Lookups Followed by Stateful DNS-over-TCP SRV Resolution (`dns_udp_and_tcp_lab.frasm`)\n\nCaptures standard UDP `AAAA` and `NXDOMAIN` (`rcode 3`) queries, then establishes\na TCP 53 session to resolve an Active Directory `_kerberos._tcp` lookup via\n`transport tcp`.\n\n```frameassembly\nhost workstation { ip 172.16.10.45 }\nhost corp_dns    { ip 172.16.10.10 }\n\ncompile {\n    // 1. Standard UDP IPv6 AAAA lookup\n    workstation -> corp_dns dns query txid 0x1001 srcport 53110 qname \"git.corp.internal\" qtype \"AAAA\" wait 1ms\n    workstation <- corp_dns dns response txid 0x1001 qname \"git.corp.internal\" qtype \"AAAA\" rdata \"2001:db8:10::443\" ansttl 120 wait 3ms\n    // 2. Non-existent domain returning NXDOMAIN (rcode 3)\n    workstation -> corp_dns dns query txid 0x1002 srcport 53111 qname \"missing-svc.corp.internal\" qtype \"A\" wait 1ms\n    workstation <- corp_dns dns response txid 0x1002 qname \"missing-svc.corp.internal\" qtype \"A\" rcode 3 wait 4ms\n    // 3. RFC 1035 DNS-over-TCP on port 53 (auto-prefixes 2-byte TCP length field)\n    workstation -> corp_dns tcp syn srcport 54053 dstport 53 win 65535 mss 1460 wait 1ms\n    workstation <- corp_dns tcp syn ack win 65535 mss 1460 wait 1ms\n    workstation -> corp_dns tcp ack wait 1ms\n    workstation -> corp_dns dns query txid 0x2001 qname \"dc01.corp.internal\" qtype \"TXT\" transport tcp wait 1ms\n    workstation <- corp_dns dns response txid 0x2001 qname \"dc01.corp.internal\" qtype \"TXT\" rdata \"v=spf1 ip4:172.16.0.0/16 -all\" ansttl 3600 transport tcp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show dns_udp_and_tcp_lab.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly dns_udp_and_tcp_lab.frasm dns_udp_and_tcp_lab.pcap\nframeassembly dns_udp_and_tcp_lab.frasm dns_udp_and_tcp_lab.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse dns_udp_and_tcp_lab.pcap dns_udp_and_tcp_lab_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r dns_udp_and_tcp_lab.pcap -Y \"dns\"\n```\n\n## All `dns` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host dns [query | response] [txid\n<0..65535>] [qname \"<text>\"] [qtype \"<text>\"] [rdata \"<text>\"] [rcode <0..15>]\n[ansttl <number>] [transport <udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `query \\| response` | Message direction keyword | `query (QR=0)` | Toggles the `QR` bit in the 12-byte DNS header (`0` query, `1` response with `Answer RRs`). |\n| `txid <0..65535>` | Whole number (0..65535) | `0x1234` | Sets the 16-bit DNS Transaction ID matching requests to responses. |\n| `qname \"<text>\"` | Domain string (labels <= 63B, total <= 253B) | `\"example.com\"` | Encodes the Question `QNAME` wire labels. |\n| `qtype \"<text>\"` | \"A\" \\| \"AAAA\" \\| \"CNAME\" \\| \"MX\" \\| \"NS\" \\| \"PTR\" \\| \"SOA\" \\| \"SRV\" \\| \"TXT\" \\| \"AXFR\" \\| \"ANY\" | `\"A\"` | Sets the 16-bit `QTYPE` (and Answer RR `TYPE` on responses). |\n| `rdata \"<text>\"` | IP string, hostname, or text value | `Omitted (or 93.184.216.34 on A response)` | Populates the Answer Resource Record `RDATA` payload on `response` frames. |\n| `rcode <0..15>` | 4-bit response code | `0 (NOERROR)` | Sets the lower 4 bits of DNS Flags (`0`=NOERROR, `1`=FORMERR, `2`=SERVFAIL, `3`=NXDOMAIN, `5`=REFUSED). |\n| `ansttl <number>` | Whole number (seconds) | `300` | Sets the 32-bit caching TTL inside the Answer Resource Record (never `ans_ttl`). |\n| `transport <udp\\|tcp>` | `udp` or `tcp` | `udp` | Switches between UDP `53` and stateful TCP `53` (adding the 2-byte RFC 1035 message length prefix). |\n\n## Cross-Layer Options Valid with `dns`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 53 (or TCP 53 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Spell Answer TTL as ansttl (Zero Underscores)\n\n- **Avoid:** `stub_client <- dns_resolv dns response rdata \"10.0.0.5\" ans_ttl 300`\n- **Valid v3.3.0 Syntax:** `stub_client <- dns_resolv dns response rdata\n  \"10.0.0.5\" ansttl 300`\n\nBuilt-in modifiers never use underscores—use `ansttl <number>` for the DNS Answer\nRR TTL so L3 `ttl <0..255>` remains free to set the IP Hop Limit.\n\n### Each Domain Label Must Be 63 Characters or Fewer\n\n- **Avoid:** `stub_client -> dns_resolv dns query qname\n  \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.internal\"`\n- **Valid v3.3.0 Syntax:** `stub_client -> dns_resolv dns query qname\n  \"part1.part2.exfil.internal\"`\n\nRFC 1035 limits each dot-separated label to `63` bytes and the full domain name to\n`253` bytes. Split long DNS tunneling test payloads across multiple dots.\n"}
{"id":"pretrain-proto-mdns","kind":"protocol_spec","title":"Multicast DNS Zero-Configuration Discovery (mdns) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/mdns","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["mdns"],"text":"# mdns — Port 5353 .local Multicast Service Discovery Frames (`mdns`)\n\n> **FrameAssembly v3.3.0** · Protocol 57 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/mdns\n\n- **Full Protocol Name:** Multicast DNS Zero-Configuration Discovery\n- **Keyword:** `mdns`\n- **OSI Layer & Transport:** Layer 7 · UDP 5353 -> 5353 (224.0.0.251 / ff02::fb)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 6762, RFC 6763\n- **Wireshark Display Filter:** `mdns`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 5353 -> 5353 (224.0.0.251 / ff02::fb) -> mDNS (Zero-Conf)`\n\n## Overview\n\nChatty printers, Apple TVs, and rogue IoT gadgets shouting `.local` records on\n`224.0.0.251:5353` — `mdns` locks both source and destination ports to `5353` per\nRFC 6762.\n\nMulticast DNS (`mdns`, RFC 6762) enables zero-configuration `.local` hostname\nresolution and DNS-SD service discovery (Apple Bonjour, Linux Avahi, Chromecast,\nAirPrint, Matter IoT) without a central DNS server. Every frame runs on **UDP\n`5353 -> 5353`**.\n\nWhen compiling `mdns`, FrameAssembly automatically rewrites the wire destination\nIP and Ethernet multicast MAC to **`224.0.0.251` (`01:00:5e:00:00:fb`)** on IPv4\nor **`ff02::fb` (`33:33:00:00:00:fb`)** on IPv6, sets `txid 0` per RFC 6762 §18.1,\nand shares full RFC 1035 label validation with `dns`.\n\n## Minimal Quickstart (`mdns_quickstart.frasm`)\n\n```frameassembly\nhost laptop  { ip 192.168.10.42 }\nhost printer { ip 192.168.10.90 }\n\ncompile {\n    laptop -> printer mdns query qname \"_ipp._tcp.local\" qtype \"PTR\" wait 3ms\n    printer -> laptop mdns response qname \"laserjet-3f.local\" qtype \"A\" rdata \"192.168.10.90\" ansttl 120\n}\n```\n\n### Automatic Wire Calculations\n\n- Overrides the L3 destination IP to link-local multicast `224.0.0.251` (IPv4) or\n  `ff02::fb` (IPv6) with matching multicast Ethernet MAC (`01:00:5e:00:00:fb` /\n  `33:33:00:00:00:fb`).\n- Fixes both UDP source and destination ports to `5353 -> 5353` and defaults\n  `txid` to `0` per RFC 6762.\n- Enforces RFC 1035 label (`<= 63`B) and total name (`<= 253`B) validation\n  identically to `dns`.\n\n## Practical Lab Example: Dual-Stack DNS-SD Service Browse (`PTR`) and Host Address Announcement (`AAAA`) (`mdns_ipv6_matter_discovery.frasm`)\n\nDiscovers `_matterc._udp.local` commissioning nodes and announces an IPv6\nlink-local service record over VLAN 30.\n\n```frameassembly\nhost controller { ip fe80::10 mac 00:1c:73:aa:00:10 }\nhost sensor_hub { ip fe80::55 mac 00:1c:73:aa:00:55 }\n\ncompile {\n    // 1. Multicast browse query to ff02::fb on UDP 5353 -> 5353\n    controller -> sensor_hub mdns query qname \"_matter._tcp.local\" qtype \"PTR\" vlan 30 ttl 255 wait 2ms\n    // 2. Hub announces PTR instance and AAAA address record\n    sensor_hub -> controller mdns response qname \"_matter._tcp.local\" qtype \"PTR\" rdata \"hub-01._matter._tcp.local\" ansttl 4500 vlan 30 ttl 255 wait 1ms\n    sensor_hub -> controller mdns response qname \"hub-01.local\" qtype \"AAAA\" rdata \"fe80::55\" ansttl 120 vlan 30 ttl 255\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show mdns_ipv6_matter_discovery.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly mdns_ipv6_matter_discovery.frasm mdns_ipv6_matter_discovery.pcap\nframeassembly mdns_ipv6_matter_discovery.frasm mdns_ipv6_matter_discovery.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse mdns_ipv6_matter_discovery.pcap mdns_ipv6_matter_discovery_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r mdns_ipv6_matter_discovery.pcap -Y \"mdns\"\n```\n\n## All `mdns` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host mdns [query | response] [txid\n<0..65535>] [qname \"<text>\"] [qtype \"<text>\"] [rdata \"<text>\"] [rcode <0..15>]\n[ansttl <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `query \\| response` | mDNS message direction keyword | `query` | Selects mDNS Question (`0x0000`) or Authoritative Multicast Response (`0x8400`). |\n| `qname \"<text>\"` | `.local` domain or service string | `\"_http._tcp.local\"` | Encodes the Question/Answer domain labels (`<= 63`B per label, `<= 253`B total). |\n| `qtype \"<text>\"` | \"PTR\" \\| \"SRV\" \\| \"TXT\" \\| \"A\" \\| \"AAAA\" \\| \"ANY\" | `\"PTR\"` | Sets the 16-bit DNS record type. |\n| `rdata \"<text>\" \\| ansttl <number>` | Record data string, u32 seconds | `ansttl 120` | Encodes the Answer RR payload and cache lifetime on `mdns response` frames. |\n| `txid <0..65535> \\| rcode <0..15>` | 16-bit ID, 4-bit RCODE | `txid 0, rcode 0` | Overrides Transaction ID (legacy unicast queries) or response code. |\n\n## Cross-Layer Options Valid with `mdns`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 5353 -> 5353 (224.0.0.251 / ff02::fb)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 5353 -> 5353 (224.0.0.251 / ff02::fb))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### mDNS Is Strictly UDP-Only (transport tcp Is Rejected)\n\n- **Avoid:** `laptop -> printer mdns query qname \"_http._tcp.local\" transport tcp`\n- **Valid v3.3.0 Syntax:** `laptop -> printer mdns query qname \"_http._tcp.local\"`\n\nRFC 6762 Multicast DNS operates exclusively over UDP `5353`; `mdns` is not on the\n9-protocol `transport` whitelist.\n\n### Use ansttl for Resource Record TTL vs ttl for IP Hop Limit\n\n- **Avoid:** `printer -> laptop mdns response rdata \"192.168.10.90\" ans_ttl 120`\n- **Valid v3.3.0 Syntax:** `printer -> laptop mdns response rdata \"192.168.10.90\"\n  ansttl 120 ttl 255`\n\n`ansttl 120` sets the mDNS resource record cache lifetime, while `ttl 255` sets\nthe IPv4/IPv6 Hop Limit.\n"}
{"id":"pretrain-proto-dhcp","kind":"protocol_spec","title":"Dynamic Host Configuration Protocol — DHCPv4 & DHCPv6 (dhcp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/dhcp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["dhcp"],"text":"# dhcp — Full DHCPv4 DORA & IPv6 DHCPv6 Lease Negotiation (`dhcp`)\n\n> **FrameAssembly v3.3.0** · Protocol 58 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/dhcp\n\n- **Full Protocol Name:** Dynamic Host Configuration Protocol — DHCPv4 & DHCPv6\n- **Keyword:** `dhcp`\n- **OSI Layer & Transport:** Layer 7 · UDP 68/67 (DHCPv4) · UDP 546/547 (DHCPv6)\n- **Host Endpoint Rule:** Dual-Stack Morphing (v4/v6)\n- **Standards:** RFC 2131, RFC 2132, RFC 8415\n- **Wireshark Display Filter:** `dhcp || dhcpv6`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 68/67 (DHCPv4) · UDP 546/547 (DHCPv6) -> DHCPv4 / DHCPv6`\n\n## Overview\n\nTest switch DHCP Snooping without plugging a rogue home router into the wall:\n`dhcp` builds BOOTP + magic cookie `0x63825363` Option TLVs on IPv4 (`68 <-> 67`)\nand morphs into DHCPv6 (`546 <-> 547`) over IPv6.\n\nDynamic Host Configuration Protocol (`dhcp`) is a **dual-stack morphing protocol**\nin FrameAssembly: over IPv4 endpoints, it compiles a 240-byte **RFC 2131 BOOTP\nheader + magic cookie `63:82:53:63`** + TLV Options (`53` Message Type, `1` Subnet\nMask, `3` Router, `6` DNS, `12` Hostname, `51` Lease Time, `255` End) on **UDP `68\n<-> 67`**. Over IPv6 endpoints, it automatically morphs into **RFC 8415 DHCPv6**\n(`solicit`, `advertise`, `request`, `reply`, `release`) with 24-bit Transaction ID\nand Client/Server DUID options on **UDP `546 <-> 547`**.\n\n## Minimal Quickstart (`dhcp_quickstart.frasm`)\n\n```frameassembly\nhost client_pc { ip 0.0.0.0 mac 00:1b:21:44:55:66 }\nhost dhcp_srv  { ip 10.10.10.1 mac 00:1b:21:00:00:01 }\n\ncompile {\n    client_pc -> dhcp_srv dhcp discover xid 0x3903f326 chaddr 00:1b:21:44:55:66 hostname \"eng-laptop-04\" wait 2ms\n    client_pc <- dhcp_srv dhcp offer xid 0x3903f326 yiaddr 10.10.10.150 siaddr 10.10.10.1 chaddr 00:1b:21:44:55:66 subnetmask 255.255.255.0 router 10.10.10.1 dnsserver 10.10.10.53 leasetime 86400\n}\n```\n\n### Automatic Wire Calculations\n\n- Selects UDP `68 -> 67` for client messages (`discover`, `request`, `release`)\n  and UDP `67 -> 68` for server messages (`offer`, `ack`) on IPv4—or UDP `546 <->\n  547` on IPv6.\n- Writes the 4-byte RFC 2132 DHCP magic cookie (`0x63825363`), packs every\n  specified option TLV (`1`, `3`, `6`, `12`, `51`, `53`), and terminates with\n  Option `255` (`0xff`).\n- Defaults `chaddr` to the sending host's Ethernet MAC when omitted so BOOTP\n  hardware fields stay consistent.\n\n## Practical Lab Example: Complete 4-Step DHCPv4 DORA Lease Workflow + DHCPv6 SARR Exchange (`dhcp_v4_dora_and_v6_sarr.frasm`)\n\nCaptures a full 4-frame IPv4 `discover -> offer -> request -> ack` cycle on VLAN\n10 followed by a 4-frame IPv6 `solicit -> advertise -> request -> reply` exchange.\n\n```frameassembly\nhost phone_v4 { ip 0.0.0.0 mac 00:50:56:aa:10:01 }\nhost srv_v4   { ip 10.20.10.1 mac 00:50:56:aa:00:01 }\nhost host_v6  { ip fe80::25 mac 00:50:56:bb:10:25 }\nhost srv_v6   { ip fe80::1 mac 00:50:56:bb:00:01 }\n\ncompile {\n    // 1. DHCPv4 DORA on VLAN 10 (UDP 68 <-> 67)\n    phone_v4 -> srv_v4 dhcp discover xid 0x77889900 chaddr 00:50:56:aa:10:01 hostname \"voip-desk-12\" vlan 10 wait 2ms\n    phone_v4 <- srv_v4 dhcp offer xid 0x77889900 yiaddr 10.20.10.112 siaddr 10.20.10.1 chaddr 00:50:56:aa:10:01 subnetmask 255.255.255.0 router 10.20.10.1 dnsserver 10.20.10.53 leasetime 43200 vlan 10 wait 1ms\n    phone_v4 -> srv_v4 dhcp request xid 0x77889900 chaddr 00:50:56:aa:10:01 hostname \"voip-desk-12\" vlan 10 wait 1ms\n    phone_v4 <- srv_v4 dhcp ack xid 0x77889900 yiaddr 10.20.10.112 siaddr 10.20.10.1 chaddr 00:50:56:aa:10:01 subnetmask 255.255.255.0 router 10.20.10.1 dnsserver 10.20.10.53 leasetime 43200 vlan 10 wait 5ms\n    // 2. DHCPv6 SARR over IPv6 link-local endpoints (UDP 546 <-> 547)\n    host_v6 -> srv_v6 dhcp solicit xid 0x00a1b2c3 dnsserver 2001:db8:20::53 wait 2ms\n    host_v6 <- srv_v6 dhcp advertise xid 0x00a1b2c3 dnsserver 2001:db8:20::53 wait 1ms\n    host_v6 -> srv_v6 dhcp request xid 0x00a1b2c3 wait 1ms\n    host_v6 <- srv_v6 dhcp reply xid 0x00a1b2c3 dnsserver 2001:db8:20::53\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show dhcp_v4_dora_and_v6_sarr.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly dhcp_v4_dora_and_v6_sarr.frasm dhcp_v4_dora_and_v6_sarr.pcap\nframeassembly dhcp_v4_dora_and_v6_sarr.frasm dhcp_v4_dora_and_v6_sarr.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse dhcp_v4_dora_and_v6_sarr.pcap dhcp_v4_dora_and_v6_sarr_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r dhcp_v4_dora_and_v6_sarr.pcap -Y \"dhcp || dhcpv6\"\n```\n\n## All `dhcp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host dhcp [discover | offer | request | ack\n| release | solicit | advertise | reply] [xid <number>] [ciaddr <ipv4>] [yiaddr\n<ipv4>] [siaddr <ipv4>] [chaddr <mac>] [subnetmask <ipv4>] [router <ipv4>]\n[dnsserver <ip>] [leasetime <number>] [hostname \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `discover \\| offer \\| request \\| ack \\| release \\| solicit \\| advertise \\| reply` | DHCPv4 / DHCPv6 message type keyword | `discover (IPv4) / solicit (IPv6)` | Sets DHCPv4 Option `53` + BOOTP `op` (`1` request, `2` reply) or DHCPv6 `msg-type` (`1` Solicit, `2` Advertise, `3` Request, `7` Reply, `8` Release). |\n| `xid <number>` | Whole number (24-bit in DHCPv6) | `0x12345678` | Sets BOOTP `xid` (4 bytes) or DHCPv6 `transaction-id` (lower 3 bytes). |\n| `ciaddr <ipv4> \\| yiaddr <ipv4> \\| siaddr <ipv4>` | IPv4 dotted-quad literals | `0.0.0.0` | Sets Client IP, Your (offered) IP, and Next Server IP in the DHCPv4 BOOTP header. |\n| `chaddr <mac>` | Colon, hyphen, or Cisco dot MAC | `Source host MAC` | Populates the 16-byte Client Hardware Address field in DHCPv4. |\n| `subnetmask <ipv4> \\| router <ipv4> \\| dnsserver <ip>` | IPv4/IPv6 address literals | `Omitted` | Appends Option `1` (Subnet Mask), Option `3` (Router), and Option `6` / DHCPv6 Option `23` (DNS Recursive Name Server). |\n| `leasetime <number> \\| hostname \"<text>\"` | u32 seconds, UTF-8 string | `leasetime 86400` | Appends Option `51` (IP Address Lease Time) and Option `12` (Host Name). |\n\n## Cross-Layer Options Valid with `dhcp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 68/67 (DHCPv4) · UDP 546/547 (DHCPv6)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 68/67 (DHCPv4) · UDP 546/547 (DHCPv6))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Both Endpoints Still Require IP Literals (Use 0.0.0.0 for Unconfigured DHCPv4 Clients)\n\n- **Avoid:** `host client_pc { mac 00:1b:21:44:55:66 }\nclient_pc -> dhcp_srv dhcp discover`\n- **Valid v3.3.0 Syntax:** `host client_pc { ip 0.0.0.0 mac 00:1b:21:44:55:66 }\nclient_pc -> dhcp_srv dhcp discover`\n\nBecause DHCP runs inside IPv4/UDP or IPv6/UDP, FrameAssembly requires an `ip`\naddress on both hosts. Use `ip 0.0.0.0` (the standard RFC 2131 pre-lease source\nIP) on unconfigured IPv4 clients, or a `fe80::...` link-local address on IPv6\nclients.\n\n### Use ack (Not dhcp_ack) for DHCPACK Replies\n\n- **Avoid:** `client_pc <- dhcp_srv dhcp dhcp_ack xid 0x1234`\n- **Valid v3.3.0 Syntax:** `client_pc <- dhcp_srv dhcp ack xid 0x1234`\n\nOn a `dhcp` line, `ack` sets DHCP Option 53 to `DHCPACK` (`5`) over UDP `67 -> 68`\nrather than a TCP flag.\n"}
{"id":"pretrain-proto-ntp","kind":"protocol_spec","title":"Network Time Protocol v1–v4 (ntp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ntp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ntp"],"text":"# ntp — 48-Byte RFC 5905 Stratum-1 Time Sync on UDP 123 (`ntp`)\n\n> **FrameAssembly v3.3.0** · Protocol 59 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ntp\n\n- **Full Protocol Name:** Network Time Protocol v1–v4\n- **Keyword:** `ntp`\n- **OSI Layer & Transport:** Layer 7 · UDP 123 (or transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 5905\n- **Wireshark Display Filter:** `ntp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 123 (or transport tcp) (transport tcp|udp) -> NTPv4`\n\n## Overview\n\nWhen Kerberos tickets start failing because two servers drifted five minutes\napart, everyone stares at UDP `123`. `ntp` writes clean 48-byte RFC 5905 packets\nright down to signed `precision` and ASCII `refid`.\n\nNetwork Time Protocol (`ntp`, RFC 5905) synchronizes system clocks across routers,\nservers, financial engines, and Kerberos/TLS infrastructure over **UDP `dstport\n123`**. Every standard NTPv4 packet is a fixed **48-byte binary structure**\npacking Leap Indicator (`li`), Version (`vn`), Mode (`mode`), `stratum`, `poll`,\nsigned log2 `precision`, Root Delay/Dispersion, 4-byte `refid` (`\"GPS\"`, `\"PPS\"`,\n`\"ATOM\"`, or kiss-o'-death `\"RATE\"`), and 64-bit NTP epoch timestamps.\n\n## Minimal Quickstart (`ntp_quickstart.frasm`)\n\n```frameassembly\nhost app_srv  { ip 10.10.20.40 }\nhost time_appliance { ip 10.10.20.123 }\n\ncompile {\n    app_srv -> time_appliance ntp vn 4 mode 3 poll 6 wait 2ms\n    app_srv <- time_appliance ntp li 0 vn 4 mode 4 stratum 1 poll 6 precision -20 refid \"GPS\" txtimestamp 0xe9b4c20000000000\n}\n```\n\n### Automatic Wire Calculations\n\n- Packs the first byte `(li << 6) | (vn << 3) | mode` cleanly (`0x23` for `li 0 vn\n  4 mode 3` client; `0x24` for `mode 4` server) inside a 48-byte RFC 5905 header.\n- Zero-pads 4-character ASCII `refid` strings (`\"GPS\\0\"`, `\"PPS\\0\"`, `\"RATE\"`) for\n  Stratum 0/1 servers.\n- Reverses ephemeral `srcport <-> 123` automatically across `->` and `<-`\n  statements.\n\n## Practical Lab Example: Stratum 1 Synchronization + Kiss-o'-Death Rate-Limit & Mode 6 Audit Probe (`ntp_sync_and_security_audit.frasm`)\n\nCaptures normal NTPv4 client/server clock sync, a `stratum 0 refid \"RATE\"`\nKiss-o'-Death response, and a blocked `mode 6` control query for IDS testing.\n\n```frameassembly\nhost branch_rtr { ip 172.16.30.1 }\nhost ntp_core   { ip 172.16.30.123 }\n\ncompile {\n    // 1. Standard NTPv4 Client (mode 3) -> Stratum 1 GPS Server (mode 4)\n    branch_rtr -> ntp_core ntp vn 4 mode 3 poll 6 precision -18 dscp 48 wait 2ms\n    branch_rtr <- ntp_core ntp li 0 vn 4 mode 4 stratum 1 poll 6 precision -24 refid \"GPS\" txtimestamp 0xe9b4d01080000000 dscp 48 wait 5ms\n    // 2. RFC 5905 Kiss-o'-Death (stratum 0, li 3, refid \"RATE\")\n    branch_rtr <- ntp_core ntp li 3 vn 4 mode 4 stratum 0 refid \"RATE\" wait 5ms\n    // 3. Mode 6 NTP Control query probe (tested against perimeter IDS/firewall)\n    branch_rtr -> ntp_core ntp vn 2 mode 6\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ntp_sync_and_security_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ntp_sync_and_security_audit.frasm ntp_sync_and_security_audit.pcap\nframeassembly ntp_sync_and_security_audit.frasm ntp_sync_and_security_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ntp_sync_and_security_audit.pcap ntp_sync_and_security_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ntp_sync_and_security_audit.pcap -Y \"ntp\"\n```\n\n## All `ntp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ntp [li <0..3>] [vn <1..4>] [mode\n<0..7>] [stratum <0..16>] [poll <0..255>] [precision <-128..127>] [refid \"<text>\"]\n[txtimestamp <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `li <0..3>` | 2-bit Leap Indicator | `0 (no warning)` | Sets bits 7..6 of byte 0 (`0`=no leap, `1`=61s minute, `2`=59s minute, `3`=unsynchronized/alarm). |\n| `vn <1..4>` | 3-bit NTP Version Number | `4 (NTPv4)` | Sets bits 5..3 of byte 0 (`1`..`4`). |\n| `mode <0..7>` | 3-bit Association Mode | `3 (Client)` | Sets bits 2..0 of byte 0 (`1`=Symmetric Active, `2`=Passive, `3`=Client, `4`=Server, `5`=Broadcast, `6`=Control, `7`=Private). |\n| `stratum <0..16>` | Whole number (0..255) | `0 (client) / 1 (when refid set)` | Sets Clock Stratum (`0`=unspecified/KoD, `1`=primary GPS/PPS, `2..15`=secondary, `16`=unsynchronized). |\n| `poll <0..255> \\| precision <-128..127>` | poll: u8 log2 seconds, precision: signed i8 (-128..127) | `poll 6 (64s), precision -20 (~1us)` | Sets 8-bit Poll Interval exponent and signed 8-bit two's-complement Clock Precision. |\n| `refid \"<text>\"` | Up to 4 ASCII chars (\"GPS\", \"PPS\", \"ATOM\", \"RATE\") | `\"LOCL\" / zeroed` | Writes the 4-byte Reference Identifier in bytes 12..15. |\n| `txtimestamp <number>` | 64-bit NTP timestamp (32b sec since 1900 + 32b frac) | `Non-zero deterministic epoch` | Writes the 8-byte Transmit Timestamp in bytes 40..47. |\n\n## Cross-Layer Options Valid with `ntp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 123 (or transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Signed precision Accepts Negative Integers Directly (precision -20)\n\n- **Avoid:** `app_srv <- time_appliance ntp mode 4 precision \"-20\"`\n- **Valid v3.3.0 Syntax:** `app_srv <- time_appliance ntp mode 4 precision -20`\n\n`precision` expects an unquoted signed 8-bit integer (`-20` represents $2^{-20}\n\\approx 0.95\\,\\mu\\text{s}$).\n\n### Set mode 4 Explicitly on Server Replies\n\n- **Avoid:** `app_srv <- time_appliance ntp stratum 1 refid \"GPS\"`\n- **Valid v3.3.0 Syntax:** `app_srv <- time_appliance ntp mode 4 stratum 1 refid\n  \"GPS\"`\n\n`ntp` defaults to `mode 3` (Client); always specify `mode 4` on `<-` server\nresponses so Wireshark labels the packet `NTP Version 4, server`.\n"}
{"id":"pretrain-proto-ptp","kind":"protocol_spec","title":"IEEE 1588 Precision Time Protocol v2 (ptp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ptp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ptp"],"text":"# ptp — Sub-Microsecond IEEE 1588v2 Hardware Clock Sync (`ptp`)\n\n> **FrameAssembly v3.3.0** · Protocol 60 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ptp\n\n- **Full Protocol Name:** IEEE 1588 Precision Time Protocol v2\n- **Keyword:** `ptp`\n- **OSI Layer & Transport:** Layer 7 · UDP 319 (Event) / UDP 320 (General)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** IEEE 1588-2008, SMPTE ST 2059-2, ITU-T G.8275.2\n- **Wireshark Display Filter:** `ptp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 319 (Event) / UDP 320 (General) -> PTPv2 (IEEE 1588)`\n\n## Overview\n\nFor high-frequency trading, 5G fronthaul, and substation synchrophasors where NTP\nis way too slow, `ptp` routes event messages to UDP `319` and general messages to\nUDP `320` automatically.\n\nIEEE 1588 Precision Time Protocol v2 (`ptp`) delivers sub-microsecond hardware\ntimestamp synchronization for **5G fronthaul (ITU-T G.8275)**, **SMPTE ST 2110\nbroadcast media**, **IEC 61850 power substations**, and **high-frequency trading\nfabrics**. PTPv2 splits messages across two UDP ports: hardware-timestamped\n**Event messages on UDP `319`** (`sync` `0x0`, `delayreq` `0x1`) and software\n**General messages on UDP `320`** (`followup` `0x8`, `delayresp` `0x9`, `announce`\n`0xb`).\n\nFrameAssembly selects UDP `319` or `320` automatically from the message type,\npopulates the 34-byte PTPv2 Common Header (`versionPTP = 2`, `domainNumber`,\n8-byte `ClockIdentity` + 2-byte `PortNumber`, `sequenceId`, `controlField`), and\nappends precision 10-byte `(48b sec, 32b nsec)` timestamp payloads.\n\n## Minimal Quickstart (`ptp_quickstart.frasm`)\n\n```frameassembly\nhost grandmaster { ip 10.60.1.1 }\nhost boundary_sw { ip 10.60.1.10 }\n\ncompile {\n    grandmaster -> boundary_sw ptp sync domain 0 seqid 100 clockid \"001c73fffe000001\" wait 200us\n    grandmaster -> boundary_sw ptp followup domain 0 seqid 100 clockid \"001c73fffe000001\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Routes time-critical Event messages (`sync`, `delayreq`) to UDP `319` and\n  General messages (`followup`, `delayresp`, `announce`) to UDP `320`\n  automatically.\n- Computes exact IEEE 1588-2008 `messageLength` (`44` bytes for\n  `sync`/`followup`/`delayreq`, `54` bytes for `delayresp`, `64` bytes for\n  `announce`) and sets `twoStepFlag` on `sync`.\n- Swaps `319`/`320` onto `srcport` cleanly when `<-` reverse arrows are used.\n\n## Practical Lab Example: Complete Two-Step IEEE 1588v2 Grandmaster <-> Ordinary Clock Exchange (.pcapng Ready) (`ptp_twostep_grandmaster.frasm`)\n\nExecutes a 5-frame PTPv2 `announce -> sync -> followup -> delayreq -> delayresp`\ncycle with sub-millisecond `wait` intervals ideal for `.pcapng` nanosecond export.\n\n```frameassembly\nhost gm_clock    { ip 172.22.0.1 }\nhost media_node  { ip 172.22.0.45 }\n\ncompile {\n    // 1. Grandmaster announces BMCA hierarchy on UDP 320 (domain 127 = SMPTE ST 2059-2)\n    gm_clock -> media_node ptp announce domain 127 seqid 500 clockid \"ec4670fffe010203\" dscp 46 wait 500us\n    // 2. Two-step Sync (UDP 319) + Follow_Up (UDP 320) with matching seqid 501\n    gm_clock -> media_node ptp sync domain 127 seqid 501 clockid \"ec4670fffe010203\" dscp 46 wait 120us\n    gm_clock -> media_node ptp followup domain 127 seqid 501 clockid \"ec4670fffe010203\" dscp 46 wait 250us\n    // 3. Slave measures reverse path delay via Delay_Req (UDP 319) -> Delay_Resp (UDP 320)\n    media_node -> gm_clock ptp delayreq domain 127 seqid 88 clockid \"001b21fffeaa0045\" dscp 46 wait 180us\n    media_node <- gm_clock ptp delayresp domain 127 seqid 88 clockid \"ec4670fffe010203\" dscp 46\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ptp_twostep_grandmaster.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ptp_twostep_grandmaster.frasm ptp_twostep_grandmaster.pcap\nframeassembly ptp_twostep_grandmaster.frasm ptp_twostep_grandmaster.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ptp_twostep_grandmaster.pcap ptp_twostep_grandmaster_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ptp_twostep_grandmaster.pcap -Y \"ptp\"\n```\n\n## All `ptp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ptp [sync | delayreq | followup |\ndelayresp | announce | msgtype \"<text>\"] [domain <0..255>] [seqid <0..65535>]\n[clockid \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `sync \\| delayreq \\| followup \\| delayresp \\| announce \\| msgtype \"<text>\"` | PTPv2 message type keyword | `sync (0x0 on UDP 319)` | Selects lower nibble of byte 0 and target UDP port (`0x0` Sync/319, `0x1` Delay_Req/319, `0x8` Follow_Up/320, `0x9` Delay_Resp/320, `0xb` Announce/320). |\n| `domain <0..255>` | Whole number (0..255) | `0` | Sets `domainNumber` in byte 4 (`0` default IEEE 1588, `24`/`44` telecom G.8275, `127` SMPTE ST 2059). |\n| `seqid <0..65535>` | Whole number (0..65535) | `1` | Sets `sequenceId` in bytes 30..31 pairing `sync` with `followup` and `delayreq` with `delayresp`. |\n| `clockid \"<text>\"` | 16-char EUI-64 hex (\"001c73fffe000001\") or 8B string | `Derived from source MAC (EUI-64 fffe)` | Populates the 8-byte `ClockIdentity` inside the 10-byte `sourcePortIdentity` field. |\n\n## Cross-Layer Options Valid with `ptp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 319 (Event) / UDP 320 (General)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 319 (Event) / UDP 320 (General))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Message Keywords Contain Zero Underscores (delayreq, followup, delayresp)\n\n- **Avoid:** `gm_clock -> media_node ptp follow_up seqid 501`\n- **Valid v3.3.0 Syntax:** `gm_clock -> media_node ptp followup seqid 501`\n\nSpell PTPv2 message types without underscores: `sync`, `delayreq`, `followup`,\n`delayresp`, and `announce`.\n\n### Export Sub-Microsecond PTP Captures as .pcapng for 1ns Timestamp Resolution\n\n- **Valid v3.3.0 Syntax:** `frameassembly ptp_twostep_grandmaster.frasm\n  ptp_twostep_grandmaster.pcapng`\n\nClassic `.pcap` (`0xa1b2c3d4`) stores `1us` timestamps; `.pcapng` writes\n`if_tsresol = 9` (`10^-9`s) so `wait 25ns` or `wait 150ns` hardware timestamps are\npreserved without rounding.\n"}
{"id":"pretrain-proto-radius","kind":"protocol_spec","title":"Remote Authentication Dial-In User Service (Auth & Accounting) (radius) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/radius","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["radius"],"text":"# radius — UDP 1812/1813 AAA Decisions & Accounting AVPs (`radius`)\n\n> **FrameAssembly v3.3.0** · Protocol 61 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/radius\n\n- **Full Protocol Name:** Remote Authentication Dial-In User Service (Auth &\n  Accounting)\n- **Keyword:** `radius`\n- **OSI Layer & Transport:** Layer 7 · UDP/TCP 1812 (Auth) / 1813 (Accounting)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 2865, RFC 2866\n- **Wireshark Display Filter:** `radius`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP/TCP 1812 (Auth) / 1813 (Accounting) (transport tcp|udp) -> RADIUS`\n\n## Overview\n\nWatch `accessrequest -> accesschallenge -> accessaccept` on UDP `1812` and switch\nseamlessly to UDP `1813` on `accountingrequest`, complete with `User-Name`,\n`NAS-IP-Address`, and `Framed-IP-Address` AVPs.\n\nRemote Authentication Dial-In User Service (`radius`, RFC 2865 / RFC 2866) carries\ncentralized Wi-Fi, 802.1X switch port, and VPN login requests between network\naccess devices and AAA servers such as FreeRADIUS, Cisco ISE, or Aruba ClearPass.\nAuthentication runs on **UDP port `1812`**, while session accounting runs on **UDP\nport `1813`**.\n\nFrameAssembly automatically selects UDP `1812` or `1813` from the message type,\nbuilds the 20-byte RADIUS header (Code, Identifier, Length, and 16-byte\nAuthenticator), and attaches standard Attribute-Value Pairs (AVPs) for `User-Name`\n(Type 1), `NAS-IP-Address` (Type 4), `Service-Type` (Type 6), and\n`Framed-IP-Address` (Type 8).\n\n## Minimal Quickstart (`radius_quickstart.frasm`)\n\n```frameassembly\nhost access_sw { ip 10.20.0.10 }\nhost ise_node  { ip 10.20.0.50 }\n\ncompile {\n    access_sw -> ise_node radius accessrequest id 1 user \"corp\\\\jdoe\" nasip 10.20.0.10 servicetype 2 wait 3ms\n    access_sw <- ise_node radius accessaccept id 1 framedip 10.20.15.42\n}\n```\n\n### Automatic Wire Calculations\n\n- Picks UDP destination port `1812` for `accessrequest`, `accessaccept`,\n  `accessreject`, and `accesschallenge`, or UDP `1813` for `accountingrequest` and\n  `accountingresponse`.\n- Calculates the exact 16-bit RADIUS Length across the 20-byte header and all\n  included AVP attributes, and reverses UDP ports automatically on `<-` replies.\n- Formats standard RFC 2865 AVP TLVs (`User-Name`, `NAS-IP-Address`,\n  `Service-Type`, `Framed-IP-Address`) so Wireshark decodes every attribute\n  cleanly.\n\n## Practical Lab Example: MFA Challenge, VPN IP Assignment & RADIUS Accounting Start (`radius_vpn_mfa_accounting.frasm`)\n\nWalks through a VPN gateway sending an Access-Request, handling an MFA\nAccess-Challenge, receiving an Access-Accept with an assigned client IP, and\nlogging an Accounting-Request on UDP 1813.\n\n```frameassembly\nhost vpn_gw    { ip 172.16.1.5 }\nhost radius_01 { ip 172.16.10.20 }\n\ncompile {\n    // 1. Initial VPN login + MFA Access-Challenge on UDP 1812\n    vpn_gw -> radius_01 radius accessrequest id 10 user \"oncall.netops\" nasip 172.16.1.5 servicetype 2 wait 2ms\n    vpn_gw <- radius_01 radius accesschallenge id 10 wait 15ms\n    // 2. Second factor approved -> Access-Accept assigns Framed-IP 10.250.0.25\n    vpn_gw -> radius_01 radius accessrequest id 11 user \"oncall.netops\" nasip 172.16.1.5 servicetype 2 wait 2ms\n    vpn_gw <- radius_01 radius accessaccept id 11 framedip 10.250.0.25 wait 5ms\n    // 3. Session accounting record on UDP 1813\n    vpn_gw -> radius_01 radius accountingrequest id 12 user \"oncall.netops\" nasip 172.16.1.5 framedip 10.250.0.25 wait 2ms\n    vpn_gw <- radius_01 radius accountingresponse id 12\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show radius_vpn_mfa_accounting.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly radius_vpn_mfa_accounting.frasm radius_vpn_mfa_accounting.pcap\nframeassembly radius_vpn_mfa_accounting.frasm radius_vpn_mfa_accounting.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse radius_vpn_mfa_accounting.pcap radius_vpn_mfa_accounting_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r radius_vpn_mfa_accounting.pcap -Y \"radius\"\n```\n\n## All `radius` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host radius [accessrequest | accessaccept |\naccessreject | accesschallenge | accountingrequest | accountingresponse | code\n\"<text>\"] [id <0..255>] [user \"<text>\"] [nasip <ipv4>] [servicetype <number>]\n[framedip <ipv4>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `accessrequest \\| accessaccept \\| accessreject \\| accesschallenge \\| accountingrequest \\| accountingresponse` | RADIUS packet code keyword (or `code \"<text>\"`) | `accessrequest (Code 1, UDP 1812)` | Sets the 1-byte RADIUS Code (`1` Access-Request, `2` Access-Accept, `3` Access-Reject, `4` Accounting-Request, `5` Accounting-Response, `11` Access-Challenge) and selects UDP `1812` or `1813`. |\n| `id <0..255>` | 1-byte identifier (0..255) | `1` | Sets the RADIUS Identifier byte used to match replies with pending requests. |\n| `user \"<text>\"` | Quoted username text | `Omitted unless set` | Adds Attribute `1` (`User-Name`) to the RADIUS packet. |\n| `nasip <ipv4>` | IPv4 address (e.g. 10.20.0.10) | `Omitted unless set` | Adds Attribute `4` (`NAS-IP-Address`) identifying the switch, WLC, or VPN concentrator. |\n| `servicetype <number>` | Whole number (`1` Login, `2` Framed, `6` Administrative) | `Omitted unless set` | Adds Attribute `6` (`Service-Type`) as a 4-byte integer. |\n| `framedip <ipv4>` | IPv4 address (e.g. 10.250.0.25) | `Omitted unless set` | Adds Attribute `8` (`Framed-IP-Address`) carrying the client’s assigned IPv4 address. |\n\n## Cross-Layer Options Valid with `radius`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP/TCP 1812 (Auth) / 1813 (Accounting)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### No Hyphens or Underscores in RADIUS Message Names\n\n- **Avoid:** `access_sw -> ise_node radius access_request user \"alice\"`\n- **Valid v3.3.0 Syntax:** `access_sw -> ise_node radius accessrequest user\n  \"alice\"`\n\nWrite RADIUS packet types as single lowercase words: `accessrequest`,\n`accessaccept`, `accessreject`, `accesschallenge`, `accountingrequest`, and\n`accountingresponse`.\n\n### Escape Backslashes in Domain Usernames\n\n- **Avoid:** `access_sw -> ise_node radius accessrequest user \"CORP\\alice\" (single\n  slash)`\n- **Valid v3.3.0 Syntax:** `access_sw -> ise_node radius accessrequest user\n  \"CORP\\\\alice\"`\n\nInside double quotes, `\\\\` writes a single literal backslash (`CORP\\alice`) on the\nwire so ` ` or `\n` are not interpreted as control characters.\n"}
{"id":"pretrain-proto-tacacs","kind":"protocol_spec","title":"Terminal Access Controller Access-Control System Plus (tacacs) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/tacacs","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tacacs"],"text":"# tacacs — Stateful TCP 49 Router CLI Auth & Command Audits (`tacacs`)\n\n> **FrameAssembly v3.3.0** · Protocol 62 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/tacacs\n\n- **Full Protocol Name:** Terminal Access Controller Access-Control System Plus\n- **Keyword:** `tacacs`\n- **OSI Layer & Transport:** Layer 7 · TCP 49\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 8907\n- **Wireshark Display Filter:** `tacplus`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 49 -> TACACS+`\n\n## Overview\n\nRouter CLI command auditing over TCP `49` — pro tip: `seq` on a `tacacs` line sets\nthe 8-bit TACACS+ `seq_no` (`1, 2, 3...`) without stomping on the underlying\n32-bit TCP sequence tracker!\n\nTACACS+ (`tacacs`, RFC 8907) handles administrative login authentication\n(`authen`), per-command CLI authorization (`author`), and command audit accounting\n(`acct`) for routers, switches, and firewalls over **TCP port `49`**. Unlike\nRADIUS (which combines authentication and authorization over UDP), TACACS+\nseparates all three AAA functions over reliable TCP.\n\nFrameAssembly builds the 12-byte RFC 8907 TACACS+ header (`version 0xc0`, `type`,\n`seq_no`, `flags`, `session_id`, and `length`) alongside user and command data,\nwhile automatically keeping TCP sequence and acknowledgment numbers in sync.\n\n## Minimal Quickstart (`tacacs_quickstart.frasm`)\n\n```frameassembly\nhost core_rtr   { ip 10.10.0.1 }\nhost tacacs_srv { ip 10.10.0.49 }\n\ncompile {\n    core_rtr -> tacacs_srv tacacs authen seq 1 sessionid 0x8001 user \"netadmin\" data \"tty0\" wait 2ms\n    core_rtr <- tacacs_srv tacacs authen seq 2 sessionid 0x8001 data \"Password: \"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `49` (`psh ack`), TACACS+ version `0xc0`, and\n  calculates the 32-bit payload `length` field automatically.\n- Treats `seq` (`0..255`) on a `tacacs` line as the 1-byte TACACS+ `seq_no` (`1`\n  client start, `2` server reply, `3` client continue) without breaking the outer\n  32-bit TCP sequence number.\n- Shares TCP sequence and acknowledgment tracking with `tcp` handshake packets on\n  port `49`.\n\n## Practical Lab Example: Full TCP 49 Handshake + TACACS+ Admin Login & Command Accounting (`tacacs_admin_session.frasm`)\n\nOpens a TCP port 49 session from a spine router to a TACACS+ server, completes an\nauthentication prompt/reply pair, and sends a command accounting record.\n\n```frameassembly\nhost spine_rtr  { ip 172.20.0.1 }\nhost tacacs_aaa { ip 172.20.0.49 }\n\ncompile {\n    // 1. TCP 3-way handshake on port 49\n    spine_rtr -> tacacs_aaa tcp syn srcport 51049 dstport 49 win 65535 mss 1460 wait 1ms\n    spine_rtr <- tacacs_aaa tcp syn ack win 65535 mss 1460 wait 1ms\n    spine_rtr -> tacacs_aaa tcp ack wait 1ms\n    // 2. TACACS+ Authentication conversation (odd seq = router, even seq = server)\n    spine_rtr -> tacacs_aaa tacacs authen seq 1 flags 1 sessionid 0x44001122 user \"secops\" data \"vty0\" wait 2ms\n    spine_rtr <- tacacs_aaa tacacs authen seq 2 flags 1 sessionid 0x44001122 data \"Password: \" wait 5ms\n    spine_rtr -> tacacs_aaa tacacs authen seq 3 flags 1 sessionid 0x44001122 user \"secops\" data \"LabPass!\" wait 2ms\n    // 3. Command authorization & accounting\n    spine_rtr -> tacacs_aaa tacacs author seq 1 flags 1 sessionid 0x44001123 user \"secops\" data \"cmd=configure\" wait 2ms\n    spine_rtr -> tacacs_aaa tacacs acct seq 1 flags 1 sessionid 0x44001124 user \"secops\" data \"task_id=42\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show tacacs_admin_session.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly tacacs_admin_session.frasm tacacs_admin_session.pcap\nframeassembly tacacs_admin_session.frasm tacacs_admin_session.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse tacacs_admin_session.pcap tacacs_admin_session_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r tacacs_admin_session.pcap -Y \"tacplus\"\n```\n\n## All `tacacs` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host tacacs [authen | author | acct | type\n<authen|author|acct>] [seq <0..255>] [flags <0..255>] [sessionid <number>] [user\n\"<text>\"] [data \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `authen \\| author \\| acct \\| type <authen\\|author\\|acct>` | TACACS+ AAA packet type | `authen (0x01)` | Selects TACACS+ Type `0x01` Authentication (`authen`), `0x02` Authorization (`author`), or `0x03` Accounting (`acct`). |\n| `seq <0..255>` | 1-byte TACACS+ sequence number (0..255) | `1` | Sets the 8-bit TACACS+ `seq_no` header field (clients send odd numbers `1, 3, 5`; servers reply with even numbers `2, 4, 6`). |\n| `flags <0..255>` | 1-byte bitmask (0..255) | `0` | Sets TACACS+ header flags (`0x01` Unencrypted cleartext lab mode, `0x04` Single-Connection mode). |\n| `sessionid <number>` | 32-bit session identifier (decimal or 0x hex) | `1` | Sets the 4-byte TACACS+ `session_id` grouping messages in one AAA exchange. |\n| `user \"<text>\" \\| data \"<text>\"` | Quoted text | `Empty` | Populates the username and port/prompt/command payload fields inside the TACACS+ body. |\n\n## Cross-Layer Options Valid with `tacacs`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 49` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 49)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| ``acknum <number> [win\\|window <0..65535>] [urgent <0..65535>] [tcpmd5 \"<hex>\"] [tfo \"<hex>\"]` (`seq` before `tacacs` sets TCP `seq`; `seq` after `tacacs` sets 8-bit TACACS+ `seq_no`)` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Protocol Keyword Is tacacs (No Plus Sign)\n\n- **Avoid:** `core_rtr -> tacacs_srv tacacs+ authen user \"admin\"`\n- **Valid v3.3.0 Syntax:** `core_rtr -> tacacs_srv tacacs authen user \"admin\"`\n\nBuilt-in protocol names only use letters and digits (`a-z0-9`), so TACACS+ is\nwritten `tacacs`.\n\n### seq Sets the 1-Byte TACACS+ Sequence Number\n\n- **Avoid:** `core_rtr -> tacacs_srv tacacs authen seq 1000`\n- **Valid v3.3.0 Syntax:** `core_rtr -> tacacs_srv tacacs authen seq 1`\n\nOn `tacacs` packets, `seq` sets the 8-bit TACACS+ `seq_no` (`0..255`), while\nFrameAssembly advances the outer 32-bit TCP sequence number automatically.\n"}
{"id":"pretrain-proto-syslog","kind":"protocol_spec","title":"Syslog Event Logging over UDP or TCP (syslog) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/syslog","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["syslog"],"text":"# syslog — RFC 5424 Structured SIEM Events Over UDP or TCP (`syslog`)\n\n> **FrameAssembly v3.3.0** · Protocol 63 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/syslog\n\n- **Full Protocol Name:** Syslog Event Logging over UDP or TCP\n- **Keyword:** `syslog`\n- **OSI Layer & Transport:** Layer 7 · UDP 514 (or TCP 514 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 5424, RFC 3164, RFC 6587\n- **Wireshark Display Filter:** `syslog`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 514 (or TCP 514 via transport tcp) (transport tcp|udp) -> Syslog`\n\n## Overview\n\nCompute `<PRI> = facility * 8 + severity` automatically (or override `pri`\ndirectly) and ship clean RFC 5424 log frames over UDP `514` or `transport tcp` to\nverify SIEM alert rules.\n\nSyslog (`syslog`, RFC 5424) is the universal log transport used by routers,\nfirewalls, Linux servers, and OT gateways to ship security and operational events\nto SIEM collectors (Splunk, Elastic, Sentinel, QRadar, Graylog, rsyslog). By\ndefault, `syslog` sends over **UDP port `514`**, and adding `transport tcp`\nswitches cleanly to **TCP port `514`**.\n\nFrameAssembly computes the RFC `<PRI>` header (`facility * 8 + severity`, or an\nexplicit `pri 0..191` override) and formats a clean RFC 5424 Version `1` message\nwith `hostname`, `app`, `procid`, `msgid`, and `msg` fields.\n\n## Minimal Quickstart (`syslog_quickstart.frasm`)\n\n```frameassembly\nhost edge_fw   { ip 10.10.0.1 }\nhost siem_node { ip 10.10.50.10 }\n\ncompile {\n    edge_fw -> siem_node syslog facility 4 severity 4 hostname \"fw-dmz-01\" app \"sshd\" msg \"Failed password for invalid user admin from 198.51.100.77\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Computes `<PRI> = facility * 8 + severity` automatically (default `facility 16`\n  `local0`, `severity 6` `info` -> `<134>`).\n- Formats a complete RFC 5424 `<PRI>1 TIMESTAMP HOSTNAME APP PROCID MSGID - MSG`\n  wire payload that Wireshark and syslog-ng/rsyslog parse out of the box.\n- Supports `transport tcp` to stream syslog messages over TCP port `514` with\n  automatic TCP sequence tracking.\n\n## Practical Lab Example: Multi-Severity Security Audit over UDP 514 & Reliable TCP 514 (`syslog_siem_pipeline.frasm`)\n\nSends a firewall drop alert and OSPF adjacency warning over UDP 514, then opens a\nTCP 514 session to deliver a high-priority authentication alert.\n\n```frameassembly\nhost branch_fw { ip 172.16.1.1 }\nhost log_relay { ip 172.16.100.10 }\n\ncompile {\n    // 1. Stateless UDP 514 security & routing logs\n    branch_fw -> log_relay syslog facility 4 severity 4 hostname \"branch-fw-01\" app \"filterlog\" msgid \"DROP\" msg \"Blocked TCP SYN 203.0.113.99:44112 -> 172.16.1.10:3389\" wait 2ms\n    branch_fw -> log_relay syslog facility 16 severity 3 hostname \"branch-fw-01\" app \"ospfd\" msgid \"ADJCHG\" msg \"Neighbor 172.16.0.2 Down: Dead timer expired\" wait 4ms\n    // 2. Reliable TCP 514 syslog stream (transport tcp)\n    branch_fw -> log_relay tcp syn srcport 52514 dstport 514 win 65535 mss 1460 wait 1ms\n    branch_fw <- log_relay tcp syn ack win 65535 mss 1460 wait 1ms\n    branch_fw -> log_relay tcp ack wait 1ms\n    branch_fw -> log_relay syslog facility 10 severity 2 hostname \"branch-fw-01\" app \"sudo\" procid \"4812\" msg \"Critical privilege escalation alert\" transport tcp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show syslog_siem_pipeline.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly syslog_siem_pipeline.frasm syslog_siem_pipeline.pcap\nframeassembly syslog_siem_pipeline.frasm syslog_siem_pipeline.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse syslog_siem_pipeline.pcap syslog_siem_pipeline_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r syslog_siem_pipeline.pcap -Y \"syslog\"\n```\n\n## All `syslog` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host syslog [facility <0..23>] [severity\n<0..7>] [pri <0..191>] [hostname \"<text>\"] [app \"<text>\"] [procid \"<text>\"] [msgid\n\"<text>\"] [msg \"<text>\"] [transport <udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `facility <0..23>` | Facility code 0..23 (`4` auth, `10` authpriv, `16..23` local0..local7) | `16 (local0)` | Sets the RFC 5424 Facility number multiplied by `8` inside `<PRI>`. |\n| `severity <0..7>` | Severity 0..7 (`0` emerg, `2` crit, `3` err, `4` warn, `6` info, `7` debug) | `6 (Informational)` | Sets the 3-bit Severity level (`0` is highest urgency, `7` is debug). |\n| `pri <0..191>` | Combined Priority value (0..191) | `Computed from facility * 8 + severity` | Directly sets the `<PRI>` value, overriding `facility` and `severity`. |\n| `hostname \"<text>\" \\| app \"<text>\" \\| procid \"<text>\" \\| msgid \"<text>\"` | Quoted text fields | `Standard RFC 5424 defaults` | Populates the structured RFC 5424 header fields before the log message body. |\n| `msg \"<text>\"` | Quoted log message text | `\"FrameAssembly syslog message\"` | Sets the UTF-8 log message text at the end of the syslog record. |\n| `transport <udp\\|tcp>` | `udp` or `tcp` | `udp` | Switches Layer 4 delivery between UDP port `514` and TCP port `514`. |\n\n## Cross-Layer Options Valid with `syslog`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 514 (or TCP 514 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Facility Must Be 0..23 and Severity Must Be 0..7\n\n- **Avoid:** `edge_fw -> siem_node syslog facility 30 severity 9`\n- **Valid v3.3.0 Syntax:** `edge_fw -> siem_node syslog facility 16 severity 4`\n\nRFC 5424 defines facilities `0` through `23` and severities `0` through `7`\n(giving maximum priority `23 * 8 + 7 = 191`).\n\n### Use msg (Not message) for the Log Body\n\n- **Avoid:** `edge_fw -> siem_node syslog message \"Interface Gi0/1 down\"`\n- **Valid v3.3.0 Syntax:** `edge_fw -> siem_node syslog msg \"Interface Gi0/1\n  down\"`\n\nThe log text option in `.frasm` is `msg \"<text>\"`.\n"}
{"id":"pretrain-proto-netflow","kind":"protocol_spec","title":"Cisco NetFlow Version 5 Flow Export (netflow) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/netflow","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["netflow"],"text":"# netflow — 72-Byte Cisco NetFlow v5 Collector Records (`netflow`)\n\n> **FrameAssembly v3.3.0** · Protocol 64 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/netflow\n\n- **Full Protocol Name:** Cisco NetFlow Version 5 Flow Export\n- **Keyword:** `netflow`\n- **OSI Layer & Transport:** Layer 7 · UDP 2055\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** Cisco NetFlow v5\n- **Wireshark Display Filter:** `cflow`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 2055 -> NetFlow v5`\n\n## Overview\n\nWant to verify your flow dashboard lights up when a workstation ships 50 GB\noutbound without actually saturating a 10G link? One `netflow` packet reports any\n`packets` and `octets` count you ask for.\n\nCisco NetFlow v5 (`netflow`) exports summarized IPv4 traffic conversations from\nrouters, switches, and firewalls to bandwidth monitors and NDR collectors\n(ElastiFlow, Akvorado, SolarWinds, ntopng, PRTG) over **UDP port `2055`**.\n\nEach `netflow` packet in FrameAssembly builds a complete `72`-byte datagram: the\n24-byte NetFlow v5 header (`version 5`, `count 1`, uptime, timestamps, sequence)\nfollowed by a 48-byte flow record containing `srcip`, `dstip`, `srcport`,\n`dstport`, IP `proto`, `packets`, and `octets` (byte count).\n\n## Minimal Quickstart (`netflow_quickstart.frasm`)\n\n```frameassembly\nhost core_rtr  { ip 10.0.0.1 }\nhost collector { ip 10.0.50.20 }\n\ncompile {\n    core_rtr -> collector netflow srcip 10.10.1.25 dstip 198.51.100.40 srcport 52410 dstport 443 proto 6 packets 120 octets 164000\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults UDP destination port to `2055` and builds the exact 24-byte NetFlow v5\n  header + 48-byte flow record (`72` UDP payload bytes).\n- Populates protocol defaults (`proto 6` TCP, `packets 10`, `octets 1500`)\n  whenever counters are omitted.\n- Works over either IPv4 or IPv6 outer exporter-to-collector transport IPs\n  (`ipfix` is available when the exported flow record itself carries IPv6\n  endpoints).\n\n## Practical Lab Example: Multi-Flow Export: HTTPS Upload Spike, DNS Lookup & ICMP Probe (`netflow_collector_test.frasm`)\n\nExports three sequential NetFlow v5 records from a border router representing a\nlarge HTTPS transfer, a UDP DNS query, and an ICMP ping flow.\n\n```frameassembly\nhost border_rtr     { ip 172.16.0.1 }\nhost flow_collector { ip 172.16.100.55 }\n\ncompile {\n    // 1. Large outbound HTTPS transfer (proto 6 = TCP)\n    border_rtr -> flow_collector netflow srcip 10.20.5.14 dstip 203.0.113.80 srcport 54120 dstport 443 proto 6 packets 8500 octets 12240000 wait 2ms\n    // 2. Internal-to-DMZ DNS flow (proto 17 = UDP)\n    border_rtr -> flow_collector netflow srcip 10.20.5.14 dstip 172.16.10.53 srcport 59102 dstport 53 proto 17 packets 2 octets 148 wait 2ms\n    // 3. ICMP reachability flow (proto 1 = ICMP)\n    border_rtr -> flow_collector netflow srcip 10.20.5.14 dstip 8.8.8.8 srcport 0 dstport 0 proto 1 packets 4 octets 336\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show netflow_collector_test.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly netflow_collector_test.frasm netflow_collector_test.pcap\nframeassembly netflow_collector_test.frasm netflow_collector_test.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse netflow_collector_test.pcap netflow_collector_test_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r netflow_collector_test.pcap -Y \"cflow\"\n```\n\n## All `netflow` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host netflow [srcip <ipv4>] [dstip <ipv4>]\n[srcport <0..65535>] [dstport <0..65535>] [proto <0..255>] [packets <number>]\n[octets <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `srcip <ipv4> \\| dstip <ipv4>` | IPv4 address (e.g. 10.10.1.25) | `Outer host IPv4 (or 10.0.0.1 / 10.0.0.2)` | Sets the exported IPv4 Source and Destination addresses inside the 48-byte NetFlow v5 record. |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `Outer UDP ports or 0 / 80` | Sets the exported flow’s L4 ports inside the NetFlow record (or overrides UDP ports when used at transport level). |\n| `proto <0..255>` | IP protocol number (`6` TCP, `17` UDP, `1` ICMP) | `6 (TCP)` | Sets byte 38 (`prot`) of the NetFlow v5 flow record. |\n| `packets <number>` | 32-bit packet count | `10` | Sets the `dPkts` 32-bit packet counter for the flow. |\n| `octets <number>` | 32-bit byte count | `1500` | Sets the `dOctets` 32-bit Layer 3 byte counter for the flow. |\n\n## Cross-Layer Options Valid with `netflow`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 2055` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 2055)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### NetFlow v5 Flow Records Only Hold IPv4 Flow Addresses (Use ipfix for IPv6 Flows)\n\n- **Avoid:** `core_rtr -> collector netflow srcip 2001:db8::10 dstip 2001:db8::20`\n- **Valid v3.3.0 Syntax:** `core_rtr -> collector ipfix srcip 2001:db8::10 dstip\n  2001:db8::20`\n\nClassic Cisco NetFlow v5 has fixed 32-bit IPv4 `srcaddr`/`dstaddr` slots. To\nexport IPv6 flow records, use `ipfix` (RFC 7011 / NetFlow v10).\n\n### Byte Count Is Called octets (Not bytes)\n\n- **Avoid:** `core_rtr -> collector netflow packets 50 bytes 64000`\n- **Valid v3.3.0 Syntax:** `core_rtr -> collector netflow packets 50 octets 64000`\n\nFollowing Cisco NetFlow terminology (`dOctets`), specify the byte counter with\n`octets <number>`.\n"}
{"id":"pretrain-proto-ipfix","kind":"protocol_spec","title":"IP Flow Information Export (NetFlow v10) (ipfix) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ipfix","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ipfix"],"text":"# ipfix — Self-Templated IPv4 & IPv6 Flow Exports (UDP 4739) (`ipfix`)\n\n> **FrameAssembly v3.3.0** · Protocol 65 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ipfix\n\n- **Full Protocol Name:** IP Flow Information Export (NetFlow v10)\n- **Keyword:** `ipfix`\n- **OSI Layer & Transport:** Layer 7 · UDP 4739\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 7011, RFC 7012\n- **Wireshark Display Filter:** `cflow.version == 10`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 4739 -> IPFIX`\n\n## Overview\n\nWireshark hates orphan IPFIX data records with missing templates, so FrameAssembly\nbundles **Template Set `2` (`256`) + Data Set `256`** inside the same UDP `4739`\npacket so every single frame dissects immediately!\n\nIP Flow Information Export (`ipfix`, RFC 7011—standardized from NetFlow v9 as\nVersion `10` / `0x000a`) exports flexible IPv4 and IPv6 traffic telemetry on **UDP\nport `4739`**. A common headache when testing IPFIX collectors or viewing partial\ncaptures in Wireshark is missing templates: without the Template Set, collectors\ncannot decode Data Sets.\n\nFrameAssembly solves that automatically by packing both the **Template Set (`Set\nID 2`)** and the matching **Data Set** inside every `ipfix` packet, so Wireshark,\nElastiFlow, pmacct, and GoFlow2 decode every field immediately on packet 1.\n\n## Minimal Quickstart (`ipfix_quickstart.frasm`)\n\n```frameassembly\nhost leaf_sw   { ip 10.30.0.1 }\nhost collector { ip 10.30.0.100 }\n\ncompile {\n    leaf_sw -> collector ipfix domainid 100 srcip 10.30.10.25 dstip 198.51.100.50 srcport 51200 dstport 443 proto 6 packets 60 octets 72000\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `4739` and builds the 16-byte IPFIX Version\n  `0x000a` header with exact total message length and Observation Domain ID.\n- Bundles a self-describing Template Set (`Set ID 2`, Template ID `256`) plus the\n  Data Set (`Set ID 256`) in one UDP datagram.\n- Automatically switches IANA Information Elements between IPv4\n  (`sourceIPv4Address 8` / `destinationIPv4Address 12`) and IPv6 (`27` / `28`)\n  based on `srcip` and `dstip`.\n\n## Practical Lab Example: Mixed IPv4 & IPv6 VRF Flow Telemetry to an IPFIX Collector (`ipfix_dualstack_flows.frasm`)\n\nExports an IPv4 enterprise HTTPS flow (`domainid 10`) followed by an IPv6\nservice-mesh gRPC flow (`domainid 20`) to UDP port 4739.\n\n```frameassembly\nhost spine_exporter { ip 172.20.0.1 }\nhost ipfix_ingest   { ip 172.20.50.10 }\n\ncompile {\n    // 1. VRF 10 IPv4 flow record\n    spine_exporter -> ipfix_ingest ipfix domainid 10 srcip 10.100.4.15 dstip 203.0.113.44 srcport 50112 dstport 443 proto 6 packets 420 octets 512000 wait 3ms\n    // 2. VRF 20 IPv6 flow record over the same exporter session\n    spine_exporter -> ipfix_ingest ipfix domainid 20 srcip 2001:db8:20::15 dstip 2001:db8:99::5051 srcport 54200 dstport 50051 proto 6 packets 95 octets 84000\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ipfix_dualstack_flows.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ipfix_dualstack_flows.frasm ipfix_dualstack_flows.pcap\nframeassembly ipfix_dualstack_flows.frasm ipfix_dualstack_flows.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ipfix_dualstack_flows.pcap ipfix_dualstack_flows_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ipfix_dualstack_flows.pcap -Y \"cflow.version == 10\"\n```\n\n## All `ipfix` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ipfix [domainid <number>] [srcip <ip>]\n[dstip <ip>] [srcport <0..65535>] [dstport <0..65535>] [proto <0..255>] [packets\n<number>] [octets <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `domainid <number>` | 32-bit Observation Domain ID | `1` | Sets the 4-byte Observation Domain ID in bytes 12..15 of the IPFIX header. |\n| `srcip <ip> \\| dstip <ip>` | IPv4 or IPv6 address | `Outer host IP` | Sets the exported flow’s source and destination IP addresses (both IPv4 or both IPv6). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `49152 / 80` | Populates `sourceTransportPort` (IE 7) and `destinationTransportPort` (IE 11) in the Data Set. |\n| `proto <0..255>` | IP protocol number (`6` TCP, `17` UDP, `58` ICMPv6) | `6 (TCP)` | Populates `protocolIdentifier` (IE 4) in the IPFIX Data Set. |\n| `packets <number> \\| octets <number>` | Packet and byte counters | `packets 10, octets 1500` | Populates `packetDeltaCount` (IE 2) and `octetDeltaCount` (IE 1) in the Data Set. |\n\n## Cross-Layer Options Valid with `ipfix`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 4739` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 4739)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Match Address Families on srcip and dstip\n\n- **Avoid:** `leaf_sw -> collector ipfix srcip 10.0.0.1 dstip 2001:db8::2`\n- **Valid v3.3.0 Syntax:** `leaf_sw -> collector ipfix srcip 2001:db8::1 dstip\n  2001:db8::2`\n\nA single flow record represents either an IPv4 conversation or an IPv6\nconversation, so `srcip` and `dstip` must use the same IP version.\n\n### Wireshark Uses the cflow Display Filter for Both NetFlow and IPFIX\n\n- **Valid v3.3.0 Syntax:** `Wireshark filter: cflow.version == 10`\n\nIn Wireshark, IPFIX is dissected under the unified `cflow` dissector\n(`cflow.version == 10`) rather than a filter named `ipfix`.\n"}
{"id":"pretrain-proto-sflow","kind":"protocol_spec","title":"sFlow Version 5 Switched & Routed Packet Sampling (sflow) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/sflow","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["sflow"],"text":"# sflow — XDR-Encoded Switch Packet Sampling on UDP 6343 (`sflow`)\n\n> **FrameAssembly v3.3.0** · Protocol 66 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/sflow\n\n- **Full Protocol Name:** sFlow Version 5 Switched & Routed Packet Sampling\n- **Keyword:** `sflow`\n- **OSI Layer & Transport:** Layer 7 · UDP 6343\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** sFlow v5 Specification\n- **Wireshark Display Filter:** `sflow`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 6343 -> sFlow v5`\n\n## Overview\n\nHardware ASICs love sFlow v5 on UDP `6343` because sampling 1-in-4096 frames takes\nzero stateful flow memory. `sflow` encodes both IPv4 (`1`) and IPv6 (`2`) XDR\nagent headers cleanly.\n\nsFlow v5 (`sflow`) is the wire-speed packet sampling telemetry protocol built into\nArista, Juniper, Cisco Nexus, HPE/Aruba, and SONiC data-center switches on **UDP\nport `6343`**. Instead of maintaining stateful flow caches on the switch ASIC,\nsFlow exports XDR-encoded packet header samples directly to collectors such as\nsFlow-RT, pmacct, Akvorado, and FastNetMon.\n\nFrameAssembly constructs a valid XDR-aligned sFlow v5 datagram containing the\nAgent IP (`agentip`, automatically tagged as IPv4 type `1` or IPv6 type `2`),\n`subagentid`, datagram `seq`, switch `uptime`, and sampled Ethernet frame header\nrecords.\n\n## Minimal Quickstart (`sflow_quickstart.frasm`)\n\n```frameassembly\nhost tor_sw01  { ip 10.40.0.11 }\nhost sflow_col { ip 10.40.0.200 }\n\ncompile {\n    tor_sw01 -> sflow_col sflow agentip 10.40.0.11 subagentid 1 seq 1 uptime 360000 samples 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults UDP destination port to `6343` and aligns all fields to 4-byte XDR\n  boundaries per the sFlow v5 specification.\n- Sets Agent Address Type to `1` (4-byte IPv4) or `2` (16-byte IPv6) automatically\n  from `agentip`.\n- Includes an Enterprise `0`, Format `1` Flow Sample containing a sampled Raw\n  Packet Header record so Wireshark dissects the full sFlow tree.\n\n## Practical Lab Example: Multi-Switch Leaf-Spine sFlow v5 Telemetry Stream (`sflow_leaf_spine.frasm`)\n\nSimulates two leaf switches exporting sequential sFlow v5 datagrams (including an\nIPv6 loopback agent IP) to a central collector.\n\n```frameassembly\nhost leaf_01   { ip 172.18.1.11 }\nhost leaf_02   { ip 172.18.1.12 }\nhost collector { ip 172.18.100.50 }\n\ncompile {\n    leaf_01 -> collector sflow agentip 172.18.1.11 subagentid 0 seq 101 uptime 450000 samples 1 wait 2ms\n    leaf_01 -> collector sflow agentip 172.18.1.11 subagentid 0 seq 102 uptime 451000 samples 1 wait 2ms\n    leaf_02 -> collector sflow agentip 2001:db8:18::12 subagentid 1 seq 55 uptime 820000 samples 1\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show sflow_leaf_spine.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly sflow_leaf_spine.frasm sflow_leaf_spine.pcap\nframeassembly sflow_leaf_spine.frasm sflow_leaf_spine.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse sflow_leaf_spine.pcap sflow_leaf_spine_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r sflow_leaf_spine.pcap -Y \"sflow\"\n```\n\n## All `sflow` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host sflow [agentip <ip>] [subagentid\n<number>] [seq <number>] [uptime <number>] [samples <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `agentip <ip>` | IPv4 or IPv6 switch management/loopback IP | `Source host IP` | Sets the sFlow Agent Address (XDR Type `1` IPv4 or Type `2` IPv6) in the datagram header. |\n| `subagentid <number>` | 32-bit Sub-Agent ID | `0` | Disambiguates multiple linecards or virtual switches sharing one `agentip`. |\n| `seq <number>` | 32-bit datagram sequence number | `1` | Sets the sFlow v5 datagram sequence counter (collectors track gaps in `seq` to detect dropped UDP telemetry). |\n| `uptime <number>` | 32-bit milliseconds since boot | `1000` | Sets `sysUpTime` in milliseconds inside the sFlow v5 header. |\n| `samples <number>` | Sample count | `1` | Sets the number of sample records carried in the sFlow datagram. |\n\n## Cross-Layer Options Valid with `sflow`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 6343` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 6343)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### seq on sflow Sets the sFlow Datagram Counter (UDP Has No TCP seq)\n\n- **Valid v3.3.0 Syntax:** `tor_sw01 -> sflow_col sflow agentip 10.40.0.11 seq 42`\n\nBecause sFlow runs over UDP `6343`, `seq` sets the 32-bit sFlow datagram sequence\nnumber rather than a TCP sequence number.\n\n### uptime Is Measured in Milliseconds\n\n- **Valid v3.3.0 Syntax:** `tor_sw01 -> sflow_col sflow uptime 600000`\n\nIn sFlow v5, `uptime 600000` represents 600 seconds (10 minutes) since the switch\nagent initialized.\n"}
{"id":"pretrain-proto-http","kind":"protocol_spec","title":"Hypertext Transfer Protocol HTTP/1.1 (http) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/http","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["http"],"text":"# http — Stateful HTTP/1.1 Requests, Headers & WAF Payloads (`http`)\n\n> **FrameAssembly v3.3.0** · Protocol 67 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/http\n\n- **Full Protocol Name:** Hypertext Transfer Protocol HTTP/1.1\n- **Keyword:** `http`\n- **OSI Layer & Transport:** Layer 7 · TCP 80\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 9110, RFC 9112\n- **Wireshark Display Filter:** `http`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 80 -> HTTP/1.1`\n\n## Overview\n\nPair a 3-way `tcp` handshake with `http get` or `http post` and FrameAssembly\nformats `\\r\\n` wire headers, computes exact `Content-Length`, and advances TCP\n`seq` numbers so Suricata and WAFs reassemble every byte.\n\nHypertext Transfer Protocol (`http`, RFC 9112) powers web traffic, REST APIs,\nwebhooks, and reverse-proxy health checks over **TCP port `80`** (or custom ports\nsuch as `8080` via `dstport`). By default, an `http` packet builds an HTTP/1.1\nrequest (`GET / HTTP/1.1`); adding `status <code_num>` (such as `status 200 reason\n\"OK\"`) switches the packet to an HTTP response.\n\nFrameAssembly computes `Content-Length` automatically whenever you include `body`,\nsupports repeatable custom `header` pairs, and keeps TCP sequence and\nacknowledgment numbers synchronized across the entire TCP connection.\n\n## Minimal Quickstart (`http_quickstart.frasm`)\n\n```frameassembly\nhost client  { ip 10.10.1.20 }\nhost web_srv { ip 10.10.1.80 }\n\ncompile {\n    client -> web_srv tcp syn srcport 52100 dstport 80 wait 1ms\n    client <- web_srv tcp syn ack wait 1ms\n    client -> web_srv tcp ack wait 1ms\n    client -> web_srv http get uri \"/healthz\" hosthdr \"api.corp.internal\" useragent \"kube-probe/1.30\" wait 2ms\n    client <- web_srv http status 200 reason \"OK\" contenttype \"application/json\" body \"{\\\"status\\\":\\\"healthy\\\"}\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `80` with `psh ack` flags and advances TCP\n  `seq` by the exact HTTP header + body byte count.\n- Computes and inserts `Content-Length: <bytes>` automatically whenever `body` is\n  present, formatting all header lines with standard `\n` CRLF terminators.\n- Remembers client/server ports on `<-` replies so `status 200` responses return\n  from port `80` to the client’s source port automatically.\n\n## Practical Lab Example: REST API JSON Webhook POST + WAF 403 Block Scenario (`http_api_waf_test.frasm`)\n\nCompletes a TCP handshake on port 8080, sends an authenticated JSON `POST` request\nwith custom HTTP headers, and captures a `403 Forbidden` gateway response.\n\n```frameassembly\nhost ext_client { ip 198.51.100.45 }\nhost waf_proxy  { ip 172.16.20.80 }\n\ncompile {\n    // 1. Complete TCP 3-way handshake on port 8080 (so Suricata stream engine tracks state)\n    ext_client -> waf_proxy tcp syn srcport 54320 dstport 8080 win 65535 mss 1460 wait 1ms\n    ext_client <- waf_proxy tcp syn ack win 65535 mss 1460 wait 1ms\n    ext_client -> waf_proxy tcp ack wait 1ms\n    // 2. HTTP POST with custom headers and JSON body\n    ext_client -> waf_proxy http post uri \"/v1/login\" hosthdr \"portal.example.com\" useragent \"Mozilla/5.0\" contenttype \"application/json\" header \"X-Request-ID\" \"req-9041\" header \"X-Forwarded-For\" \"203.0.113.9\" body \"{\\\"user\\\":\\\"admin\\\"}\" wait 3ms\n    // 3. WAF blocks request with HTTP 403 Forbidden + TCP FIN\n    ext_client <- waf_proxy http status 403 reason \"Forbidden\" contenttype \"application/json\" body \"{\\\"error\\\":\\\"blocked_by_policy\\\"}\" wait 1ms\n    ext_client <- waf_proxy tcp fin ack wait 1ms\n    ext_client -> waf_proxy tcp ack\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show http_api_waf_test.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly http_api_waf_test.frasm http_api_waf_test.pcap\nframeassembly http_api_waf_test.frasm http_api_waf_test.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse http_api_waf_test.pcap http_api_waf_test_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r http_api_waf_test.pcap -Y \"http\"\n```\n\n## All `http` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host http [get | post | put | delete | head\n| options | patch | method \"<text>\"] [uri \"<text>\"] [version \"<text>\"] [hosthdr\n\"<text>\"] [useragent \"<text>\"] [contenttype \"<text>\"] [status <100..599>] [reason\n\"<text>\"] [header \"<name>\" \"<value>\" ...] [body \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `get \\| post \\| put \\| delete \\| head \\| options \\| patch \\| method \"<text>\"` | HTTP request method | `get` | Sets the HTTP request verb at the start of the request line. |\n| `uri \"<text>\" \\| version \"<text>\"` | Request path and HTTP version string | `uri \"/\", version \"HTTP/1.1\"` | Sets the request target path and protocol version (`GET /path HTTP/1.1`). |\n| `hosthdr \"<text>\"` | Quoted hostname (e.g. \"api.internal\") | `Destination IP` | Writes the `Host:` HTTP header (named `hosthdr` so it never conflicts with the top-level `host` block keyword). |\n| `useragent \"<text>\" \\| contenttype \"<text>\"` | Quoted header values | `Omitted unless set` | Writes `User-Agent:` and `Content-Type:` headers. |\n| `header \"<name>\" \"<value>\"` | Repeatable header name + value pair | `Omitted` | Appends one or more custom HTTP headers (`Authorization`, `Cookie`, `X-Forwarded-For`, etc.). |\n| `status <100..599> [reason \"<text>\"]` | HTTP status code + optional reason phrase | `Omitted (emits request); reason \"OK\" when status is set` | Switches the packet from an HTTP request to an HTTP response (`HTTP/1.1 200 OK`). |\n| `body \"<text>\"` | Quoted response or request payload | `Empty` | Appends the HTTP body after `\\r\\n\\r\\n` and calculates `Content-Length` automatically. |\n\n## Cross-Layer Options Valid with `http`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 80` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 80)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Use hosthdr (Not host) for the HTTP Host Header\n\n- **Avoid:** `client -> web_srv http get uri \"/\" host \"api.example.com\"`\n- **Valid v3.3.0 Syntax:** `client -> web_srv http get uri \"/\" hosthdr\n  \"api.example.com\"`\n\nBecause `host` declares network endpoints at the top of a `.frasm` file, HTTP and\nSSDP use `hosthdr \"<text>\"` to set the `Host:` header.\n\n### Include a 3-Way TCP Handshake Before HTTP for Suricata / Zeek\n\n- **Valid v3.3.0 Syntax:** `client -> web_srv tcp syn dstport 80\nclient <- web_srv tcp syn ack\nclient -> web_srv tcp ack\nclient -> web_srv http get uri \"/\"`\n\nWireshark decodes standalone `http` packets immediately, but stateful IDS sensors\nlike Suricata (`flow:established,to_server`) require the 3-packet TCP handshake\nfirst.\n"}
{"id":"pretrain-proto-http2","kind":"protocol_spec","title":"Hypertext Transfer Protocol Version 2 Binary Framing (http2) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/http2","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["http2"],"text":"# http2 — RFC 9113 Connection Prefaces & Multiplexed Frames (`http2`)\n\n> **FrameAssembly v3.3.0** · Protocol 68 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/http2\n\n- **Full Protocol Name:** Hypertext Transfer Protocol Version 2 Binary Framing\n- **Keyword:** `http2`\n- **OSI Layer & Transport:** Layer 7 · TCP 443\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 9113\n- **Wireshark Display Filter:** `http2`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 443 -> HTTP/2`\n\n## Overview\n\nPlaintext `GET /` turned into 9-byte binary frame headers (`Length`, `Type`,\n`Flags`, 31-bit `Stream ID`) — start with `http2 preface` + `settings` and watch\nWireshark dissect your multiplexed `streamid` flows.\n\nHTTP/2 (`http2`, RFC 9113) replaces plain-text HTTP/1.1 lines with multiplexed\nbinary frames over **TCP port `443`** (or cleartext `h2c` on port `80`/`8080`).\nEvery HTTP/2 frame carries a 9-byte header: 24-bit Payload Length, 8-bit Frame\nType, 8-bit Flags, and a 31-bit Stream Identifier (`streamid`).\n\nFrameAssembly automatically builds RFC-compliant frame lengths for connection\n`preface` (`PRI * HTTP/2.0\n\nSM\n\n` + initial `SETTINGS`), `settings`, HPACK-indexed `headers`, `data`,\n`windowupdate` (4-byte window increment), `ping` (8-byte opaque payload), and\n`goaway` teardown frames.\n\n## Minimal Quickstart (`http2_quickstart.frasm`)\n\n```frameassembly\nhost app_client { ip 10.20.1.10 }\nhost api_gw     { ip 10.20.1.44 }\n\ncompile {\n    app_client -> api_gw http2 preface dstport 8080 wait 1ms\n    app_client <- api_gw http2 settings wait 1ms\n    app_client -> api_gw http2 headers streamid 1 wait 1ms\n    app_client <- api_gw http2 data streamid 1 payload \"{\\\"ok\\\":true}\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `443` (`psh ack`) and keeps TCP `seq` /\n  `acknum` synchronized across multiplexed frames.\n- Enforces RFC 9113 frame size rules automatically: 24-byte magic string +\n  `SETTINGS` on `preface`, 8-byte payload on `ping` (`streamid 0`), 4-byte window\n  increment on `windowupdate`, and 8-byte `last_stream_id + error_code` on\n  `goaway`.\n- Encodes valid HPACK indexed pseudo-headers (`:method GET`, `:scheme https`,\n  `:path /`) on `headers` when no raw override is supplied.\n\n## Practical Lab Example: Cleartext h2c Connection Preface, Stream 1 Request, PING & Graceful GOAWAY (`http2_multiplexed_session.frasm`)\n\nEstablishes a TCP port 8080 connection, exchanges HTTP/2 connection prefaces,\nserves a Stream 1 request/data exchange, tests liveness with `ping`, and closes\ncleanly via `goaway`.\n\n```frameassembly\nhost mesh_sidecar { ip 172.16.30.11 }\nhost upstream_svc { ip 172.16.30.80 }\n\ncompile {\n    mesh_sidecar -> upstream_svc tcp syn srcport 53080 dstport 8080 win 65535 mss 1460 wait 1ms\n    mesh_sidecar <- upstream_svc tcp syn ack win 65535 mss 1460 wait 1ms\n    mesh_sidecar -> upstream_svc tcp ack wait 1ms\n    // 1. Client magic preface + server SETTINGS\n    mesh_sidecar -> upstream_svc http2 preface wait 1ms\n    mesh_sidecar <- upstream_svc http2 settings wait 1ms\n    // 2. Stream 1 request headers + response data + flow-control window update\n    mesh_sidecar -> upstream_svc http2 headers streamid 1 wait 2ms\n    mesh_sidecar <- upstream_svc http2 headers streamid 1 wait 1ms\n    mesh_sidecar <- upstream_svc http2 data streamid 1 payload \"{\\\"items\\\":[]}\" wait 1ms\n    mesh_sidecar -> upstream_svc http2 windowupdate streamid 0 wait 5ms\n    // 3. Keepalive PING & graceful connection drain (GOAWAY on stream 0)\n    mesh_sidecar -> upstream_svc http2 ping streamid 0 wait 2ms\n    mesh_sidecar <- upstream_svc http2 goaway streamid 0\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show http2_multiplexed_session.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly http2_multiplexed_session.frasm http2_multiplexed_session.pcap\nframeassembly http2_multiplexed_session.frasm http2_multiplexed_session.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse http2_multiplexed_session.pcap http2_multiplexed_session_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r http2_multiplexed_session.pcap -Y \"http2\"\n```\n\n## All `http2` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host http2 [preface | settings | headers |\ndata | windowupdate | ping | goaway] [streamid <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `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`). |\n| `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. |\n\n## Cross-Layer Options Valid with `http2`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `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. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 443)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Connection-Level Control Frames Use streamid 0\n\n- **Valid v3.3.0 Syntax:** `app_client -> api_gw http2 ping streamid 0`\n\nPer RFC 9113, `settings`, `ping`, and `goaway` apply to the entire connection\n(`streamid 0`), whereas client-initiated requests use odd stream IDs (`streamid\n1`, `streamid 3`).\n\n### No Hyphens or Underscores in windowupdate or goaway\n\n- **Avoid:** `app_client -> api_gw http2 window_update stream_id 1`\n- **Valid v3.3.0 Syntax:** `app_client -> api_gw http2 windowupdate streamid 1`\n\nSpell HTTP/2 keywords without underscores: `windowupdate`, `goaway`, and\n`streamid`.\n"}
{"id":"pretrain-proto-grpc","kind":"protocol_spec","title":"gRPC Remote Procedure Calls over HTTP/2 (grpc) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/grpc","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["grpc"],"text":"# grpc — Microservice RPCs & Router gNMI Streams (TCP 50051) (`grpc`)\n\n> **FrameAssembly v3.3.0** · Protocol 69 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/grpc\n\n- **Full Protocol Name:** gRPC Remote Procedure Calls over HTTP/2\n- **Keyword:** `grpc`\n- **OSI Layer & Transport:** Layer 7 · TCP 50051\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** gRPC over HTTP/2, RFC 9113\n- **Wireshark Display Filter:** `grpc || http2`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 50051 -> gRPC`\n\n## Overview\n\nWhether it is Kubernetes east-west microservices or Arista/Cisco\n`gnmi.gNMI/Subscribe` streaming telemetry on TCP `50051`, `grpc` builds the\nlength-prefixed Protobuf envelope and `grpc-status` trailers.\n\ngRPC (`grpc`) runs Remote Procedure Calls over HTTP/2 on **TCP port `50051`** (and\nnetwork telemetry ports such as `57400`/`9339` for gNMI). On the wire, a gRPC call\nencodes `:path /<service>/<method>` with `content-type: application/grpc` inside\nHTTP/2 `HEADERS`, followed by a 5-byte length-prefixed gRPC `DATA` frame (`1-byte\ncompressed flag` + `4-byte message length` + Protobuf payload), and finishes with\nan HTTP/2 trailer carrying `grpc-status`.\n\nFrameAssembly builds valid HTTP/2 + gRPC request frames from `service` and\n`method` names, or emits a gRPC response trailer when you specify `grpcstatus`\n(`0` OK, `7` PERMISSION_DENIED, `14` UNAVAILABLE).\n\n## Minimal Quickstart (`grpc_quickstart.frasm`)\n\n```frameassembly\nhost caller  { ip 10.42.0.15 }\nhost backend { ip 10.42.0.50 }\n\ncompile {\n    caller -> backend grpc service \"inventory.StockService\" method \"CheckItem\" wait 2ms\n    caller <- backend grpc grpcstatus 0\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `50051` (`psh ack`) and formats HTTP/2\n  `HEADERS` (`:method POST`, `:path /<service>/<method>`, `content-type:\n  application/grpc`).\n- Wraps request payloads in the 5-byte gRPC Length-Prefixed-Message header\n  (`Compressed-Flag = 0` + 32-bit big-endian message length).\n- Emits an HTTP/2 `END_STREAM | END_HEADERS` trailer frame carrying `grpc-status:\n  <code_num>` whenever `grpcstatus` is set.\n\n## Practical Lab Example: gNMI Router Telemetry Subscription + Backend UNAVAILABLE Failover (`grpc_service_mesh_lab.frasm`)\n\nOpens a TCP 50051 connection, invokes a `telemetry.Collector/Export` RPC\nsucceeding with `grpcstatus 0`, and captures a second call returning `grpcstatus\n14` (`UNAVAILABLE`).\n\n```frameassembly\nhost edge_agent { ip 172.16.40.12 }\nhost mesh_gw    { ip 172.16.40.50 }\n\ncompile {\n    edge_agent -> mesh_gw tcp syn srcport 55051 dstport 50051 win 65535 mss 1460 wait 1ms\n    edge_agent <- mesh_gw tcp syn ack win 65535 mss 1460 wait 1ms\n    edge_agent -> mesh_gw tcp ack wait 1ms\n    // 1. Healthy gRPC Export call -> OK (0)\n    edge_agent -> mesh_gw grpc service \"telemetry.Collector\" method \"Export\" wait 2ms\n    edge_agent <- mesh_gw grpc grpcstatus 0 wait 4ms\n    // 2. Upstream maintenance -> UNAVAILABLE (14)\n    edge_agent -> mesh_gw grpc service \"auth.TokenVerifier\" method \"Validate\" wait 2ms\n    edge_agent <- mesh_gw grpc grpcstatus 14\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show grpc_service_mesh_lab.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly grpc_service_mesh_lab.frasm grpc_service_mesh_lab.pcap\nframeassembly grpc_service_mesh_lab.frasm grpc_service_mesh_lab.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse grpc_service_mesh_lab.pcap grpc_service_mesh_lab_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r grpc_service_mesh_lab.pcap -Y \"grpc || http2\"\n```\n\n## All `grpc` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host grpc [service \"<text>\"] [method\n\"<text>\"] [grpcstatus <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `service \"<text>\"` | Package-qualified gRPC service name | `\"helloworld.Greeter\"` | Sets the service prefix in the HTTP/2 `:path` pseudo-header (`/<service>/<method>`). |\n| `method \"<text>\"` | gRPC RPC method name | `\"SayHello\"` | Sets the method suffix in the HTTP/2 `:path` pseudo-header. |\n| `grpcstatus <number>` | gRPC status code (`0` OK, `3` INVALID_ARGUMENT, `7` PERMISSION_DENIED, `14` UNAVAILABLE, `16` UNAUTHENTICATED) | `Omitted on requests` | Switches the packet to a gRPC Trailers response frame carrying `grpc-status`. |\n\n## Cross-Layer Options Valid with `grpc`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 50051` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 50051)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Use grpcstatus (Not status) for gRPC Status Codes\n\n- **Avoid:** `caller <- backend grpc status 14`\n- **Valid v3.3.0 Syntax:** `caller <- backend grpc grpcstatus 14`\n\ngRPC reports RPC completion codes in the `grpc-status` trailer (`0..16`) rather\nthan HTTP status `200`, so the modifier is named `grpcstatus`.\n\n### Do Not Include Leading Slashes in service or method\n\n- **Avoid:** `caller -> backend grpc service \"/helloworld.Greeter\" method\n  \"/SayHello\"`\n- **Valid v3.3.0 Syntax:** `caller -> backend grpc service \"helloworld.Greeter\"\n  method \"SayHello\"`\n\nFrameAssembly automatically joins `service` and `method` into\n`/:service/:method`—pass plain names without extra `/` slashes.\n"}
{"id":"pretrain-proto-websocket","kind":"protocol_spec","title":"WebSocket Framed Bidirectional Messaging (websocket) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/websocket","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["websocket"],"text":"# websocket — RFC 6455 Upgraded Sockets & XOR-Masked Frames (`websocket`)\n\n> **FrameAssembly v3.3.0** · Protocol 70 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/websocket\n\n- **Full Protocol Name:** WebSocket Framed Bidirectional Messaging\n- **Keyword:** `websocket`\n- **OSI Layer & Transport:** Layer 7 · TCP 80\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 6455\n- **Wireshark Display Filter:** `websocket`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 80 -> WebSocket`\n\n## Overview\n\nPass `maskkey 0x37fa213d` on a `client -> server` `websocket text` frame and the\ncompiler genuinely XOR-masks your payload bytes on the wire, so you can watch\nWireshark unmask and display the cleartext right in the tree!\n\nWebSocket (`websocket`, RFC 6455) upgrades an HTTP/1.1 TCP connection into a\npersistent, low-latency bidirectional message channel on **TCP port `80`** (or\ncustom ports). A critical RFC 6455 wire rule is **client-to-server masking**:\nframes sent by a browser or client carry a 32-bit `maskkey` (`MASK=1`) that\nXOR-scrambles the payload bytes on the wire, whereas server-to-client frames\ntravel unmasked (`MASK=0`).\n\nWhen you provide `maskkey` (for example `maskkey 0x37fa213d`), FrameAssembly sets\nthe `MASK` bit, writes the 4-byte key into the WebSocket header, and XOR-masks\nyour `payload` automatically so Wireshark unmasks and displays the exact JSON or\ntext cleanly.\n\n## Minimal Quickstart (`websocket_quickstart.frasm`)\n\n```frameassembly\nhost browser { ip 10.10.2.15 }\nhost ws_srv  { ip 10.10.2.80 }\n\ncompile {\n    browser -> ws_srv websocket text maskkey 0x37fa213d payload \"{\\\"subscribe\\\":\\\"alerts\\\"}\" wait 2ms\n    browser <- ws_srv websocket text payload \"{\\\"event\\\":\\\"link_up\\\"}\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `80` (`psh ack`), `text` frame (`opcode 0x1`),\n  and `finbit 1` (complete unfragmented message).\n- Encodes RFC 6455 extended 16-bit (`126`) or 64-bit (`127`) payload lengths\n  automatically when payloads exceed 125 bytes.\n- Applies RFC 6455 4-byte XOR payload masking automatically whenever `maskkey` is\n  specified.\n\n## Practical Lab Example: Full HTTP 101 Upgrade Handshake Into Masked WebSocket Stream & Close (`websocket_upgrade_session.frasm`)\n\nPerforms a TCP handshake + HTTP `101 Switching Protocols` WebSocket upgrade so\nWireshark and Suricata track the protocol switch, then exchanges masked client\nJSON, server events, `ping`/`pong`, and `close`.\n\n```frameassembly\nhost dashboard_ui { ip 172.16.10.25 }\nhost realtime_gw  { ip 172.16.10.80 }\n\ncompile {\n    // 1. TCP 3-way handshake + HTTP 101 WebSocket Upgrade\n    dashboard_ui -> realtime_gw tcp syn srcport 52800 dstport 80 win 65535 mss 1460 wait 1ms\n    dashboard_ui <- realtime_gw tcp syn ack win 65535 mss 1460 wait 1ms\n    dashboard_ui -> realtime_gw tcp ack wait 1ms\n    dashboard_ui -> realtime_gw http get uri \"/ws\" hosthdr \"noc.corp.internal\" header \"Upgrade\" \"websocket\" header \"Connection\" \"Upgrade\" header \"Sec-WebSocket-Version\" \"13\" header \"Sec-WebSocket-Key\" \"dGhlIHNhbXBsZSBub25jZQ==\" wait 2ms\n    dashboard_ui <- realtime_gw http status 101 reason \"Switching Protocols\" header \"Upgrade\" \"websocket\" header \"Connection\" \"Upgrade\" wait 2ms\n    // 2. Masked client text frame + unmasked server push + Ping/Pong + Close\n    dashboard_ui -> realtime_gw websocket text maskkey 0x12345678 payload \"{\\\"op\\\":\\\"subscribe\\\",\\\"channel\\\":\\\"bgp\\\"}\" wait 2ms\n    dashboard_ui <- realtime_gw websocket text payload \"{\\\"peer\\\":\\\"10.0.0.2\\\",\\\"state\\\":\\\"Established\\\"}\" wait 10ms\n    dashboard_ui <- realtime_gw websocket ping payload \"hb\" wait 1ms\n    dashboard_ui -> realtime_gw websocket pong maskkey 0xabcdef01 payload \"hb\" wait 5ms\n    dashboard_ui -> realtime_gw websocket close maskkey 0x11223344\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show websocket_upgrade_session.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly websocket_upgrade_session.frasm websocket_upgrade_session.pcap\nframeassembly websocket_upgrade_session.frasm websocket_upgrade_session.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse websocket_upgrade_session.pcap websocket_upgrade_session_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r websocket_upgrade_session.pcap -Y \"websocket\"\n```\n\n## All `websocket` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host websocket [text | binary | close | ping\n| pong | opcode \"<text>\"] [finbit <0|1>] [maskkey <number>] [payload \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `text \\| binary \\| close \\| ping \\| pong \\| opcode \"<text>\"` | WebSocket frame opcode | `text (0x1)` | Selects RFC 6455 opcode `0x1` (`text`), `0x2` (`binary`), `0x8` (`close`), `0x9` (`ping`), `0xa` (`pong`), or `\"continuation\"` (`0x0`). |\n| `finbit <0\\|1>` | `1` (final frame) or `0` (more fragments follow) | `1` | Sets the `FIN` bit in byte 0 of the WebSocket header. |\n| `maskkey <number>` | 32-bit masking key (e.g. 0x37fa213d) | `Unmasked (MASK=0)` | Sets `MASK=1`, inserts the 4-byte Masking-Key in the header, and XOR-masks payload bytes on the wire. |\n| `payload \"<text>\"` | Quoted UTF-8 message payload | `Empty` | Sets the WebSocket message data (automatically masked when `maskkey` is present). |\n\n## Cross-Layer Options Valid with `websocket`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 80` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 80)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Include HTTP 101 Upgrade If You Want Automatic Wireshark Dissection on Non-Standard Ports\n\n- **Valid v3.3.0 Syntax:** `Send http get header \"Upgrade\" \"websocket\" -> http\n  status 101 before websocket frames`\n\nWireshark recognizes the transition from HTTP to WebSocket on TCP port `80` best\nwhen preceded by the HTTP `Upgrade: websocket` / `101 Switching Protocols`\nexchange (or via Decode As -> WebSocket).\n\n### RFC 6455 Requires maskkey on Client-to-Server Frames\n\n- **Valid v3.3.0 Syntax:** `browser -> ws_srv websocket text maskkey 0x37fa213d\n  payload \"hello\"`\n\nStrict WebSocket servers close connections (`1002 Protocol Error`) if\nclient-to-server frames omit `maskkey`, while server-to-client replies omit\n`maskkey`.\n"}
{"id":"pretrain-proto-tls","kind":"protocol_spec","title":"Transport Layer Security Record & Handshake Layer (tls) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/tls","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tls"],"text":"# tls — TLS 1.2/1.3 Handshakes, Cleartext SNI & ALPN Records (`tls`)\n\n> **FrameAssembly v3.3.0** · Protocol 71 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/tls\n\n- **Full Protocol Name:** Transport Layer Security Record & Handshake Layer\n- **Keyword:** `tls`\n- **OSI Layer & Transport:** Layer 7 · TCP 443\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 8446, RFC 5246, RFC 6066\n- **Wireshark Display Filter:** `tls`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 443 -> TLS 1.2 / 1.3`\n\n## Overview\n\nNext-gen firewalls and NDR sensors live and breathe the `sni` and `alpn`\nextensions inside `tls clienthello`. FrameAssembly computes all nested Record,\nHandshake, and Extension length fields automatically.\n\nTransport Layer Security (`tls`, RFC 8446 / RFC 5246) encrypts HTTPS, API, mail,\nand VPN sessions over **TCP port `443`**. Even when payload bytes are encrypted,\nfirewalls, web proxies, and IDS engines (Suricata `tls.sni`, Zeek `ssl.log`) rely\nheavily on the unencrypted **TLS `ClientHello`**, specifically the **Server Name\nIndication (`sni`)**, **ALPN (`alpn`, such as `\"h2\"`)**, negotiated `ciphersuite`,\nand TLS version extensions.\n\nFrameAssembly builds valid TLS 1.2 and TLS 1.3 record headers and handshake\nmessages (`clienthello`, `serverhello`, `certificate`, `finished`, `appdata`, and\n`alert`) with automatic nested length fields across the Record header, Handshake\nheader, and Extensions block.\n\n## Minimal Quickstart (`tls_quickstart.frasm`)\n\n```frameassembly\nhost workstation { ip 10.10.5.20 }\nhost https_edge  { ip 198.51.100.44 }\n\ncompile {\n    workstation -> https_edge tcp syn srcport 53443 dstport 443 wait 1ms\n    workstation <- https_edge tcp syn ack wait 1ms\n    workstation -> https_edge tcp ack wait 1ms\n    workstation -> https_edge tls clienthello sni \"portal.corp.internal\" ciphersuite 0x1301 alpn \"h2\" wait 2ms\n    workstation <- https_edge tls serverhello ciphersuite 0x1301\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `443` (`psh ack`), TLS record version `0x0303`\n  (RFC 8446 compatibility layer), and TLS 1.3 cipher suite `0x1301`\n  (`TLS_AES_128_GCM_SHA256`).\n- Automatically encodes Extension `0x0000` (`server_name` when `sni` is set),\n  Extension `0x002b` (`supported_versions` advertising TLS 1.3 `0x0304` + TLS 1.2\n  `0x0303`), and Extension `0x0010` (`alpn` when `alpn` is set).\n- Computes all nested 16-bit and 24-bit TLS Record, Handshake, and Extension\n  lengths automatically.\n\n## Practical Lab Example: Full TLS 1.3 Handshake (`sni` + `alpn \"h2\"`), Encrypted AppData & Alert Teardown (`tls13_sni_handshake.frasm`)\n\nCompletes a TCP 443 handshake, negotiates `TLS_CHACHA20_POLY1305_SHA256`\n(`0x1303`) with SNI and ALPN, exchanges encrypted Application Data records, and\ncloses with a TLS `alert`.\n\n```frameassembly\nhost branch_pc { ip 172.16.12.34 }\nhost saas_gw   { ip 203.0.113.100 }\n\ncompile {\n    branch_pc -> saas_gw tcp syn srcport 54443 dstport 443 win 65535 mss 1460 sackperm wait 1ms\n    branch_pc <- saas_gw tcp syn ack win 65535 mss 1460 sackperm wait 1ms\n    branch_pc -> saas_gw tcp ack wait 1ms\n    // 1. TLS 1.3 ClientHello + ServerHello + Encrypted Handshake / AppData\n    branch_pc -> saas_gw tls clienthello sni \"api.saas-vendor.example\" ciphersuite 0x1303 alpn \"h2\" wait 2ms\n    branch_pc <- saas_gw tls serverhello ciphersuite 0x1303 wait 1ms\n    branch_pc <- saas_gw tls certificate wait 1ms\n    branch_pc <- saas_gw tls finished wait 1ms\n    branch_pc -> saas_gw tls finished wait 2ms\n    // 2. Encrypted TLS Record Type 23 (Application Data) + Record Type 21 (Alert)\n    branch_pc -> saas_gw tls appdata hexpayload \"9f4a1c880021bc773310aa55\" wait 3ms\n    branch_pc <- saas_gw tls appdata hexpayload \"41e82209ff12008ac491bb02\" wait 5ms\n    branch_pc -> saas_gw tls alert\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show tls13_sni_handshake.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly tls13_sni_handshake.frasm tls13_sni_handshake.pcap\nframeassembly tls13_sni_handshake.frasm tls13_sni_handshake.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse tls13_sni_handshake.pcap tls13_sni_handshake_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r tls13_sni_handshake.pcap -Y \"tls\"\n```\n\n## All `tls` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host tls [clienthello | serverhello |\ncertificate | finished | appdata | alert] [recordversion <hex>] [handshakeversion\n<hex>] [sni \"<text>\"] [ciphersuite <hex>] [alpn \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `clienthello \\| serverhello \\| certificate \\| finished \\| appdata \\| alert` | TLS record / handshake message type | `clienthello` | Selects Handshake (`22`: `clienthello`, `serverhello`, `certificate`, `finished`), Application Data (`23`: `appdata`), or Alert (`21`: `alert`). |\n| `sni \"<text>\"` | Quoted hostname (e.g. \"api.example.com\") | `Omitted unless set` | Adds TLS Extension `0x0000` (`server_name`) to `clienthello` for proxy/firewall SNI inspection. |\n| `alpn \"<text>\"` | Quoted protocol ID (`\"h2\"`, `\"http/1.1\"`, `\"mqtt\"`) | `Omitted unless set` | Adds TLS Extension `0x0010` (Application-Layer Protocol Negotiation) to `clienthello`. |\n| `ciphersuite <hex>` | 16-bit IANA cipher code (`0x1301` AES-128-GCM, `0x1302` AES-256-GCM, `0x1303` ChaCha20) | `0x1301` | Sets the offered or selected Cipher Suite in `clienthello` / `serverhello`. |\n| `recordversion <hex> \\| handshakeversion <hex>` | 16-bit TLS version (`0x0301` TLS 1.0, `0x0303` TLS 1.2/1.3 record) | `0x0303` | Overrides the outer 5-byte TLS Record version or inner Handshake legacy version. |\n\n## Cross-Layer Options Valid with `tls`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `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. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 443)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### TLS 1.3 Still Uses 0x0303 in the Outer Record Header by RFC 8446 Design\n\n- **Valid v3.3.0 Syntax:** `tls clienthello sni \"app.local\" ciphersuite 0x1301`\n\nPer RFC 8446, TLS 1.3 keeps `recordversion` at `0x0303` for middlebox\ncompatibility and negotiates TLS 1.3 (`0x0304`) inside the `supported_versions`\nextension—which FrameAssembly adds automatically.\n\n### No Underscores in clienthello, serverhello, or ciphersuite\n\n- **Avoid:** `a -> b tls client_hello cipher_suite 0x1301`\n- **Valid v3.3.0 Syntax:** `a -> b tls clienthello ciphersuite 0x1301`\n\nWrite `clienthello`, `serverhello`, `appdata`, `recordversion`,\n`handshakeversion`, and `ciphersuite` as single lowercase words.\n"}
{"id":"pretrain-proto-quic","kind":"protocol_spec","title":"QUIC v1 & v2 Encrypted UDP Transport (quic) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/quic","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["quic"],"text":"# quic — RFC 9000 Encrypted UDP 443 Handshakes & Connection IDs (`quic`)\n\n> **FrameAssembly v3.3.0** · Protocol 72 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/quic\n\n- **Full Protocol Name:** QUIC v1 & v2 Encrypted UDP Transport\n- **Keyword:** `quic`\n- **OSI Layer & Transport:** Layer 7 · UDP 443\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 9000, RFC 9369\n- **Wireshark Display Filter:** `quic`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 443 -> QUIC (HTTP/3)`\n\n## Overview\n\nHalf of enterprise firewall policy is \"block UDP `443` so browsers fall back to\nTLS over TCP where we can inspect it\" — `quic initial` lets you test whether that\npolicy actually works.\n\nQUIC (`quic`, RFC 9000 / RFC 9369) is the encrypted transport underlying\n**HTTP/3** on **UDP port `443`**. Enterprise firewalls frequently block or inspect\nUDP `443` differently from TCP `443` (forcing browsers back to TLS-over-TCP when\nUDP `443` is dropped), while security sensors inspect QUIC Long Headers\n(`initial`, `zerortt`, `handshake`, `retry`) and Connection IDs (`dcid`, `scid`).\n\nFrameAssembly encodes both RFC 9000 **Long Header** packets (including Version `1`\n`0x00000001` or QUIC v2 `0x6b3343cf`, 8-byte Destination/Source Connection IDs,\nRetry/Initial `token`, and 2-byte RFC 9000 §16 variable-length Length integers)\nand **1-RTT Short Header** (`short`) data packets.\n\n## Minimal Quickstart (`quic_quickstart.frasm`)\n\n```frameassembly\nhost browser { ip 10.20.4.15 }\nhost cdn_vip { ip 198.51.100.44 }\n\ncompile {\n    browser -> cdn_vip quic initial version 1 dcid 0x1122334455667788 scid 0xaabbccddeeff0011 pktnum 1 wait 2ms\n    browser <- cdn_vip quic handshake version 1 dcid 0xaabbccddeeff0011 scid 0x1122334455667788 pktnum 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `443`, QUIC v1 (`version 1` `0x00000001`), and\n  sets the mandatory Fixed Bit (`0x40`) in byte 0.\n- Encodes 8-byte `dcid` and `scid` Connection IDs plus RFC 9000 variable-length\n  integer payload lengths automatically on Long Header packets.\n- Emits compact 1-RTT Short Header frames (`0x40` + 8-byte `dcid` + `pktnum`) when\n  `short` is selected.\n\n## Practical Lab Example: QUIC v1 Retry Token Challenge, Handshake & 1-RTT Connection Migration (`quic_connection_migration.frasm`)\n\nShows a server challenging an initial client packet with `retry`, completing the\nQUIC handshake, and maintaining the same `dcid` across a NAT source-port rebind on\n`short` packets.\n\n```frameassembly\nhost mobile_app { ip 198.51.100.70 }\nhost edge_pop   { ip 203.0.113.44 }\n\ncompile {\n    // 1. Initial attempt -> Server sends stateless Retry token\n    mobile_app -> edge_pop quic initial srcport 51443 dcid 0x0102030405060708 scid 0x1111222233334444 pktnum 0 wait 2ms\n    mobile_app <- edge_pop quic retry dcid 0x1111222233334444 scid 0x9999888877776666 token \"addr-verified-tok\" wait 2ms\n    // 2. Client resends Initial with token + Handshake completion\n    mobile_app -> edge_pop quic initial dcid 0x9999888877776666 scid 0x1111222233334444 token \"addr-verified-tok\" pktnum 1 wait 2ms\n    mobile_app <- edge_pop quic handshake dcid 0x1111222233334444 scid 0x9999888877776666 pktnum 1 wait 3ms\n    // 3. 1-RTT Short Header packets (client migrates from srcport 51443 -> 60222 keeping dcid)\n    mobile_app -> edge_pop quic short dcid 0x9999888877776666 pktnum 2 payload \"h3-stream-frame-1\" wait 5ms\n    mobile_app -> edge_pop quic short srcport 60222 dstport 443 dcid 0x9999888877776666 pktnum 3 payload \"h3-migrated-port\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show quic_connection_migration.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly quic_connection_migration.frasm quic_connection_migration.pcap\nframeassembly quic_connection_migration.frasm quic_connection_migration.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse quic_connection_migration.pcap quic_connection_migration_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r quic_connection_migration.pcap -Y \"quic\"\n```\n\n## All `quic` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host quic [initial | zerortt | handshake |\nretry | short] [version <number>] [dcid <hex_or_num>] [scid <hex_or_num>] [token\n\"<text>\"] [pktnum <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `initial \\| zerortt \\| handshake \\| retry \\| short` | QUIC packet header type | `initial` | Selects Long Header (`initial`, `zerortt`, `handshake`, `retry`) or 1-RTT Short Header (`short`). |\n| `version <number>` | `1` (RFC 9000 QUIC v1) or `0x6b3343cf` (RFC 9369 QUIC v2) | `1 (0x00000001)` | Sets the 32-bit Version field in Long Header packets. |\n| `dcid <hex_or_num> \\| scid <hex_or_num>` | 64-bit Connection IDs (e.g. 0x1122334455667788) | `Deterministic 8-byte IDs` | Sets the 8-byte Destination Connection ID (`dcid`) and Source Connection ID (`scid`, Long Header only). |\n| `token \"<text>\"` | Quoted Retry / address-validation token | `Empty (length 0)` | Populates the Token field on `initial` and `retry` packets. |\n| `pktnum <number>` | Packet Number | `1` | Sets the packet number field in `initial`, `zerortt`, `handshake`, and `short` frames. |\n\n## Cross-Layer Options Valid with `quic`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 443` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 443)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### 0-RTT Is Spelled zerortt (Letters Before Digits Pattern)\n\n- **Avoid:** `browser -> cdn_vip quic 0rtt dcid 0x1234`\n- **Valid v3.3.0 Syntax:** `browser -> cdn_vip quic zerortt dcid 0x1234`\n\nSpell 0-RTT early-data packets as `zerortt` with no hyphen.\n\n### QUIC Runs Over UDP 443 (Do Not Add TCP Flags Like syn or ack)\n\n- **Avoid:** `browser -> cdn_vip quic initial syn`\n- **Valid v3.3.0 Syntax:** `browser -> cdn_vip quic initial pktnum 1`\n\nQUIC handles reliability inside UDP datagrams rather than TCP, so TCP flags\n(`syn`, `ack`, `fin`) are rejected.\n"}
{"id":"pretrain-proto-ssh","kind":"protocol_spec","title":"Secure Shell Transport Layer Protocol (ssh) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ssh","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ssh"],"text":"# ssh — Port 22 Version Banners & Binary KEXINIT Framing (`ssh`)\n\n> **FrameAssembly v3.3.0** · Protocol 73 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ssh\n\n- **Full Protocol Name:** Secure Shell Transport Layer Protocol\n- **Keyword:** `ssh`\n- **OSI Layer & Transport:** Layer 7 · TCP 22\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 4253\n- **Wireshark Display Filter:** `ssh`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 22 -> SSH-2`\n\n## Overview\n\nTest SSH version-banner threat signatures (`SSH-2.0-OpenSSH_9.6` vs legacy `1.99`)\nand RFC 4253 binary `kexinit -> newkeys` framing over stateful TCP port `22`.\n\nSecure Shell (`ssh`, RFC 4253) provides encrypted CLI administration, SFTP file\ntransfer, and port forwarding on **TCP port `22`**. Before encryption starts, both\nsides exchange cleartext `SSH-2.0-...` identification banners followed by binary\n`SSH_MSG_KEXINIT` (`msgcode 20`) algorithm negotiation and `SSH_MSG_NEWKEYS`\n(`msgcode 21`) packets—which IDS engines (Suricata `ssh.protoversion`,\n`ssh.software`, Zeek HASSH) inspect to spot outdated SSH servers, lateral\nmovement, or C2 tunnels.\n\nFrameAssembly formats `\n`-terminated SSH version banners (`banner`), RFC 4253 binary padded `kexinit`\nframes (with 16-byte `cookie` and algorithm lists), `newkeys` transitions, and\ncustom `msgcode` binary packets.\n\n## Minimal Quickstart (`ssh_quickstart.frasm`)\n\n```frameassembly\nhost jump_box { ip 10.10.99.5 }\nhost core_sw  { ip 10.10.0.1 }\n\ncompile {\n    jump_box -> core_sw tcp syn srcport 51022 dstport 22 wait 1ms\n    jump_box <- core_sw tcp syn ack wait 1ms\n    jump_box -> core_sw tcp ack wait 1ms\n    jump_box -> core_sw ssh banner \"SSH-2.0-OpenSSH_9.7\" wait 1ms\n    jump_box <- core_sw ssh banner \"SSH-2.0-Cisco-2.0\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `22` (`psh ack`) and appends standard RFC 4253\n  `\n` terminators to `banner` strings.\n- Computes RFC 4253 binary packet framing (`4-byte packet_length`, `1-byte\n  padding_length`, payload, and 8-byte block padding) automatically on `kexinit`,\n  `newkeys`, and `msgcode` packets.\n- Populates valid curve25519 / chacha20-poly1305 / ssh-ed25519 name-lists inside\n  `kexinit` so Wireshark dissects every KEX field cleanly.\n\n## Practical Lab Example: Complete SSH-2 Banner Exchange, KEXINIT Negotiation & NEWKEYS Cutover (`ssh_handshake_audit.frasm`)\n\nEstablishes a TCP 22 session between an admin workstation and a Linux server,\nexchanges version banners, negotiates keys via `kexinit`, activates encryption\nwith `newkeys`, and sends encrypted session data.\n\n```frameassembly\nhost admin_ws  { ip 172.16.99.10 }\nhost linux_srv { ip 172.16.10.22 }\n\ncompile {\n    admin_ws -> linux_srv tcp syn srcport 53220 dstport 22 win 65535 mss 1460 wait 1ms\n    admin_ws <- linux_srv tcp syn ack win 65535 mss 1460 wait 1ms\n    admin_ws -> linux_srv tcp ack wait 1ms\n    // 1. Cleartext RFC 4253 §4.2 protocol version exchange\n    admin_ws -> linux_srv ssh banner \"SSH-2.0-OpenSSH_9.7p1\" wait 1ms\n    admin_ws <- linux_srv ssh banner \"SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13\" wait 2ms\n    // 2. Binary KEXINIT (msgcode 20) + NEWKEYS (msgcode 21)\n    admin_ws -> linux_srv ssh kexinit cookie \"0102030405060708\" wait 1ms\n    admin_ws <- linux_srv ssh kexinit cookie \"aabbccddeeff0011\" wait 2ms\n    admin_ws -> linux_srv ssh newkeys wait 1ms\n    admin_ws <- linux_srv ssh newkeys\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ssh_handshake_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ssh_handshake_audit.frasm ssh_handshake_audit.pcap\nframeassembly ssh_handshake_audit.frasm ssh_handshake_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ssh_handshake_audit.pcap ssh_handshake_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ssh_handshake_audit.pcap -Y \"ssh\"\n```\n\n## All `ssh` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ssh [banner \"<text>\"] [kexinit]\n[newkeys] [msgcode <0..255>] [cookie \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `banner \"<text>\"` | Quoted SSH identification string (e.g. \"SSH-2.0-OpenSSH_9.7\") | `\"SSH-2.0-OpenSSH_9.6\"` | Emits the cleartext `\\r\\n`-terminated SSH version banner. |\n| `kexinit` | Keyword flag | `Omitted` | Emits a binary RFC 4253 `SSH_MSG_KEXINIT` (`20`) packet with 16-byte cookie and KEX algorithm lists. |\n| `newkeys` | Keyword flag | `Omitted` | Emits a binary `SSH_MSG_NEWKEYS` (`21`) packet signaling transition to negotiated keys. |\n| `msgcode <0..255>` | RFC 4253 message number (e.g. `5` SERVICE_REQUEST, `50` USERAUTH_REQUEST) | `Omitted` | Emits a properly length-prefixed and block-padded SSH binary packet with the chosen message code. |\n| `cookie \"<text>\"` | Quoted cookie value for `kexinit` | `16 deterministic bytes` | Populates the 16-byte KEX cookie inside `kexinit` messages. |\n\n## Cross-Layer Options Valid with `ssh`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 22` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 22)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Start Custom Banners With SSH-2.0- so Wireshark Dissects Them as SSH\n\n- **Avoid:** `jump_box -> core_sw ssh banner \"OpenSSH_9.7\"`\n- **Valid v3.3.0 Syntax:** `jump_box -> core_sw ssh banner \"SSH-2.0-OpenSSH_9.7\"`\n\nRFC 4253 requires SSH version strings to start with\n`SSH-protoversion-softwareversion` (`SSH-2.0-...`).\n\n### Send Banners Before kexinit on the Same 4-Tuple\n\n- **Valid v3.3.0 Syntax:** `Exchange ssh banner lines before ssh kexinit`\n\nStateful analyzers like Zeek and Suricata expect the cleartext `SSH-2.0-` banner\nexchange at the start of the TCP stream before binary `kexinit` frames.\n"}
{"id":"pretrain-proto-telnet","kind":"protocol_spec","title":"Telnet Cleartext Terminal & IAC Negotiation (telnet) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/telnet","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["telnet"],"text":"# telnet — Port 23 IAC Option Negotiations & Login Alarms (`telnet`)\n\n> **FrameAssembly v3.3.0** · Protocol 74 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/telnet\n\n- **Full Protocol Name:** Telnet Cleartext Terminal & IAC Negotiation\n- **Keyword:** `telnet`\n- **OSI Layer & Transport:** Layer 7 · TCP 23\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 854, RFC 855\n- **Wireshark Display Filter:** `telnet`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 23 -> Telnet`\n\n## Overview\n\nIf TCP `23` fires on a modern network, either someone powered on a museum switch\nor a red teamer is having a great afternoon. `telnet` emits authentic `0xff` IAC\n`will`/`do` bytes plus cleartext prompts.\n\nTelnet (`telnet`, RFC 854 / RFC 855) sends terminal sessions and `0xff`\nInterpret-As-Command (**IAC**) option triplets (`WILL`, `WONT`, `DO`, `DONT`) in\ncleartext over **TCP port `23`**. Because credentials and commands travel\nunencrypted, detecting unexpected Telnet connections is a mandatory compliance\ncheck in PCI-DSS, NIST 800-53, CIS Benchmarks, and IEC 62443 OT networks.\n\nFrameAssembly encodes `0xff` IAC negotiation triplets (`do`, `dont`, `will`,\n`wont`) alongside ASCII terminal prompts and CLI commands (`data`) so you can\nverify IDS and NAC cleartext-management alerts safely without enabling Telnet on a\nreal switch.\n\n## Minimal Quickstart (`telnet_quickstart.frasm`)\n\n```frameassembly\nhost audit_pc  { ip 10.10.10.50 }\nhost legacy_sw { ip 10.10.10.2 }\n\ncompile {\n    audit_pc -> legacy_sw tcp syn srcport 51023 dstport 23 wait 1ms\n    audit_pc <- legacy_sw tcp syn ack wait 1ms\n    audit_pc -> legacy_sw tcp ack wait 1ms\n    audit_pc <- legacy_sw telnet will 1 do 24 data \"User Access Verification\\r\\nUsername: \" wait 3ms\n    audit_pc -> legacy_sw telnet do 1 wont 24 data \"operator\\r\\n\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `23` (`psh ack`) and tracks TCP sequence\n  numbers automatically.\n- Prefixes every `will` (`251`), `wont` (`252`), `do` (`253`), and `dont` (`254`)\n  option with the `0xff` IAC escape byte.\n- Appends `data` text immediately after any IAC negotiation bytes in the same TCP\n  segment.\n\n## Practical Lab Example: Legacy OT RTU Telnet Login Detection Scenario (`telnet_cleartext_audit.frasm`)\n\nModels a TCP 23 connection to a legacy serial-to-Ethernet terminal server,\nnegotiating Echo/Suppress-Go-Ahead options and sending a `show running-config`\ncommand.\n\n```frameassembly\nhost eng_laptop { ip 192.168.50.15 }\nhost rtu_gw     { ip 192.168.50.200 }\n\ncompile {\n    eng_laptop -> rtu_gw tcp syn srcport 50123 dstport 23 win 65535 mss 1460 wait 1ms\n    eng_laptop <- rtu_gw tcp syn ack win 65535 mss 1460 wait 1ms\n    eng_laptop -> rtu_gw tcp ack wait 1ms\n    eng_laptop <- rtu_gw telnet will 1 do 24 wait 2ms\n    eng_laptop <- rtu_gw telnet will 3 data \"RTU-GW01 login: \" wait 5ms\n    eng_laptop -> rtu_gw telnet do 1 wont 24 wait 2ms\n    eng_laptop -> rtu_gw telnet do 3 data \"maint\\r\\n\" wait 3ms\n    eng_laptop <- rtu_gw telnet data \"Password: \" wait 5ms\n    eng_laptop -> rtu_gw telnet data \"show version\\r\\n\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show telnet_cleartext_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly telnet_cleartext_audit.frasm telnet_cleartext_audit.pcap\nframeassembly telnet_cleartext_audit.frasm telnet_cleartext_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse telnet_cleartext_audit.pcap telnet_cleartext_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r telnet_cleartext_audit.pcap -Y \"telnet\"\n```\n\n## All `telnet` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host telnet [do <0..255>] [dont <0..255>]\n[will <0..255>] [wont <0..255>] [option <0..255>] [data \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `do <0..255> \\| dont <0..255> \\| will <0..255> \\| wont <0..255>` | Telnet option code (`1` Echo, `3` Suppress Go Ahead, `24` Terminal Type, `31` Window Size) | `Omitted` | Emits the 3-byte `0xff <CMD> <OPT>` IAC negotiation triplet. |\n| `option <0..255>` | 1-byte option number | `Omitted` | Specifies an auxiliary Telnet option code. |\n| `data \"<text>\"` | Quoted terminal text (supports `\\r\\n`) | `Empty` | Writes NVT ASCII terminal characters into the Telnet segment. |\n\n## Cross-Layer Options Valid with `telnet`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 23` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 23)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Include \\r\\n Line Endings in Interactive Commands\n\n- **Valid v3.3.0 Syntax:** `eng_laptop -> rtu_gw telnet data \"show ip interface\n  brief\\r\\n\"`\n\nRFC 854 Network Virtual Terminal (NVT) lines end with CR-LF (`\\r\\n`), which IDS\ncommand signatures often check for.\n\n### One Option Per IAC Verb Per Packet Line\n\n- **Avoid:** `eng_laptop <- rtu_gw telnet will 1 will 3`\n- **Valid v3.3.0 Syntax:** `eng_laptop <- rtu_gw telnet will 1 do 24`\n\nEach IAC verb (`will`, `wont`, `do`, `dont`) may appear once on a packet line.\nCombine different verbs on one segment (`will 1 do 24`) or send a second `will 3`\non the next Telnet segment.\n"}
{"id":"pretrain-proto-tftp","kind":"protocol_spec","title":"Trivial File Transfer Protocol (tftp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/tftp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tftp"],"text":"# tftp — UDP 69 Config Read/Write Requests & Block Transfers (`tftp`)\n\n> **FrameAssembly v3.3.0** · Protocol 75 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/tftp\n\n- **Full Protocol Name:** Trivial File Transfer Protocol\n- **Keyword:** `tftp`\n- **OSI Layer & Transport:** Layer 7 · UDP 69\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 1350\n- **Wireshark Display Filter:** `tftp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 69 -> TFTP`\n\n## Overview\n\nZero passwords, UDP `69`, and still the fastest way network gear leaks\n`\"startup-config\"` — `tftp` scripts `rrq -> data -> ack` block transfers and error\ncodes in seconds.\n\nTrivial File Transfer Protocol (`tftp`, RFC 1350) transfers VoIP phone firmware,\nPXE network bootloaders, and legacy router/switch `running-config` files over\n**UDP port `69`** without authentication. Because attackers frequently abuse TFTP\nto pull cleartext switch configurations (`copy running-config tftp:`) or stage\ntools inside OT networks, TFTP monitoring is a staple IDS and NAC control.\n\nFrameAssembly encodes all five RFC 1350 opcodes: Read Request (`rrq`, Opcode `1`),\nWrite Request (`wrq`, Opcode `2`), numbered Data blocks (`data`, Opcode `3`),\nBlock Acknowledgments (`ack`, Opcode `4`), and Error packets (`error` / `err`,\nOpcode `5`).\n\n## Minimal Quickstart (`tftp_quickstart.frasm`)\n\n```frameassembly\nhost voip_phone { ip 10.20.30.112 }\nhost tftp_srv   { ip 10.20.30.10 }\n\ncompile {\n    voip_phone -> tftp_srv tftp rrq filename \"SIPDefault.cnf\" mode \"octet\" wait 2ms\n    voip_phone <- tftp_srv tftp data block 1 payload \"[device]\\nproxy=10.20.30.5\\n\" wait 1ms\n    voip_phone -> tftp_srv tftp ack block 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults UDP destination port to `69` and writes NUL-terminated (`0x00`)\n  `filename` and transfer `mode` (`\"octet\"` or `\"netascii\"`) strings on\n  `rrq`/`wrq`.\n- Encodes 2-byte big-endian Opcode + 2-byte `block` number on `data` (`3`) and\n  `ack` (`4`) packets.\n- Formats Opcode `5` (`error` / `err`) with 2-byte `errcode` and NUL-terminated\n  `errmsg`.\n\n## Practical Lab Example: PXE Bootloader Download + Missing Config File Error (`tftp_pxe_boot.frasm`)\n\nRequests `pxelinux.0` in binary `\"octet\"` mode, transfers Block 1 with TFTP `ack`,\nand then requests a missing board config returning RFC 1350 Error Code `1`.\n\n```frameassembly\nhost pxe_host { ip 172.16.50.101 }\nhost boot_srv { ip 172.16.50.10 }\n\ncompile {\n    // 1. Successful Read Request (RRQ) + Block 1 transfer\n    pxe_host -> boot_srv tftp rrq filename \"pxelinux.0\" mode \"octet\" wait 2ms\n    pxe_host <- boot_srv tftp data block 1 hexpayload \"7f454c46020101000000000000000000\" wait 1ms\n    pxe_host -> boot_srv tftp ack block 1 wait 4ms\n    // 2. Missing profile returns TFTP Error (Opcode 5, Error Code 1 = File not found)\n    pxe_host -> boot_srv tftp rrq filename \"pxelinux.cfg/default\" mode \"octet\" wait 2ms\n    pxe_host <- boot_srv tftp error errcode 1 errmsg \"File not found\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show tftp_pxe_boot.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly tftp_pxe_boot.frasm tftp_pxe_boot.pcap\nframeassembly tftp_pxe_boot.frasm tftp_pxe_boot.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse tftp_pxe_boot.pcap tftp_pxe_boot_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r tftp_pxe_boot.pcap -Y \"tftp\"\n```\n\n## All `tftp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host tftp [rrq | wrq | data | ack | error |\nerr] [filename \"<text>\"] [mode \"<text>\"] [block <0..65535>] [errcode <0..65535>]\n[errmsg \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `rrq \\| wrq \\| data \\| ack \\| error \\| err` | TFTP opcode keyword | `rrq (Opcode 1)` | Selects Opcode `1` Read Request (`rrq`), `2` Write Request (`wrq`), `3` Data (`data`), `4` Acknowledgment (`ack`), or `5` Error (`error` / `err`). |\n| `filename \"<text>\" \\| mode \"<text>\"` | Quoted filename and mode (`\"octet\"` or `\"netascii\"`) | `filename \"boot.bin\", mode \"octet\"` | Writes NUL-terminated filename and transfer mode strings in `rrq` and `wrq` packets. |\n| `block <0..65535>` | 16-bit block number | `1` | Sets the 2-byte Block Number in `data` and `ack` packets (`0` acknowledges a `wrq`). |\n| `errcode <0..65535> \\| errmsg \"<text>\"` | RFC 1350 error code (`1` File not found, `2` Access violation) + message | `errcode 1, errmsg \"File not found\"` | Populates the error code and NUL-terminated error string in `error` / `err` packets. |\n\n## Cross-Layer Options Valid with `tftp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 69` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 69)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### ack Inside a tftp Packet Emits TFTP Opcode 4 (Not TCP ACK)\n\n- **Valid v3.3.0 Syntax:** `voip_phone -> tftp_srv tftp ack block 1`\n\nOn a `tftp` line, `ack` builds the 4-byte UDP TFTP Block Acknowledgment (`0x0004`\n+ 2-byte `block`), whereas TCP flags are not allowed on UDP protocols.\n\n### Quote Filenames Containing Dots, Slashes, or Hyphens\n\n- **Avoid:** `voip_phone -> tftp_srv tftp rrq filename router-confg.cfg`\n- **Valid v3.3.0 Syntax:** `voip_phone -> tftp_srv tftp rrq filename\n  \"router-confg.cfg\"`\n\nAlways wrap file paths and names in double quotes (`\"router-confg.cfg\"`).\n"}
{"id":"pretrain-proto-ftp","kind":"protocol_spec","title":"File Transfer Protocol Control Channel (ftp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ftp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ftp"],"text":"# ftp — Stateful TCP 21 Control Sessions & Firewall ALG Tests (`ftp`)\n\n> **FrameAssembly v3.3.0** · Protocol 76 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ftp\n\n- **Full Protocol Name:** File Transfer Protocol Control Channel\n- **Keyword:** `ftp`\n- **OSI Layer & Transport:** Layer 7 · TCP 21\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 959, RFC 2428\n- **Wireshark Display Filter:** `ftp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 21 -> FTP`\n\n## Overview\n\nNothing stresses a stateful firewall’s Application Layer Gateway quite like FTP on\nTCP `21`. Pair `code 220` server greetings with `cmd \"USER\" arg \"anonymous\"` and\nwatch your IDS light up.\n\nFile Transfer Protocol (`ftp`, RFC 959) sends human-readable control commands\n(`USER`, `PASS`, `SYST`, `PASV`, `EPSV`, `RETR`, `STOR`, `QUIT`) and 3-digit\nserver status replies (`220`, `331`, `230`, `227`, `530`) over **TCP port `21`**.\n\nIn FrameAssembly, specifying `code <num>` (such as `code 220 reply \"FTP Server\nReady\"`) emits an FTP server reply line (`220 FTP Server Ready\n`), while specifying `cmd \"<verb>\"` (with optional `arg \"<text>\"`) emits a client\ncommand line (`USER anonymous\n`) with automatic TCP sequence number tracking.\n\n## Minimal Quickstart (`ftp_quickstart.frasm`)\n\n```frameassembly\nhost client  { ip 10.10.4.20 }\nhost ftp_srv { ip 10.10.4.21 }\n\ncompile {\n    client -> ftp_srv tcp syn srcport 51021 dstport 21 wait 1ms\n    client <- ftp_srv tcp syn ack wait 1ms\n    client -> ftp_srv tcp ack wait 1ms\n    client <- ftp_srv ftp code 220 reply \"vsFTPd 3.0.5\" wait 2ms\n    client -> ftp_srv ftp cmd \"USER\" arg \"anonymous\" wait 2ms\n    client <- ftp_srv ftp code 331 reply \"Please specify the password.\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `21` (`psh ack`) and terminates every command\n  or reply with standard `\n` CRLF.\n- Formats `<code_num> <reply>\n` automatically when `code` is provided, or `<cmd> <arg>\n` for client requests.\n- Keeps bidirectional TCP sequence and acknowledgment numbers synchronized across\n  multi-step login sessions.\n\n## Practical Lab Example: FTP Banner, Failed Brute-Force Login (`530`) & Successful Passive Retrieval (`ftp_login_and_pasv.frasm`)\n\nCompletes a TCP 21 handshake, tests a failed `530 Login incorrect` attempt, then\nlogs in cleanly and enters `PASV` mode to retrieve an archive.\n\n```frameassembly\nhost branch_host { ip 172.16.20.35 }\nhost dmz_ftp     { ip 172.16.100.21 }\n\ncompile {\n    branch_host -> dmz_ftp tcp syn srcport 52121 dstport 21 win 65535 mss 1460 wait 1ms\n    branch_host <- dmz_ftp tcp syn ack win 65535 mss 1460 wait 1ms\n    branch_host -> dmz_ftp tcp ack wait 1ms\n    branch_host <- dmz_ftp ftp code 220 reply \"DMZ Archive FTP Ready\" wait 2ms\n    // 1. Rejected login attempt -> 530 Login incorrect\n    branch_host -> dmz_ftp ftp cmd \"USER\" arg \"admin\" wait 1ms\n    branch_host <- dmz_ftp ftp code 331 reply \"Password required for admin\" wait 2ms\n    branch_host -> dmz_ftp ftp cmd \"PASS\" arg \"wrongpass\" wait 5ms\n    branch_host <- dmz_ftp ftp code 530 reply \"Login incorrect.\" wait 5ms\n    // 2. Authorized backup user + PASV + RETR\n    branch_host -> dmz_ftp ftp cmd \"USER\" arg \"svc_backup\" wait 1ms\n    branch_host <- dmz_ftp ftp code 331 reply \"Password required\" wait 1ms\n    branch_host -> dmz_ftp ftp cmd \"PASS\" arg \"LabOnlyToken99\" wait 2ms\n    branch_host <- dmz_ftp ftp code 230 reply \"User logged in, proceed.\" wait 2ms\n    branch_host -> dmz_ftp ftp cmd \"PASV\" wait 1ms\n    branch_host <- dmz_ftp ftp code 227 reply \"Entering Passive Mode (172,16,100,21,195,80).\" wait 1ms\n    branch_host -> dmz_ftp ftp cmd \"RETR\" arg \"daily-config.tar.gz\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ftp_login_and_pasv.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ftp_login_and_pasv.frasm ftp_login_and_pasv.pcap\nframeassembly ftp_login_and_pasv.frasm ftp_login_and_pasv.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ftp_login_and_pasv.pcap ftp_login_and_pasv_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ftp_login_and_pasv.pcap -Y \"ftp\"\n```\n\n## All `ftp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ftp [cmd \"<text>\"] [arg \"<text>\"] [code\n<100..599>] [reply \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `cmd \"<text>\"` | Quoted FTP command verb (`\"USER\"`, `\"PASS\"`, `\"PASV\"`, `\"RETR\"`, `\"STOR\"`, `\"QUIT\"`) | `\"USER\"` | Writes the FTP client command verb. |\n| `arg \"<text>\"` | Quoted command argument (username, path, etc.) | `Omitted unless set` | Appends a space and argument after `cmd` before `\\r\\n`. |\n| `code <100..599>` | 3-digit FTP reply code (`220`, `227`, `230`, `331`, `530`) | `Omitted on client commands` | Switches the packet to an FTP server status response starting with the 3-digit code. |\n| `reply \"<text>\"` | Quoted server response message | `\"OK\" when code is set` | Sets the human-readable text following the 3-digit FTP `code`. |\n\n## Cross-Layer Options Valid with `ftp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 21` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 21)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Use code (Not status) for FTP Server Replies\n\n- **Avoid:** `client <- ftp_srv ftp status 220 reply \"Ready\"`\n- **Valid v3.3.0 Syntax:** `client <- ftp_srv ftp code 220 reply \"Ready\"`\n\nFTP and SMTP use `code <num> reply \"<text>\"` (`status` is used by HTTP, SIP, RTSP,\nIMAP, and SMB).\n\n### Wrap Command Verbs Like \"USER\" and \"PASV\" in Double Quotes\n\n- **Avoid:** `client -> ftp_srv ftp cmd USER arg anonymous`\n- **Valid v3.3.0 Syntax:** `client -> ftp_srv ftp cmd \"USER\" arg \"anonymous\"`\n\nKeep `cmd` and `arg` values inside double quotes so uppercase FTP verbs and file\npaths parse cleanly.\n"}
{"id":"pretrain-proto-whois","kind":"protocol_spec","title":"WHOIS Domain & IP Directory Query Protocol (whois) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/whois","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["whois"],"text":"# whois — Port 43 Domain & ASN Registry Query Sessions (`whois`)\n\n> **FrameAssembly v3.3.0** · Protocol 77 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/whois\n\n- **Full Protocol Name:** WHOIS Domain & IP Directory Query Protocol\n- **Keyword:** `whois`\n- **OSI Layer & Transport:** Layer 7 · TCP 43\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 3912\n- **Wireshark Display Filter:** `whois`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 43 -> WHOIS`\n\n## Overview\n\nOne of the simplest protocols in IETF history (`domain\\r\\n` out -> multi-line\nregistry text back over TCP `43`), handy for testing threat-enrichment egress\nrules.\n\nWHOIS (`whois`, RFC 3912) queries domain registrars and Regional Internet\nRegistries (ARIN, RIPE, APNIC) over **TCP port `43`**. A client opens a TCP\nconnection, sends a `\n`-terminated domain or prefix query (`query`), and the server returns structured\n`Domain Name:` / `Registrar:` text lines (`response`) before closing the\nconnection.\n\nFrameAssembly supports both `whois query` and `whois response` frames while\ncleanly distinguishing standalone `whois` (TCP `43`) from `bacnet whois` (ASHRAE\n135 building-automation discovery on UDP `47808`).\n\n## Minimal Quickstart (`whois_quickstart.frasm`)\n\n```frameassembly\nhost soar_runner { ip 10.30.10.15 }\nhost whois_srv   { ip 199.7.51.74 }\n\ncompile {\n    soar_runner -> whois_srv tcp syn srcport 53043 dstport 43 wait 1ms\n    soar_runner <- whois_srv tcp syn ack wait 1ms\n    soar_runner -> whois_srv tcp ack wait 1ms\n    soar_runner -> whois_srv whois query domain \"example.org\" wait 3ms\n    soar_runner <- whois_srv whois response domain \"example.org\" registrar \"RESERVED-Internet Assigned Numbers Authority\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `43` (`psh ack`) and appends `\n` to `domain` on `query` frames.\n- Formats standard multi-line `Domain Name: <domain>\nRegistrar: <registrar>\n` directory output on `response` frames.\n- Tracks TCP sequence and acknowledgment numbers automatically across the\n  query/response exchange.\n\n## Practical Lab Example: Full TCP 43 WHOIS Lookup & Clean FIN Teardown (`whois_soc_enrichment.frasm`)\n\nOpens TCP port 43 from a SOC automation host, queries `suspicious-login.example`,\nreceives registrar metadata, and closes the TCP session cleanly per RFC 3912.\n\n```frameassembly\nhost soc_bot  { ip 172.16.80.12 }\nhost rir_node { ip 198.51.100.43 }\n\ncompile {\n    soc_bot -> rir_node tcp syn srcport 54043 dstport 43 win 65535 mss 1460 wait 1ms\n    soc_bot <- rir_node tcp syn ack win 65535 mss 1460 wait 1ms\n    soc_bot -> rir_node tcp ack wait 1ms\n    soc_bot -> rir_node whois query domain \"suspicious-login.example\" wait 4ms\n    soc_bot <- rir_node whois response domain \"suspicious-login.example\" registrar \"Example Registrar LLC\" wait 1ms\n    soc_bot <- rir_node tcp fin ack wait 1ms\n    soc_bot -> rir_node tcp fin ack wait 1ms\n    soc_bot <- rir_node tcp ack\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show whois_soc_enrichment.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly whois_soc_enrichment.frasm whois_soc_enrichment.pcap\nframeassembly whois_soc_enrichment.frasm whois_soc_enrichment.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse whois_soc_enrichment.pcap whois_soc_enrichment_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r whois_soc_enrichment.pcap -Y \"whois\"\n```\n\n## All `whois` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host whois [query | response] [domain\n\"<text>\"] [registrar \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `query \\| response` | Message direction keyword | `query` | Selects a `\\r\\n`-terminated lookup string (`query`) or formatted WHOIS record (`response`). |\n| `domain \"<text>\"` | Quoted domain name or IP query | `\"example.com\"` | Sets the queried domain name or the `Domain Name:` line in responses. |\n| `registrar \"<text>\"` | Quoted registrar organization name | `\"IANA\" on response` | Populates the `Registrar:` record line inside `whois response` frames. |\n\n## Cross-Layer Options Valid with `whois`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 43` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 43)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Standalone whois (TCP 43) vs bacnet whois (UDP 47808)\n\n- **Valid v3.3.0 Syntax:** `a -> b whois query domain \"example.com\" // vs: a -> b\n  bacnet whois`\n\nPlacing `whois` right after the endpoints (`a -> b whois ...`) selects RFC 3912\nWHOIS on TCP `43`; placing it after `bacnet` (`a -> b bacnet whois`) selects\nBACnet Who-Is device discovery on UDP `47808`.\n"}
{"id":"pretrain-proto-sip","kind":"protocol_spec","title":"Session Initiation Protocol VoIP Signaling (sip) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/sip","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["sip"],"text":"# sip — VoIP INVITE, SDP & Call-ID Ladders Over UDP/TCP 5060 (`sip`)\n\n> **FrameAssembly v3.3.0** · Protocol 78 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/sip\n\n- **Full Protocol Name:** Session Initiation Protocol VoIP Signaling\n- **Keyword:** `sip`\n- **OSI Layer & Transport:** Layer 7 · UDP 5060 (or TCP 5060 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 3261\n- **Wireshark Display Filter:** `sip`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 5060 (or TCP 5060 via transport tcp) (transport tcp|udp) -> SIP (VoIP)`\n\n## Overview\n\nDebugging why desk phones ring once and drop at the Session Border Controller?\n`sip` builds full RFC 3261 `Via`, `From`, `To`, `Call-ID`, and `CSeq` headers over\nUDP `5060` or `transport tcp`.\n\nSession Initiation Protocol (`sip`, RFC 3261) sets up, modifies, and tears down\nVoIP phone calls and SIP trunks across IP PBXs (Asterisk, FreeSWITCH, Cisco CUCM)\nand Session Border Controllers (SBCs) on **port `5060`**. `sip` defaults to **UDP\nport `5060`**, and adding `transport tcp` switches to **TCP port `5060`**.\n\nWriting valid SIP messages by hand is tedious because strict parsers reject\npackets missing RFC 3261 headers or the `z9hG4bK` branch magic cookie.\nFrameAssembly automatically builds `Via` (with `z9hG4bK` branch cookie), `From`,\n`To`, `Call-ID`, `CSeq`, `Max-Forwards: 70`, `Contact`, and `Content-Length`—so\nWireshark’s **Telephony -> VoIP Calls** ladder diagram renders your call flow\nimmediately.\n\n## Minimal Quickstart (`sip_quickstart.frasm`)\n\n```frameassembly\nhost desk_phone { ip 10.30.20.101 }\nhost corp_pbx   { ip 10.30.20.10 }\n\ncompile {\n    desk_phone -> corp_pbx sip invite uri \"sip:1002@pbx.internal\" from \"sip:1001@pbx.internal\" to \"sip:1002@pbx.internal\" callid \"call-401\" cseq 1 wait 2ms\n    desk_phone <- corp_pbx sip status 180 reason \"Ringing\" callid \"call-401\" cseq 1 wait 10ms\n    desk_phone <- corp_pbx sip status 200 reason \"OK\" callid \"call-401\" cseq 1 wait 2ms\n    desk_phone -> corp_pbx sip ack uri \"sip:1002@pbx.internal\" callid \"call-401\" cseq 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP `5060` (`SIP/2.0/UDP`) or switches `Via` and Layer 4 to TCP\n  `5060` (`SIP/2.0/TCP`) when `transport tcp` is added.\n- Generates mandatory RFC 3261 headers (`Via` with `branch=z9hG4bK...`, `From`,\n  `To`, `Call-ID`, `CSeq`, `Max-Forwards: 70`, `Contact`, and exact\n  `Content-Length`).\n- Treats `ack` on a `sip` line as the SIP `ACK` request method (even when\n  `transport tcp` is used).\n\n## Practical Lab Example: Complete VoIP Call Setup (`INVITE` + SDP), `RTP` Audio & `BYE` Hangup (`sip_rtp_voip_call.frasm`)\n\nEstablishes a SIP call with an `application/sdp` offer on VLAN 30, streams G.711\n`rtp` voice packets with `dscp 46` (EF), and hangs up cleanly via `bye` + `200\nOK`.\n\n```frameassembly\nhost phone_a { ip 172.16.30.101 }\nhost sbc_01  { ip 172.16.30.10 }\n\ncompile {\n    // 1. SIP INVITE with SDP offer + 180 Ringing + 200 OK + SIP ACK\n    phone_a -> sbc_01 sip invite uri \"sip:2050@voice.internal\" from \"sip:1010@voice.internal\" to \"sip:2050@voice.internal\" callid \"voip-8801\" cseq 1 contenttype \"application/sdp\" body \"v=0\\r\\no=- 1 1 IN IP4 172.16.30.101\\r\\ns=-\\r\\nc=IN IP4 172.16.30.101\\r\\nt=0 0\\r\\nm=audio 5004 RTP/AVP 0\\r\\n\" vlan 30 dscp 24 wait 2ms\n    phone_a <- sbc_01 sip status 180 reason \"Ringing\" callid \"voip-8801\" cseq 1 vlan 30 dscp 24 wait 20ms\n    phone_a <- sbc_01 sip status 200 reason \"OK\" callid \"voip-8801\" cseq 1 vlan 30 dscp 24 wait 2ms\n    phone_a -> sbc_01 sip ack uri \"sip:2050@voice.internal\" callid \"voip-8801\" cseq 1 vlan 30 dscp 24 wait 5ms\n    // 2. Bidirectional G.711 PCMU RTP audio (DSCP 46 Expedited Forwarding)\n    phone_a -> sbc_01 rtp pt 0 seq 1 timestamp 160 ssrc 0x11223344 marker 1 payload \"g711-audio-1\" vlan 30 dscp 46 wait 20ms\n    phone_a <- sbc_01 rtp pt 0 seq 1 timestamp 160 ssrc 0x55667788 marker 1 payload \"g711-reply-1\" vlan 30 dscp 46 wait 20ms\n    // 3. Call hangup (BYE -> 200 OK)\n    phone_a -> sbc_01 sip bye uri \"sip:2050@voice.internal\" callid \"voip-8801\" cseq 2 vlan 30 dscp 24 wait 2ms\n    phone_a <- sbc_01 sip status 200 reason \"OK\" callid \"voip-8801\" cseq 2 vlan 30 dscp 24\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show sip_rtp_voip_call.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly sip_rtp_voip_call.frasm sip_rtp_voip_call.pcap\nframeassembly sip_rtp_voip_call.frasm sip_rtp_voip_call.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse sip_rtp_voip_call.pcap sip_rtp_voip_call_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r sip_rtp_voip_call.pcap -Y \"sip\"\n```\n\n## All `sip` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host sip [invite | ack | bye | cancel |\nregister | options | method \"<text>\"] [uri \"<text>\"] [status <100..699>] [reason\n\"<text>\"] [from \"<text>\"] [to \"<text>\"] [callid \"<text>\"] [cseq <number>] [via\n\"<text>\"] [contact \"<text>\"] [contenttype \"<text>\"] [body \"<text>\"] [transport\n<udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `invite \\| ack \\| bye \\| cancel \\| register \\| options \\| method \"<text>\"` | SIP request method | `invite` | Sets the SIP request verb on the start line and inside the `CSeq` header. |\n| `status <100..699> [reason \"<text>\"]` | SIP response status code (`100`, `180`, `200`, `401`, `404`, `486`) | `Omitted on requests` | Switches the packet to a `SIP/2.0 <status> <reason>` response. |\n| `uri \"<text>\" \\| from \"<text>\" \\| to \"<text>\" \\| contact \"<text>\" \\| via \"<text>\"` | Quoted SIP URIs / header values | `RFC 3261 defaults` | Populates the request URI and corresponding SIP signaling headers. |\n| `callid \"<text>\" \\| cseq <number>` | Quoted Call-ID string + sequence number | `callid \"call-1\", cseq 1` | Links all messages belonging to the same VoIP dialog (`Call-ID:`) and transaction (`CSeq:`). |\n| `contenttype \"<text>\" \\| body \"<text>\"` | MIME type (e.g. `\"application/sdp\"`) and SDP body | `Empty` | Appends an SDP or message body and calculates `Content-Length` automatically. |\n| `transport <udp\\|tcp>` | `udp` or `tcp` | `udp` | Switches SIP transport between UDP `5060` and TCP `5060`. |\n\n## Cross-Layer Options Valid with `sip`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 5060 (or TCP 5060 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Keep callid Identical Across INVITE, 200 OK, ACK & BYE\n\n- **Valid v3.3.0 Syntax:** `Use callid \"voip-8801\" on every packet in the same\n  call`\n\nWireshark and SBCs group VoIP dialogs by `Call-ID`. Matching `callid` lets\nWireshark render the entire call in Telephony -> VoIP Calls.\n\n### No Hyphens in callid or contenttype Keyword Names\n\n- **Avoid:** `phone_a -> sbc_01 sip invite call_id \"123\" content_type\n  \"application/sdp\"`\n- **Valid v3.3.0 Syntax:** `phone_a -> sbc_01 sip invite callid \"123\" contenttype\n  \"application/sdp\"`\n\nSpell SIP modifiers without hyphens or underscores: `callid` and `contenttype`.\n"}
{"id":"pretrain-proto-rtp","kind":"protocol_spec","title":"Real-time Transport Protocol Audio & Video Streams (rtp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/rtp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["rtp"],"text":"# rtp — 12-Byte Voice/Video Media Streams & DSCP EF Marking (`rtp`)\n\n> **FrameAssembly v3.3.0** · Protocol 79 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/rtp\n\n- **Full Protocol Name:** Real-time Transport Protocol Audio & Video Streams\n- **Keyword:** `rtp`\n- **OSI Layer & Transport:** Layer 7 · UDP 5004\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 3550, RFC 3551, RFC 4733\n- **Wireshark Display Filter:** `rtp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 5004 -> RTP (Media)`\n\n## Overview\n\nSIP sets up the call and `rtp` carries the actual voice packets — tack `dscp 46`\n(`EF`) and `wait 20ms` onto G.711 `pt 0` frames to verify your WAN routers aren’t\ndropping voice into best-effort queues.\n\nReal-time Transport Protocol (`rtp`, RFC 3550) carries live VoIP voice (`G.711`,\n`Opus`), WebRTC video (`VP9`, `H.264`), and IP camera streams over **UDP**\n(default `dstport 5004`). Every RTP packet begins with a 12-byte RTP v2 (`0x80`)\nheader containing the 1-bit `marker`, 7-bit Payload Type (`pt`), 16-bit `seq`,\n32-bit media sample `timestamp`, and 32-bit Synchronization Source (`ssrc`).\n\nCombining `rtp` with FrameAssembly’s precision `wait` clock (`wait 20ms` for\nstandard 50-pps G.711 audio, or variable delays to simulate WAN jitter) and `dscp\n46` (Expedited Forwarding) lets you test QoS queues and Wireshark RTP Stream\nAnalysis with microsecond accuracy.\n\n## Minimal Quickstart (`rtp_quickstart.frasm`)\n\n```frameassembly\nhost handset_a { ip 10.30.1.101 }\nhost handset_b { ip 10.30.1.102 }\n\ncompile {\n    handset_a -> handset_b rtp pt 0 seq 1 timestamp 160 ssrc 0x12345678 marker 1 dscp 46 payload \"frame-1\" wait 20ms\n    handset_a -> handset_b rtp pt 0 seq 2 timestamp 320 ssrc 0x12345678 marker 0 dscp 46 payload \"frame-2\" wait 20ms\n    handset_a -> handset_b rtp pt 0 seq 3 timestamp 480 ssrc 0x12345678 marker 0 dscp 46 payload \"frame-3\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `5004` and writes RTP Version `2` (`0x80`) in\n  the upper bits of byte 0.\n- Packs the 1-bit `marker` and 7-bit Payload Type (`pt`) cleanly into byte 1\n  (`(marker << 7) | pt`).\n- Treats `seq` on an `rtp` line as the 16-bit RTP header Sequence Number.\n\n## Practical Lab Example: G.711 VoIP Stream With Simulated WAN Jitter & Single-Packet Drop (`rtp_qos_jitter_lab.frasm`)\n\nEmits a G.711 PCMU (`pt 0`, 8 kHz = `+160` timestamp ticks per `20ms`) voice burst\ncontaining a skipped sequence number (`seq 3` dropped) and a `55ms` jitter spike.\n\n```frameassembly\nhost branch_phone { ip 172.16.30.21 }\nhost hq_gateway   { ip 172.16.1.10 }\n\ncompile {\n    // Normal 20ms pacing (+160 samples at 8000 Hz)\n    branch_phone -> hq_gateway rtp srcport 16384 dstport 16400 pt 0 seq 1 timestamp 160 ssrc 0xdeadbeef marker 1 dscp 46 payload \"audio-pkt-1\" wait 20ms\n    branch_phone -> hq_gateway rtp pt 0 seq 2 timestamp 320 ssrc 0xdeadbeef marker 0 dscp 46 payload \"audio-pkt-2\" wait 55ms\n    // seq 3 intentionally omitted to test 1-packet loss + 55ms jitter detection!\n    branch_phone -> hq_gateway rtp pt 0 seq 4 timestamp 640 ssrc 0xdeadbeef marker 0 dscp 46 payload \"audio-pkt-4\" wait 5ms\n    branch_phone -> hq_gateway rtp pt 0 seq 5 timestamp 800 ssrc 0xdeadbeef marker 0 dscp 46 payload \"audio-pkt-5\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show rtp_qos_jitter_lab.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly rtp_qos_jitter_lab.frasm rtp_qos_jitter_lab.pcap\nframeassembly rtp_qos_jitter_lab.frasm rtp_qos_jitter_lab.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse rtp_qos_jitter_lab.pcap rtp_qos_jitter_lab_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r rtp_qos_jitter_lab.pcap -Y \"rtp\"\n```\n\n## All `rtp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host rtp [pt <0..127>] [seq <0..65535>]\n[timestamp <number>] [ssrc <hex_or_num>] [marker <0|1>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `pt <0..127>` | 7-bit RTP Payload Type (`0` PCMU, `8` PCMA, `9` G.722, `96` Opus/H.264, `101` DTMF) | `0 (G.711 PCMU)` | Sets the lower 7 bits of byte 1 in the 12-byte RTP header. |\n| `seq <0..65535>` | 16-bit RTP Sequence Number | `1` | Sets bytes 2..3 of the RTP header used by receivers to detect packet loss and reordering. |\n| `timestamp <number>` | 32-bit media sampling clock timestamp | `160` | Sets bytes 4..7 of the RTP header (`+160` per 20ms for 8kHz voice; `+1800` per frame for 90kHz 50fps video). |\n| `ssrc <hex_or_num>` | 32-bit Synchronization Source ID | `0x12345678` | Uniquely identifies the unidirectional RTP media stream in bytes 8..11. |\n| `marker <0\\|1>` | `1` (talkspurt start / end-of-video-frame) or `0` | `0` | Sets the 1-bit `M` flag at the top of byte 1. |\n\n## Cross-Layer Options Valid with `rtp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 5004` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 5004)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Enable Wireshark \"Try to decode RTP outside of conversations\" for Standalone RTP Captures\n\n- **Valid v3.3.0 Syntax:** `Pair rtp with sip invite + SDP, or enable RTP\n  heuristic dissection in Wireshark`\n\nBecause RTP uses dynamic even UDP ports without a fixed magic header, Wireshark\nauto-detects RTP when preceded by `sip` / `rtsp` setup—or on any UDP port when\n*Analyze -> Enabled Protocols -> rtp_udp* is checked.\n\n### pt Maximum Value Is 127 (7 Bits)\n\n- **Avoid:** `handset_a -> handset_b rtp pt 200`\n- **Valid v3.3.0 Syntax:** `handset_a -> handset_b rtp pt 96`\n\nThe RTP Payload Type shares byte 1 with the 1-bit `marker` flag, so `pt` must be\n`0..127`.\n"}
{"id":"pretrain-proto-rtsp","kind":"protocol_spec","title":"Real Time Streaming Protocol IP Camera & Media Control (rtsp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/rtsp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["rtsp"],"text":"# rtsp — Port 554 Camera Stream Control & transporthdr Rules (`rtsp`)\n\n> **FrameAssembly v3.3.0** · Protocol 80 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/rtsp\n\n- **Full Protocol Name:** Real Time Streaming Protocol IP Camera & Media Control\n- **Keyword:** `rtsp`\n- **OSI Layer & Transport:** Layer 7 · TCP 554 (or transport udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 2326, RFC 7826\n- **Wireshark Display Filter:** `rtsp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 554 (or transport udp) (transport tcp|udp) -> RTSP`\n\n## Overview\n\nControlling CCTV cameras and media relays on TCP `554` — remember to spell the\nRTSP `Transport:` header `transporthdr` so it never collides with FrameAssembly’s\nLayer 4 `transport` keyword!\n\nReal Time Streaming Protocol (`rtsp`, RFC 2326 / RFC 7826) controls IP security\ncameras, NVRs, and live video servers over **TCP port `554`**. An NVR typically\nsends `OPTIONS`, `DESCRIBE`, `SETUP` (negotiating client RTP/RTCP UDP ports inside\nthe `Transport:` header), `PLAY`, and `TEARDOWN`.\n\nFrameAssembly formats RTSP/1.0 requests and `status` responses (`RTSP/1.0 200 OK`)\nwith `CSeq`, `Transport` (`transporthdr`), and `Session` headers while tracking\nTCP sequence numbers automatically.\n\n## Minimal Quickstart (`rtsp_quickstart.frasm`)\n\n```frameassembly\nhost nvr_srv { ip 10.50.10.10 }\nhost ip_cam  { ip 10.50.20.45 }\n\ncompile {\n    nvr_srv -> ip_cam rtsp options uri \"rtsp://10.50.20.45:554/stream1\" cseq 1 wait 2ms\n    nvr_srv <- ip_cam rtsp status 200 cseq 1 wait 2ms\n    nvr_srv -> ip_cam rtsp setup uri \"rtsp://10.50.20.45:554/stream1/track1\" cseq 2 transporthdr \"RTP/AVP;unicast;client_port=5004-5005\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `554` (`psh ack`) and writes `\n`-terminated `RTSP/1.0` lines with `CSeq`.\n- Switches from an RTSP client request to an `RTSP/1.0 <status> OK` server reply\n  whenever `status` is set.\n- Writes `Transport:` (`transporthdr`) and `Session:` (`session`) headers cleanly\n  for Wireshark RTSP/RTP conversation tracking.\n\n## Practical Lab Example: Full IP Camera RTSP Setup, PLAY, RTP Video Frame & TEARDOWN (`rtsp_camera_session.frasm`)\n\nWalks through TCP 554 connection setup, `DESCRIBE`, `SETUP`\n(`client_port=5004-5005`), `PLAY`, an H.264 `rtp pt 96` packet from the camera,\nand `TEARDOWN`.\n\n```frameassembly\nhost vms_nvr  { ip 192.168.60.10 }\nhost gate_cam { ip 192.168.60.105 }\n\ncompile {\n    vms_nvr -> gate_cam tcp syn srcport 51554 dstport 554 win 65535 mss 1460 wait 1ms\n    vms_nvr <- gate_cam tcp syn ack win 65535 mss 1460 wait 1ms\n    vms_nvr -> gate_cam tcp ack wait 1ms\n    vms_nvr -> gate_cam rtsp describe uri \"rtsp://192.168.60.105/h264\" cseq 1 wait 2ms\n    vms_nvr <- gate_cam rtsp status 200 cseq 1 wait 2ms\n    vms_nvr -> gate_cam rtsp setup uri \"rtsp://192.168.60.105/h264/trackID=1\" cseq 2 transporthdr \"RTP/AVP;unicast;client_port=5004-5005\" wait 2ms\n    vms_nvr <- gate_cam rtsp status 200 cseq 2 transporthdr \"RTP/AVP;unicast;client_port=5004-5005;server_port=8000-8001\" session \"98112233\" wait 2ms\n    vms_nvr -> gate_cam rtsp play uri \"rtsp://192.168.60.105/h264\" cseq 3 session \"98112233\" wait 2ms\n    vms_nvr <- gate_cam rtsp status 200 cseq 3 session \"98112233\" wait 5ms\n    // Camera sends H.264 RTP packet (pt 96) to client port 5004\n    gate_cam -> vms_nvr rtp srcport 8000 dstport 5004 pt 96 seq 1 timestamp 90000 ssrc 0xcafebabe marker 1 payload \"h264-nal-idr\" wait 10ms\n    vms_nvr -> gate_cam rtsp teardown uri \"rtsp://192.168.60.105/h264\" cseq 4 session \"98112233\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show rtsp_camera_session.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly rtsp_camera_session.frasm rtsp_camera_session.pcap\nframeassembly rtsp_camera_session.frasm rtsp_camera_session.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse rtsp_camera_session.pcap rtsp_camera_session_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r rtsp_camera_session.pcap -Y \"rtsp\"\n```\n\n## All `rtsp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host rtsp [options | describe | setup | play\n| teardown | method \"<text>\"] [uri \"<text>\"] [status <100..599>] [cseq <number>]\n[transporthdr \"<text>\"] [session \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `options \\| describe \\| setup \\| play \\| teardown \\| method \"<text>\"` | RTSP request verb | `options` | Sets the RTSP command method on the request line. |\n| `uri \"<text>\"` | Quoted `rtsp://...` stream URL | `\"rtsp://camera.local/stream\"` | Sets the target stream URL in the RTSP request line. |\n| `status <100..599>` | RTSP response status code (`200`, `401`, `404`, `454`) | `Omitted on requests` | Switches the packet to an `RTSP/1.0 <status> OK` response. |\n| `cseq <number>` | Command sequence counter | `1` | Writes the mandatory `CSeq:` header matching requests to responses. |\n| `transporthdr \"<text>\"` | Quoted RTSP `Transport:` header string | `Omitted unless set` | Writes the `Transport:` header (named `transporthdr` so it never collides with Layer 4 `transport tcp\\|udp`). |\n| `session \"<text>\"` | Quoted RTSP Session ID | `Omitted unless set` | Writes the `Session:` header linking `SETUP`, `PLAY`, and `TEARDOWN`. |\n\n## Cross-Layer Options Valid with `rtsp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 554 (or transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Always Use transporthdr (Never transport) for the RTSP Transport Header\n\n- **Avoid:** `nvr_srv -> ip_cam rtsp setup transport\n  \"RTP/AVP;unicast;client_port=5004-5005\"`\n- **Valid v3.3.0 Syntax:** `nvr_srv -> ip_cam rtsp setup transporthdr\n  \"RTP/AVP;unicast;client_port=5004-5005\"`\n\nIn FrameAssembly, `transport` is reserved for switching Layer 4 TCP/UDP on\ndual-transport protocols. RTSP runs over TCP `554` and uses `transporthdr` for the\n`Transport:` header.\n"}
{"id":"pretrain-proto-stun","kind":"protocol_spec","title":"Session Traversal Utilities for NAT (stun) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/stun","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["stun"],"text":"# stun — WebRTC NAT Hole-Punching & 0x2112a442 XOR Mapping (`stun`)\n\n> **FrameAssembly v3.3.0** · Protocol 81 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/stun\n\n- **Full Protocol Name:** Session Traversal Utilities for NAT\n- **Keyword:** `stun`\n- **OSI Layer & Transport:** Layer 7 · UDP 3478\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 5389\n- **Wireshark Display Filter:** `stun`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 3478 -> STUN (NAT)`\n\n## Overview\n\nPass `xormappedaddr 203.0.113.42` on `stun bindingresponse` and the compiler\ngenuinely XORs your IPv4 or IPv6 address against magic cookie `0x2112a442` (+\ntransaction ID on IPv6) so Wireshark decodes the reflexive NAT address cleanly!\n\nSession Traversal Utilities for NAT (`stun`, RFC 5389) lets WebRTC browsers,\nZoom/Teams clients, VoIP phones, and peer-to-peer VPNs (Tailscale/WireGuard)\ndiscover their public reflexive IP and port via **UDP port `3478`** (or `19302`).\nEvery RFC 5389 STUN header carries the 2-byte Message Type, 2-byte Message Length,\n4-byte Magic Cookie **`0x2112a442`**, and 96-bit Transaction ID.\n\nOn `bindingresponse`, RFC 5389 requires the `XOR-MAPPED-ADDRESS` attribute\n(`0x0020`) to be XOR-masked against `0x2112a442` (for IPv4) or `0x2112a442 ||\ntransaction_id` (for IPv6) so legacy NAT routers cannot corrupt the payload.\nFrameAssembly computes that XOR masking automatically so Wireshark displays your\nexact `xormappedaddr` IP cleanly.\n\n## Minimal Quickstart (`stun_quickstart.frasm`)\n\n```frameassembly\nhost webrtc_tab { ip 10.10.20.45 }\nhost stun_srv   { ip 198.51.100.34 }\n\ncompile {\n    webrtc_tab -> stun_srv stun bindingrequest txid 0x10203040 software \"webrtc-client\" wait 3ms\n    webrtc_tab <- stun_srv stun bindingresponse txid 0x10203040 xormappedaddr 203.0.113.88\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `3478` and writes the mandatory RFC 5389 magic\n  cookie `0x2112a442` in bytes 4..7.\n- XOR-encodes IPv4 (`32-bit ^ 0x2112a442`) and IPv6 (`128-bit ^ (0x2112a442 ||\n  txid)`) `xormappedaddr` attributes (`0x0020`) automatically.\n- Pads `software` (`0x8022`) TLV strings to 4-byte boundaries as required by RFC\n  5389 §15.\n\n## Practical Lab Example: Dual-Stack IPv4 & IPv6 WebRTC ICE STUN Discovery + Error Response (`stun_webrtc_ice.frasm`)\n\nPerforms an IPv4 STUN check on port 19302, an IPv6 STUN check on port 3478, and a\n`bindingerror` (`0x0111`) test.\n\n```frameassembly\nhost client_v4 { ip 172.16.10.25 }\nhost stun_v4   { ip 198.51.100.10 }\nhost client_v6 { ip 2001:db8:10::25 }\nhost stun_v6   { ip 2001:db8:99::3478 }\n\ncompile {\n    // 1. WebRTC UDP 19302 STUN check returning NAT public IPv4 203.0.113.50\n    client_v4 -> stun_v4 stun bindingrequest dstport 19302 txid 0xa1b2c3d4 software \"Chromium-ICE\" wait 2ms\n    client_v4 <- stun_v4 stun bindingresponse txid 0xa1b2c3d4 xormappedaddr 203.0.113.50 software \"coturn-4.6\" wait 4ms\n    // 2. IPv6 STUN Binding check + Error response\n    client_v6 -> stun_v6 stun bindingrequest txid 0x55667788 wait 2ms\n    client_v6 <- stun_v6 stun bindingresponse txid 0x55667788 xormappedaddr 2001:db8:10::25 wait 3ms\n    client_v4 <- stun_v4 stun bindingerror txid 0x99990000\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show stun_webrtc_ice.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly stun_webrtc_ice.frasm stun_webrtc_ice.pcap\nframeassembly stun_webrtc_ice.frasm stun_webrtc_ice.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse stun_webrtc_ice.pcap stun_webrtc_ice_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r stun_webrtc_ice.pcap -Y \"stun\"\n```\n\n## All `stun` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host stun [bindingrequest | bindingresponse\n| bindingerror] [txid <hex_or_num>] [xormappedaddr <ip>] [software \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `bindingrequest \\| bindingresponse \\| bindingerror` | STUN message class/method | `bindingrequest (0x0001)` | Selects STUN Binding Request (`0x0001`), Binding Success Response (`0x0101`), or Binding Error Response (`0x0111`). |\n| `txid <hex_or_num>` | 32-bit Transaction ID seed (placed into the 96-bit STUN Transaction ID) | `0x12345678` | Matches STUN responses to their initiating request. |\n| `xormappedaddr <ip>` | IPv4 or IPv6 public/reflexive IP address | `Client IP on bindingresponse` | Adds Attribute `0x0020` (`XOR-MAPPED-ADDRESS`) with RFC 5389 XOR obfuscation applied. |\n| `software \"<text>\"` | Quoted agent/server string | `Omitted unless set` | Adds 4-byte-padded Attribute `0x8022` (`SOFTWARE`). |\n\n## Cross-Layer Options Valid with `stun`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 3478` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 3478)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### No Hyphens or Underscores in xormappedaddr or bindingrequest\n\n- **Avoid:** `webrtc_tab <- stun_srv stun binding_response xor_mapped_addr\n  203.0.113.88`\n- **Valid v3.3.0 Syntax:** `webrtc_tab <- stun_srv stun bindingresponse\n  xormappedaddr 203.0.113.88`\n\nSpell STUN keywords in strict lowercase without underscores: `bindingrequest`,\n`bindingresponse`, `bindingerror`, and `xormappedaddr`.\n"}
{"id":"pretrain-proto-ssdp","kind":"protocol_spec","title":"Simple Service Discovery Protocol & UPnP Multicast (ssdp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ssdp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ssdp"],"text":"# ssdp — Multicast UDP 1900 UPnP M-SEARCH & NOTIFY Frames (`ssdp`)\n\n> **FrameAssembly v3.3.0** · Protocol 82 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ssdp\n\n- **Full Protocol Name:** Simple Service Discovery Protocol & UPnP Multicast\n- **Keyword:** `ssdp`\n- **OSI Layer & Transport:** Layer 7 · UDP 1900 (239.255.255.250 / ff02::c)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** UPnP Device Architecture 2.0\n- **Wireshark Display Filter:** `ssdp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 1900 (239.255.255.250 / ff02::c) -> SSDP (UPnP)`\n\n## Overview\n\nHTTP headers stuffed into UDP `1900` multicast (`239.255.255.250`) — `ssdp` uses\n`hosthdr` for the `HOST:` header and catches unauthorized UPnP port-forwarding\nchatter on enterprise VLANs.\n\nSimple Service Discovery Protocol (`ssdp`) powers UPnP plug-and-play device\ndiscovery across smart TVs, printers, media servers, and home/branch routers using\nHTTP-over-UDP (**HTTPU**) on **UDP port `1900`** (multicast `239.255.255.250` on\nIPv4 or `ff02::c` on IPv6).\n\nBecause exposed UDP `1900` responders are a classic DDoS reflection vector (`ST:\nssdp:all`) and unauthorized UPnP `InternetGatewayDevice` port-forwarding is a\nfrequent enterprise security finding, FrameAssembly lets you build both `msearch`\ndiscovery probes and `notify` presence announcements cleanly.\n\n## Minimal Quickstart (`ssdp_quickstart.frasm`)\n\n```frameassembly\nhost laptop    { ip 10.10.20.42 }\nhost ssdp_mcast { ip 239.255.255.250 }\n\ncompile {\n    laptop -> ssdp_mcast ssdp msearch hosthdr \"239.255.255.250:1900\" mx 3 st \"ssdp:all\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults UDP destination port to `1900` and automatically derives the RFC 1112\n  multicast MAC `01:00:5e:7f:ff:fa` when sending to `239.255.255.250`.\n- Formats `M-SEARCH * HTTP/1.1\n` with `HOST`, `MAN: \"ssdp:discover\"`, `MX`, and `ST` headers on `msearch`\npackets.\n- Formats `NOTIFY * HTTP/1.1\n` with `HOST`, `NT`, `NTS` (default `\"ssdp:alive\"`), `USN`, and `LOCATION` headers\non `notify` packets.\n\n## Practical Lab Example: IoT Gateway SSDP M-SEARCH Sweep & UPnP IGD Alive Notification (`ssdp_upnp_audit.frasm`)\n\nSends a multicast `msearch` looking for UPnP Internet Gateway Devices, followed by\na router `notify` advertisement pointing to its XML description URL.\n\n```frameassembly\nhost scanner   { ip 192.168.10.55 }\nhost upnp_grp  { ip 239.255.255.250 }\nhost rogue_rtr { ip 192.168.10.254 }\n\ncompile {\n    scanner -> upnp_grp ssdp msearch hosthdr \"239.255.255.250:1900\" man \"\\\"ssdp:discover\\\"\" mx 2 st \"urn:schemas-upnp-org:device:InternetGatewayDevice:1\" wait 5ms\n    rogue_rtr -> upnp_grp ssdp notify hosthdr \"239.255.255.250:1900\" nt \"urn:schemas-upnp-org:device:InternetGatewayDevice:1\" nts \"ssdp:alive\" usn \"uuid:f81d4fae-7dec::upnp:rootdevice\" location \"http://192.168.10.254:49152/rootDesc.xml\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ssdp_upnp_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ssdp_upnp_audit.frasm ssdp_upnp_audit.pcap\nframeassembly ssdp_upnp_audit.frasm ssdp_upnp_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ssdp_upnp_audit.pcap ssdp_upnp_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ssdp_upnp_audit.pcap -Y \"ssdp\"\n```\n\n## All `ssdp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ssdp [msearch | notify] [hosthdr\n\"<text>\"] [man \"<text>\"] [mx <0..255>] [st \"<text>\"] [nt \"<text>\"] [nts \"<text>\"]\n[usn \"<text>\"] [location \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `msearch \\| notify` | SSDP HTTPU method | `msearch` | Selects `M-SEARCH * HTTP/1.1` active discovery or `NOTIFY * HTTP/1.1` multicast announcement. |\n| `hosthdr \"<text>\"` | Quoted `HOST:` header value | `\"239.255.255.250:1900\"` | Sets the `HOST:` header (named `hosthdr` to avoid clashing with top-level `host` blocks). |\n| `man \"<text>\" \\| mx <0..255> \\| st \"<text>\"` | M-SEARCH discovery headers (`MX` max wait seconds, `ST` Search Target) | `man \"\\\"ssdp:discover\\\"\", mx 3, st \"ssdp:all\"` | Populates mandatory UPnP discovery request headers on `msearch` packets. |\n| `nt \"<text>\" \\| nts \"<text>\" \\| usn \"<text>\" \\| location \"<text>\"` | NOTIFY advertisement headers (`NTS` `\"ssdp:alive\"` or `\"ssdp:byebye\"`) | `nts \"ssdp:alive\"` | Populates Notification Type, Sub-Type, Unique Service Name, and XML `LOCATION` URL on `notify` packets. |\n\n## Cross-Layer Options Valid with `ssdp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 1900 (239.255.255.250 / ff02::c)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 1900 (239.255.255.250 / ff02::c))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Use msearch (No Hyphen) and hosthdr (Not host)\n\n- **Avoid:** `laptop -> ssdp_mcast ssdp m-search host \"239.255.255.250:1900\"`\n- **Valid v3.3.0 Syntax:** `laptop -> ssdp_mcast ssdp msearch hosthdr\n  \"239.255.255.250:1900\"`\n\nSpell `msearch` without a hyphen and use `hosthdr` for the `HOST:` header.\n"}
{"id":"pretrain-proto-gtpc","kind":"protocol_spec","title":"GPRS Tunneling Protocol v2 Control Plane (4G S11 / S5-C) (gtpc) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/gtpc","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["gtpc"],"text":"# gtpc — 3GPP S11/N26 GTPv2-C Session & Bearer Signaling (`gtpc`)\n\n> **FrameAssembly v3.3.0** · Protocol 83 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/gtpc\n\n- **Full Protocol Name:** GPRS Tunneling Protocol v2 Control Plane (4G S11 / S5-C)\n- **Keyword:** `gtpc`\n- **OSI Layer & Transport:** Layer 7 · UDP 2123\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** 3GPP TS 29.274, RFC 768\n- **Wireshark Display Filter:** `gtpv2`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 2123 -> GTPv2-C (3GPP TS 29.274)`\n\n## Overview\n\nNeed to test S11 or S5/S8 roaming firewalls on UDP `2123` without spinning up\nOpen5GS? `gtpc` packs 3GPP TS 29.274 GTPv2-C headers, TBCD-encoded `imsi`,\nDNS-label `apn`, `teid`, and `cause` IEs automatically.\n\nGPRS Tunneling Protocol version 2 Control Plane (`gtpc`, 3GPP TS 29.274)\norchestrates subscriber bearer sessions across **4G LTE Evolved Packet Core (`S11`\nMME <-> SGW, `S5`/`S8` SGW <-> PGW)** and **4G/5G interworking (`N26` AMF <->\nMME)** interfaces on **UDP port `2123`**. Every GTPv2-C PDU starts with a Version\n`2` header (`Flags` with `T`-bit TEID presence, 1-byte `Message Type`, 16-bit\n`Message Length`, optional 32-bit `TEID`, 24-bit `Sequence Number`, and spare\nbyte) followed by TLV Information Elements (`IMSI`, `Access Point Name`, `RAT\nType`, `Cause`, `Recovery`, `PDN Address Allocation`).\n\nFrameAssembly encodes valid BCD-packed `IMSI` digits, DNS-label-encoded `APN`\nstrings, 24-bit sequence numbers, and automatic `T`-bit header formatting\n(omitting the 4-byte TEID slot on path-management `echorequest`/`echoreply`\nmessages per TS 29.274 Section 5.1).\n\n## Minimal Quickstart (`gtpc_quickstart.frasm`)\n\n```frameassembly\nhost mme_s11 { ip 10.200.11.10 }\nhost sgw_s11 { ip 10.200.11.20 }\n\ncompile {\n    mme_s11 -> sgw_s11 gtpc createsessionrequest teid 0x00000000 seqnum 101 imsi \"001010123456789\" apn \"internet\" rat 6 wait 4ms\n    mme_s11 <- sgw_s11 gtpc createsessionresponse teid 0x10012002 seqnum 101 cause 16 addr 100.64.10.25\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `2123` (swapping ports automatically on `<-`\n  responses) and computes the 16-bit GTPv2-C `Message Length` (excluding the\n  initial 4 octets per 3GPP TS 29.274).\n- Packs `imsi` decimal strings into TBCD octets (`0xf` filler nibble on odd-length\n  IMSIs) and encodes `apn` labels in RFC 1035 length-prefixed wire format.\n- Clears the `T` flag (8-byte header without TEID) on `echorequest` / `echoreply`\n  and sets `T=1` (12-byte header with 32-bit `teid`) on session/bearer messages.\n\n## Practical Lab Example: 4G LTE S11 Session Setup, S1-U Bearer Handshake & Session Teardown (`gtpc_s11_bearer_lifecycle.frasm`)\n\nSimulates an MME and Serving Gateway running an Echo liveness check, establishing\nan E-UTRAN (`rat 6`) subscriber session (`cause 16` Request Accepted), modifying\nthe bearer after eNodeB S1-U setup, and tearing down the session.\n\n```frameassembly\nhost mme_01 { ip 172.22.11.5 }\nhost sgw_01 { ip 172.22.11.50 }\n\ncompile {\n    // 1. S11 GTPv2-C Path Management Echo (T-bit = 0)\n    mme_01 -> sgw_01 gtpc echorequest seqnum 1 recovery 14 wait 2ms\n    mme_01 <- sgw_01 gtpc echoreply seqnum 1 recovery 8 wait 5ms\n    // 2. Initial Attach: Create Session Request (initial TEID 0) & Accepted Response (cause 16)\n    mme_01 -> sgw_01 gtpc createsessionrequest teid 0x00000000 seqnum 2 imsi \"310260987654321\" apn \"ims\" rat 6 dscp 46 wait 6ms\n    mme_01 <- sgw_01 gtpc createsessionresponse teid 0x00a10001 seqnum 2 cause 16 addr 10.96.0.42 dscp 46 wait 4ms\n    // 3. Modify Bearer after eNodeB allocates S1-U downlink TEID\n    mme_01 -> sgw_01 gtpc modifybearerrequest teid 0x00b20001 seqnum 3 rat 6 wait 3ms\n    mme_01 <- sgw_01 gtpc modifybearerresponse teid 0x00a10001 seqnum 3 cause 16 wait 20ms\n    // 4. Detach: Delete Session Request / Response\n    mme_01 -> sgw_01 gtpc deletesessionrequest teid 0x00b20001 seqnum 4 wait 3ms\n    mme_01 <- sgw_01 gtpc deletesessionresponse teid 0x00a10001 seqnum 4 cause 16\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show gtpc_s11_bearer_lifecycle.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly gtpc_s11_bearer_lifecycle.frasm gtpc_s11_bearer_lifecycle.pcap\nframeassembly gtpc_s11_bearer_lifecycle.frasm gtpc_s11_bearer_lifecycle.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse gtpc_s11_bearer_lifecycle.pcap gtpc_s11_bearer_lifecycle_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r gtpc_s11_bearer_lifecycle.pcap -Y \"gtpv2\"\n```\n\n## All `gtpc` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host gtpc [echorequest | echoreply |\nechoresponse | createsessionrequest | createsessionresponse | modifybearerrequest\n| modifybearerresponse | deletesessionrequest | deletesessionresponse | msgtype\n\"<text>\"] [teid <number>] [seqnum <0..16777215>] [cause <0..255>] [imsi \"<text>\"]\n[apn \"<text>\"] [rat <0..255>] [recovery <0..255>] [addr <ip>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `echorequest \\| echoreply \\| echoresponse \\| createsessionrequest \\| createsessionresponse \\| modifybearerrequest \\| modifybearerresponse \\| deletesessionrequest \\| deletesessionresponse \\| msgtype \"<text>\"` | 3GPP TS 29.274 Message Type keyword or name | `echorequest (1)` | Sets byte 1 of the GTPv2-C header (`1` Echo Req, `2` Echo Resp, `32`/`33` Create Session, `34`/`35` Modify Bearer, `36`/`37` Delete Session). |\n| `teid <number>` | 32-bit Tunnel Endpoint Identifier | `0` | Writes bytes 4..7 of the GTPv2-C header when `T=1` (`0x00000000` on initial `createsessionrequest`). |\n| `seqnum <0..16777215>` | 24-bit GTPv2-C Sequence Number | `1` | Writes the big-endian 3-byte transaction Sequence Number matching requests to responses. |\n| `cause <0..255>` | 8-bit GTPv2 Cause value (IE Type 2) | `16 (Request accepted) on responses` | Appends the Cause TLV IE (`16` Request accepted, `64` Context not found, `72` No resources available). |\n| `imsi \"<text>\"` | 15-digit International Mobile Subscriber Identity string (IE Type 1) | `Omitted (or default on Create Session)` | Encodes the subscriber IMSI in 3GPP TBCD nibble-swapped format inside IE Type `1`. |\n| `apn \"<text>\"` | Access Point Name string (IE Type 71) | `Omitted` | Appends IE Type `71` (`APN`, e.g. `\"internet\"` or `\"ims.mnc001.mcc001.gprs\"`). |\n| `rat <0..255>` | 8-bit RAT Type (IE Type 82) | `6 (EUTRAN) when set` | Appends IE Type `82` (`1` UTRAN, `2` GERAN, `3` WLAN, `6` EUTRAN/LTE, `8` NR/5G). |\n| `recovery <0..255>` | 8-bit Restart Counter (IE Type 3) | `Omitted` | Appends IE Type `3` (`Recovery` node restart counter) for peer reboot detection. |\n| `addr <ip>` | IPv4 or IPv6 subscriber PDN address (IE Type 79 PAA) | `Omitted` | Appends IE Type `79` (`PDN Address Allocation`) with PDN Type `IPv4` (`1`) or `IPv6` (`2`). |\n\n## Cross-Layer Options Valid with `gtpc`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 2123` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 2123)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Use gtpc (UDP 2123) for Control Signaling and gtpu (UDP 2152) for User Data\n\n- **Avoid:** `mme -> sgw gtpu createsessionrequest teid 0x100 imsi\n  \"001010123456789\"`\n- **Valid v3.3.0 Syntax:** `mme -> sgw gtpc createsessionrequest teid 0x0 seqnum 1\n  imsi \"001010123456789\"`\n\nGTPv2-C (`gtpc`, UDP `2123`) negotiates control-plane tunnels and TEIDs, whereas\nGTPv1-U (`gtpu`, UDP `2152`) encapsulates subscriber user-plane IP packets\n(`gpdu`).\n\n### Quote 15-Digit IMSI Values That Begin with Leading Zeros\n\n- **Avoid:** `mme -> sgw gtpc createsessionrequest imsi 001010123456789`\n- **Valid v3.3.0 Syntax:** `mme -> sgw gtpc createsessionrequest imsi\n  \"001010123456789\"`\n\nTest PLMN IMSIs (`00101...`) start with leading zeros that an unquoted integer\nwould strip; pass `imsi` as a double-quoted string so all 15 TBCD digits are\npreserved.\n"}
{"id":"pretrain-proto-pfcp","kind":"protocol_spec","title":"Packet Forwarding Control Protocol (5G N4 / 4G Sxa-Sxb CUPS) (pfcp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/pfcp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["pfcp"],"text":"# pfcp — 5G N4 SMF-to-UPF Session Establishment & SEID Rules (`pfcp`)\n\n> **FrameAssembly v3.3.0** · Protocol 84 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/pfcp\n\n- **Full Protocol Name:** Packet Forwarding Control Protocol (5G N4 / 4G Sxa-Sxb\n  CUPS)\n- **Keyword:** `pfcp`\n- **OSI Layer & Transport:** Layer 7 · UDP 8805\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** 3GPP TS 29.244, RFC 768\n- **Wireshark Display Filter:** `pfcp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 8805 -> PFCP (3GPP TS 29.244)`\n\n## Overview\n\nWhere 5G SMF control plane meets the UPF user plane on UDP `8805` — `pfcp` builds\n3GPP TS 29.244 Heartbeat, Association Setup, and 64-bit `seid` Session\nEstablishment/Modification/Deletion frames cleanly.\n\nPacket Forwarding Control Protocol (`pfcp`, 3GPP TS 29.244) is the **5G Core `N4`\ninterface** (between **SMF** Session Management Function and **UPF** User Plane\nFunction) and the **4G CUPS `Sxa`/`Sxb`/`Sxc`** control-to-user-plane separation\nprotocol on **UDP port `8805`**. PFCP separates node-level messages (`S=0`:\nHeartbeat, Association Setup/Update/Release) from session-level messages (`S=1`:\nSession Establishment, Modification, Deletion, Report carrying a **64-bit Session\nEndpoint Identifier `seid`** + 24-bit `Sequence Number`).\n\nFrameAssembly automatically sets or clears the `S`-bit (`Version 1`) based on\nmessage type, writes 8-byte `seid` headers on session PDUs (`50`..`57`), and\nencodes `Node ID` (IPv4, IPv6, or FQDN), `Recovery Time Stamp`, and `Cause` TLV\nIEs.\n\n## Minimal Quickstart (`pfcp_quickstart.frasm`)\n\n```frameassembly\nhost smf_n4 { ip 10.55.4.10 }\nhost upf_n4 { ip 10.55.4.20 }\n\ncompile {\n    smf_n4 -> upf_n4 pfcp sessionestablishmentrequest seid 0x0000000000001001 seqnum 1 nodeid 10.55.4.10 wait 3ms\n    smf_n4 <- upf_n4 pfcp sessionestablishmentresponse seid 0x0000000000002001 seqnum 1 nodeid 10.55.4.20 cause 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `8805` and auto-toggles the PFCP header `S`\n  flag (`S=0` 8-byte node header on Heartbeat/Association; `S=1` 16-byte session\n  header with 64-bit `seid` on Session messages).\n- Computes the 16-bit PFCP `Message Length` (covering SEID, 24-bit Sequence\n  Number, Spare byte, and all TLV IEs).\n- Detects IPv4, IPv6, or FQDN strings passed to `nodeid` and formats IE Type `60`\n  (`Node ID`) with the matching address-type selector byte (`0`=IPv4, `1`=IPv6,\n  `2`=FQDN).\n\n## Practical Lab Example: 5G Standalone N4 Lifecycle: Association Setup, PDU Session Establishment & Heartbeat (`pfcp_5g_n4_lifecycle.frasm`)\n\nWalks through N4 Association Setup between an SMF and edge UPF, establishes a 5G\nPDU session (`cause 1` Request accepted), updates forwarding rules after gNB N3\ntunnel binding, and exchanges N4 Heartbeats.\n\n```frameassembly\nhost smf_core { ip 10.250.4.11 }\nhost upf_edge { ip 10.250.4.51 }\n\ncompile {\n    // 1. Node-level N4 Association Setup (S-bit = 0, no SEID field)\n    smf_core -> upf_edge pfcp associationsetuprequest seqnum 10 nodeid 10.250.4.11 recovery 3910000000 wait 2ms\n    smf_core <- upf_edge pfcp associationsetupresponse seqnum 10 nodeid 10.250.4.51 cause 1 recovery 3910000005 wait 4ms\n    // 2. Session-level PDU Session Establishment (S-bit = 1, 64-bit F-SEID)\n    smf_core -> upf_edge pfcp sessionestablishmentrequest seid 0x00000001000000a1 seqnum 11 nodeid 10.250.4.11 dscp 46 wait 3ms\n    smf_core <- upf_edge pfcp sessionestablishmentresponse seid 0x00000002000000b1 seqnum 11 nodeid 10.250.4.51 cause 1 dscp 46 wait 3ms\n    // 3. Session Modification (activates downlink FAR after NGAP InitialContextSetup)\n    smf_core -> upf_edge pfcp sessionmodificationrequest seid 0x00000001000000a1 seqnum 12 wait 2ms\n    smf_core <- upf_edge pfcp sessionmodificationresponse seid 0x00000002000000b1 seqnum 12 cause 1 wait 10ms\n    // 4. Periodic N4 Heartbeat\n    smf_core -> upf_edge pfcp heartbeatrequest seqnum 13 recovery 3910000000 wait 1ms\n    smf_core <- upf_edge pfcp heartbeatresponse seqnum 13 recovery 3910000005\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show pfcp_5g_n4_lifecycle.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly pfcp_5g_n4_lifecycle.frasm pfcp_5g_n4_lifecycle.pcap\nframeassembly pfcp_5g_n4_lifecycle.frasm pfcp_5g_n4_lifecycle.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse pfcp_5g_n4_lifecycle.pcap pfcp_5g_n4_lifecycle_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r pfcp_5g_n4_lifecycle.pcap -Y \"pfcp\"\n```\n\n## All `pfcp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host pfcp [heartbeatrequest |\nheartbeatresponse | associationsetuprequest | associationsetupresponse |\nsessionestablishmentrequest | sessionestablishmentresponse |\nsessionmodificationrequest | sessionmodificationresponse | sessiondeletionrequest\n| sessiondeletionresponse | msgtype \"<text>\"] [seid <number>] [seqnum\n<0..16777215>] [cause <0..255>] [nodeid <ip_or_text>] [recovery <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `heartbeatrequest \\| heartbeatresponse \\| associationsetuprequest \\| associationsetupresponse \\| sessionestablishmentrequest \\| sessionestablishmentresponse \\| sessionmodificationrequest \\| sessionmodificationresponse \\| sessiondeletionrequest \\| sessiondeletionresponse \\| msgtype \"<text>\"` | 3GPP TS 29.244 PFCP Message Type | `heartbeatrequest (1)` | Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup, `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and `S` flag. |\n| `seid <number>` | 64-bit Session Endpoint Identifier | `1 (on session messages)` | Writes the 8-byte big-endian `SEID` in bytes 4..11 of session-related (`S=1`) PFCP headers. |\n| `seqnum <0..16777215>` | 24-bit PFCP Sequence Number | `1` | Writes the 3-byte big-endian transaction Sequence Number. |\n| `cause <0..255>` | 8-bit PFCP Cause IE (IE Type 19) | `1 (Request accepted) on responses` | Appends IE Type `19` (`1` Request accepted, `64` Session context not found, `69` Mandatory IE missing). |\n| `nodeid <ip_or_text>` | IPv4, IPv6, or FQDN string (IE Type 60) | `Source host IP on setup/establishment` | Appends IE Type `60` (`Node ID`) identifying the originating SMF or UPF control plane. |\n| `recovery <number>` | 32-bit NTP-era Recovery Time Stamp (IE Type 96) | `Auto-populated on Heartbeat / Association` | Appends IE Type `96` (`Recovery Time Stamp`, seconds since 1900-01-01). |\n\n## Cross-Layer Options Valid with `pfcp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 8805` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 8805)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### PFCP Accepted Cause Code Is 1 (Unlike GTPv2-C Cause 16)\n\n- **Avoid:** `smf <- upf pfcp sessionestablishmentresponse seid 0x10 seqnum 1\n  cause 16`\n- **Valid v3.3.0 Syntax:** `smf <- upf pfcp sessionestablishmentresponse seid 0x10\n  seqnum 1 cause 1`\n\nIn 3GPP TS 29.244 PFCP, `cause 1` means `Request accepted` (whereas `16` is\nGTPv2-C’s accepted code in TS 29.274).\n\n### Node-Level Messages Do Not Carry a Wire SEID\n\n- **Valid v3.3.0 Syntax:** `smf -> upf pfcp heartbeatrequest seqnum 1 recovery\n  3910000000`\n\n`heartbeat*` and `associationsetup*` transmit `S=0` (8-byte header without a SEID\nslot); use `seid` on `sessionestablishment*`, `sessionmodification*`, and\n`sessiondeletion*`.\n"}
{"id":"pretrain-proto-diameter","kind":"protocol_spec","title":"Diameter Base, Credit-Control & 3GPP S6a/Gx/Gy AAA Signaling (diameter) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/diameter","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["diameter"],"text":"# diameter — 4G EPC S6a/Gx/Gy AVPs over TCP or SCTP 3868 (`diameter`)\n\n> **FrameAssembly v3.3.0** · Protocol 85 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/diameter\n\n- **Full Protocol Name:** Diameter Base, Credit-Control & 3GPP S6a/Gx/Gy AAA\n  Signaling\n- **Keyword:** `diameter`\n- **OSI Layer & Transport:** Layer 7 · TCP 3868 (or SCTP 3868 / PPID 46 via\n  transport sctp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 6733, RFC 8506, 3GPP TS 29.272\n- **Wireshark Display Filter:** `diameter`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 3868 (or SCTP 3868 / PPID 46 via transport sctp) -> Diameter (RFC 6733)`\n\n## Overview\n\n4G LTE HSS and PCRF billing diameter peers are notoriously picky about 32-bit AVP\npadding — `diameter` aligns `Origin-Host`, `Origin-Realm`, `Session-Id`, and\n`Result-Code` AVPs over TCP `3868` or `transport sctp` (PPID `46`).\n\nDiameter (`diameter`, RFC 6733 / RFC 8506 / 3GPP TS 29.272) is the telecom AAA,\nHSS subscriber authentication (`S6a`), policy control (`Gx` PCRF), online charging\n(`Gy` OCS), and IMS (`Cx`/`Sh`) signaling backbone on **TCP or SCTP port `3868`**.\nEvery Diameter message starts with a 20-byte header (`Version = 1`, 24-bit\n`Message Length`, `Command Flags` `R`/`P`/`E`/`T`, 24-bit `Command-Code`, 32-bit\n`Application-ID`, `Hop-by-Hop ID`, and `End-to-End ID`) followed by **32-bit\nword-aligned Attribute-Value Pairs (AVPs)**.\n\nFrameAssembly aligns and zero-pads every AVP (`Origin-Host` `264`, `Origin-Realm`\n`296`, `Destination-Host` `293`, `Destination-Realm` `283`, `Session-Id` `263`,\n`Result-Code` `268`, `User-Name` `1`) to 4-byte boundaries automatically and sets\n**SCTP Payload Protocol Identifier `46` (`Diameter`)** whenever `transport sctp`\nis appended.\n\n## Minimal Quickstart (`diameter_quickstart.frasm`)\n\n```frameassembly\nhost mme_s6a { ip 10.88.6.10 }\nhost hss_s6a { ip 10.88.6.20 }\n\ncompile {\n    mme_s6a -> hss_s6a diameter cer hopid 0x1001 endid 0x2001 originhost \"mme01.epc.internal\" realm \"epc.internal\" transport sctp wait 3ms\n    mme_s6a <- hss_s6a diameter cea hopid 0x1001 endid 0x2001 originhost \"hss01.epc.internal\" realm \"epc.internal\" resultcode 2001 transport sctp\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `3868`, or switches to SCTP port `3868` (`DATA`\n  chunk `PPID = 46`, Castagnoli CRC-32c) when `transport sctp` is added.\n- Computes the exact 24-bit `Message Length` in bytes 1..3 and pads every\n  variable-length UTF-8/DiameterIdentity AVP to 4-octet boundaries while recording\n  unpadded length in the 24-bit `AVP Length` field.\n- Sets the `R` (`0x80` Request) flag automatically on `cer`/`dwr`/`ccr`/`request`\n  and clears `R` while appending `Result-Code` (`2001` `DIAMETER_SUCCESS`) on\n  `cea`/`dwa`/`cca`/`response`.\n\n## Practical Lab Example: SCTP 3868 Diameter Peer Bring-Up (CER/CEA), Credit-Control (CCR/CCA) & Watchdog (`diameter_gy_charging_sctp.frasm`)\n\nEstablishes an SCTP Diameter association between a PGW/SMF and Online Charging\nSystem (OCS), exchanges `CER`/`CEA`, authorizes subscriber quota via `CCR`/`CCA`\n(`appid 4`), and verifies liveness via `DWR`/`DWA`.\n\n```frameassembly\nhost pgw_gy { ip 172.28.10.15 }\nhost ocs_gy { ip 172.28.10.80 }\n\ncompile {\n    // 1. Capabilities-Exchange (Code 257, AppID 0) over SCTP 3868 (PPID 46)\n    pgw_gy -> ocs_gy diameter cer hopid 0x00010001 endid 0x99000001 originhost \"pgw01.epc.internal\" realm \"epc.internal\" transport sctp wait 2ms\n    pgw_gy <- ocs_gy diameter cea hopid 0x00010001 endid 0x99000001 originhost \"ocs01.epc.internal\" realm \"epc.internal\" resultcode 2001 transport sctp wait 5ms\n    // 2. RFC 8506 Credit-Control Request / Answer (Code 272, AppID 4 = Diameter Credit Control)\n    pgw_gy -> ocs_gy diameter ccr appid 4 hopid 0x00010002 endid 0x99000002 sessionid \"pgw01.epc.internal;170001;1\" originhost \"pgw01.epc.internal\" realm \"epc.internal\" dstrealm \"epc.internal\" user \"001010123456789\" transport sctp wait 4ms\n    pgw_gy <- ocs_gy diameter cca appid 4 hopid 0x00010002 endid 0x99000002 sessionid \"pgw01.epc.internal;170001;1\" originhost \"ocs01.epc.internal\" realm \"epc.internal\" resultcode 2001 transport sctp wait 15ms\n    // 3. Device-Watchdog Heartbeat (Code 280)\n    pgw_gy -> ocs_gy diameter dwr hopid 0x00010003 endid 0x99000003 originhost \"pgw01.epc.internal\" realm \"epc.internal\" transport sctp wait 2ms\n    pgw_gy <- ocs_gy diameter dwa hopid 0x00010003 endid 0x99000003 originhost \"ocs01.epc.internal\" realm \"epc.internal\" resultcode 2001 transport sctp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show diameter_gy_charging_sctp.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly diameter_gy_charging_sctp.frasm diameter_gy_charging_sctp.pcap\nframeassembly diameter_gy_charging_sctp.frasm diameter_gy_charging_sctp.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse diameter_gy_charging_sctp.pcap diameter_gy_charging_sctp_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r diameter_gy_charging_sctp.pcap -Y \"diameter\"\n```\n\n## All `diameter` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host diameter [cer | cea | dwr | dwa | ccr |\ncca] [request | response] [cmd|command \"<text_or_num>\"] [flags <0..255>] [appid\n<number>] [hopid <number>] [endid <number>] [originhost \"<text>\"] [realm \"<text>\"]\n[dsthost \"<text>\"] [dstrealm \"<text>\"] [sessionid \"<text>\"] [resultcode <number>]\n[user \"<text>\"] [transport sctp]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `cer \\| cea \\| dwr \\| dwa \\| ccr \\| cca \\| request \\| response \\| cmd\\|command \"<text_or_num>\"` | Diameter Command shorthand or 24-bit Command-Code (e.g. 318 ULR/ULA) | `cer (257 Request)` | Selects `257` Capabilities-Exchange (`cer`/`cea`), `280` Device-Watchdog (`dwr`/`dwa`), `272` Credit-Control (`ccr`/`cca`), or any custom 3GPP Command-Code (e.g. `cmd 316` S6a ULR, `cmd 318` AIA). |\n| `appid <number>` | 32-bit Diameter Application-ID | `0 (Base) or 4 (on CCR/CCA)` | Writes bytes 8..11 (`0` Common, `4` Credit-Control, `16777251` 3GPP S6a, `16777238` 3GPP Gx). |\n| `flags <0..255>` | 8-bit Command Flags bitmask (`0x80` R, `0x40` P, `0x20` E, `0x10` T) | `0x80 on Request, 0x00 on Answer` | Overrides byte 4 of the Diameter header. |\n| `hopid <number> \\| endid <number>` | 32-bit Hop-by-Hop and End-to-End Identifiers | `Auto-populated non-zero IDs` | Writes bytes 12..19 used by peers and DRAs to match Answers to Requests. |\n| `originhost \"<text>\" \\| realm \"<text>\"` | DiameterIdentity strings (AVPs 264 & 296) | `\"client.example.com\" / \"example.com\"` | Encodes mandatory `Origin-Host` (AVP `264`, M-bit `0x40`) and `Origin-Realm` (AVP `296`, M-bit `0x40`). |\n| `dsthost \"<text>\" \\| dstrealm \"<text>\"` | DiameterIdentity strings (AVPs 293 & 283) | `Omitted` | Appends `Destination-Host` (AVP `293`) and `Destination-Realm` (AVP `283`) for DRA realm routing. |\n| `sessionid \"<text>\" \\| user \"<text>\"` | UTF8String AVPs (AVP 263 Session-Id & AVP 1 User-Name) | `Omitted` | Appends `Session-Id` (`263`) and `User-Name` (`1`, IMSI/NAI) AVPs. |\n| `resultcode <number>` | 32-bit Unsigned32 Result-Code (AVP 268) | `2001 (DIAMETER_SUCCESS) on Answers` | Appends AVP `268` (`2001` Success, `3002` Unable to Deliver, `5001` AVP Unsupported, `5030` User Unknown). |\n| `transport sctp` | Optional SCTP transport selector | `TCP 3868` | Encapsulates the Diameter PDU inside SCTP port `3868` with `PPID = 46` instead of TCP. |\n\n## Cross-Layer Options Valid with `diameter`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 3868 (or SCTP 3868 / PPID 46 via transport sctp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 3868 (or SCTP 3868 / PPID 46 via transport sctp))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Diameter Uses TCP or SCTP Only (Never transport udp)\n\n- **Avoid:** `mme -> hss diameter cer originhost \"mme.epc\" realm \"epc\" transport\n  udp`\n- **Valid v3.3.0 Syntax:** `mme -> hss diameter cer originhost \"mme.epc\" realm\n  \"epc\" transport sctp`\n\nRFC 6733 specifies reliable stream/message transports (`TCP` default or `transport\nsctp`, never connectionless UDP like legacy RADIUS).\n\n### Preserve Matching hopid and endid on Answer Frames\n\n- **Valid v3.3.0 Syntax:** `c -> s diameter dwr hopid 101 endid 501\nc <- s diameter dwa hopid 101 endid 501 resultcode 2001`\n\nWireshark’s `diameter` response-time analyzer pairs `CEA`/`DWA`/`CCA` answers with\nrequests using matching `Hop-by-Hop` and `End-to-End` IDs.\n"}
{"id":"pretrain-proto-ngap","kind":"protocol_spec","title":"5G Next Generation Application Protocol (N2 gNB <-> AMF over SCTP) (ngap) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ngap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ngap"],"text":"# ngap — 3GPP 5G N2 gNodeB-to-AMF ASN.1 APER over SCTP 38412 (`ngap`)\n\n> **FrameAssembly v3.3.0** · Protocol 86 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ngap\n\n- **Full Protocol Name:** 5G Next Generation Application Protocol (N2 gNB <-> AMF\n  over SCTP)\n- **Keyword:** `ngap`\n- **OSI Layer & Transport:** Layer 7 · SCTP 38412 (PPID 60)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** 3GPP TS 38.413, 3GPP TS 24.501, RFC 9260\n- **Wireshark Display Filter:** `ngap`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  SCTP 38412 (PPID 60) -> 5G NGAP (3GPP TS 38.413)`\n\n## Overview\n\nNative SCTP `38412` (`PPID 60`) with zero external gNodeB simulator: `ngap`\nencodes 3GPP TS 38.413 ASN.1 Aligned PER PDUs (`ngsetuprequest`,\n`initialuemessage`, `plmn`, `gnbid`, `tac`, and `naspdu` hex).\n\nNext Generation Application Protocol (`ngap`, 3GPP TS 38.413) is the **5G\nStandalone `N2` control-plane interface** connecting 5G **gNodeB (`gNB`)** radio\nbase stations to the **Access and Mobility Management Function (`AMF`)**\nexclusively over **SCTP port `38412` (`PPID = 60`)**. Crafting valid NGAP frames\nmanually is notoriously difficult because NGAP uses **ASN.1 Aligned Packed\nEncoding Rules (APER)** with sorted ProtocolIE-Container sequences, PLMN BCD\nnibbles, 24-bit Tracking Area Codes (`tac`), `AMF-UE-NGAP-ID` / `RAN-UE-NGAP-ID`,\nand embedded **5G-NAS (`3GPP TS 24.501`)** payloads.\n\nFrameAssembly encodes genuine ASN.1 APER `InitiatingMessage`, `SuccessfulOutcome`,\nand `UnsuccessfulOutcome` PDUs wrapped inside Castagnoli CRC-32c SCTP `DATA`\nchunks (`PPID 60`), rejecting invalid TCP/UDP transport overrides at compile time.\n\n## Minimal Quickstart (`ngap_quickstart.frasm`)\n\n```frameassembly\nhost gnb_01   { ip 10.52.2.11 }\nhost amf_core { ip 10.52.2.100 }\n\ncompile {\n    gnb_01 -> amf_core ngap ngsetuprequest gnbid 0x000101 plmn \"00101\" tac 1 ranname \"gnb-cell-01\" wait 4ms\n    gnb_01 <- amf_core ngap ngsetupresponse plmn \"00101\" ranname \"amf-region01\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Encapsulates every PDU inside IP Protocol `132` **SCTP (`dstport 38412`, `DATA`\n  chunk `PPID = 60`)** with automatic Castagnoli CRC-32c and SCTP Verification Tag\n  / TSN progression.\n- Formats ASN.1 APER `NGAP-PDU` headers (`InitiatingMessage` `0x00`,\n  `SuccessfulOutcome` `0x20`, `UnsuccessfulOutcome` `0x40`), Procedure Codes (`21`\n  NGSetup, `15` InitialUEMessage, `4` DownlinkNASTransport, `46`\n  UplinkNASTransport, `41` UEContextRelease), and ProtocolIE lengths.\n- Encodes 5- or 6-digit `plmn` MCC/MNC strings into 3-byte 3GPP BCD format\n  (`\"00101\"` -> `00 f1 10`) and 24-bit `tac` values automatically.\n\n## Practical Lab Example: 5G Standalone N2 Call Flow:SCTP 4-Way Handshake, NGSetup, UE Registration & Release (`ngap_5g_n2_registration.frasm`)\n\nBrings up a complete SCTP `38412` association\n(`INIT`/`INIT_ACK`/`COOKIE_ECHO`/`COOKIE_ACK`), completes N2 `NGSetup`, transports\na 5GS Registration Request + Downlink Authentication NAS exchange, and releases\nthe UE context.\n\n```frameassembly\nhost gnb_du01 { ip 172.30.2.15 }\nhost amf_01   { ip 172.30.2.200 }\n\ncompile {\n    // 1. Explicit 4-way SCTP association bring-up on N2 port 38412\n    gnb_du01 -> amf_01 sctp init srcport 38412 dstport 38412 vtag 0 tsn 1000 wait 1ms\n    gnb_du01 <- amf_01 sctp initack vtag 0x44556677 tsn 2000 wait 1ms\n    gnb_du01 -> amf_01 sctp cookieecho vtag 0x8899aabb wait 1ms\n    gnb_du01 <- amf_01 sctp cookieack vtag 0x44556677 wait 3ms\n    // 2. Non-UE-associated NGSetup handshake (Procedure Code 21, Stream 0)\n    gnb_du01 -> amf_01 ngap ngsetuprequest gnbid 1024 plmn \"99970\" tac 100 ranname \"factory-gnb-01\" wait 3ms\n    gnb_du01 <- amf_01 ngap ngsetupresponse plmn \"99970\" ranname \"private5g-amf-01\" wait 8ms\n    // 3. UE-associated InitialUEMessage + Downlink/Uplink 5G-NAS transport\n    gnb_du01 -> amf_01 ngap initialuemessage ranueid 1 plmn \"99970\" tac 100 naspdu \"7e004179000d0199f9070000000000000010\" wait 4ms\n    gnb_du01 <- amf_01 ngap downlinknastransport amfueid 5001 ranueid 1 naspdu \"7e005600020000\" wait 4ms\n    gnb_du01 -> amf_01 ngap uplinknastransport amfueid 5001 ranueid 1 naspdu \"7e00572d10aabbccddeeff00112233445566778899\" wait 15ms\n    // 4. UE Context Release Command & Complete (Procedure Code 41)\n    gnb_du01 <- amf_01 ngap uecontextreleasecommand amfueid 5001 ranueid 1 wait 2ms\n    gnb_du01 -> amf_01 ngap uecontextreleasecomplete amfueid 5001 ranueid 1\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ngap_5g_n2_registration.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ngap_5g_n2_registration.frasm ngap_5g_n2_registration.pcap\nframeassembly ngap_5g_n2_registration.frasm ngap_5g_n2_registration.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ngap_5g_n2_registration.pcap ngap_5g_n2_registration_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ngap_5g_n2_registration.pcap -Y \"ngap\"\n```\n\n## All `ngap` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ngap [ngsetuprequest | ngsetupresponse\n| ngsetupfailure | initialuemessage | downlinknastransport | uplinknastransport |\nuecontextreleasecommand | uecontextreleasecomplete | errorindication] [msgtype\n\"<text>\"] [proccode <0..255>] [criticality \"<text>\"] [amfueid <number>] [ranueid\n<number>] [plmn \"<text>\"] [gnbid <number>] [tac <0..16777215>] [ranname \"<text>\"]\n[naspdu \"<hex>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `ngsetuprequest \\| ngsetupresponse \\| ngsetupfailure \\| initialuemessage \\| downlinknastransport \\| uplinknastransport \\| uecontextreleasecommand \\| uecontextreleasecomplete \\| errorindication` | 3GPP TS 38.413 NGAP Elementary Procedure | `ngsetuprequest` | Selects both the APER PDU Choice (`InitiatingMessage` / `SuccessfulOutcome` / `UnsuccessfulOutcome`) and mandatory 3GPP TS 38.413 Procedure Code + ProtocolIEs. |\n| `msgtype \"<text>\" \\| proccode <0..255> \\| criticality \"<text>\"` | Explicit APER PDU class, ProcedureCode (0..255), and Criticality (\"reject\"\\|\"ignore\"\\|\"notify\") | `Derived from procedure keyword` | Overrides the outer ASN.1 APER `procedureCode` and `criticality` enum (`0` reject, `1` ignore, `2` notify). |\n| `amfueid <number> \\| ranueid <number>` | 40-bit AMF-UE-NGAP-ID (IE 10) & 32-bit RAN-UE-NGAP-ID (IE 85) | `amfueid 1, ranueid 1 on UE messages` | Encodes APER integer IEs correlating a specific UE across N2 uplink and downlink NAS messages. |\n| `plmn \"<text>\"` | 5- or 6-digit MCC+MNC string (e.g. \"00101\", \"310260\", \"99970\") | `\"00101\"` | Packs the 3-octet 3GPP `PLMNIdentity` inside GlobalRANNodeID, BroadcastPLMNList, and UserLocationInformation IEs. |\n| `gnbid <number> \\| tac <0..16777215> \\| ranname \"<text>\"` | gNB-ID integer, 24-bit Tracking Area Code, and PrintableString RANNodeName | `gnbid 1, tac 1, ranname \"gNB-01\"` | Populates IE `27` (`GlobalRANNodeID`), IE `102` (`SupportedTAList`), IE `121` (`UserLocationInformation`), and IE `82` (`RANNodeName`). |\n| `naspdu \"<hex>\"` | Even-length hex byte string (IE 38 NAS-PDU) | `\"7e0041\" (5GS Registration stub)` | Embeds raw `3GPP TS 24.501` 5G-NAS message octets inside IE `38` (`NAS-PDU`) for full Wireshark `nas-5gs` decoding. |\n\n## Cross-Layer Options Valid with `ngap`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), SCTP 38412 (PPID 60)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n\n## Common Mistakes & Quick Fixes\n\n### ngap Is Strictly SCTP-Only (Do Not Add transport tcp or transport udp)\n\n- **Avoid:** `gnb -> amf ngap ngsetuprequest transport tcp`\n- **Valid v3.3.0 Syntax:** `gnb -> amf ngap ngsetuprequest gnbid 1 plmn \"00101\"`\n\n3GPP TS 38.412 mandates SCTP (`38412`, `PPID 60`) for N2; `validate_semantics`\nrejects `transport tcp` and `transport udp` on `ngap` at compile time.\n\n### Pass naspdu as Valid Hex Octets\n\n- **Avoid:** `gnb -> amf ngap initialuemessage naspdu \"registration-req\"`\n- **Valid v3.3.0 Syntax:** `gnb -> amf ngap initialuemessage ranueid 1 naspdu\n  \"7e0041\"`\n\n`naspdu` expects hexadecimal bytes (`\"7e0041\"` or `\"7e:00:41\"`) representing\nbinary 3GPP TS 24.501 5G-NAS PDUs.\n"}
{"id":"pretrain-proto-s1ap","kind":"protocol_spec","title":"4G LTE S1 Application Protocol (S1-MME eNB <-> MME over SCTP) (s1ap) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/s1ap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["s1ap"],"text":"# s1ap — 3GPP 4G S1-MME eNodeB-to-MME ASN.1 APER over SCTP 36412 (`s1ap`)\n\n> **FrameAssembly v3.3.0** · Protocol 87 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/s1ap\n\n- **Full Protocol Name:** 4G LTE S1 Application Protocol (S1-MME eNB <-> MME over\n  SCTP)\n- **Keyword:** `s1ap`\n- **OSI Layer & Transport:** Layer 7 · SCTP 36412 (PPID 18)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** 3GPP TS 36.413, 3GPP TS 24.301, RFC 9260\n- **Wireshark Display Filter:** `s1ap`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  SCTP 36412 (PPID 18) -> 4G S1AP (3GPP TS 36.413)`\n\n## Overview\n\nTest 4G LTE S1-MME security gateways and telecom NDR probes offline: `s1ap` emits\n3GPP TS 36.413 ASN.1 APER frames straight inside SCTP `36412` (`PPID 18`) with\nCastagnoli CRC-32c.\n\nS1 Application Protocol (`s1ap`, 3GPP TS 36.413) is the **4G LTE `S1-MME`\ncontrol-plane protocol** linking **eNodeB (`eNB`)** radio base stations to the\n**Mobility Management Entity (`MME`)** exclusively over **SCTP port `36412` (`PPID\n= 18`)**. Like 5G NGAP, S1AP uses **ASN.1 Aligned PER (APER)** encoding to carry\ncell-level setup (`S1SetupRequest`/`Response` with `Global-ENB-ID`, `SupportedTAs`\n16-bit `TAC`, and `eNBname`) and UE-associated signaling (`InitialUEMessage`,\n`DownlinkNASTransport`, `UplinkNASTransport`, `UEContextRelease` with\n`MME-UE-S1AP-ID`, `eNB-UE-S1AP-ID`, and embedded **EPS-NAS `3GPP TS 24.301`**\nPDUs).\n\nFrameAssembly packs compliant APER S1AP containers inside CRC-32c SCTP `DATA`\nchunks (`PPID 18`) over IPv4 or IPv6 backhaul hosts.\n\n## Minimal Quickstart (`s1ap_quickstart.frasm`)\n\n```frameassembly\nhost enb_01  { ip 10.44.1.11 }\nhost mme_epc { ip 10.44.1.100 }\n\ncompile {\n    enb_01 -> mme_epc s1ap s1setuprequest enbid 0x001a2 plmn \"00101\" tac 10 enbname \"enb-macro-01\" wait 4ms\n    enb_01 <- mme_epc s1ap s1setupresponse plmn \"00101\" enbname \"mme-epc-01\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Wraps every S1AP message inside IP Protocol `132` **SCTP (`dstport 36412`,\n  `DATA` chunk `PPID = 18`)** with valid Castagnoli CRC-32c.\n- Encodes ASN.1 APER `S1AP-PDU` Procedure Codes (`17` S1Setup, `12`\n  InitialUEMessage, `11` DownlinkNASTransport, `13` UplinkNASTransport, `23`\n  UEContextRelease, `15` ErrorIndication) and sorted ProtocolIE fields.\n- Formats 3-byte BCD `PLMNidentity`, 20-bit Macro `eNB-ID`, and 16-bit LTE `TAC`\n  (`0..65535`) automatically.\n\n## Practical Lab Example: 4G LTE S1-MME Attach Signaling: S1Setup, InitialUEMessage, EPS-NAS Auth & Release (`s1ap_lte_attach_flow.frasm`)\n\nSimulates a CBRS private-LTE eNodeB onboarding onto an MME over SCTP `36412`,\nforwarding an EPS Attach Request (`naspdu \"0741...\"`), completing mutual\nauthentication, and releasing the S1 UE context.\n\n```frameassembly\nhost cbrs_enb { ip 172.24.36.12 }\nhost epc_mme  { ip 172.24.36.100 }\n\ncompile {\n    // 1. S1Setup Request & Response (Procedure Code 17, SCTP 36412 PPID 18)\n    cbrs_enb -> epc_mme s1ap s1setuprequest enbid 0x01020 plmn \"315010\" tac 401 enbname \"cbrs-warehouse-enb1\" wait 3ms\n    cbrs_enb <- epc_mme s1ap s1setupresponse plmn \"315010\" enbname \"magma-mme-01\" wait 6ms\n    // 2. UE Attach: InitialUEMessage (Procedure Code 12) carrying EPS Attach Request (0x07 0x41)\n    cbrs_enb -> epc_mme s1ap initialuemessage enbueid 101 plmn \"315010\" tac 401 naspdu \"074171080910101234567890\" wait 4ms\n    // 3. Downlink & Uplink NAS Transport (Authentication Request 0x07 0x52 / Response 0x07 0x53)\n    cbrs_enb <- epc_mme s1ap downlinknastransport mmeueid 9001 enbueid 101 naspdu \"075200100102030405060708090a0b0c0d0e0f10\" wait 4ms\n    cbrs_enb -> epc_mme s1ap uplinknastransport mmeueid 9001 enbueid 101 naspdu \"075308aabbccddeeff0011\" wait 20ms\n    // 4. Inactivity S1 UE Context Release (Procedure Code 23)\n    cbrs_enb <- epc_mme s1ap uecontextreleasecommand mmeueid 9001 enbueid 101 wait 2ms\n    cbrs_enb -> epc_mme s1ap uecontextreleasecomplete mmeueid 9001 enbueid 101\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show s1ap_lte_attach_flow.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly s1ap_lte_attach_flow.frasm s1ap_lte_attach_flow.pcap\nframeassembly s1ap_lte_attach_flow.frasm s1ap_lte_attach_flow.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse s1ap_lte_attach_flow.pcap s1ap_lte_attach_flow_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r s1ap_lte_attach_flow.pcap -Y \"s1ap\"\n```\n\n## All `s1ap` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host s1ap [s1setuprequest | s1setupresponse\n| s1setupfailure | initialuemessage | downlinknastransport | uplinknastransport |\nuecontextreleasecommand | uecontextreleasecomplete | errorindication] [msgtype\n\"<text>\"] [proccode <0..255>] [criticality \"<text>\"] [mmeueid <number>] [enbueid\n<0..16777215>] [plmn \"<text>\"] [enbid <number>] [tac <0..65535>] [enbname\n\"<text>\"] [naspdu \"<hex>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `s1setuprequest \\| s1setupresponse \\| s1setupfailure \\| initialuemessage \\| downlinknastransport \\| uplinknastransport \\| uecontextreleasecommand \\| uecontextreleasecomplete \\| errorindication` | 3GPP TS 36.413 S1AP Elementary Procedure | `s1setuprequest` | Selects the ASN.1 APER PDU Choice and TS 36.413 Procedure Code + mandatory ProtocolIE sequence. |\n| `msgtype \"<text>\" \\| proccode <0..255> \\| criticality \"<text>\"` | Explicit APER PDU Choice, ProcedureCode, and Criticality | `Derived from procedure keyword` | Overrides the outer S1AP `procedureCode` and `criticality` (`\"reject\"`, `\"ignore\"`, `\"notify\"`). |\n| `mmeueid <number> \\| enbueid <0..16777215>` | 32-bit MME-UE-S1AP-ID (IE 0) & 24-bit eNB-UE-S1AP-ID (IE 8) | `mmeueid 1, enbueid 1 on UE messages` | Writes the APER integer UE context identifiers pairing eNB and MME state machines. |\n| `plmn \"<text>\"` | 5- or 6-digit MCC+MNC string (e.g. \"00101\", \"315010\") | `\"00101\"` | Encodes the 3-octet TBCD `PLMNidentity` in Global-ENB-ID, SupportedTAs, TAI, and EUTRAN-CGI. |\n| `enbid <number> \\| tac <0..65535> \\| enbname \"<text>\"` | 20-bit Macro eNB-ID, 16-bit LTE TAC (0..65535), and PrintableString eNBname | `enbid 1, tac 1, enbname \"eNB-01\"` | Populates IE `59` (`Global-ENB-ID`), IE `64` (`SupportedTAs`), IE `67` (`TAI`), and IE `60` (`eNBname`). |\n| `naspdu \"<hex>\"` | Even-length hex byte string (IE 26 NAS-PDU) | `\"0741\" (EPS Attach stub)` | Embeds binary `3GPP TS 24.301` EPS-NAS octets inside IE `26` for Wireshark `nas-eps` dissection. |\n\n## Cross-Layer Options Valid with `s1ap`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), SCTP 36412 (PPID 18)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n\n## Common Mistakes & Quick Fixes\n\n### 4G S1AP TAC Is 16-Bit (0..65535), Unlike 5G NGAP 24-Bit TAC\n\n- **Avoid:** `enb -> mme s1ap s1setuprequest tac 100000`\n- **Valid v3.3.0 Syntax:** `enb -> mme s1ap s1setuprequest tac 401`\n\nIn 4G LTE (`3GPP TS 36.413`), `TAC` is a 2-octet `OCTET STRING (SIZE(2))`\n(`0..=65535`), whereas 5G NR (`ngap`) widened `TAC` to 3 octets (`0..=16777215`).\n\n### s1ap Is Strictly SCTP-Only (SCTP 36412, PPID 18)\n\n- **Avoid:** `enb -> mme s1ap initialuemessage transport udp`\n- **Valid v3.3.0 Syntax:** `enb -> mme s1ap initialuemessage enbueid 1 naspdu\n  \"0741\"`\n\n3GPP TS 36.412 mandates SCTP for S1-MME; `validate_semantics` rejects `transport\ntcp` and `transport udp` on `s1ap`.\n"}
{"id":"pretrain-proto-smtp","kind":"protocol_spec","title":"Simple Mail Transfer Protocol (smtp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/smtp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["smtp"],"text":"# smtp — Stateful TCP 25/587 Mail Relay Conversations (`smtp`)\n\n> **FrameAssembly v3.3.0** · Protocol 88 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/smtp\n\n- **Full Protocol Name:** Simple Mail Transfer Protocol\n- **Keyword:** `smtp`\n- **OSI Layer & Transport:** Layer 7 · TCP 25 (or dstport 587 Submission)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 5321\n- **Wireshark Display Filter:** `smtp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 25 (or dstport 587 Submission) -> SMTP`\n\n## Overview\n\nStep through a real RFC 5321 mail relay (`220` greeting -> `ehlo` -> `mailfrom` ->\n`rcptto` -> `354` -> `body` -> `250 OK`) over stateful TCP `25` to test\nmail-gateway DLP and open-relay signatures.\n\nSimple Mail Transfer Protocol (`smtp`, RFC 5321) relays email between Mail\nTransfer Agents (MTAs) on **TCP port `25`** and mail submission gateways on **TCP\nport `587`**. An SMTP envelope steps through server `220` greeting -> client\n`EHLO` -> `MAIL FROM:<...>` -> `RCPT TO:<...>` -> `DATA` (`354`) -> RFC 5322\nmessage `body` -> `250` acceptance -> `QUIT` (`221`).\n\nFrameAssembly gives you clean keywords for every envelope command (`ehlo`, `helo`,\n`mailfrom`, `rcptto`, `data`, `quit`, or custom `cmd`) plus `code` / `reply` for\nserver responses and `body` for message content.\n\n## Minimal Quickstart (`smtp_quickstart.frasm`)\n\n```frameassembly\nhost app_srv { ip 10.20.10.15 }\nhost mail_gw { ip 10.20.10.25 }\n\ncompile {\n    app_srv -> mail_gw tcp syn srcport 51025 dstport 25 wait 1ms\n    app_srv <- mail_gw tcp syn ack wait 1ms\n    app_srv -> mail_gw tcp ack wait 1ms\n    app_srv <- mail_gw smtp code 220 reply \"mx01.corp.internal ESMTP Postfix\" wait 2ms\n    app_srv -> mail_gw smtp ehlo \"app01.corp.internal\" wait 2ms\n    app_srv <- mail_gw smtp code 250 reply \"mx01.corp.internal\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `25` (`psh ack`; use `dstport 587` for\n  submission) and terminates SMTP lines with `\n`.\n- Formats `MAIL FROM:<...>` (`mailfrom`) and `RCPT TO:<...>` (`rcptto`) cleanly\n  and terminates `body` payloads with `\n.\n` when needed.\n- Tracks TCP sequence and acknowledgment numbers automatically across the full\n  multi-step envelope.\n\n## Practical Lab Example: Complete End-to-End RFC 5321 Email Delivery Transaction (`smtp_full_envelope.frasm`)\n\nWalks through a full TCP 25 session from `220` banner and `EHLO` through `MAIL\nFROM`, `RCPT TO`, `DATA` (`354`), message headers/body, `250 Queued`, and `QUIT`.\n\n```frameassembly\nhost alert_bot { ip 172.16.15.20 }\nhost smtp_relay { ip 172.16.15.25 }\n\ncompile {\n    alert_bot -> smtp_relay tcp syn srcport 52025 dstport 25 win 65535 mss 1460 wait 1ms\n    alert_bot <- smtp_relay tcp syn ack win 65535 mss 1460 wait 1ms\n    alert_bot -> smtp_relay tcp ack wait 1ms\n    alert_bot <- smtp_relay smtp code 220 reply \"relay.corp.internal ESMTP\" wait 2ms\n    alert_bot -> smtp_relay smtp ehlo \"alert-bot.corp.internal\" wait 1ms\n    alert_bot <- smtp_relay smtp code 250 reply \"PIPELINING\" wait 1ms\n    alert_bot -> smtp_relay smtp mailfrom \"<noc-alerts@corp.internal>\" wait 1ms\n    alert_bot <- smtp_relay smtp code 250 reply \"2.1.0 Ok\" wait 1ms\n    alert_bot -> smtp_relay smtp rcptto \"<oncall@corp.internal>\" wait 1ms\n    alert_bot <- smtp_relay smtp code 250 reply \"2.1.5 Ok\" wait 1ms\n    alert_bot -> smtp_relay smtp data wait 1ms\n    alert_bot <- smtp_relay smtp code 354 reply \"End data with <CR><LF>.<CR><LF>\" wait 2ms\n    alert_bot -> smtp_relay smtp body \"Subject: Core Link Down\\r\\nFrom: noc-alerts@corp.internal\\r\\n\\r\\nGi1/0/49 went down.\\r\\n.\" wait 2ms\n    alert_bot <- smtp_relay smtp code 250 reply \"2.0.0 Ok: queued as 9F4A1\" wait 1ms\n    alert_bot -> smtp_relay smtp quit wait 1ms\n    alert_bot <- smtp_relay smtp code 221 reply \"2.0.0 Bye\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show smtp_full_envelope.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly smtp_full_envelope.frasm smtp_full_envelope.pcap\nframeassembly smtp_full_envelope.frasm smtp_full_envelope.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse smtp_full_envelope.pcap smtp_full_envelope_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r smtp_full_envelope.pcap -Y \"smtp\"\n```\n\n## All `smtp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host smtp [ehlo [\"<domain>\"] | helo\n[\"<domain>\"] | mailfrom \"<addr>\" | rcptto \"<addr>\" | data | quit | cmd \"<verb>\"\n[param \"<text>\"]] [code <200..599>] [reply \"<text>\"] [body \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `ehlo [\"<domain>\"] \\| helo [\"<domain>\"]` | Extended or classic SMTP greeting + client hostname | `\"localhost\"` | Writes `EHLO <domain>\\r\\n` or `HELO <domain>\\r\\n`. |\n| `mailfrom \"<addr>\" \\| rcptto \"<addr>\"` | Quoted sender or recipient email address | `Omitted unless set` | Writes `MAIL FROM:<addr>\\r\\n` or `RCPT TO:<addr>\\r\\n`. |\n| `data \\| quit \\| cmd \"<verb>\" [param \"<text>\"]` | Envelope command or custom verb (e.g. `cmd \"STARTTLS\"`) | `Omitted` | Writes `DATA\\r\\n`, `QUIT\\r\\n`, or `<verb> <param>\\r\\n`. |\n| `code <200..599> [reply \"<text>\"]` | 3-digit SMTP reply code (`220`, `250`, `354`, `421`, `550`) + text | `Omitted on client commands` | Emits a server reply line (`250 2.0.0 Ok\\r\\n`). |\n| `body \"<text>\"` | Quoted RFC 5322 email headers + message body | `Empty` | Transmits the email message payload following `354` `DATA` acceptance. |\n\n## Cross-Layer Options Valid with `smtp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 25 (or dstport 587 Submission)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 25 (or dstport 587 Submission))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### No Spaces or Underscores in mailfrom and rcptto\n\n- **Avoid:** `alert_bot -> smtp_relay smtp mail_from \"<a@b>\" rcpt_to \"<c@d>\"`\n- **Valid v3.3.0 Syntax:** `alert_bot -> smtp_relay smtp mailfrom \"<a@b>\"`\n\nSend `mailfrom` and `rcptto` on separate packet lines (one SMTP command per\npacket, spelled with zero underscores).\n"}
{"id":"pretrain-proto-imap","kind":"protocol_spec","title":"Internet Message Access Protocol IMAP4rev1 (imap) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/imap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["imap"],"text":"# imap — Correlation-Tagged TCP 143 Mailbox Command Streams (`imap`)\n\n> **FrameAssembly v3.3.0** · Protocol 89 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/imap\n\n- **Full Protocol Name:** Internet Message Access Protocol IMAP4rev1\n- **Keyword:** `imap`\n- **OSI Layer & Transport:** Layer 7 · TCP 143\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 3501, RFC 9051\n- **Wireshark Display Filter:** `imap`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 143 -> IMAP4`\n\n## Overview\n\nEvery IMAP command wears a client correlation tag (`A001 LOGIN`, `A002 SELECT\nINBOX`) on TCP `143`, making it easy to test cleartext credential alerts and\nlegacy mail-protocol blocks.\n\nInternet Message Access Protocol (`imap`, RFC 3501) lets email clients synchronize\nfolders and messages on **TCP port `143`** (cleartext / `STARTTLS`) or `993`\n(IMAPS). Every IMAP client command starts with a short alphanumeric `tag` (such as\n`A001`, `A002`) so the server can match tagged completion replies (`A001 OK LOGIN\ncompleted`, `A001 NO Authentication failed`) alongside untagged `* OK` greetings.\n\nFrameAssembly formats both tagged client commands (`tag`, `cmd`, `arg`) and server\nresponses (`status` `\"OK\"` / `\"NO\"` / `\"BAD\"` + `response`) cleanly over TCP port\n`143`.\n\n## Minimal Quickstart (`imap_quickstart.frasm`)\n\n```frameassembly\nhost mail_app { ip 10.20.15.30 }\nhost imap_srv { ip 10.20.15.143 }\n\ncompile {\n    mail_app -> imap_srv tcp syn srcport 51143 dstport 143 wait 1ms\n    mail_app <- imap_srv tcp syn ack wait 1ms\n    mail_app -> imap_srv tcp ack wait 1ms\n    mail_app <- imap_srv imap tag \"*\" status \"OK\" response \"Dovecot ready.\" wait 2ms\n    mail_app -> imap_srv imap tag \"A01\" cmd \"CAPABILITY\" wait 2ms\n    mail_app <- imap_srv imap tag \"A01\" status \"OK\" response \"CAPABILITY completed\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `143` (`psh ack`) and appends `\n` to every IMAP command or response line.\n- Formats `<tag> <cmd> <arg>\n` on client requests and `<tag> <status> <response>\n` when `status` or `response` is provided.\n- Keeps TCP sequence numbers synchronized across multi-command sessions.\n\n## Practical Lab Example: Cleartext IMAP Login Failure Followed by Authorized Inbox Selection (`imap_login_audit.frasm`)\n\nCaptures an untagged server greeting, a failed `A01 LOGIN` returning `NO`, and an\nauthorized `A02 LOGIN` + `A03 SELECT INBOX`.\n\n```frameassembly\nhost laptop   { ip 172.16.25.44 }\nhost mail_box { ip 172.16.25.10 }\n\ncompile {\n    laptop -> mail_box tcp syn srcport 52143 dstport 143 win 65535 mss 1460 wait 1ms\n    laptop <- mail_box tcp syn ack win 65535 mss 1460 wait 1ms\n    laptop -> mail_box tcp ack wait 1ms\n    laptop <- mail_box imap tag \"*\" status \"OK\" response \"IMAP4rev1 Service Ready\" wait 2ms\n    // 1. Failed login -> tagged NO\n    laptop -> mail_box imap tag \"A01\" cmd \"LOGIN\" arg \"jdoe WrongPass1\" wait 3ms\n    laptop <- mail_box imap tag \"A01\" status \"NO\" response \"LOGIN failed.\" wait 5ms\n    // 2. Valid login + SELECT INBOX\n    laptop -> mail_box imap tag \"A02\" cmd \"LOGIN\" arg \"jdoe LabPass2026\" wait 2ms\n    laptop <- mail_box imap tag \"A02\" status \"OK\" response \"LOGIN completed\" wait 2ms\n    laptop -> mail_box imap tag \"A03\" cmd \"SELECT\" arg \"INBOX\" wait 2ms\n    laptop <- mail_box imap tag \"A03\" status \"OK\" response \"[READ-WRITE] SELECT completed\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show imap_login_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly imap_login_audit.frasm imap_login_audit.pcap\nframeassembly imap_login_audit.frasm imap_login_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse imap_login_audit.pcap imap_login_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r imap_login_audit.pcap -Y \"imap\"\n```\n\n## All `imap` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host imap [tag \"<text>\"] [cmd \"<text>\"] [arg\n\"<text>\"] [status \"<text>\"] [response \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `tag \"<text>\"` | Quoted command tag (`\"A01\"`, `\"a1\"`, or `\"*\"` untagged) | `\"A001\" (or \"*\" on untagged server greeting)` | Writes the leading IMAP tag token. |\n| `cmd \"<text>\" [arg \"<text>\"]` | IMAP command verb (`\"CAPABILITY\"`, `\"LOGIN\"`, `\"SELECT\"`, `\"FETCH\"`, `\"LOGOUT\"`) + arguments | `cmd \"CAPABILITY\"` | Writes the client command and optional argument string. |\n| `status \"<text>\" [response \"<text>\"]` | Quoted completion status (`\"OK\"`, `\"NO\"`, `\"BAD\"`) + text | `Omitted on client commands` | Emits an IMAP server status response line. |\n\n## Cross-Layer Options Valid with `imap`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 143` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 143)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### IMAP status Takes a Quoted String (\"OK\", \"NO\", \"BAD\"), Not a Number\n\n- **Avoid:** `mail_app <- imap_srv imap tag \"A01\" status 200`\n- **Valid v3.3.0 Syntax:** `mail_app <- imap_srv imap tag \"A01\" status \"OK\"\n  response \"Done\"`\n\nUnlike HTTP (`status 200`), RFC 3501 IMAP uses text completion tokens (`\"OK\"`,\n`\"NO\"`, `\"BAD\"`).\n"}
{"id":"pretrain-proto-pop3","kind":"protocol_spec","title":"Post Office Protocol Version 3 (pop3) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/pop3","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["pop3"],"text":"# pop3 — TCP 110 +OK / -ERR Logins & Password-Spray Traces (`pop3`)\n\n> **FrameAssembly v3.3.0** · Protocol 90 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/pop3\n\n- **Full Protocol Name:** Post Office Protocol Version 3\n- **Keyword:** `pop3`\n- **OSI Layer & Transport:** Layer 7 · TCP 110\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 1939\n- **Wireshark Display Filter:** `pop`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 110 -> POP3`\n\n## Overview\n\nThirty lines of `-ERR Authentication failed` on TCP `110`? Classic password-spray\nterritory — `pop3` pairs `cmd \"USER\"` and `cmd \"PASS\"` with `ok` (`+OK`) and `err`\n(`-ERR`) responses.\n\nPost Office Protocol v3 (`pop3`, RFC 1939) downloads messages from legacy mail\nservers over **TCP port `110`**. POP3 uses a concise line protocol: clients send\n4-letter commands (`USER`, `PASS`, `STAT`, `LIST`, `RETR`, `QUIT`) and servers\nreply with either `+OK <response>` (`ok`) or `-ERR <response>` (`err`).\n\nBecause legacy POP3 exposes usernames and passwords in plain text on port `110`,\nsecurity teams use `pop3` `.pcap` fixtures to test cleartext-credential alerts and\nlegacy protocol deprecation rules.\n\n## Minimal Quickstart (`pop3_quickstart.frasm`)\n\n```frameassembly\nhost client   { ip 10.20.16.25 }\nhost pop3_srv { ip 10.20.16.110 }\n\ncompile {\n    client -> pop3_srv tcp syn srcport 51110 dstport 110 wait 1ms\n    client <- pop3_srv tcp syn ack wait 1ms\n    client -> pop3_srv tcp ack wait 1ms\n    client <- pop3_srv pop3 ok response \"POP3 server ready\" wait 2ms\n    client -> pop3_srv pop3 cmd \"STAT\" wait 2ms\n    client <- pop3_srv pop3 ok response \"2 320\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `110` (`psh ack`) and appends `\n` per RFC 1939.\n- Formats `+OK <response>\n` on `ok` and `-ERR <response>\n` on `err`.\n- Tracks TCP sequence and acknowledgment numbers automatically across\n  client/server turns.\n\n## Practical Lab Example: POP3 Failed Login (`-ERR`) + Successful Mailbox `STAT` & `QUIT` (`pop3_session_audit.frasm`)\n\nEstablishes a TCP 110 session, captures a rejected password attempt (`err`), then\ncompletes `USER` -> `PASS` -> `STAT` -> `QUIT`.\n\n```frameassembly\nhost workstation { ip 172.16.16.40 }\nhost legacy_mail { ip 172.16.16.110 }\n\ncompile {\n    workstation -> legacy_mail tcp syn srcport 52110 dstport 110 win 65535 mss 1460 wait 1ms\n    workstation <- legacy_mail tcp syn ack win 65535 mss 1460 wait 1ms\n    workstation -> legacy_mail tcp ack wait 1ms\n    workstation <- legacy_mail pop3 ok response \"Dovecot POP3 ready.\" wait 2ms\n    workstation -> legacy_mail pop3 cmd \"USER\" arg \"ops_scanner\" wait 1ms\n    workstation <- legacy_mail pop3 ok response \"Pass required\" wait 1ms\n    workstation -> legacy_mail pop3 cmd \"PASS\" arg \"BadPass1\" wait 4ms\n    workstation <- legacy_mail pop3 err response \"[AUTH] Authentication failed.\" wait 5ms\n    workstation -> legacy_mail pop3 cmd \"USER\" arg \"ops_scanner\" wait 1ms\n    workstation <- legacy_mail pop3 ok wait 1ms\n    workstation -> legacy_mail pop3 cmd \"PASS\" arg \"LabPass99\" wait 2ms\n    workstation <- legacy_mail pop3 ok response \"Logged in.\" wait 1ms\n    workstation -> legacy_mail pop3 cmd \"STAT\" wait 1ms\n    workstation <- legacy_mail pop3 ok response \"3 4096\" wait 1ms\n    workstation -> legacy_mail pop3 cmd \"QUIT\" wait 1ms\n    workstation <- legacy_mail pop3 ok response \"Logging out.\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show pop3_session_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly pop3_session_audit.frasm pop3_session_audit.pcap\nframeassembly pop3_session_audit.frasm pop3_session_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse pop3_session_audit.pcap pop3_session_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r pop3_session_audit.pcap -Y \"pop\"\n```\n\n## All `pop3` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host pop3 [cmd \"<text>\"] [arg \"<text>\"] [ok\n| err] [response \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `cmd \"<text>\" [arg \"<text>\"]` | POP3 client command (`\"USER\"`, `\"PASS\"`, `\"STAT\"`, `\"LIST\"`, `\"RETR\"`, `\"QUIT\"`) + argument | `cmd \"STAT\"` | Writes `<cmd> <arg>\\r\\n` from the client. |\n| `ok \\| err` | POP3 server status indicator | `Omitted on client commands` | Emits `+OK` (`ok`) or `-ERR` (`err`) at the start of a server reply. |\n| `response \"<text>\"` | Quoted server status text | `Empty` | Appends human-readable status details after `+OK` or `-ERR`. |\n\n## Cross-Layer Options Valid with `pop3`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 110` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 110)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Do Not Include + or - in ok / err Keywords\n\n- **Avoid:** `client <- pop3_srv pop3 +ok response \"Ready\"`\n- **Valid v3.3.0 Syntax:** `client <- pop3_srv pop3 ok response \"Ready\"`\n\nWrite `ok` or `err` without `+` or `-`; FrameAssembly writes `+OK` and `-ERR` on\nthe wire automatically.\n"}
{"id":"pretrain-proto-kerberos","kind":"protocol_spec","title":"Kerberos Network Authentication Service v5 (Active Directory) (kerberos) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/kerberos","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["kerberos"],"text":"# kerberos — Port 88 ASN.1 DER Tickets & RC4 Kerberoast Checks (`kerberos`)\n\n> **FrameAssembly v3.3.0** · Protocol 91 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/kerberos\n\n- **Full Protocol Name:** Kerberos Network Authentication Service v5 (Active\n  Directory)\n- **Keyword:** `kerberos`\n- **OSI Layer & Transport:** Layer 7 · UDP 88 (or TCP 88 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 4120, RFC 3962, RFC 4757\n- **Wireshark Display Filter:** `kerberos`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 88 (or TCP 88 via transport tcp) (transport tcp|udp) -> Kerberos v5`\n\n## Overview\n\nTrigger SOC Kerberoasting rules (`tgsreq` + `sname \"MSSQLSvc/...\"` + `etype 23`)\nwithout firing offensive tools at a real Domain Controller — add `transport tcp`\nand the compiler prepends the 4-byte RFC 4120 TCP record length automatically.\n\nKerberos v5 (`kerberos`, RFC 4120) is the core ticket-granting authentication\nprotocol in Microsoft Active Directory and enterprise Linux realms on **port\n`88`**. `kerberos` defaults to **UDP port `88`**, and adding `transport tcp`\nswitches to **TCP port `88`**—automatically prepending the mandatory 4-byte RFC\n4120 big-endian record-length header used by Windows Domain Controllers when\ntickets carry large PAC group memberships.\n\nFrameAssembly encodes full ASN.1 DER Kerberos v5 (`pvno 5`) messages for `asreq`,\n`asrep`, `tgsreq`, `tgsrep`, and `krberror` with customizable `realm`, client\nprincipal (`cname`), service SPN (`sname`), and encryption type (`etype`, such as\n`18` for AES256 or `23` for RC4-HMAC).\n\n## Minimal Quickstart (`kerberos_quickstart.frasm`)\n\n```frameassembly\nhost domain_pc { ip 10.10.20.45 }\nhost ad_dc01   { ip 10.10.0.10 }\n\ncompile {\n    domain_pc -> ad_dc01 kerberos asreq realm \"CORP.INTERNAL\" cname \"jdoe\" sname \"krbtgt/CORP.INTERNAL\" etype 18 wait 2ms\n    domain_pc <- ad_dc01 kerberos asrep realm \"CORP.INTERNAL\" cname \"jdoe\" etype 18\n}\n```\n\n### Automatic Wire Calculations\n\n- Encodes valid ASN.1 DER RFC 4120 `APPLICATION` tags (`10` AS-REQ, `11` AS-REP,\n  `12` TGS-REQ, `13` TGS-REP, `30` KRB-ERROR) with `pvno = 5`.\n- Splits slash-separated SPNs like `\"MSSQLSvc/db01.corp.internal:1433\"` into\n  multi-component `PrincipalName` ASN.1 sequences automatically.\n- Prepends the 4-byte RFC 4120 §7.2.2 TCP record-mark length automatically\n  whenever `transport tcp` is specified.\n\n## Practical Lab Example: AES256 TGT Login Over TCP 88 + RC4 (`etype 23`) Kerberoasting Detection Lab (`kerberos_ad_detection_lab.frasm`)\n\nModels a normal Windows workstation obtaining an AES256 TGT over TCP port 88,\nfollowed by an RC4 (`etype 23`) `tgsreq`/`tgsrep` SPN ticket request to trigger\nSOC Kerberoasting signatures.\n\n```frameassembly\nhost wkstn_14 { ip 172.16.20.14 }\nhost dc01_ad  { ip 172.16.1.10 }\n\ncompile {\n    // 1. Normal Active Directory TGT exchange over TCP port 88 (etype 18 = AES256)\n    wkstn_14 -> dc01_ad tcp syn srcport 53088 dstport 88 win 65535 mss 1460 wait 1ms\n    wkstn_14 <- dc01_ad tcp syn ack win 65535 mss 1460 wait 1ms\n    wkstn_14 -> dc01_ad tcp ack wait 1ms\n    wkstn_14 -> dc01_ad kerberos asreq realm \"CORP.INTERNAL\" cname \"alice\" sname \"krbtgt/CORP.INTERNAL\" etype 18 transport tcp wait 2ms\n    wkstn_14 <- dc01_ad kerberos asrep realm \"CORP.INTERNAL\" cname \"alice\" etype 18 transport tcp wait 5ms\n    // 2. Suspicious RC4-HMAC (etype 23) Service Ticket Request for SQL SPN (Kerberoasting test)\n    wkstn_14 -> dc01_ad kerberos tgsreq realm \"CORP.INTERNAL\" cname \"alice\" sname \"MSSQLSvc/db-prod.corp.internal:1433\" etype 23 transport tcp wait 2ms\n    wkstn_14 <- dc01_ad kerberos tgsrep realm \"CORP.INTERNAL\" cname \"alice\" sname \"MSSQLSvc/db-prod.corp.internal:1433\" etype 23 transport tcp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show kerberos_ad_detection_lab.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly kerberos_ad_detection_lab.frasm kerberos_ad_detection_lab.pcap\nframeassembly kerberos_ad_detection_lab.frasm kerberos_ad_detection_lab.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse kerberos_ad_detection_lab.pcap kerberos_ad_detection_lab_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r kerberos_ad_detection_lab.pcap -Y \"kerberos\"\n```\n\n## All `kerberos` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host kerberos [asreq | asrep | tgsreq |\ntgsrep | krberror] [realm \"<text>\"] [cname \"<text>\"] [sname \"<text>\"] [etype\n<number>] [transport <udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `asreq \\| asrep \\| tgsreq \\| tgsrep \\| krberror` | Kerberos v5 message type | `asreq (msg-type 10)` | Selects Authentication Service Request/Reply (`10`/`11`), Ticket-Granting Service Request/Reply (`12`/`13`), or Error (`30`). |\n| `realm \"<text>\"` | Quoted uppercase Kerberos realm (e.g. \"CORP.INTERNAL\") | `\"EXAMPLE.COM\"` | Encodes the `Realm` `GeneralString` inside the ASN.1 DER body. |\n| `cname \"<text>\" \\| sname \"<text>\"` | Quoted Client Principal Name or Service Principal Name (SPN) | `cname \"alice\", sname \"krbtgt/EXAMPLE.COM\"` | Encodes `PrincipalName` components in `KDC-REQ-BODY` / `KDC-REP`. |\n| `etype <number>` | RFC 3961 encryption ID (`18` AES256, `17` AES128, `23` RC4-HMAC; negative vendor IDs allowed) | `18 (aes256-cts-hmac-sha1-96)` | Sets the requested or encrypted-part `etype` integer. |\n| `transport <udp\\|tcp>` | `udp` or `tcp` | `udp` | Switches between UDP `88` and TCP `88` (with 4-byte RFC 4120 TCP length prefix). |\n\n## Cross-Layer Options Valid with `kerberos`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 88 (or TCP 88 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### No Hyphens in asreq, asrep, tgsreq, tgsrep, or krberror\n\n- **Avoid:** `domain_pc -> ad_dc01 kerberos tgs-req etype 23`\n- **Valid v3.3.0 Syntax:** `domain_pc -> ad_dc01 kerberos tgsreq etype 23`\n\nWrite Kerberos message types as single lowercase words without hyphens.\n"}
{"id":"pretrain-proto-ldap","kind":"protocol_spec","title":"Lightweight Directory Access Protocol v3 (ASN.1 BER) (ldap) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ldap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ldap"],"text":"# ldap — ASN.1 BER Directory Binds & AD Recon Search Filters (`ldap`)\n\n> **FrameAssembly v3.3.0** · Protocol 92 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ldap\n\n- **Full Protocol Name:** Lightweight Directory Access Protocol v3 (ASN.1 BER)\n- **Keyword:** `ldap`\n- **OSI Layer & Transport:** Layer 7 · TCP 389 (or CLDAP transport udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 4511\n- **Wireshark Display Filter:** `ldap`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 389 (or CLDAP transport udp) (transport tcp|udp) -> LDAPv3`\n\n## Overview\n\nTest Active Directory reconnaissance detections (`filter \"(adminCount=1)\"`) and\nanonymous bind alerts over TCP `389` with real ASN.1 BER sequences and zero Domain\nController required.\n\nLightweight Directory Access Protocol (`ldap`, RFC 4511) queries user accounts,\nsecurity groups, and organizational units in Microsoft Active Directory and\nOpenLDAP over **TCP port `389`** (or Global Catalog port `3268`). Unlike HTTP or\nSMTP, LDAP is a binary **ASN.1 BER** protocol.\n\nFrameAssembly encodes valid ASN.1 BER `LDAPMessage` sequences for `bindreq`,\n`bindres`, `searchreq`, `searchentry`, `searchdone`, and `unbindreq`—allowing\ncybersecurity teams to simulate BloodHound/SharpHound-style reconnaissance\nfilters, cleartext simple binds, or `resultcode 49` (`invalidCredentials`)\nfailures without running enumeration tools on a production domain.\n\n## Minimal Quickstart (`ldap_quickstart.frasm`)\n\n```frameassembly\nhost app_srv { ip 10.10.30.25 }\nhost dc01    { ip 10.10.0.10 }\n\ncompile {\n    app_srv -> dc01 tcp syn srcport 51389 dstport 389 wait 1ms\n    app_srv <- dc01 tcp syn ack wait 1ms\n    app_srv -> dc01 tcp ack wait 1ms\n    app_srv -> dc01 ldap bindreq msgid 1 basedn \"cn=svc_portal,ou=Services,dc=corp,dc=internal\" wait 2ms\n    app_srv <- dc01 ldap bindres msgid 1 resultcode 0\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `389` (`psh ack`) and wraps every operation in\n  an ASN.1 BER `SEQUENCE` (`0x30`) with exact definite-length tags.\n- Encodes RFC 4511 protocolOp tags (`0x60` BindRequest, `0x61` BindResponse,\n  `0x63` SearchRequest, `0x64` SearchResultEntry, `0x65` SearchResultDone, `0x42`\n  UnbindRequest).\n- Encodes LDAP search filters (`filter`) so Wireshark displays the Base DN and\n  filter expression cleanly.\n\n## Practical Lab Example: AD Bind Failure (`49`), Authorized Bind, Privileged Group Search & Unbind (`ldap_ad_search_audit.frasm`)\n\nCaptures a rejected bind (`resultcode 49`), a successful bind (`resultcode 0`), an\n`(adminCount=1)` privileged-account search returning an entry + `searchdone`, and\na clean `unbindreq`.\n\n```frameassembly\nhost jump_ws { ip 172.16.30.44 }\nhost ad_dc   { ip 172.16.1.10 }\n\ncompile {\n    jump_ws -> ad_dc tcp syn srcport 52389 dstport 389 win 65535 mss 1460 wait 1ms\n    jump_ws <- ad_dc tcp syn ack win 65535 mss 1460 wait 1ms\n    jump_ws -> ad_dc tcp ack wait 1ms\n    // 1. Failed Simple Bind -> resultcode 49 (invalidCredentials)\n    jump_ws -> ad_dc ldap bindreq msgid 1 basedn \"cn=backup_ro,dc=corp,dc=internal\" wait 2ms\n    jump_ws <- ad_dc ldap bindres msgid 1 resultcode 49 wait 5ms\n    // 2. Successful Bind -> Search privileged accounts -> Unbind\n    jump_ws -> ad_dc ldap bindreq msgid 2 basedn \"cn=backup_ro,dc=corp,dc=internal\" wait 2ms\n    jump_ws <- ad_dc ldap bindres msgid 2 resultcode 0 wait 2ms\n    jump_ws -> ad_dc ldap searchreq msgid 3 basedn \"dc=corp,dc=internal\" filter \"(adminCount=1)\" wait 3ms\n    jump_ws <- ad_dc ldap searchentry msgid 3 basedn \"cn=Domain Admins,cn=Users,dc=corp,dc=internal\" wait 1ms\n    jump_ws <- ad_dc ldap searchdone msgid 3 resultcode 0 wait 2ms\n    jump_ws -> ad_dc ldap unbindreq msgid 4\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ldap_ad_search_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ldap_ad_search_audit.frasm ldap_ad_search_audit.pcap\nframeassembly ldap_ad_search_audit.frasm ldap_ad_search_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ldap_ad_search_audit.pcap ldap_ad_search_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ldap_ad_search_audit.pcap -Y \"ldap\"\n```\n\n## All `ldap` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ldap [msgid <number>] [bindreq |\nbindres | searchreq | searchentry | searchdone | unbindreq] [basedn \"<text>\"]\n[filter \"<text>\"] [resultcode <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `bindreq \\| bindres \\| searchreq \\| searchentry \\| searchdone \\| unbindreq` | LDAPv3 protocol operation keyword | `searchreq` | Selects the ASN.1 BER `protocolOp` tag inside `LDAPMessage`. |\n| `msgid <number>` | LDAP MessageID integer (`1, 2, 3...`) | `1` | Correlates asynchronous LDAP requests (`searchreq`) with replies (`searchentry`, `searchdone`). |\n| `basedn \"<text>\"` | Quoted Distinguished Name (`\"dc=corp,dc=internal\"`) | `\"dc=example,dc=com\"` | Sets the Bind DN on `bindreq`, Base Object on `searchreq`, or Object Name on `searchentry`. |\n| `filter \"<text>\"` | Quoted LDAP search filter (`\"(objectClass=*)\"`, `\"(sAMAccountName=jdoe)\"`) | `\"(objectClass=*)\"` | Encodes the filter inside `searchreq` frames. |\n| `resultcode <number>` | RFC 4511 LDAPResult code (`0` success, `32` noSuchObject, `49` invalidCredentials, `50` insufficientAccessRights) | `0 (success)` | Sets the `ENUMERATED` result code in `bindres` and `searchdone` replies. |\n\n## Cross-Layer Options Valid with `ldap`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 389 (or CLDAP transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Match msgid Between Request and Response Pairs\n\n- **Valid v3.3.0 Syntax:** `a -> b ldap searchreq msgid 3 ...\na <- b ldap searchdone msgid 3 resultcode 0`\n\nIncrement `msgid` for each new request (`1`, `2`, `3`) and echo the same `msgid`\non its `bindres`, `searchentry`, and `searchdone` replies.\n"}
{"id":"pretrain-proto-smb","kind":"protocol_spec","title":"Server Message Block SMB2 & SMB3 File Sharing (smb) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/smb","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["smb"],"text":"# smb — Stateful TCP 445 SMB2/3 TreeConnect & Lateral Traces (`smb`)\n\n> **FrameAssembly v3.3.0** · Protocol 93 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/smb\n\n- **Full Protocol Name:** Server Message Block SMB2 & SMB3 File Sharing\n- **Keyword:** `smb`\n- **OSI Layer & Transport:** Layer 7 · TCP 445\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** MS-SMB2\n- **Wireshark Display Filter:** `smb2`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 445 -> SMB2 / SMB3`\n\n## Overview\n\nPort `445` is ground zero for east-west lateral movement (`\\\\filesrv\\IPC$`,\n`svcctl`, `ADMIN$`). `smb` packs the 4-byte NetBIOS session length + 64-byte\n`\\xfeSMB` header cleanly over stateful TCP.\n\nServer Message Block (`smb`, MS-SMB2) handles Windows file shares, domain `SYSVOL`\nGroup Policy delivery, and remote administration (`IPC$`, `ADMIN$`, `C$`) over\n**TCP port `445`**. Because lateral-movement tools (PsExec, Impacket, ransomware)\ntarget TCP `445`, East-West SMB monitoring is one of the highest-priority\ndetections in every SOC.\n\nFrameAssembly prepends the 4-byte NetBIOS Session Service length header plus the\n64-byte `þSMB` SMB2/3 header, encodes UTF-16LE UNC paths (`share`) and file paths\n(`filename`), and sets `SMB2_FLAGS_SERVER_TO_REDIRECTOR` automatically on `<-`\nreplies or NTSTATUS error responses.\n\n## Minimal Quickstart (`smb_quickstart.frasm`)\n\n```frameassembly\nhost client_pc { ip 10.10.20.31 }\nhost file_srv  { ip 10.10.1.45 }\n\ncompile {\n    client_pc -> file_srv tcp syn srcport 51445 dstport 445 wait 1ms\n    client_pc <- file_srv tcp syn ack wait 1ms\n    client_pc -> file_srv tcp ack wait 1ms\n    client_pc -> file_srv smb negotiate msgid 0 wait 1ms\n    client_pc <- file_srv smb negotiate msgid 0 status 0 wait 2ms\n    client_pc -> file_srv smb treeconnect sessionid 0x1001 msgid 1 share \"\\\\\\\\file_srv\\\\Engineering\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `445` (`psh ack`) and prepends the 4-byte\n  big-endian NetBIOS Session length header (`0x00` + 24-bit size).\n- Builds the full 64-byte `þSMB` header (`StructureSize = 64`, `Command`,\n  `NTSTATUS`, `MessageId`, `TreeId`, `SessionId`) and sets the Server-to-Client\n  flag on `<-` replies.\n- Encodes `share` UNC strings and `filename` strings in Windows little-endian\n  UTF-16LE automatically.\n\n## Practical Lab Example: SMB2 Login Failure (`0xc000006d`) + Administrative `ADMIN$` Named-Pipe Access (`smb_lateral_movement_lab.frasm`)\n\nCompletes TCP 445 setup, captures a failed `sessionsetup`, then connects to\n`\\\\srv01\\ADMIN$` and opens a remote file handle (`create` + `read` + `close`).\n\n```frameassembly\nhost admin_pc { ip 172.16.20.55 }\nhost srv_01   { ip 172.16.10.45 }\n\ncompile {\n    admin_pc -> srv_01 tcp syn srcport 52445 dstport 445 win 65535 mss 1460 wait 1ms\n    admin_pc <- srv_01 tcp syn ack win 65535 mss 1460 wait 1ms\n    admin_pc -> srv_01 tcp ack wait 1ms\n    // 1. SMB2 Negotiate + Failed SessionSetup (STATUS_LOGON_FAILURE = 0xc000006d)\n    admin_pc -> srv_01 smb negotiate msgid 0 wait 1ms\n    admin_pc <- srv_01 smb negotiate msgid 0 status 0 wait 1ms\n    admin_pc -> srv_01 smb sessionsetup msgid 1 wait 2ms\n    admin_pc <- srv_01 smb sessionsetup msgid 1 status 0xc000006d wait 5ms\n    // 2. Successful SessionSetup + ADMIN$ TreeConnect + Create/Read/Close\n    admin_pc -> srv_01 smb sessionsetup msgid 2 sessionid 0x400001 wait 1ms\n    admin_pc <- srv_01 smb sessionsetup msgid 2 sessionid 0x400001 status 0 wait 1ms\n    admin_pc -> srv_01 smb treeconnect msgid 3 sessionid 0x400001 share \"\\\\\\\\srv_01\\\\ADMIN$\" wait 2ms\n    admin_pc <- srv_01 smb treeconnect msgid 3 sessionid 0x400001 treeid 1 status 0 wait 1ms\n    admin_pc -> srv_01 smb create msgid 4 sessionid 0x400001 treeid 1 filename \"System32\\\\drivers\\\\etc\\\\hosts\" wait 2ms\n    admin_pc <- srv_01 smb create msgid 4 sessionid 0x400001 treeid 1 status 0 wait 1ms\n    admin_pc -> srv_01 smb treedisconnect msgid 5 sessionid 0x400001 treeid 1\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show smb_lateral_movement_lab.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly smb_lateral_movement_lab.frasm smb_lateral_movement_lab.pcap\nframeassembly smb_lateral_movement_lab.frasm smb_lateral_movement_lab.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse smb_lateral_movement_lab.pcap smb_lateral_movement_lab_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r smb_lateral_movement_lab.pcap -Y \"smb2\"\n```\n\n## All `smb` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host smb [negotiate | sessionsetup |\ntreeconnect | treedisconnect | create | close | read | write | logoff | command\n\"<text>\"] [status <hex_or_num>] [treeid <number>] [sessionid <hex_or_num>] [msgid\n<number>] [share \"<unc_path>\"] [filename \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `negotiate \\| sessionsetup \\| treeconnect \\| treedisconnect \\| create \\| close \\| read \\| write \\| logoff` | SMB2/3 command keyword (or `command \"<text>\"`) | `negotiate (0x0000)` | Selects the 16-bit MS-SMB2 command (`0x00` Negotiate, `0x01` SessionSetup, `0x02` Logoff, `0x03` TreeConnect, `0x04` TreeDisconnect, `0x05` Create, `0x06` Close, `0x08` Read, `0x09` Write). |\n| `status <hex_or_num>` | 32-bit NTSTATUS code (`0` STATUS_SUCCESS, `0xc000006d` LOGON_FAILURE, `0xc0000022` ACCESS_DENIED) | `0 (STATUS_SUCCESS)` | Sets bytes 8..11 (`Status`) of the 64-byte SMB2 header. |\n| `sessionid <hex_or_num> \\| treeid <number> \\| msgid <number>` | 64-bit SessionId, 32-bit TreeId, 64-bit MessageId | `0` | Links SMB2 requests and replies across authenticated sessions and mounted shares. |\n| `share \"<unc_path>\"` | Quoted UNC share path (`\"\\\\server\\IPC$\"`) | `\"\\\\server\\IPC$\" on treeconnect` | Encodes the UTF-16LE share path inside `treeconnect` requests. |\n| `filename \"<text>\"` | Quoted file or pipe name | `\"test.txt\" on create` | Encodes the UTF-16LE target filename inside `create` requests. |\n\n## Cross-Layer Options Valid with `smb`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 445` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 445)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Escape Backslashes in UNC Share Paths (\"\\\\\\\\srv\\\\IPC$\")\n\n- **Avoid:** `client_pc -> file_srv smb treeconnect share \"\\srv\\IPC$\"`\n- **Valid v3.3.0 Syntax:** `client_pc -> file_srv smb treeconnect share\n  \"\\\\srv\\IPC$\"`\n\nEach `\\\\` in a double-quoted `.frasm` string writes one literal `\\` character, so\n`\"\\\\srv\\IPC$\"` produces `\\srvIPC$` on the wire (or `\"\\\\\\\\srv\\\\IPC$\"` for double\nleading slashes `\\\\srv\\IPC$`).\n\n### Wireshark Filter for SMB2/3 Is smb2 (Not smb)\n\n- **Valid v3.3.0 Syntax:** `Wireshark display filter: smb2`\n\nIn Wireshark, `smb` filters legacy 1990s SMBv1 (`ÿSMB`), while modern SMB2 and\nSMB3 (`þSMB`) use the `smb2` display filter.\n"}
{"id":"pretrain-proto-nfs","kind":"protocol_spec","title":"Network File System over ONC RPC (nfs) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/nfs","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["nfs"],"text":"# nfs — Port 2049 ONC RPC Record-Marking & NFSv4 COMPOUND (`nfs`)\n\n> **FrameAssembly v3.3.0** · Protocol 94 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/nfs\n\n- **Full Protocol Name:** Network File System over ONC RPC\n- **Keyword:** `nfs`\n- **OSI Layer & Transport:** Layer 7 · TCP 2049 (or UDP 2049 via transport udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 7530, RFC 8881, RFC 1813\n- **Wireshark Display Filter:** `nfs || rpc`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 2049 (or UDP 2049 via transport udp) (transport tcp|udp) -> NFSv3 / v4`\n\n## Overview\n\nVerify storage-VLAN segmentation on port `2049`: over default TCP, FrameAssembly\nautomatically prepends the 4-byte ONC RPC Record-Marking fragment header\n(`0x80000000 | len`) so Wireshark dissects NFSv4 `COMPOUND` calls cleanly.\n\nNetwork File System (`nfs`, RFC 7530 / RFC 1813) mounts shared NAS volumes across\nLinux, VMware ESXi, and Kubernetes nodes on **port `2049`** (ONC RPC Program\n`100003`). Unlike legacy NFSv3 setups requiring separate portmapper ports, modern\n**NFSv4** (`vers 4`, default) consolidates mounting, locking, and file operations\ninside single `compound` RPC calls over **TCP port `2049`** (with `transport udp`\navailable for UDP `2049` legacy tests).\n\nFrameAssembly builds the ONC RPC v2 Call/Reply header (including the 4-byte\nLast-Fragment Record Marking header over TCP), XDR-padded UTF-8 `tag` and export\n`path` strings, and NFSv4 `PUTFH` / `LOOKUP` operations automatically.\n\n## Minimal Quickstart (`nfs_quickstart.frasm`)\n\n```frameassembly\nhost esxi_node { ip 10.40.10.21 }\nhost nas_filer { ip 10.40.10.100 }\n\ncompile {\n    esxi_node -> nas_filer tcp syn srcport 892 dstport 2049 wait 1ms\n    esxi_node <- nas_filer tcp syn ack wait 1ms\n    esxi_node -> nas_filer tcp ack wait 1ms\n    esxi_node -> nas_filer nfs vers 4 compound xid 0x55001122 tag \"lookup-datastore\" path \"/vol/vmstore01\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `2049` (`vers 4`, RPC Program `100003`) and\n  prepends the 4-byte ONC RPC Record Marking header (`0x80000000 | length`) over\n  TCP (omitting it cleanly when `transport udp` is selected).\n- Aligns `tag` and `path` UTF-8 strings to 4-byte XDR boundaries per RFC 4506.\n- Uses privileged client ports easily (`srcport 892`) when testing `root_squash` /\n  `insecure` NFS export rules.\n\n## Practical Lab Example: NFSv4 TCP 2049 Export Lookup + Legacy NFSv3 UDP Probe (`nfs_storage_audit.frasm`)\n\nOpens TCP port 2049 from a privileged source port (`srcport 850`) to mount\n`/exports/backups`, then tests a legacy NFSv3 `NULL` ping over UDP 2049.\n\n```frameassembly\nhost worker_01 { ip 172.16.40.25 }\nhost netapp_01 { ip 172.16.40.200 }\n\ncompile {\n    // 1. Stateful NFSv4 COMPOUND over TCP 2049 from privileged port 850 (< 1024)\n    worker_01 -> netapp_01 tcp syn srcport 850 dstport 2049 win 65535 mss 1460 wait 1ms\n    worker_01 <- netapp_01 tcp syn ack win 65535 mss 1460 wait 1ms\n    worker_01 -> netapp_01 tcp ack wait 1ms\n    worker_01 -> netapp_01 nfs vers 4 compound xid 0x7001 tag \"mount-backups\" path \"/exports/backups\" wait 3ms\n    // 2. Legacy NFSv3 NULL RPC check over UDP 2049\n    worker_01 -> netapp_01 nfs vers 3 proc \"NULL\" xid 0x7002 transport udp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show nfs_storage_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly nfs_storage_audit.frasm nfs_storage_audit.pcap\nframeassembly nfs_storage_audit.frasm nfs_storage_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse nfs_storage_audit.pcap nfs_storage_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r nfs_storage_audit.pcap -Y \"nfs || rpc\"\n```\n\n## All `nfs` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host nfs [vers <3|4>] [compound | proc\n\"<text>\"] [tag \"<text>\"] [path \"<text>\"] [xid <hex_or_num>] [transport <tcp|udp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `vers <3\\|4>` | NFS protocol version (`4` default, or `3`) | `4` | Sets the ONC RPC Program Version (`4` or `3`) for Program `100003`. |\n| `compound \\| proc \"<text>\"` | `compound` or procedure name (`\"NULL\"`, `\"GETATTR\"`, `\"LOOKUP\"`, `\"READ\"`, `\"WRITE\"`) | `compound` | Selects RPC procedure `1` (`COMPOUND` on NFSv4) or named NFSv3/v4 procedure. |\n| `tag \"<text>\" \\| path \"<text>\"` | Quoted NFSv4 compound tag and export path | `tag \"fa\", path \"/export\"` | Encodes XDR length-prefixed `tag` and `LOOKUP` component path inside NFSv4 `COMPOUND`. |\n| `xid <hex_or_num>` | 32-bit ONC RPC Transaction ID | `0x12345678` | Sets the 4-byte RPC `XID` matching RPC replies to calls. |\n| `transport <tcp\\|udp>` | `tcp` or `udp` | `tcp` | Switches between TCP `2049` (with 4-byte RPC record mark) and UDP `2049`. |\n\n## Cross-Layer Options Valid with `nfs`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 2049 (or UDP 2049 via transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### NFS Defaults to TCP (Unlike DNS/Syslog Which Default to UDP)\n\n- **Valid v3.3.0 Syntax:** `worker_01 -> netapp_01 nfs vers 3 proc \"NULL\"\n  transport udp`\n\n`nfs` defaults to `transport tcp` on port `2049` because RFC 7530 NFSv4 mandates\nTCP; add `transport udp` explicitly when testing UDP.\n"}
{"id":"pretrain-proto-iscsi","kind":"protocol_spec","title":"Internet Small Computer Systems Interface Block SAN (iscsi) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/iscsi","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["iscsi"],"text":"# iscsi — Port 3260 48-Byte BHS Login, SCSI Read/Write & NOPs (`iscsi`)\n\n> **FrameAssembly v3.3.0** · Protocol 95 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/iscsi\n\n- **Full Protocol Name:** Internet Small Computer Systems Interface Block SAN\n- **Keyword:** `iscsi`\n- **OSI Layer & Transport:** Layer 7 · TCP 3260\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 7143, RFC 3720, SAM-5\n- **Wireshark Display Filter:** `iscsi`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 3260 -> iSCSI (RFC 7143)`\n\n## Overview\n\nEvery iSCSI PDU starts with a strict 48-byte Basic Header Segment on TCP `3260` —\n`iscsi` builds IQN `login` key-value pairs, `lun`-addressed SCSI commands,\n`itt`/`cmdsn`/`statsn` counters, and `nop` keepalives.\n\nInternet Small Computer Systems Interface (`iscsi`, RFC 7143 / RFC 3720)\ntransports block-level SCSI commands, NVMe/hypervisor datastore I/O, and cluster\nshared volumes across IP storage networks on **TCP port `3260`**. Every iSCSI\nProtocol Data Unit begins with a **48-byte Basic Header Segment (BHS)** containing\na 6-bit `Opcode` (plus `I` Immediate bit), `Flags` (`Final` `0x80`,\n`Read`/`Write`, `Transit`/`Continue`), 24-bit `DataSegmentLength` (padded to\n4-byte boundaries), 64-bit `LUN`, `Initiator Task Tag (itt)`, `CmdSN`, `ExpStatSN`\n/ `StatSN`, and 16-byte SCSI Command Descriptor Blocks (CDBs) or `key=value`\nLogin/Text operational parameters.\n\nFrameAssembly packs exact 48-byte BHS frames + 4-byte padded `InitiatorName` /\n`TargetName` IQN text segments over stateful 4-tuple TCP (`3260`).\n\n## Minimal Quickstart (`iscsi_quickstart.frasm`)\n\n```frameassembly\nhost esxi_host  { ip 10.70.20.11 }\nhost san_target { ip 10.70.20.50 }\n\ncompile {\n    esxi_host -> san_target tcp syn srcport 51320 dstport 3260 win 65535 mss 8960 wait 1ms\n    esxi_host <- san_target tcp syn ack win 65535 mss 8960 wait 1ms\n    esxi_host -> san_target tcp ack wait 1ms\n    esxi_host -> san_target iscsi login initiator \"iqn.2026-01.corp.vm:esxi01\" target \"iqn.2026-01.corp.san:datastore01\" itt 1 cmdsn 1 wait 2ms\n    esxi_host <- san_target iscsi response opcode 0x23 itt 1 statsn 1 status 0\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `3260` (`psh ack`, automatic `seq`/`acknum`\n  progression across 48-byte BHS + padded data segments).\n- Formats null-delimited `InitiatorName=<iqn>` and `TargetName=<iqn>` operational\n  key-value pairs on `login` (`0x03`), writing unpadded `DataSegmentLength` into\n  BHS bytes 5..7 while zero-padding the wire segment to 4-byte alignment.\n- Populates 10-byte SCSI `READ(10)` (`0x28`) and `WRITE(10)` (`0x2a`) CDBs inside\n  `SCSI Command` (`0x01`) BHS headers using `lun` and `offset` LBA.\n\n## Practical Lab Example: Storage VLAN 200 iSCSI Session Login, SCSI READ(10) Data-In & NOP-Out Ping (`iscsi_san_read_cycle.frasm`)\n\nEstablishes an iSCSI Full Feature Phase session over VLAN `200`, executes a SCSI\n`READ` on `LUN 1` (`offset 4096`), returns `SCSI Data-In` (`0x25`) with status\ncompletion, and exchanges `NOP-Out` / `NOP-In` keepalives.\n\n```frameassembly\nhost hv_node01 { ip 172.18.200.11 mac 00:25:b5:01:00:11 }\nhost flash_san { ip 172.18.200.80 mac 00:25:b5:02:00:80 }\n\ncompile {\n    hv_node01 -> flash_san tcp syn srcport 54320 dstport 3260 vlan 200 pcp 4 df wait 1ms\n    hv_node01 <- flash_san tcp syn ack vlan 200 pcp 4 df wait 1ms\n    hv_node01 -> flash_san tcp ack vlan 200 pcp 4 df wait 1ms\n    // 1. iSCSI Login Request (0x03) -> Login Response (0x23, StatusClass=0 Success)\n    hv_node01 -> flash_san iscsi login initiator \"iqn.2026-01.internal.hv:node01\" target \"iqn.2026-01.internal.san:lun-db01\" itt 0x1001 cmdsn 1 vlan 200 pcp 4 wait 2ms\n    hv_node01 <- flash_san iscsi response opcode 0x23 itt 0x1001 statsn 1 status 0 vlan 200 pcp 4 wait 2ms\n    // 2. SCSI READ(10) Command on LUN 1 at LBA 4096 -> Data-In (0x25) + SCSI Response (0x21)\n    hv_node01 -> flash_san iscsi read lun 1 itt 0x1002 cmdsn 2 statsn 1 offset 4096 vlan 200 pcp 4 wait 1ms\n    hv_node01 <- flash_san iscsi data opcode 0x25 lun 1 itt 0x1002 statsn 2 payload \"BLOCK-SECTOR-4096-DATA\" vlan 200 pcp 4 wait 1ms\n    hv_node01 <- flash_san iscsi response lun 1 itt 0x1002 statsn 3 status 0 vlan 200 pcp 4 wait 10ms\n    // 3. iSCSI NOP-Out (0x00) -> NOP-In (0x20) storage fabric liveness check\n    hv_node01 -> flash_san iscsi nop itt 0x1003 cmdsn 3 statsn 3 vlan 200 pcp 4 wait 1ms\n    hv_node01 <- flash_san iscsi response opcode 0x20 itt 0x1003 statsn 4 vlan 200 pcp 4\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show iscsi_san_read_cycle.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly iscsi_san_read_cycle.frasm iscsi_san_read_cycle.pcap\nframeassembly iscsi_san_read_cycle.frasm iscsi_san_read_cycle.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse iscsi_san_read_cycle.pcap iscsi_san_read_cycle_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r iscsi_san_read_cycle.pcap -Y \"iscsi\"\n```\n\n## All `iscsi` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host iscsi [login | logout | read | write |\nnop | response | data | text | cmd \"<text>\"] [opcode <0..63>] [initiator \"<text>\"]\n[target \"<text>\"] [lun <0..65535>] [itt <number>] [cmdsn <number>] [statsn\n<number>] [status <0..255>] [flags <0..255>] [offset <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `login \\| logout \\| read \\| write \\| nop \\| response \\| data \\| text \\| cmd \"<text>\"` | iSCSI BHS PDU type shorthand | `nop (0x00)` | Selects `0x00` NOP-Out, `0x01` SCSI Command (`read`/`write`), `0x03` Login Request, `0x04` Text Request, `0x05` SCSI Data-Out, `0x06` Logout, `0x21` SCSI Response, `0x23` Login Response, or `0x25` SCSI Data-In. |\n| `opcode <0..63>` | 6-bit RFC 7143 BHS Opcode override | `Derived from command keyword` | Explicitly sets byte 0 (`0x20` NOP-In, `0x21` SCSI Resp, `0x23` Login Resp, `0x24` Text Resp, `0x25` Data-In, `0x31` R2T). |\n| `initiator \"<text>\" \\| target \"<text>\"` | iSCSI Qualified Name (IQN / EUI) strings | `\"iqn.2026-01.com.example:initiator\" / \"...:target\"` | Appends `InitiatorName=\"<text>\"` and `TargetName=\"<text>\"` key-value pairs in Login/Text DataSegments. |\n| `lun <0..65535>` | 16-bit single-level Logical Unit Number | `0` | Writes the big-endian LUN in bytes 8..15 of the 48-byte BHS. |\n| `itt <number> \\| cmdsn <number> \\| statsn <number>` | 32-bit Initiator Task Tag, Command SeqNum, and Status SeqNum | `itt 1, cmdsn 1, statsn 1` | Populates BHS bytes 16..19 (`ITT`) and 24..31 (`CmdSN` / `ExpStatSN` / `StatSN`). |\n| `status <0..255> \\| flags <0..255> \\| offset <number>` | 8-bit SCSI Status (`0x00` Good, `0x02` Check Cond), BHS Flags, and 32-bit LBA/Buffer Offset | `status 0, flags 0x80 (Final), offset 0` | Sets BHS byte 1 (`flags`), byte 3 (`status`), and CDB LBA or Data-In/Out `Buffer Offset`. |\n\n## Cross-Layer Options Valid with `iscsi`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 3260` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 3260)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Match Initiator Task Tag (itt) Across Command, Data, and Response PDUs\n\n- **Valid v3.3.0 Syntax:** `h -> s iscsi read lun 1 itt 0x42\nh <- s iscsi response lun 1 itt 0x42 status 0`\n\nWireshark’s `iscsi` dissector uses the 32-bit `Initiator Task Tag (itt)` to link a\nSCSI Command (`0x01`) with its Data-In/Out and Response PDUs and compute SAN I/O\nlatency.\n\n### Target-to-Initiator Opcodes Set Bit 0x20\n\n- **Valid v3.3.0 Syntax:** `h <- s iscsi response opcode 0x23 itt 1 statsn 1\n  status 0`\n\nIn RFC 7143, initiator-to-target opcodes occupy `0x00..0x1f` (`0x03` Login Req)\nwhile target-to-initiator opcodes add `0x20` (`0x20` NOP-In, `0x21` SCSI Resp,\n`0x23` Login Resp, `0x25` Data-In).\n"}
{"id":"pretrain-proto-nvmetcp","kind":"protocol_spec","title":"NVM Express over Fabrics TCP Transport (TP 8000) (nvmetcp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/nvmetcp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["nvmetcp"],"text":"# nvmetcp — Port 4420 NVMe/TCP ICReq/ICResp & Fabrics Capsules (`nvmetcp`)\n\n> **FrameAssembly v3.3.0** · Protocol 96 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/nvmetcp\n\n- **Full Protocol Name:** NVM Express over Fabrics TCP Transport (TP 8000)\n- **Keyword:** `nvmetcp`\n- **OSI Layer & Transport:** Layer 7 · TCP 4420\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** NVM Express TCP Transport 1.0c, NVMe Base Spec 2.0\n- **Wireshark Display Filter:** `nvme-tcp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 4420 -> NVMe/TCP (NVMe-oF)`\n\n## Overview\n\nDisaggregated NVMe-oF storage over standard Ethernet on TCP `4420`: `nvmetcp`\nemits 128-byte `icreq`/`icresp` connection handshakes plus 72-byte NVMe\nSubmission/Completion Capsules (`nsid`, `qid`, `offset`, `count`).\n\nNVMe over TCP (`nvmetcp`, NVM Express TCP Transport Specification) delivers\ndisaggregated NVMe SSD block storage across standard Ethernet data centers on\n**TCP port `4420`** without requiring lossless RDMA NICs. Every NVMe/TCP PDU\nstarts with an **8-byte Common Header** (`PDU Type`, `Flags`, `Header Length HL`,\n`Payload Data Offset PDO`, and little-endian 32-bit `Packet Length PLEN`),\nbeginning each queue TCP connection with a 128-byte **`ICReq` (`0x00`) <->\n`ICResp` (`0x01`)** Initialize Connection handshake before exchanging 64-byte\n**`CapsuleCmd` (`0x04`)**, **`CapsuleResp` (`0x05`)**, **`H2CData` (`0x06`)**,\n**`C2HData` (`0x07`)**, and **`R2T` (`0x09`)** PDUs.\n\nFrameAssembly encodes exact little-endian NVMe/TCP headers, 128-byte\n`ICReq`/`ICResp` structures, 64-byte NVMe Submission Queue Entries (`NSID`,\n`Command ID`, `SLBA`, `NLB`), and 16-byte Completion Queue Entries (`Status`,\n`QID`, `Command ID`).\n\n## Minimal Quickstart (`nvmetcp_quickstart.frasm`)\n\n```frameassembly\nhost k8s_worker  { ip 10.80.44.11 }\nhost nvme_target { ip 10.80.44.50 }\n\ncompile {\n    k8s_worker -> nvme_target tcp syn srcport 52420 dstport 4420 win 65535 mss 8960 wait 1ms\n    k8s_worker <- nvme_target tcp syn ack win 65535 mss 8960 wait 1ms\n    k8s_worker -> nvme_target tcp ack wait 1ms\n    k8s_worker -> nvme_target nvmetcp icreq wait 1ms\n    k8s_worker <- nvme_target nvmetcp icresp wait 2ms\n    k8s_worker -> nvme_target nvmetcp read qid 1 reqid 10 nsid 1 offset 0 count 8 wait 1ms\n    k8s_worker <- nvme_target nvmetcp response qid 1 reqid 10 status 0\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `4420` and calculates little-endian `HL` (Header\n  Length), `PDO` (Payload Data Offset), and 32-bit `PLEN` (Total PDU Length)\n  automatically for every PDU type.\n- Emits full 128-byte `ICReq` (`0x00`) and `ICResp` (`0x01`)\n  connection-initialization frames (`PFFORMAT = 0`, `MAXR2T` / `MAXH2CDATA`)\n  required by Wireshark’s `nvme-tcp` state tracker.\n- Encodes 64-byte NVMe SQE capsules (`0x01` Write, `0x02` Read, `0x7f` Fabrics\n  Connect) and 16-byte CQE responses (`Status << 1 | Phase`).\n\n## Practical Lab Example: NVMe/TCP I/O Queue Bring-Up: ICReq/ICResp, NVMe Write (R2T + H2CData) & NVMe Read (C2HData) (`nvmetcp_io_queue_flow.frasm`)\n\nInitializes an NVMe/TCP queue on TCP `4420`, performs a Ready-to-Transfer (`R2T`)\nhost-to-controller write to Namespace `1`, and reads blocks back via\nController-to-Host Data (`C2HData`).\n\n```frameassembly\nhost spdk_init { ip 172.29.44.10 }\nhost jbof_tgt  { ip 172.29.44.80 }\n\ncompile {\n    spdk_init -> jbof_tgt tcp syn srcport 53420 dstport 4420 dscp 26 df wait 1ms\n    spdk_init <- jbof_tgt tcp syn ack dscp 26 df wait 1ms\n    spdk_init -> jbof_tgt tcp ack dscp 26 df wait 1ms\n    // 1. 128-byte Initialize Connection Request (0x00) & Response (0x01)\n    spdk_init -> jbof_tgt nvmetcp icreq wait 1ms\n    spdk_init <- jbof_tgt nvmetcp icresp wait 2ms\n    // 2. NVMe Write CapsuleCmd (Opcode 0x01) -> Target R2T (0x09) -> Host H2CData (0x06) -> CapsuleResp (0x05)\n    spdk_init -> jbof_tgt nvmetcp write qid 1 reqid 101 nsid 1 offset 2048 count 8 wait 1ms\n    spdk_init <- jbof_tgt nvmetcp r2t reqid 101 offset 0 count 4096 wait 1ms\n    spdk_init -> jbof_tgt nvmetcp h2cdata reqid 101 offset 0 payload \"NVME-4K-PAGE-PAYLOAD\" flags 0x04 wait 1ms\n    spdk_init <- jbof_tgt nvmetcp response qid 1 reqid 101 status 0 wait 3ms\n    // 3. NVMe Read CapsuleCmd (Opcode 0x02) -> Controller C2HData (0x07, LAST_PDU|SUCCESS)\n    spdk_init -> jbof_tgt nvmetcp read qid 1 reqid 102 nsid 1 offset 2048 count 8 wait 1ms\n    spdk_init <- jbof_tgt nvmetcp c2hdata reqid 102 offset 0 payload \"NVME-4K-PAGE-PAYLOAD\" flags 0x0c wait 1ms\n    spdk_init <- jbof_tgt nvmetcp response qid 1 reqid 102 status 0\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show nvmetcp_io_queue_flow.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly nvmetcp_io_queue_flow.frasm nvmetcp_io_queue_flow.pcap\nframeassembly nvmetcp_io_queue_flow.frasm nvmetcp_io_queue_flow.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse nvmetcp_io_queue_flow.pcap nvmetcp_io_queue_flow_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r nvmetcp_io_queue_flow.pcap -Y \"nvme-tcp\"\n```\n\n## All `nvmetcp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host nvmetcp [icreq | icresp | read | write\n| response | h2cdata | c2hdata | r2t | msgtype \"<text>\" | cmd \"<text>\"] [opcode\n<0..255>] [nsid <number>] [qid <0..65535>] [reqid <0..65535>] [flags <0..255>]\n[status <0..65535>] [offset <number>] [count <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `icreq \\| icresp \\| read \\| write \\| response \\| h2cdata \\| c2hdata \\| r2t \\| msgtype \"<text>\" \\| cmd \"<text>\"` | NVMe/TCP PDU Type or NVMe Command selector | `icreq (0x00)` | Selects `0x00` ICReq, `0x01` ICResp, `0x04` CapsuleCmd (`read` NVMe `0x02`, `write` NVMe `0x01`), `0x05` CapsuleResp, `0x06` H2CData, `0x07` C2HData, or `0x09` R2T. |\n| `opcode <0..255>` | 8-bit NVMe SQE Opcode override | `0x02 (Read) / 0x01 (Write) / 0x06 (Identify)` | Sets byte 0 of the 64-byte NVMe Submission Queue Entry inside `CapsuleCmd`. |\n| `nsid <number>` | 32-bit NVMe Namespace Identifier (`1..0xffffffff`) | `1` | Writes little-endian `NSID` in bytes 4..7 of the NVMe SQE. |\n| `qid <0..65535> \\| reqid <0..65535>` | 16-bit Queue ID (`0` Admin, `1+` I/O) & Command ID (`CID`) | `qid 1, reqid 1` | Writes the 16-bit `Command ID` (`CID`) and Completion `SQID` correlating capsules and data PDUs. |\n| `offset <number> \\| count <number>` | Starting LBA / Data Offset and Block / Byte Transfer Count | `offset 0, count 1 (or payload len)` | Sets SQE `SLBA` + `NLB` on `read`/`write`, or `DATAO` + `DATAL` on `h2cdata`/`c2hdata`/`r2t`. |\n| `flags <0..255> \\| status <0..65535>` | 8-bit PDU Header Flags (`0x04` LAST_PDU, `0x08` SUCCESS) & 15-bit NVMe CQE Status | `flags 0, status 0 (Success)` | Sets Common Header byte 1 (`FLAGS`) and CQE Status Field (`0` = Successful Completion). |\n\n## Cross-Layer Options Valid with `nvmetcp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 4420` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 4420)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Begin NVMe/TCP Captures with icreq and icresp for Full Wireshark Dissection\n\n- **Valid v3.3.0 Syntax:** `init -> tgt nvmetcp icreq\ninit <- tgt nvmetcp icresp\ninit -> tgt nvmetcp read nsid 1`\n\nWireshark’s `nvme-tcp` dissector learns PDU alignment and digest settings from the\ninitial `ICReq`/`ICResp` exchange on TCP `4420`.\n\n### Keep reqid Consistent Across CapsuleCmd, R2T/Data, and CapsuleResp\n\n- **Valid v3.3.0 Syntax:** `init -> tgt nvmetcp read reqid 7 nsid 1\ninit <- tgt nvmetcp response reqid 7 status 0`\n\n`reqid` populates the 16-bit NVMe Command Identifier (`CID`) used to match\nasynchronous data transfers and completions.\n"}
{"id":"pretrain-proto-rocev2","kind":"protocol_spec","title":"RDMA over Converged Ethernet v2 (InfiniBand Annex A17) (rocev2) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/rocev2","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["rocev2"],"text":"# rocev2 — UDP 4791 InfiniBand BTH/RETH/AETH & Variant ICRC-32 (`rocev2`)\n\n> **FrameAssembly v3.3.0** · Protocol 97 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/rocev2\n\n- **Full Protocol Name:** RDMA over Converged Ethernet v2 (InfiniBand Annex A17)\n- **Keyword:** `rocev2`\n- **OSI Layer & Transport:** Layer 7 · UDP 4791\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** IBTA RoCEv2 Annex A17, InfiniBand Arch Vol 1\n- **Wireshark Display Filter:** `infiniband`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 4791 -> RoCEv2 (InfiniBand BTH)`\n\n## Overview\n\nAI GPU cluster fabrics live on UDP `4791` paired with `dscp 26` + `ecn 2` and\n`pfc`: `rocev2` packs the 12-byte InfiniBand BTH (`destqp`, `seqnum`), 16-byte\nRETH (`addr`, `key`, `count`), and 4-byte Invariant CRC (`crc`) automatically!\n\nRDMA over Converged Ethernet v2 (`rocev2`, IBTA Annex A17) powers **AI/LLM GPU\ntraining fabrics (NCCL collective all-reduce)**, **NVMe-oF/RDMA storage**, and\nultra-low-latency HPC clusters by encapsulating **InfiniBand Base Transport\nHeaders (BTH)** inside **IPv4/IPv6 + UDP port `4791`**. Every RoCEv2 packet\ncarries a 12-byte **BTH** (`OpCode`, `Solicited/Migrate/Pad`, `Partition Key\npkey`, 24-bit `Destination Queue Pair destqp`, `Acknowledge Request ackreq`, and\n24-bit `Packet Sequence Number seqnum`), optional **RETH** (`64-bit Virtual\nAddress addr`, `32-bit R_Key key`, `32-bit DMA Length count`) or **AETH**\n(`Syndrome/Status`, `24-bit Message SeqNum msgid`), payload, and a trailing\n**4-byte Invariant CRC (`ICRC`)**.\n\nFrameAssembly computes the InfiniBand Annex A17 **RoCEv2 ICRC** (masking mutable\nIP TTL/DSCP/ECN, UDP checksum, and BTH Resv8a bits to `1`s per spec!)\nautomatically and lets you pair `rocev2` with `dscp 26 ecn 3` (CE) and Layer 2\n`pfc` pause frames for end-to-end DCQCN lossless fabric labs.\n\n## Minimal Quickstart (`rocev2_quickstart.frasm`)\n\n```frameassembly\nhost gpu_node_01 { ip 10.90.3.11 }\nhost gpu_node_02 { ip 10.90.3.12 }\n\ncompile {\n    gpu_node_01 -> gpu_node_02 rocev2 write pkey 0xffff destqp 0x000104 ackreq seqnum 1000 addr 0x7f8000100000 key 0xa1b2c3d4 count 4096 dscp 26 ecn 2 payload \"NCCL-ALLREDUCE-SHARD\" wait 50us\n    gpu_node_01 <- gpu_node_02 rocev2 opcode \"ack\" pkey 0xffff destqp 0x000103 seqnum 1000 status 0x00 msgid 1 dscp 26 ecn 2\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `4791` (`srcport` entropy for ECMP hashing) and\n  writes the 12-byte InfiniBand Base Transport Header (`BTH`).\n- Attaches the 16-byte RDMA Extended Transport Header (`RETH`: `va`, `rkey`,\n  `dma_len`) on RC RDMA `write` (`0x0a`) / `read` (`0x0c`), or the 4-byte `AETH`\n  (`syndrome`, `msn`) on `ack` (`0x11`) / Read Responses.\n- Computes the genuine IEEE 802.3 CRC-32 **IBTA Annex A17 Invariant CRC (`ICRC`)**\n  over the masked pseudo-IP + UDP + BTH + payload automatically (unless `crc` is\n  overridden).\n\n## Practical Lab Example: AI Training Cluster DCQCN Loop: ECN-Marked RDMA Write, RoCEv2 CNP (0x81) & RC ACK (`rocev2_dcqcn_gpu_fabric.frasm`)\n\nCaptures a GPU node sending an RDMA Write (`ECN = CE 3` marked by a congested\nspine switch), the receiver returning a RoCEv2 Congestion Notification Packet\n(`opcode 0x81` on QP `1` / data QP) plus RC `ACK`, followed by a paced RDMA Read.\n\n```frameassembly\nhost h100_rank0 { ip 10.192.0.10 mac 0c:42:a1:00:00:10 }\nhost h100_rank1 { ip 10.192.0.11 mac 0c:42:a1:00:00:11 }\n\ncompile {\n    // 1. RC RDMA Write Only (0x0a) on CoS 3 / DSCP 26 experiencing switch ECN Congestion Experienced (ecn 3)\n    h100_rank0 -> h100_rank1 rocev2 write srcport 58100 pkey 0xffff destqp 0x000200 ackreq seqnum 5001 addr 0x00007f0040000000 key 0x11223344 count 65536 vlan 100 pcp 3 dscp 26 ecn 3 payload \"FP16-GRADIENT-TENSOR\" wait 20us\n    // 2. Receiver immediately fires DCQCN Congestion Notification Packet (BTH OpCode 0x81 CNP, DSCP 48 CS6)\n    h100_rank0 <- h100_rank1 rocev2 opcode 0x81 pkey 0xffff destqp 0x0001ff seqnum 0 vlan 100 pcp 6 dscp 48 wait 15us\n    // 3. Receiver returns RC Acknowledge (OpCode 0x11, AETH ACK credit syndrome 0x00)\n    h100_rank0 <- h100_rank1 rocev2 opcode \"ack\" pkey 0xffff destqp 0x0001ff seqnum 5001 status 0x00 msgid 42 vlan 100 pcp 3 dscp 26 ecn 2 wait 80us\n    // 4. Rate-paced RC RDMA Read Request (OpCode 0x0c, ECN ECT(0) = 2)\n    h100_rank0 -> h100_rank1 rocev2 read srcport 58100 pkey 0xffff destqp 0x000200 ackreq seqnum 5002 addr 0x00007f0040010000 key 0x11223344 count 4096 vlan 100 pcp 3 dscp 26 ecn 2\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show rocev2_dcqcn_gpu_fabric.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly rocev2_dcqcn_gpu_fabric.frasm rocev2_dcqcn_gpu_fabric.pcap\nframeassembly rocev2_dcqcn_gpu_fabric.frasm rocev2_dcqcn_gpu_fabric.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse rocev2_dcqcn_gpu_fabric.pcap rocev2_dcqcn_gpu_fabric_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r rocev2_dcqcn_gpu_fabric.pcap -Y \"infiniband\"\n```\n\n## All `rocev2` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host rocev2 [read | write | opcode\n\"<text_or_num>\"] [pkey <0..65535>] [destqp <0..16777215>] [ackreq] [seqnum\n<0..16777215>] [addr <number>] [key <number>] [count <number>] [status <0..255>]\n[msgid <0..16777215>] [crc <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `read \\| write \\| opcode \"<text_or_num>\"` | RC RDMA OpCode keyword (\"send\",\"write\",\"read\",\"ack\",\"cnp\") or 8-bit BTH OpCode (`0x04` Send, `0x0a` Write, `0x0c` Read, `0x11` ACK, `0x81` CNP) | `send (0x04 RC Send Only)` | Sets byte 0 of the 12-byte InfiniBand Base Transport Header (`BTH`) and selects optional `RETH` / `AETH` subheaders. |\n| `pkey <0..65535>` | 16-bit Partition Key | `0xffff (Default full-member partition)` | Writes bytes 2..3 of the BTH. |\n| `destqp <0..16777215>` | 24-bit Destination Queue Pair number | `0x000100` | Writes bytes 5..7 of the BTH identifying the remote HCA Queue Pair. |\n| `ackreq \\| seqnum <0..16777215>` | Acknowledge Request bit (`0x80`) & 24-bit Packet Sequence Number (`PSN`) | `ackreq off, seqnum 1` | Populates BTH bytes 8..11 (`A`-bit in MSB of byte 8 + 24-bit `PSN` in bytes 9..11). |\n| `addr <number> \\| key <number> \\| count <number>` | 64-bit Virtual Address, 32-bit R_Key, and 32-bit DMA Length (`RETH`) | `addr 0, key 0, count 0` | Writes the 16-byte RDMA Extended Transport Header (`RETH`) on `write` and `read` requests. |\n| `status <0..255> \\| msgid <0..16777215>` | 8-bit AETH Syndrome (`0x00` ACK, `0x60` RNR NAK) & 24-bit Message Sequence Number | `status 0, msgid 1` | Writes the 4-byte ACK Extended Transport Header (`AETH`) on `ack` and RDMA Read Response packets. |\n| `crc <number>` | Optional 32-bit Invariant CRC override | `Auto-computed IBTA Annex A17 ICRC` | Overrides the trailing 4-byte little-endian `ICRC` for negative NIC drop testing. |\n\n## Cross-Layer Options Valid with `rocev2`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 4791` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 4791)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### destqp and seqnum (PSN) Are 24-Bit Fields (0..16777215)\n\n- **Avoid:** `n1 -> n2 rocev2 write destqp 0x01000000 seqnum 1`\n- **Valid v3.3.0 Syntax:** `n1 -> n2 rocev2 write destqp 0x000200 seqnum 1`\n\nInfiniBand BTH reserves the upper byte before both `Destination QP` and `PSN`\n(`A`-bit + reserved bits), capping `destqp` and `seqnum` at `0xffffff`\n(`16,777,215`).\n\n### Pair RoCEv2 with ECN-Capable Transport Markings (ecn 2 or ecn 3)\n\n- **Valid v3.3.0 Syntax:** `n1 -> n2 rocev2 write destqp 256 seqnum 1 dscp 26 ecn\n  2`\n\nProduction RoCEv2 lossless fabrics rely on IP header ECN bits (`ecn 2` `ECT(0)` in\nnormal operation, `ecn 3` `CE` under congestion) to trigger DCQCN rate control\nbefore PFC buffer exhaustion.\n"}
{"id":"pretrain-proto-redis","kind":"protocol_spec","title":"Redis Serialization Protocol Cache & Broker (redis) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/redis","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["redis"],"text":"# redis — Stateful TCP 6379 RESP Arrays & Unauth Cache Probes (`redis`)\n\n> **FrameAssembly v3.3.0** · Protocol 98 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/redis\n\n- **Full Protocol Name:** Redis Serialization Protocol Cache & Broker\n- **Keyword:** `redis`\n- **OSI Layer & Transport:** Layer 7 · TCP 6379\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** Redis RESP2 / RESP3\n- **Wireshark Display Filter:** `redis || tcp.port == 6379`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 6379 -> Redis (RESP)`\n\n## Overview\n\nAn exposed Redis port `6379` on a cloud subnet gets owned in about 90 seconds —\n`redis` formats exact RESP bulk-string arrays (`cmd \"CONFIG\" args \"GET dir\"`) to\nverify NDR east-west alerts.\n\nRedis and Valkey communicate over **TCP port `6379`** using the **Redis\nSerialization Protocol (RESP)**, where client commands are formatted as\nlength-prefixed multibulk arrays (`*3\n$3\nSET\n...`) and server replies use type prefixes (`+` simple string, `-` error, `:`\ninteger, `$` bulk string). Exposed unauthenticated Redis instances (`CONFIG SET\ndir`, `SLAVEOF`, `EVAL`) are a top cloud/container attack vector.\n\nFrameAssembly computes every `*N` array count and `$len` byte-length prefix\nautomatically for `get`, `set`, or arbitrary `cmd` (`\"AUTH\"`, `\"INFO\"`,\n`\"CONFIG\"`) requests, as well as typed `replytype` server responses.\n\n## Minimal Quickstart (`redis_quickstart.frasm`)\n\n```frameassembly\nhost api_pod   { ip 10.44.1.12 }\nhost redis_primary { ip 10.44.2.10 }\n\ncompile {\n    api_pod -> redis_primary tcp syn srcport 51637 dstport 6379 wait 1ms\n    api_pod <- redis_primary tcp syn ack wait 1ms\n    api_pod -> redis_primary tcp ack wait 1ms\n    api_pod -> redis_primary redis set key \"session:4821\" value \"active\" wait 1ms\n    api_pod <- redis_primary redis replytype \"ok\" value \"OK\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `6379` (`psh ack`) and formats exact `*N\n$<len>\n...` RESP multibulk wire arrays.\n- Emits `+OK\n` (`replytype \"ok\"`), `-ERR ...\n` (`replytype \"err\"`), `:<num>\n` (`replytype \"integer\"`), or `$<len>\n<value>\n` (`replytype \"bulk\"`) on server responses.\n- Tracks TCP sequence numbers automatically across commands and replies.\n\n## Practical Lab Example: Blocked Unauthenticated `CONFIG` Probe (`-NOAUTH`) + Authenticated Cache Read/Write (`redis_security_audit.frasm`)\n\nTests an unauthenticated command rejected with `-NOAUTH Authentication required.`,\nfollowed by `AUTH`, `SET`, and bulk `GET`.\n\n```frameassembly\nhost app_worker { ip 172.16.44.20 }\nhost cache_node { ip 172.16.44.63 }\n\ncompile {\n    app_worker -> cache_node tcp syn srcport 52637 dstport 6379 win 65535 mss 1460 wait 1ms\n    app_worker <- cache_node tcp syn ack win 65535 mss 1460 wait 1ms\n    app_worker -> cache_node tcp ack wait 1ms\n    // 1. Unauthenticated probe rejected with RESP error (-)\n    app_worker -> cache_node redis cmd \"INFO\" wait 1ms\n    app_worker <- cache_node redis replytype \"err\" value \"NOAUTH Authentication required.\" wait 3ms\n    // 2. Authenticate + SET + GET\n    app_worker -> cache_node redis cmd \"AUTH\" args \"LabCacheToken2026\" wait 1ms\n    app_worker <- cache_node redis replytype \"ok\" value \"OK\" wait 1ms\n    app_worker -> cache_node redis set key \"ratelimit:198.51.100.9\" value \"42\" wait 1ms\n    app_worker <- cache_node redis replytype \"ok\" value \"OK\" wait 1ms\n    app_worker -> cache_node redis get key \"ratelimit:198.51.100.9\" wait 1ms\n    app_worker <- cache_node redis replytype \"bulk\" value \"42\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show redis_security_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly redis_security_audit.frasm redis_security_audit.pcap\nframeassembly redis_security_audit.frasm redis_security_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse redis_security_audit.pcap redis_security_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r redis_security_audit.pcap -Y \"redis || tcp.port == 6379\"\n```\n\n## All `redis` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host redis [get | set | cmd \"<text>\"] [key\n\"<text>\"] [args \"<text>\"] [value \"<text>\"] [replytype \"<ok|err|integer|bulk>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `get \\| set \\| cmd \"<text>\"` | Redis command (`get`, `set`, or quoted command such as `\"AUTH\"`, `\"PING\"`, `\"DEL\"`) | `get` | Sets the first bulk string element of the RESP command array. |\n| `key \"<text>\" \\| value \"<text>\" \\| args \"<text>\"` | Quoted key, value, or extra arguments | `key \"mykey\" on get/set` | Populates subsequent `$len\\r\\n...` elements in requests or payload text in server replies. |\n| `replytype \"<ok\\|err\\|integer\\|bulk>\"` | RESP reply type selector | `Omitted on client requests` | Switches the packet to a server reply using `+`, `-`, `:`, or `$` RESP framing. |\n\n## Cross-Layer Options Valid with `redis`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 6379` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 6379)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Use replytype on Server Replies So Redis Does Not Emit Another Client Command\n\n- **Avoid:** `api_pod <- redis_primary redis value \"OK\"`\n- **Valid v3.3.0 Syntax:** `api_pod <- redis_primary redis replytype \"ok\" value\n  \"OK\"`\n\nAdding `replytype` (`\"ok\"`, `\"err\"`, `\"integer\"`, or `\"bulk\"`) tells FrameAssembly\nto format a server RESP reply rather than a client `*N` command array.\n"}
{"id":"pretrain-proto-memcached","kind":"protocol_spec","title":"Memcached ASCII & Binary Cache Protocol (memcached) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/memcached","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["memcached"],"text":"# memcached — UDP 11211 8-Byte Frame Headers & TCP Cache Ops (`memcached`)\n\n> **FrameAssembly v3.3.0** · Protocol 99 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/memcached\n\n- **Full Protocol Name:** Memcached ASCII & Binary Cache Protocol\n- **Keyword:** `memcached`\n- **OSI Layer & Transport:** Layer 7 · UDP 11211 (or TCP 11211 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** Memcached Protocol Specification\n- **Wireshark Display Filter:** `memcache`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 11211 (or TCP 11211 via transport tcp) (transport tcp|udp) -> Memcached`\n\n## Overview\n\nInfamous for 51,000x UDP `11211` reflection attacks: `memcached` includes the\n8-byte Memcached UDP frame header by default and drops cleanly onto raw TCP stream\nframing when you add `transport tcp`.\n\nMemcached (`memcached`) serves distributed in-memory key-value caches on **port\n`11211`**. Historically, exposed **UDP port `11211`** servers caused\nrecord-breaking `51,000x` DDoS reflection attacks (via the 8-byte Memcached UDP\nframe header + `stats` / `get`), whereas production internal clusters run over\n**TCP port `11211`** (`transport tcp`) using either the **ASCII text protocol** or\nthe **24-byte Binary protocol** (`0x80`/`0x81`).\n\nFrameAssembly supports all four combinations: UDP or `transport tcp`, and ASCII\n(`get`, `set`, `cmd \"stats\"`) or Binary (`opcode 0x00`, `opaque`, `cas`).\n\n## Minimal Quickstart (`memcached_quickstart.frasm`)\n\n```frameassembly\nhost web_app    { ip 10.45.1.15 }\nhost cache_pool { ip 10.45.1.112 }\n\ncompile {\n    web_app -> cache_pool tcp syn srcport 51211 dstport 11211 wait 1ms\n    web_app <- cache_pool tcp syn ack wait 1ms\n    web_app -> cache_pool tcp ack wait 1ms\n    web_app -> cache_pool memcached set key \"user:profile:42\" value \"{\\\"tier\\\":\\\"pro\\\"}\" exptime 300 transport tcp\n}\n```\n\n### Automatic Wire Calculations\n\n- Prepends the mandatory 8-byte Memcached UDP frame header (`Request ID`, `Seq 0`,\n  `Total Datagrams 1`, `Reserved 0`) automatically on UDP `11211`, and omits it\n  cleanly when `transport tcp` is set.\n- Formats exact `<byte_len>\n<value>\n` blocks on ASCII `set` commands.\n- Switches to the 24-byte `0x80` Memcached Binary Protocol header whenever\n  `opcode` is specified.\n\n## Practical Lab Example: UDP 11211 `stats` Amplification Audit + TCP ASCII & Binary Cache Operations (`memcached_udp_and_tcp.frasm`)\n\nTests a UDP 11211 `stats` probe, then opens a TCP 11211 session exercising both\nASCII `set`/`get` and Binary (`opcode 0x00`) `get`.\n\n```frameassembly\nhost auditor   { ip 172.16.45.10 }\nhost memcache  { ip 172.16.45.112 }\n\ncompile {\n    // 1. UDP 11211 amplification audit probe (with 8-byte UDP header)\n    auditor -> memcache memcached cmd \"stats\" wait 4ms\n    // 2. Authorized internal TCP 11211 session (ASCII + Binary)\n    auditor -> memcache tcp syn srcport 53211 dstport 11211 win 65535 mss 1460 wait 1ms\n    auditor <- memcache tcp syn ack win 65535 mss 1460 wait 1ms\n    auditor -> memcache tcp ack wait 1ms\n    auditor -> memcache memcached set key \"cfg:feature_x\" value \"enabled\" flags 0 exptime 600 transport tcp wait 2ms\n    auditor -> memcache memcached get key \"cfg:feature_x\" opcode 0x00 opaque 0x99 transport tcp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show memcached_udp_and_tcp.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly memcached_udp_and_tcp.frasm memcached_udp_and_tcp.pcap\nframeassembly memcached_udp_and_tcp.frasm memcached_udp_and_tcp.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse memcached_udp_and_tcp.pcap memcached_udp_and_tcp_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r memcached_udp_and_tcp.pcap -Y \"memcache\"\n```\n\n## All `memcached` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host memcached [get | set | cmd \"<text>\"]\n[key \"<text>\"] [value \"<text>\"] [flags <number>] [exptime <number>] [opcode\n<hex_or_num>] [opaque <hex_or_num>] [cas <hex_or_num>] [transport <udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `get \\| set \\| cmd \"<text>\"` | ASCII Memcached command (`get`, `set`, `cmd \"stats\"`, `cmd \"delete\"`) | `get` | Selects the ASCII command line. |\n| `key \"<text>\" \\| value \"<text>\"` | Quoted cache key (no spaces) and payload value | `key \"test\"` | Populates key and data block bytes in ASCII or Binary frames. |\n| `flags <number> \\| exptime <number>` | 32-bit client flags + TTL expiration in seconds | `flags 0, exptime 0` | Sets `flags` and `exptime` in `set` requests. |\n| `opcode <hex_or_num> [opaque <hex_or_num>] [cas <hex_or_num>]` | Binary protocol opcode (`0x00` Get, `0x01` Set, `0x07` Quit) | `Omitted (uses ASCII mode)` | Switches the packet to the 24-byte `0x80` Memcached Binary Protocol. |\n| `transport <udp\\|tcp>` | `udp` or `tcp` | `udp` | Switches between UDP `11211` (8-byte UDP header) and TCP `11211`. |\n\n## Cross-Layer Options Valid with `memcached`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 11211 (or TCP 11211 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Memcached ASCII Keys Cannot Contain Spaces\n\n- **Avoid:** `web_app -> cache_pool memcached get key \"user profile 42\" transport\n  tcp`\n- **Valid v3.3.0 Syntax:** `web_app -> cache_pool memcached get key\n  \"user:profile:42\" transport tcp`\n\nMemcached’s ASCII protocol uses whitespace to separate tokens on the command line;\nuse colons or hyphens inside keys.\n"}
{"id":"pretrain-proto-mysql","kind":"protocol_spec","title":"MySQL & MariaDB Wire Protocol v10 (mysql) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/mysql","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["mysql"],"text":"# mysql — Port 3306 Handshakes, COM_QUERY SQL & Error Frames (`mysql`)\n\n> **FrameAssembly v3.3.0** · Protocol 100 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/mysql\n\n- **Full Protocol Name:** MySQL & MariaDB Wire Protocol v10\n- **Keyword:** `mysql`\n- **OSI Layer & Transport:** Layer 7 · TCP 3306\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** MySQL Client/Server Protocol v10\n- **Wireshark Display Filter:** `mysql`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 3306 -> MySQL / MariaDB`\n\n## Overview\n\nNeed to test a database activity monitor or IDS rule against `sql \"SELECT * FROM\nusers WHERE '1'='1';\"` without spinning up a live MySQL instance? `mysql` handles\nthe 24-bit little-endian packet length and sequence byte automatically.\n\nMySQL and MariaDB (`mysql`) communicate over **TCP port `3306`** using a binary\npacket framing where every message begins with a **3-byte little-endian payload\nlength** and a **1-byte packet sequence number** (`0`, `1`, `2`...). Unlike HTTP,\nthe MySQL server speaks first immediately after the TCP handshake by sending a\nProtocol v10 `greeting` banner.\n\nFrameAssembly encodes valid MySQL v10 `greeting` handshakes (`serverversion`),\n`login` (`HandshakeResponse41` carrying `user` and `db`), `COM_QUERY` (`0x03`,\n`query` + `sql`), `ok` (`0x00`), `err` (`0xff`, e.g. `errcode 1045` Access\nDenied), and `eof` (`0xfe`) packets.\n\n## Minimal Quickstart (`mysql_quickstart.frasm`)\n\n```frameassembly\nhost app_srv  { ip 10.50.1.20 }\nhost mysql_db { ip 10.50.2.33 }\n\ncompile {\n    app_srv -> mysql_db tcp syn srcport 53306 dstport 3306 wait 1ms\n    app_srv <- mysql_db tcp syn ack wait 1ms\n    app_srv -> mysql_db tcp ack wait 1ms\n    app_srv <- mysql_db mysql greeting serverversion \"8.0.36\" wait 2ms\n    app_srv -> mysql_db mysql login user \"app_rw\" db \"orders\" wait 2ms\n    app_srv <- mysql_db mysql ok\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `3306` (`psh ack`) and computes the 3-byte\n  little-endian MySQL packet length automatically.\n- Encodes NUL-terminated server version, thread ID, auth-plugin-data salt, and\n  capability flags inside `greeting` so Wireshark recognizes the session as MySQL.\n- Prefixes `sql` strings with `0x03` (`COM_QUERY`) on `query` frames and encodes\n  little-endian 16-bit error numbers on `err` frames.\n\n## Practical Lab Example: Blocked `root` Login (`errcode 1045`) + Authorized Application SQL Session (`mysql_dam_audit.frasm`)\n\nShows a rejected `root` login returning MySQL Error `1045`, followed by an\nauthorized `app_ro` connection running a `SELECT` query.\n\n```frameassembly\nhost web_node { ip 172.16.50.15 }\nhost db_main  { ip 172.16.60.10 }\n\ncompile {\n    // 1. Unauthorized root login attempt -> MySQL Error 1045\n    web_node -> db_main tcp syn srcport 54306 dstport 3306 win 65535 mss 1460 wait 1ms\n    web_node <- db_main tcp syn ack win 65535 mss 1460 wait 1ms\n    web_node -> db_main tcp ack wait 1ms\n    web_node <- db_main mysql greeting serverversion \"8.0.37-commercial\" wait 2ms\n    web_node -> db_main mysql login user \"root\" db \"mysql\" wait 2ms\n    web_node <- db_main mysql err errcode 1045 wait 5ms\n    // 2. Authorized query on a second connection\n    web_node -> db_main tcp syn srcport 54307 dstport 3306 win 65535 mss 1460 wait 1ms\n    web_node <- db_main tcp syn ack win 65535 mss 1460 wait 1ms\n    web_node -> db_main tcp ack wait 1ms\n    web_node <- db_main mysql greeting serverversion \"8.0.37-commercial\" wait 1ms\n    web_node -> db_main mysql login user \"app_ro\" db \"billing\" wait 1ms\n    web_node <- db_main mysql ok wait 2ms\n    web_node -> db_main mysql query sql \"SELECT invoice_id, total_cents FROM invoices WHERE paid = 0 LIMIT 25\" wait 3ms\n    web_node <- db_main mysql ok\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show mysql_dam_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly mysql_dam_audit.frasm mysql_dam_audit.pcap\nframeassembly mysql_dam_audit.frasm mysql_dam_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse mysql_dam_audit.pcap mysql_dam_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r mysql_dam_audit.pcap -Y \"mysql\"\n```\n\n## All `mysql` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host mysql [greeting | login | query | ok |\nerr | eof] [serverversion \"<text>\"] [user \"<text>\"] [db \"<text>\"] [sql \"<text>\"]\n[errcode <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `greeting \\| login \\| query \\| ok \\| err \\| eof` | MySQL packet type keyword | `query (COM_QUERY 0x03)` | Selects Server Greeting v10 (`greeting`), Client HandshakeResponse41 (`login`), SQL Query (`query`), `0x00` OK (`ok`), `0xff` Error (`err`), or `0xfe` EOF (`eof`). |\n| `serverversion \"<text>\"` | Quoted version banner on `greeting` | `\"8.0.36\"` | Sets the NUL-terminated server version string in `greeting` packets. |\n| `user \"<text>\" \\| db \"<text>\"` | Quoted MySQL username and schema name on `login` | `user \"root\", db \"\"` | Populates username and initial database inside `login` packets. |\n| `sql \"<text>\"` | Quoted SQL statement on `query` | `\"SELECT 1\"` | Writes the SQL query string following `COM_QUERY` (`0x03`). |\n| `errcode <0..65535>` | 16-bit MySQL error code (`1045` Access denied, `1049` Unknown DB, `1064` Syntax error) | `1045 on err` | Sets the 2-byte little-endian error code in `err` (`0xff`) packets. |\n\n## Cross-Layer Options Valid with `mysql`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 3306` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 3306)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Include Server greeting First for Full Wireshark Conversation State\n\n- **Valid v3.3.0 Syntax:** `app_srv <- mysql_db mysql greeting serverversion\n  \"8.0.36\"`\n\nBecause MySQL is server-speaks-first, emitting `mysql greeting` from the server\nbefore `mysql login` helps Wireshark and Zeek classify the handshake phase\naccurately.\n"}
{"id":"pretrain-proto-postgres","kind":"protocol_spec","title":"PostgreSQL Frontend/Backend Wire Protocol v3.0 (postgres) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/postgres","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["postgres"],"text":"# postgres — Port 5432 v3.0 Startup, SQL Queries & Wire Tags (`postgres`)\n\n> **FrameAssembly v3.3.0** · Protocol 101 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/postgres\n\n- **Full Protocol Name:** PostgreSQL Frontend/Backend Wire Protocol v3.0\n- **Keyword:** `postgres`\n- **OSI Layer & Transport:** Layer 7 · TCP 5432\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** PostgreSQL Protocol v3.0\n- **Wireshark Display Filter:** `pgsql`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 5432 -> PostgreSQL`\n\n## Overview\n\nSpeak fluent PostgreSQL v3.0 wire protocol (`'Q'`, `'R'`, `'C'`, `'Z'`, `'E'`\ntagged messages with big-endian length prefixes) over stateful TCP `5432`, working\nidentically over IPv4 or IPv6 `flow` blocks.\n\nPostgreSQL (`postgres`) communicates over **TCP port `5432`** using the\nFrontend/Backend v3.0 wire protocol (`0x00030000`). Unlike MySQL (where the server\nspeaks first), PostgreSQL is client-speaks-first: the client sends a\nlength-prefixed `StartupMessage` (`startup`) containing `user` and `database`\n(`db`) NUL-separated key/value pairs, followed by 1-byte tagged messages (`'R'`\n`authok`, `'Q'` `query`, `'C'` `commandcomplete`, `'Z'` `readyforquery`, and `'E'`\n`errorresponse`).\n\nFrameAssembly calculates every 32-bit big-endian PostgreSQL length field\nautomatically and keeps TCP sequence numbers synchronized across the full session.\n\n## Minimal Quickstart (`postgres_quickstart.frasm`)\n\n```frameassembly\nhost app_pod { ip 10.50.10.12 }\nhost pg_db   { ip 10.50.20.54 }\n\ncompile {\n    app_pod -> pg_db tcp syn srcport 55432 dstport 5432 wait 1ms\n    app_pod <- pg_db tcp syn ack wait 1ms\n    app_pod -> pg_db tcp ack wait 1ms\n    app_pod -> pg_db postgres startup user \"app_ro\" db \"inventory\" wait 2ms\n    app_pod <- pg_db postgres authok wait 1ms\n    app_pod <- pg_db postgres readyforquery wait 2ms\n    app_pod -> pg_db postgres query sql \"SELECT sku, qty FROM stock WHERE qty < 10;\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `5432` (`psh ack`) and writes Protocol Version\n  `3.0` (`0x00030000`) inside `startup` frames.\n- Computes the 32-bit big-endian self-inclusive length (`4 + body_bytes`) on every\n  `'R'`, `'Q'`, `'C'`, `'Z'`, and `'E'` message.\n- Terminates `sql` strings with a NUL byte (`0x00`) inside Simple Query (`'Q'`)\n  frames so Wireshark’s `pgsql` dissector parses the SQL statement cleanly.\n\n## Practical Lab Example: Full PostgreSQL v3.0 Startup, SQL Query Lifecycle & ErrorResponse (`postgres_session_audit.frasm`)\n\nCompletes a TCP 5432 handshake, authenticates via `startup` -> `authok` ->\n`readyforquery`, runs an audit query (`commandcomplete` + `readyforquery`), and\ntriggers an `errorresponse` on a restricted table.\n\n```frameassembly\nhost api_svc { ip 172.16.54.15 }\nhost pg_pri  { ip 172.16.54.100 }\n\ncompile {\n    api_svc -> pg_pri tcp syn srcport 51432 dstport 5432 win 65535 mss 1460 wait 1ms\n    api_svc <- pg_pri tcp syn ack win 65535 mss 1460 wait 1ms\n    api_svc -> pg_pri tcp ack wait 1ms\n    // 1. Client-first StartupMessage -> AuthenticationOk + ReadyForQuery ('I')\n    api_svc -> pg_pri postgres startup user \"reporting_ro\" db \"analytics\" wait 2ms\n    api_svc <- pg_pri postgres authok wait 1ms\n    api_svc <- pg_pri postgres readyforquery wait 2ms\n    // 2. Authorized SELECT query -> CommandComplete + ReadyForQuery\n    api_svc -> pg_pri postgres query sql \"SELECT count(*) FROM daily_events;\" wait 3ms\n    api_svc <- pg_pri postgres commandcomplete wait 1ms\n    api_svc <- pg_pri postgres readyforquery wait 4ms\n    // 3. Unauthorized write attempt -> ErrorResponse ('E')\n    api_svc -> pg_pri postgres query sql \"DROP TABLE audit_trail;\" wait 2ms\n    api_svc <- pg_pri postgres errorresponse\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show postgres_session_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly postgres_session_audit.frasm postgres_session_audit.pcap\nframeassembly postgres_session_audit.frasm postgres_session_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse postgres_session_audit.pcap postgres_session_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r postgres_session_audit.pcap -Y \"pgsql\"\n```\n\n## All `postgres` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host postgres [startup | authok | query |\ncommandcomplete | readyforquery | errorresponse] [user \"<text>\"] [db \"<text>\"]\n[sql \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `startup \\| authok \\| query \\| commandcomplete \\| readyforquery \\| errorresponse` | PostgreSQL v3.0 message type | `query ('Q')` | Selects untagged `StartupMessage` (`startup`), `'R'` AuthOK (`authok`), `'Q'` Simple Query (`query`), `'C'` CommandComplete, `'Z'` ReadyForQuery, or `'E'` ErrorResponse. |\n| `user \"<text>\" \\| db \"<text>\"` | Quoted database role and database name on `startup` | `user \"postgres\", db \"postgres\"` | Writes NUL-delimited `user` and `database` parameters in `startup` packets. |\n| `sql \"<text>\"` | Quoted SQL statement on `query` | `\"SELECT 1;\"` | Sets the NUL-terminated SQL query string inside `'Q'` packets. |\n\n## Cross-Layer Options Valid with `postgres`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 5432` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 5432)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### PostgreSQL Wireshark Display Filter Is pgsql (Not postgres)\n\n- **Valid v3.3.0 Syntax:** `Wireshark display filter: pgsql`\n\nWhile the FrameAssembly keyword is `postgres`, Wireshark names its dissector\n`pgsql` (`pgsql.query`, `pgsql.user`).\n"}
{"id":"pretrain-proto-mqtt","kind":"protocol_spec","title":"Message Queuing Telemetry Transport (IoT & IIoT) (mqtt) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/mqtt","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["mqtt"],"text":"# mqtt — Port 1883 IoT Broker Publishes, QoS & Subscriptions (`mqtt`)\n\n> **FrameAssembly v3.3.0** · Protocol 102 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/mqtt\n\n- **Full Protocol Name:** Message Queuing Telemetry Transport (IoT & IIoT)\n- **Keyword:** `mqtt`\n- **OSI Layer & Transport:** Layer 7 · TCP 1883 (or transport udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** OASIS MQTT v3.1.1, OASIS MQTT v5.0\n- **Wireshark Display Filter:** `mqtt`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 1883 (or transport udp) (transport tcp|udp) -> MQTT`\n\n## Overview\n\nTest whether a compromised smart thermostat can subscribe to `\"factory/#\"` on TCP\n`1883` — `mqtt` computes the variable-byte Remaining Length encoding\nautomatically.\n\nMessage Queuing Telemetry Transport (`mqtt`, OASIS MQTT v3.1.1) connects IoT\nsensors, smart-grid meters, and Industrial IoT (Sparkplug B / IIoT) gateways to\nbrokers (Mosquitto, EMQX, HiveMQ, AWS IoT) over **TCP port `1883`** (or `8883`\nover TLS).\n\nFrameAssembly encodes the MQTT Fixed Header (4-bit Control Packet Type +\nQoS/Retain flags + variable-byte Remaining Length) and Variable Header for\n`connect`, `connack`, `publish`, `puback`, `subscribe`, `suback`, `pingreq`,\n`pingresp`, and `disconnect`.\n\n## Minimal Quickstart (`mqtt_quickstart.frasm`)\n\n```frameassembly\nhost edge_gw { ip 10.60.10.25 }\nhost broker  { ip 10.60.10.10 }\n\ncompile {\n    edge_gw -> broker tcp syn srcport 51883 dstport 1883 wait 1ms\n    edge_gw <- broker tcp syn ack wait 1ms\n    edge_gw -> broker tcp ack wait 1ms\n    edge_gw -> broker mqtt connect clientid \"gw-rack04\" keepalive 60 wait 2ms\n    edge_gw <- broker mqtt connack returncode 0 wait 2ms\n    edge_gw -> broker mqtt publish topic \"dc1/rack04/kw\" qos 0 retain payload \"4.85\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `1883` (`psh ack`) and encodes the multi-byte\n  variable-length `Remaining Length` field per OASIS MQTT §2.2.3.\n- Encodes the `\"MQTT\"` Protocol Level `4` header inside `connect`, and includes\n  the 2-byte Packet Identifier (`pktid`) automatically on `qos 1` / `qos 2`\n  `publish`, `puback`, `subscribe`, and `suback` packets.\n- Appends `payload \"<text>\"` directly as the UTF-8 topic message payload on\n  `publish` frames.\n\n## Practical Lab Example: IIoT Gateway Connect, Wildcard Topic Subscribe, QoS 1 Publish & Keepalive Ping (`mqtt_iiot_telemetry.frasm`)\n\nConnects an industrial gateway to TCP 1883, subscribes to control commands,\npublishes a `qos 1` retained sensor reading acknowledged via `puback`, and\nexchanges `pingreq`/`pingresp`.\n\n```frameassembly\nhost plc_gw      { ip 192.168.80.21 }\nhost mqtt_broker { ip 192.168.80.10 }\n\ncompile {\n    plc_gw -> mqtt_broker tcp syn srcport 52883 dstport 1883 win 65535 mss 1460 wait 1ms\n    plc_gw <- mqtt_broker tcp syn ack win 65535 mss 1460 wait 1ms\n    plc_gw -> mqtt_broker tcp ack wait 1ms\n    plc_gw -> mqtt_broker mqtt connect clientid \"line2-plc-gw\" keepalive 30 wait 2ms\n    plc_gw <- mqtt_broker mqtt connack returncode 0 wait 2ms\n    // 1. Subscribe to actuator commands (pktid 1)\n    plc_gw -> mqtt_broker mqtt subscribe pktid 1 topic \"plant1/line2/cmd\" qos 1 wait 2ms\n    plc_gw <- mqtt_broker mqtt suback pktid 1 wait 3ms\n    // 2. Publish QoS 1 retained telemetry (pktid 2 -> puback)\n    plc_gw -> mqtt_broker mqtt publish topic \"plant1/line2/pressure_bar\" qos 1 retain pktid 2 payload \"{\\\"bar\\\":6.42}\" wait 2ms\n    plc_gw <- mqtt_broker mqtt puback pktid 2 wait 10ms\n    // 3. Keepalive heartbeat + clean disconnect\n    plc_gw -> mqtt_broker mqtt pingreq wait 1ms\n    plc_gw <- mqtt_broker mqtt pingresp wait 2ms\n    plc_gw -> mqtt_broker mqtt disconnect\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show mqtt_iiot_telemetry.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly mqtt_iiot_telemetry.frasm mqtt_iiot_telemetry.pcap\nframeassembly mqtt_iiot_telemetry.frasm mqtt_iiot_telemetry.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse mqtt_iiot_telemetry.pcap mqtt_iiot_telemetry_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r mqtt_iiot_telemetry.pcap -Y \"mqtt\"\n```\n\n## All `mqtt` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host mqtt [connect | connack | publish |\npuback | subscribe | suback | pingreq | pingresp | disconnect | pkttype \"<text>\"]\n[clientid \"<text>\"] [topic \"<text>\"] [qos <0..2>] [retain] [pktid <0..65535>]\n[keepalive <0..65535>] [returncode <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `connect \\| connack \\| publish \\| puback \\| subscribe \\| suback \\| pingreq \\| pingresp \\| disconnect` | MQTT Control Packet type (or `pkttype \"<text>\"`) | `publish` | Sets the upper 4-bit Control Packet Type (`1`..`14`) in byte 0 of the MQTT header. |\n| `clientid \"<text>\" \\| keepalive <0..65535>` | Quoted Client ID + keepalive seconds on `connect` | `clientid \"frameassembly\", keepalive 60` | Populates the `CONNECT` payload Client Identifier and Keep Alive timer. |\n| `topic \"<text>\"` | Quoted slash-delimited MQTT topic (`\"sensors/temp\"`) | `\"sensors/temp\"` | Encodes the 2-byte length-prefixed Topic Name in `publish` or Topic Filter in `subscribe`. |\n| `qos <0..2> \\| retain` | QoS delivery level (`0`, `1`, or `2`) + `retain` flag | `qos 0, retain off` | Sets QoS bits `1..2` and Retain bit `0` in the Fixed Header. |\n| `pktid <0..65535>` | 16-bit Packet Identifier | `1 (when qos > 0 or subscribe/puback)` | Matches `publish` <-> `puback` and `subscribe` <-> `suback`. |\n| `returncode <0..255>` | CONNACK return code (`0` Accepted, `4` Bad user/pass, `5` Not authorized) | `0 (Connection Accepted)` | Sets byte 3 (`Connect Return Code`) of `connack`. |\n\n## Cross-Layer Options Valid with `mqtt`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 1883 (or transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### QoS Maximum Value Is 2 (0, 1, or 2)\n\n- **Avoid:** `edge_gw -> broker mqtt publish topic \"a/b\" qos 3`\n- **Valid v3.3.0 Syntax:** `edge_gw -> broker mqtt publish topic \"a/b\" qos 1 pktid\n  10`\n\nMQTT reserves `QoS 3` (`0b11`) as a protocol violation (` Malformed Packet`);\nvalid levels are `0`, `1`, and `2`.\n"}
{"id":"pretrain-proto-coap","kind":"protocol_spec","title":"Constrained Application Protocol (coap) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/coap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["coap"],"text":"# coap — 4-Byte UDP 5683 RESTful IoT Datagrams & Options (`coap`)\n\n> **FrameAssembly v3.3.0** · Protocol 103 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/coap\n\n- **Full Protocol Name:** Constrained Application Protocol\n- **Keyword:** `coap`\n- **OSI Layer & Transport:** Layer 7 · UDP 5683 (or RFC 8323 transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 7252\n- **Wireshark Display Filter:** `coap`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 5683 (or RFC 8323 transport tcp) (transport tcp|udp) -> CoAP (IoT)`\n\n## Overview\n\nHTTP shrunk down to a 4-byte UDP `5683` header for battery-powered sensors: just\npick *either* a named method (`get`, `post`, `created`) *or* dotted `code \"0.01\"`\n(combining both on one line triggers a helpful compiler error).\n\nConstrained Application Protocol (`coap`, RFC 7252) brings REST-like `GET`,\n`POST`, `PUT`, and `DELETE` semantics to low-power microcontrollers, NB-IoT\nmeters, and Thread/6LoWPAN sensors in a compact **4-byte UDP header** on **UDP\nport `5683`**.\n\nFrameAssembly encodes CoAP Version `1`, Message Type (`con` Confirmable, `non`\nNon-confirmable, `ack` Acknowledgment, `rst` Reset), `class.detail`\nMethod/Response Codes (`0.01` GET, `2.05` Content, `4.04` Not Found),\nvariable-length `token`, delta-encoded `Uri-Path` (`uripath`) and `Content-Format`\n(`contentformat`) options, and the `0xff` payload marker.\n\n## Minimal Quickstart (`coap_quickstart.frasm`)\n\n```frameassembly\nhost sensor_01 { ip 10.70.1.50 }\nhost iot_gw    { ip 10.70.1.1 }\n\ncompile {\n    sensor_01 -> iot_gw coap con post msgid 101 token 0x4a1b uripath \"telemetry/humidity\" contentformat 50 payload \"{\\\"rh\\\":48.2}\" wait 3ms\n    sensor_01 <- iot_gw coap ack changed msgid 101 token 0x4a1b\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `5683` and packs CoAP Version `1`, 2-bit Type,\n  Token Length (`TKL`), 1-byte `c.dd` Code (`(class << 5) | detail`), and 16-bit\n  `msgid`.\n- Splits slash-separated `uripath` strings (`\"telemetry/humidity\"`) into\n  individual delta-encoded Option `11` (`Uri-Path`) segments automatically.\n- Inserts Option `12` (`Content-Format`) and the mandatory `0xff` Payload Marker\n  byte whenever `payload` or `hexpayload` is present.\n\n## Practical Lab Example: Confirmable CoAP Sensor GET (`2.05 Content`) & Missing Resource (`4.04`) (`coap_ipv6_sensors.frasm`)\n\nQueries `/sensors/temp` over IPv6 receiving a piggybacked `ack` with `code \"2.05\"`\nJSON payload, then queries an unknown path returning `notfound` (`4.04`).\n\n```frameassembly\nhost collector { ip 2001:db8:70::1 }\nhost mote_12   { ip 2001:db8:70::12 }\n\ncompile {\n    // 1. Confirmable GET -> Piggybacked ACK 2.05 Content (contentformat 50 = application/json)\n    collector -> mote_12 coap con get msgid 500 token 0x0102 uripath \"sensors/temp\" wait 4ms\n    collector <- mote_12 coap ack code \"2.05\" msgid 500 token 0x0102 contentformat 50 payload \"{\\\"c\\\":22.4}\" wait 5ms\n    // 2. Unknown URI -> 4.04 Not Found\n    collector -> mote_12 coap con get msgid 501 token 0x0103 uripath \"sensors/valve9\" wait 4ms\n    collector <- mote_12 coap ack notfound msgid 501 token 0x0103\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show coap_ipv6_sensors.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly coap_ipv6_sensors.frasm coap_ipv6_sensors.pcap\nframeassembly coap_ipv6_sensors.frasm coap_ipv6_sensors.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse coap_ipv6_sensors.pcap coap_ipv6_sensors_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r coap_ipv6_sensors.pcap -Y \"coap\"\n```\n\n## All `coap` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host coap [con | non | ack | rst | msgtype\n\"<text>\"] [get | post | put | delete | created | changed | notfound | code\n\"<c.dd>\"] [msgid <0..65535>] [token <hex_or_num>] [uripath \"<text>\"]\n[contentformat <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `con \\| non \\| ack \\| rst \\| msgtype \"<text>\"` | CoAP Message Type (`0` CON, `1` NON, `2` ACK, `3` RST) | `con (Confirmable)` | Sets the 2-bit `T` field in byte 0 (`ack` and `rst` are CoAP UDP message types, not TCP flags). |\n| `get \\| post \\| put \\| delete \\| created \\| changed \\| notfound \\| code \"<c.dd>\"` | Shorthand keyword OR dotted code (`\"0.01\"`..`\"5.05\"`, choose one) | `get (\"0.01\")` | Encodes byte 1 (`(class << 5) \\| detail`, e.g. `\"2.05\"` Content = `0x45`). |\n| `msgid <0..65535> \\| token <hex_or_num>` | 16-bit Message ID + Token value | `msgid 1, token omitted` | Matches `con` <-> `ack` deduplication (`msgid`) and asynchronous request/response correlation (`token`). |\n| `uripath \"<text>\"` | Slash-separated resource path without leading slash (`\"sensors/temp\"`) | `Omitted unless set` | Encodes repeatable delta-encoded CoAP Option `11` (`Uri-Path`). |\n| `contentformat <0..65535>` | IANA CoAP Content-Format (`0` text/plain, `40` link-format, `50` JSON, `60` CBOR) | `Omitted unless set` | Encodes CoAP Option `12` (`Content-Format`). |\n\n## Cross-Layer Options Valid with `coap`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 5683 (or RFC 8323 transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Never Combine a Shorthand Verb (get) and code \"0.01\" on the Same Packet\n\n- **Avoid:** `collector -> mote_12 coap con get code \"0.01\" msgid 1`\n- **Valid v3.3.0 Syntax:** `collector -> mote_12 coap con get msgid 1 // OR: coap\n  ack code \"2.05\" msgid 1`\n\nBoth `get` and `code \"...\"` set the same 1-byte CoAP Code field—pick either a bare\nshorthand (`get`, `post`, `changed`, `notfound`) or `code \"2.05\"`, never both on\none line.\n"}
{"id":"pretrain-proto-amqp","kind":"protocol_spec","title":"Advanced Message Queuing Protocol (RabbitMQ) (amqp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/amqp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["amqp"],"text":"# amqp — Port 5672 RabbitMQ Exchanges, Channels & Deliveries (`amqp`)\n\n> **FrameAssembly v3.3.0** · Protocol 104 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/amqp\n\n- **Full Protocol Name:** Advanced Message Queuing Protocol (RabbitMQ)\n- **Keyword:** `amqp`\n- **OSI Layer & Transport:** Layer 7 · TCP 5672\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** AMQP 0-9-1\n- **Wireshark Display Filter:** `amqp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 5672 -> AMQP 0-9-1`\n\n## Overview\n\nFrom the 8-byte `\"AMQP\\x00\\x00\\x09\\x01\"` greeting to `basicpublish` and `0xce`\nframe-end markers on TCP `5672`, `amqp` lets you verify message-bus firewall rules\nwithout spinning up RabbitMQ.\n\nAdvanced Message Queuing Protocol (`amqp`, AMQP 0-9-1) powers RabbitMQ and\nenterprise event-driven message queues over **TCP port `5672`**. Connections open\nwith the 8-byte `AMQP \u0001` `protocolheader`, negotiate channels (`connectionstart`,\n`channelopen`), route messages via `exchange` and `routingkey` (`basicpublish`,\n`basicdeliver`), and keep idle sockets open with `heartbeat` frames—each\nterminated by the `0xce` frame-end byte.\n\nFrameAssembly computes AMQP frame sizes, Class/Method IDs (`10.10`\nConnection.Start, `20.10` Channel.Open, `60.40` Basic.Publish, `60.60`\nBasic.Deliver), and the `0xce` frame-end marker automatically.\n\n## Minimal Quickstart (`amqp_quickstart.frasm`)\n\n```frameassembly\nhost producer { ip 10.65.1.15 }\nhost rabbitmq { ip 10.65.1.56 }\n\ncompile {\n    producer -> rabbitmq tcp syn srcport 55672 dstport 5672 wait 1ms\n    producer <- rabbitmq tcp syn ack wait 1ms\n    producer -> rabbitmq tcp ack wait 1ms\n    producer -> rabbitmq amqp protocolheader wait 1ms\n    producer <- rabbitmq amqp connectionstart channel 0 wait 2ms\n    producer -> rabbitmq amqp basicpublish channel 1 exchange \"orders\" routingkey \"order.created\" payload \"{\\\"id\\\":901}\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `5672` (`psh ack`) and appends the mandatory\n  `0xce` frame-end octet to every AMQP 0-9-1 frame.\n- Emits the exact 8-byte `AMQP\\x00\\x00\\x09\\x01` connection header on\n  `protocolheader` so Wireshark locks onto the AMQP dissector.\n- Encodes short-string length prefixes for `exchange` and `routingkey` inside\n  Class `60` (`Basic.Publish` / `Basic.Deliver`) Method frames.\n\n## Practical Lab Example: Full RabbitMQ Connection Startup, Channel Open, Publish, Deliver & Heartbeat (`amqp_rabbitmq_flow.frasm`)\n\nWalks through TCP 5672 connection startup, opening Channel 1, publishing an audit\nevent to `\"sec.events\"`, delivering to a worker, and sending a Channel 0\nheartbeat.\n\n```frameassembly\nhost auth_svc { ip 172.16.65.10 }\nhost mq_node  { ip 172.16.65.56 }\n\ncompile {\n    auth_svc -> mq_node tcp syn srcport 51672 dstport 5672 win 65535 mss 1460 wait 1ms\n    auth_svc <- mq_node tcp syn ack win 65535 mss 1460 wait 1ms\n    auth_svc -> mq_node tcp ack wait 1ms\n    auth_svc -> mq_node amqp protocolheader wait 1ms\n    auth_svc <- mq_node amqp connectionstart channel 0 wait 2ms\n    auth_svc -> mq_node amqp channelopen channel 1 wait 2ms\n    auth_svc -> mq_node amqp basicpublish channel 1 exchange \"sec.events\" routingkey \"login.mfa\" payload \"{\\\"user\\\":\\\"netadmin\\\"}\" wait 3ms\n    auth_svc <- mq_node amqp basicdeliver channel 1 exchange \"sec.events\" routingkey \"login.mfa\" payload \"{\\\"user\\\":\\\"netadmin\\\"}\" wait 10ms\n    auth_svc <- mq_node amqp heartbeat channel 0\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show amqp_rabbitmq_flow.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly amqp_rabbitmq_flow.frasm amqp_rabbitmq_flow.pcap\nframeassembly amqp_rabbitmq_flow.frasm amqp_rabbitmq_flow.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse amqp_rabbitmq_flow.pcap amqp_rabbitmq_flow_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r amqp_rabbitmq_flow.pcap -Y \"amqp\"\n```\n\n## All `amqp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host amqp [protocolheader | connectionstart\n| channelopen | basicpublish | basicdeliver | heartbeat] [channel <0..65535>]\n[exchange \"<text>\"] [routingkey \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `protocolheader \\| connectionstart \\| channelopen \\| basicpublish \\| basicdeliver \\| heartbeat` | AMQP 0-9-1 frame/method selector | `basicpublish (channel 1)` | Selects the 8-byte AMQP header, Method frame (`Type 1`), or Heartbeat frame (`Type 8`). |\n| `channel <0..65535>` | 16-bit AMQP channel number (`0` for connection/heartbeat, `>= 1` for work channels) | `1 (0 on connectionstart/heartbeat)` | Sets bytes 1..2 of the 7-byte AMQP frame header. |\n| `exchange \"<text>\" \\| routingkey \"<text>\"` | Quoted exchange name and routing key | `exchange \"\", routingkey \"test\"` | Populates the Exchange and Routing-Key short strings in `basicpublish` and `basicdeliver`. |\n\n## Cross-Layer Options Valid with `amqp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 5672` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 5672)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Heartbeats Always Use Channel 0 Per AMQP 0-9-1\n\n- **Valid v3.3.0 Syntax:** `auth_svc <- mq_node amqp heartbeat channel 0`\n\nAMQP 0-9-1 requires `Type 8` Heartbeat frames to carry `channel 0` (`channel >= 1`\nis used for `channelopen`, `basicpublish`, and `basicdeliver`).\n"}
{"id":"pretrain-proto-modbus","kind":"protocol_spec","title":"Modbus TCP / UDP Industrial Application Protocol (modbus) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/modbus","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["modbus"],"text":"# modbus — Port 502 MBAP Register Reads & Coil Write Audits (`modbus`)\n\n> **FrameAssembly v3.3.0** · Protocol 105 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/modbus\n\n- **Full Protocol Name:** Modbus TCP / UDP Industrial Application Protocol\n- **Keyword:** `modbus`\n- **OSI Layer & Transport:** Layer 7 · TCP 502 (or UDP 502 via transport udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** Modbus Application Protocol v1.1b3\n- **Wireshark Display Filter:** `mbtcp || modbus`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 502 (or UDP 502 via transport udp) (transport tcp|udp) -> Modbus TCP`\n\n## Overview\n\nModbus has zero authentication: anyone who can reach TCP `502` can flip coils.\nCraft `readholdingregisters` (`FC 3`), `writesinglecoil` (`FC 5`), and\n`isresponse` PLC replies offline without making the plant manager sweat.\n\nModbus TCP (`modbus`) is the most widely deployed industrial protocol connecting\nSCADA HMIs, historians, VFDs, smart breakers, and PLCs over **TCP port `502`**\n(with `transport udp` available for Modbus-over-UDP gateways). Because Modbus has\n**zero built-in authentication**, industrial firewalls (Palo Alto, Fortinet,\nTofino/Hirschmann) and OT IDS platforms (Claroty, Nozomi, Dragos, Suricata, Zeek)\ninspect every **7-byte MBAP header + Function Code** to allow safe read polling\n(`FC 1..4`) while alerting on or blocking write commands (`FC 5, 6, 15, 16`).\n\nFrameAssembly builds exact MBAP headers (`txid`, `protoid 0`, `length`, `unitid`)\nand Modbus request or PLC reply (`isresponse`) PDUs completely offline—without\never touching live plant equipment.\n\n## Minimal Quickstart (`modbus_quickstart.frasm`)\n\n```frameassembly\nhost scada_hmi { ip 192.168.100.10 }\nhost plc_pump1 { ip 192.168.100.50 }\n\ncompile {\n    scada_hmi -> plc_pump1 tcp syn srcport 50502 dstport 502 wait 1ms\n    scada_hmi <- plc_pump1 tcp syn ack wait 1ms\n    scada_hmi -> plc_pump1 tcp ack wait 1ms\n    scada_hmi -> plc_pump1 modbus readholdingregisters txid 1 unitid 1 addr 100 count 2 wait 3ms\n    scada_hmi <- plc_pump1 modbus readholdingregisters txid 1 unitid 1 count 2 value 1500 isresponse\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `502` (`psh ack`), Protocol ID `0`, `unitid 1`,\n  and computes the 16-bit MBAP `Length` (`unitid + PDU bytes`) automatically.\n- Formats client Request PDUs (`addr` + `count` / `value`) by default, and\n  switches to PLC Response PDUs (`byte_count` + register/coil values) when\n  `isresponse` is set.\n- Translates `writesinglecoil value 1` into the standard Modbus `0xff00` (`ON`)\n  coil value automatically.\n\n## Practical Lab Example: Normal Historian Read Polling (`FC 3`) + Unauthorized Coil/Register Write (`FC 5` / `FC 6`) (`modbus_ot_conduit_test.frasm`)\n\nModels an HMI polling Holding Registers on Unit 1 (`FC 3` request + `isresponse`\nreply), followed by a `writesinglecoil` (`FC 5`) and `writesingleregister` (`FC\n6`) command to test OT write-detection alarms.\n\n```frameassembly\nhost hmi_01   { ip 10.100.10.15 }\nhost vfd_plc  { ip 10.100.20.50 }\n\ncompile {\n    hmi_01 -> vfd_plc tcp syn srcport 51502 dstport 502 win 65535 mss 1460 wait 1ms\n    hmi_01 <- vfd_plc tcp syn ack win 65535 mss 1460 wait 1ms\n    hmi_01 -> vfd_plc tcp ack wait 1ms\n    // 1. Authorized Read Holding Registers (FC 3) + PLC Response (isresponse)\n    hmi_01 -> vfd_plc modbus readholdingregisters txid 101 unitid 1 addr 0 count 4 wait 2ms\n    hmi_01 <- vfd_plc modbus readholdingregisters txid 101 unitid 1 count 4 value 3600 isresponse wait 5ms\n    // 2. Write Single Coil (FC 5) & Write Single Register (FC 6) -> triggers OT IDS write alert!\n    hmi_01 -> vfd_plc modbus writesinglecoil txid 102 unitid 1 addr 10 value 1 wait 2ms\n    hmi_01 <- vfd_plc modbus writesinglecoil txid 102 unitid 1 addr 10 value 1 isresponse wait 3ms\n    hmi_01 -> vfd_plc modbus writesingleregister txid 103 unitid 1 addr 200 value 1800\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show modbus_ot_conduit_test.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly modbus_ot_conduit_test.frasm modbus_ot_conduit_test.pcap\nframeassembly modbus_ot_conduit_test.frasm modbus_ot_conduit_test.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse modbus_ot_conduit_test.pcap modbus_ot_conduit_test_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r modbus_ot_conduit_test.pcap -Y \"mbtcp || modbus\"\n```\n\n## All `modbus` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host modbus [readcoils | readdiscreteinputs\n| readholdingregisters | readinputregisters | writesinglecoil |\nwritesingleregister | writemultipleregisters | func \"<name_or_fc>\"] [txid\n<0..65535>] [protoid <0..65535>] [unitid <0..255>] [addr <0..65535>] [count\n<0..65535>] [value <0..65535>] [isresponse] [transport <tcp|udp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `readcoils \\| readdiscreteinputs \\| readholdingregisters \\| readinputregisters \\| writesinglecoil \\| writesingleregister \\| writemultipleregisters \\| func \"<fc>\"` | Function Code keyword or number (`\"1\"`, `\"2\"`, `\"3\"`, `\"4\"`, `\"5\"`, `\"6\"`, `\"15\"`, `\"16\"`) | `readholdingregisters (FC 3)` | Sets the 1-byte Modbus Function Code immediately after `unitid`. |\n| `txid <0..65535> \\| protoid <0..65535> \\| unitid <0..255>` | MBAP Transaction ID, Protocol ID (`0` = Modbus), and Slave/Unit ID | `txid 1, protoid 0, unitid 1` | Populates the 7-byte MBAP header preceding the Modbus PDU. |\n| `addr <0..65535> \\| count <0..65535> \\| value <0..65535>` | 0-indexed starting register/coil address, item quantity, and write/reply value | `addr 0, count 1, value 0` | Populates register addresses, counts, and 16-bit data words. |\n| `isresponse` | Keyword flag on PLC replies | `Request format when omitted` | Formats `FC 1..4` packets as PLC responses (`[FC][ByteCount][Data...]`) so Wireshark dissects the reply without malformed-length warnings. |\n| `transport <tcp\\|udp>` | `tcp` or `udp` | `tcp` | Switches between Modbus TCP (`502`) and Modbus UDP (`502`). |\n\n## Cross-Layer Options Valid with `modbus`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 502 (or UDP 502 via transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Add isresponse on <- PLC Replies to Read Requests (FC 1..4)\n\n- **Avoid:** `scada_hmi <- plc_pump1 modbus readholdingregisters txid 1 count 2\n  value 1500`\n- **Valid v3.3.0 Syntax:** `scada_hmi <- plc_pump1 modbus readholdingregisters\n  txid 1 count 2 value 1500 isresponse`\n\nModbus uses the same Function Code (`0x03`) for both requests and responses, with\ndifferent wire layouts. Adding `isresponse` emits the PLC’s `Byte Count + Register\nValues` reply structure.\n"}
{"id":"pretrain-proto-bacnet","kind":"protocol_spec","title":"BACnet/IP Building Automation & Control Networks (bacnet) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/bacnet","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["bacnet"],"text":"# bacnet — UDP 47808 (0xbac0) BMS Who-Is & Property Frames (`bacnet`)\n\n> **FrameAssembly v3.3.0** · Protocol 106 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/bacnet\n\n- **Full Protocol Name:** BACnet/IP Building Automation & Control Networks\n- **Keyword:** `bacnet`\n- **OSI Layer & Transport:** Layer 7 · UDP 47808 (0xbac0)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** ASHRAE 135, ISO 16484-5\n- **Wireshark Display Filter:** `bacnet || bvlc || bacapp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 47808 (0xbac0) -> BACnet/IP`\n\n## Overview\n\nRunning on UDP `47808` (`0xbac0` — literally spells `BAC0` in hex!) across\nhospital chillers and data-center CRAC units, `bacnet` packs BVLC, NPDU, and\nconfirmed/unconfirmed APDUs cleanly.\n\nBACnet/IP (`bacnet`, ASHRAE 135) manages data-center chillers, CRAC cooling units,\nhospital HVAC controllers, elevators, and access-control panels over **UDP port\n`47808`** (`0xbac0`). Every BACnet/IP frame stacks three headers: the 4-byte\n**BVLC** (`0x81` BACnet/IP, Original-Broadcast `0x0b` or Original-Unicast `0x0a` +\n16-bit total length), the **NPDU** (`0x01`), and the **APDU** carrying Unconfirmed\n(`whois`, `iam`) or Confirmed (`readproperty`, `writeproperty`) services.\n\nFrameAssembly encodes context-tagged BACnet Object Identifiers (`objecttype` +\n22-bit `objectinstance`), Property Identifiers (`propertyid`, such as `85` for\n`Present-Value`), and application-tagged values automatically.\n\n## Minimal Quickstart (`bacnet_quickstart.frasm`)\n\n```frameassembly\nhost bms_srv     { ip 10.80.10.10 }\nhost chiller_ahu { ip 10.80.10.55 }\n\ncompile {\n    bms_srv -> chiller_ahu bacnet whois wait 3ms\n    bms_srv <- chiller_ahu bacnet iam objecttype 8 objectinstance 1055 wait 3ms\n    bms_srv -> chiller_ahu bacnet readproperty invokeid 1 objecttype 0 objectinstance 1 propertyid 85\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP source and destination port `47808` (`0xbac0`) and sets BVLC\n  Function to `0x0b` (`Original-Broadcast-NPDU`) on `whois`/`iam` or `0x0a`\n  (`Original-Unicast-NPDU`) on `readproperty`/`writeproperty`.\n- Bit-packs the 10-bit `objecttype` and 22-bit `objectinstance` into the 32-bit\n  ASHRAE 135 `BACnetObjectIdentifier` tag.\n- Defaults `propertyid` to `85` (`Present-Value`) and `objecttype` to `0`\n  (`Analog-Input`) when reading sensor points.\n\n## Practical Lab Example: Data-Center CRAC Discovery (`Who-Is`/`I-Am`), Temperature Read & Setpoint Write (`bacnet_dc_cooling_audit.frasm`)\n\nDiscovers CRAC device instance `2001`, reads Analog-Input 1 `Present-Value`\n(`propertyid 85`), and tests an unauthorized `writeproperty` setpoint change.\n\n```frameassembly\nhost bms_workstation { ip 192.168.90.10 }\nhost crac_unit_04    { ip 192.168.90.40 }\n\ncompile {\n    // 1. Device discovery: Who-Is -> I-Am (Object Type 8 = Device, Instance 2001)\n    bms_workstation -> crac_unit_04 bacnet whois wait 2ms\n    bms_workstation <- crac_unit_04 bacnet iam objecttype 8 objectinstance 2001 wait 5ms\n    // 2. Read return-air temperature (Object Type 0 = Analog-Input, Property 85 = Present-Value)\n    bms_workstation -> crac_unit_04 bacnet readproperty invokeid 10 objecttype 0 objectinstance 1 propertyid 85 wait 4ms\n    // 3. Write chiller setpoint (Object Type 2 = Analog-Value, Property 85 = Present-Value)\n    bms_workstation -> crac_unit_04 bacnet writeproperty invokeid 11 objecttype 2 objectinstance 1 propertyid 85 value 24\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show bacnet_dc_cooling_audit.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly bacnet_dc_cooling_audit.frasm bacnet_dc_cooling_audit.pcap\nframeassembly bacnet_dc_cooling_audit.frasm bacnet_dc_cooling_audit.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse bacnet_dc_cooling_audit.pcap bacnet_dc_cooling_audit_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r bacnet_dc_cooling_audit.pcap -Y \"bacnet || bvlc || bacapp\"\n```\n\n## All `bacnet` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host bacnet [whois | iam | readproperty |\nwriteproperty] [invokeid <0..255>] [objecttype <0..1023>] [objectinstance\n<number>] [propertyid <number>] [value <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `whois \\| iam \\| readproperty \\| writeproperty` | BACnet APDU service selector | `whois` | Selects Unconfirmed `Who-Is` (`8`), Unconfirmed `I-Am` (`0`), Confirmed `ReadProperty` (`12`), or Confirmed `WriteProperty` (`15`). |\n| `invokeid <0..255>` | 1-byte Confirmed-Request Invoke ID | `1` | Matches Confirmed `readproperty` / `writeproperty` requests with Complex-ACK / Simple-ACK replies. |\n| `objecttype <0..1023> \\| objectinstance <number>` | `0` Analog-Input, `1` Analog-Output, `2` Analog-Value, `3` Binary-Input, `8` Device + 22-bit instance | `objecttype 0, objectinstance 1 (or 8 / 1000 on iam)` | Packs the 4-byte `BACnetObjectIdentifier` (`(objecttype << 22) \\| objectinstance`). |\n| `propertyid <number>` | `85` Present-Value, `77` Object-Name, `28` Description | `85 (Present-Value)` | Encodes Context Tag `[1]` (`Property-Identifier`) in `readproperty` / `writeproperty`. |\n| `value <number>` | Unsigned value written on `writeproperty` | `0` | Encodes the `[3]` opening/closing context-tagged `Property-Value` inside `writeproperty`. |\n\n## Cross-Layer Options Valid with `bacnet`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 47808 (0xbac0)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 47808 (0xbac0))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Place bacnet Before whois (bacnet whois, Not Standalone whois)\n\n- **Avoid:** `bms_srv -> chiller_ahu whois`\n- **Valid v3.3.0 Syntax:** `bms_srv -> chiller_ahu bacnet whois`\n\nStandalone `whois` sends an Internet domain lookup on TCP port `43`; `bacnet\nwhois` sends an ASHRAE 135 BACnet/IP `Who-Is` broadcast on UDP port `47808`.\n"}
{"id":"pretrain-proto-dnp3","kind":"protocol_spec","title":"Distributed Network Protocol 3 (Electric & Water Utilities) (dnp3) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/dnp3","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["dnp3"],"text":"# dnp3 — Substation RTU Commands & Automatic Per-Chunk CRC-16 (`dnp3`)\n\n> **FrameAssembly v3.3.0** · Protocol 107 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/dnp3\n\n- **Full Protocol Name:** Distributed Network Protocol 3 (Electric & Water\n  Utilities)\n- **Keyword:** `dnp3`\n- **OSI Layer & Transport:** Layer 7 · TCP 20000 (or UDP 20000 via transport udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** IEEE 1815-2012\n- **Wireshark Display Filter:** `dnp3`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 20000 (or UDP 20000 via transport udp) (transport tcp|udp) -> DNP3 (IEEE\n  1815)`\n\n## Overview\n\nHand-crafting DNP3 usually makes grown engineers cry because IEEE 1815 demands a\nreflected CRC-16 after the `0x0564` link header *and* every 16 payload bytes —\n`dnp3` calculates every block CRC automatically (unless you pass `crc 0xdead` to\ntest bad-CRC alarms!).\n\nDistributed Network Protocol 3 (`dnp3`, IEEE 1815) is the primary SCADA telemetry\nand breaker-control protocol in North American electric substations, solar/wind\nfarms, and water/wastewater utilities on **TCP or UDP port `20000`**. Crafting\nvalid DNP3 packets by hand is notoriously hard because DNP3 inserts a reflected\n**IEEE 1815 CRC-16 (`0x3d65`, inverted)** after the 8-byte `0x0564` Data Link\nheader **and** after every 16-byte Data Link user-data block.\n\nFrameAssembly calculates every per-block DNP3 CRC-16 automatically (and also lets\nyou override `crc` deliberately if you want to test dissector malformed-CRC\nhandling!).\n\n## Minimal Quickstart (`dnp3_quickstart.frasm`)\n\n```frameassembly\nhost scada_master { ip 10.100.1.10 }\nhost sub_rtu_10   { ip 10.100.2.10 }\n\ncompile {\n    scada_master -> sub_rtu_10 tcp syn srcport 52000 dstport 20000 wait 1ms\n    scada_master <- sub_rtu_10 tcp syn ack wait 1ms\n    scada_master -> sub_rtu_10 tcp ack wait 1ms\n    scada_master -> sub_rtu_10 dnp3 read src 1 dst 10 group 30 variation 1 wait 3ms\n    scada_master <- sub_rtu_10 dnp3 response src 10 dst 1 group 30 variation 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `20000` (`transport udp` switches to UDP\n  `20000`) and builds the `0x0564` Data Link + Transport (`FIN|FIR`) + Application\n  headers.\n- Computes the reflected IEEE 1815 `0x3d65` CRC-16 across the 8-byte Data Link\n  header and every 16-byte user-data chunk automatically.\n- Encodes `src` and `dst` 16-bit DNP3 station addresses in little-endian wire\n  order per IEEE 1815.\n\n## Practical Lab Example: Substation Analog Input Poll (`Group 30`) + Select-Before-Operate (`Group 12` CROB) (`dnp3_substation_sbo.frasm`)\n\nPolls Analog Inputs (`group 30 variation 1`), receives an RTU\n`unsolicitedresponse` event (`group 2` Binary Input Change), and executes a\ntwo-step `select` -> `operate` breaker sequence.\n\n```frameassembly\nhost ems_master { ip 172.25.1.5 }\nhost feeder_rtu { ip 172.25.10.20 }\n\ncompile {\n    ems_master -> feeder_rtu tcp syn srcport 53000 dstport 20000 win 65535 mss 1460 wait 1ms\n    ems_master <- feeder_rtu tcp syn ack win 65535 mss 1460 wait 1ms\n    ems_master -> feeder_rtu tcp ack wait 1ms\n    // 1. Class/Group 30 Analog Input Read + RTU Response\n    ems_master -> feeder_rtu dnp3 read src 1 dst 20 group 30 variation 1 wait 3ms\n    ems_master <- feeder_rtu dnp3 response src 20 dst 1 group 30 variation 1 wait 10ms\n    // 2. RTU Unsolicited Event (Group 2 Binary Input Event) + Master Confirm\n    ems_master <- feeder_rtu dnp3 unsolicitedresponse src 20 dst 1 group 2 variation 2 wait 2ms\n    ems_master -> feeder_rtu dnp3 confirm src 1 dst 20 wait 5ms\n    // 3. Select-Before-Operate (Group 12 Variation 1 CROB) -> triggers high-priority OT alert\n    ems_master -> feeder_rtu dnp3 select src 1 dst 20 group 12 variation 1 wait 2ms\n    ems_master <- feeder_rtu dnp3 response src 20 dst 1 group 12 variation 1 wait 2ms\n    ems_master -> feeder_rtu dnp3 operate src 1 dst 20 group 12 variation 1\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show dnp3_substation_sbo.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly dnp3_substation_sbo.frasm dnp3_substation_sbo.pcap\nframeassembly dnp3_substation_sbo.frasm dnp3_substation_sbo.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse dnp3_substation_sbo.pcap dnp3_substation_sbo_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r dnp3_substation_sbo.pcap -Y \"dnp3\"\n```\n\n## All `dnp3` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host dnp3 [read | write | select | operate |\ndirectoperate | confirm | response | unsolicitedresponse | func \"<text>\"] [src\n<0..65535>] [dst <0..65535>] [group <0..255>] [variation <0..255>] [crc\n<hex_or_num>] [transport <tcp|udp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `read \\| write \\| select \\| operate \\| directoperate \\| confirm \\| response \\| unsolicitedresponse \\| func \"<text>\"` | DNP3 Application Function Code | `read (0x01)` | Selects `0x00` Confirm, `0x01` Read, `0x02` Write, `0x03` Select, `0x04` Operate, `0x05` Direct Operate, `0x81` Response, or `0x82` Unsolicited Response. |\n| `src <0..65535> \\| dst <0..65535>` | 16-bit DNP3 Data Link station addresses | `src 1, dst 10` | Sets the 2-byte little-endian DNP3 Source and Destination outstation/master addresses. |\n| `group <0..255> \\| variation <0..255>` | DNP3 Object Group (`1` Binary In, `12` CROB, `30` Analog In, `60` Class Data) + Variation | `group 30, variation 1` | Populates the Object Header `(Group, Variation)` inside the Application Layer. |\n| `crc <hex_or_num>` | Optional 16-bit link-header CRC override | `Auto-computed IEEE 1815 CRC-16` | Replaces the computed Data Link header CRC for negative/fuzz testing (omit for valid packets!). |\n| `transport <tcp\\|udp>` | `tcp` or `udp` | `tcp` | Switches Layer 4 between TCP `20000` and UDP `20000`. |\n\n## Cross-Layer Options Valid with `dnp3`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 20000 (or UDP 20000 via transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Swap DNP3 src and dst Station Addresses on <- RTU Replies\n\n- **Valid v3.3.0 Syntax:** `master -> rtu dnp3 read src 1 dst 10\nmaster <- rtu dnp3 response src 10 dst 1`\n\nWhile `<-` automatically flips Ethernet, IP, and TCP ports, DNP3 `src` and `dst`\nexplicitly set the Data Link station fields (`src 10 dst 1` when the RTU replies\nto Master `1`).\n\n### Omit crc Unless You Intentionally Want a Bad Checksum\n\n- **Valid v3.3.0 Syntax:** `scada_master -> sub_rtu_10 dnp3 read src 1 dst 10`\n\nFrameAssembly calculates the exact IEEE 1815 CRC-16 automatically whenever `crc`\nis omitted.\n"}
{"id":"pretrain-proto-s7comm","kind":"protocol_spec","title":"Siemens S7 Communication Protocol over ISO-on-TCP (s7comm) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/s7comm","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["s7comm"],"text":"# s7comm — Port 102 TPKT/COTP Siemens S7 Reads, Writes & Stop (`s7comm`)\n\n> **FrameAssembly v3.3.0** · Protocol 108 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/s7comm\n\n- **Full Protocol Name:** Siemens S7 Communication Protocol over ISO-on-TCP\n- **Keyword:** `s7comm`\n- **OSI Layer & Transport:** Layer 7 · TCP 102 (ISO-on-TCP)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 1006 (TPKT), ISO 8073 (COTP), Siemens S7comm\n- **Wireshark Display Filter:** `s7comm`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 102 (ISO-on-TCP) -> Siemens S7comm`\n\n## Overview\n\nWrapped inside RFC 1006 TPKT + ISO 8073 COTP on TCP `102`, `s7comm` builds Siemens\n`0x32` `readvar`, `writevar`, and high-severity `plcstop` frames so you can verify\nOT IDS signatures safely.\n\nSiemens S7 Communication (`s7comm`) connects TIA Portal / STEP 7 engineering\nstations and WinCC HMIs to SIMATIC S7-300, S7-400, S7-1200, and S7-1500 PLCs over\n**ISO-on-TCP port `102`**. Every S7comm packet wraps the `0x32` S7 PDU inside a\n**4-byte RFC 1006 TPKT header** (`0x03 0x00` + 16-bit total length) and a **3-byte\nISO 8073 COTP Data header** (`0x02 0xf0 0x80`).\n\nFrameAssembly builds the complete `TPKT + COTP + S7comm` stack for connection\nnegotiation (`setupcomm`), Data Block variable reads (`readvar`), variable writes\n(`writevar`), and high-impact `plccontrol` CPU Run/Stop commands—ideal for testing\nIEC 62443 OT firewalls and ICS threat detections safely offline.\n\n## Minimal Quickstart (`s7comm_quickstart.frasm`)\n\n```frameassembly\nhost wincc_hmi { ip 192.168.10.20 }\nhost s7_plc    { ip 192.168.10.100 }\n\ncompile {\n    wincc_hmi -> s7_plc tcp syn srcport 50102 dstport 102 wait 1ms\n    wincc_hmi <- s7_plc tcp syn ack wait 1ms\n    wincc_hmi -> s7_plc tcp ack wait 1ms\n    wincc_hmi -> s7_plc s7comm rosctr \"job\" setupcomm pduref 1 wait 2ms\n    wincc_hmi <- s7_plc s7comm rosctr \"ackdata\" setupcomm pduref 1 wait 2ms\n    wincc_hmi -> s7_plc s7comm rosctr \"job\" readvar pduref 2 area 0x84 dbnum 1 offset 0 count 4\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `102` (`psh ack`) and computes the outer 4-byte\n  TPKT (`0x03 0x00 <len>`) + 3-byte COTP DT (`0x02 0xf0 0x80`) framing\n  automatically.\n- Writes the `0x32` S7 Protocol ID, ROSCTR (`0x01` Job, `0x02` Ack, `0x03`\n  Ack_Data, `0x07` Userdata), 2-byte error class/code on `ackdata`, and exact\n  Parameter/Data lengths.\n- Encodes 12-byte S7Any (`0x12 0x0a 0x10`) variable item addressing (`area`,\n  `dbnum`, bit-shifted `offset * 8`, and `count`) automatically on\n  `readvar`/`writevar` Jobs.\n\n## Practical Lab Example: S7 Communication Setup, DB1 Read Poll, DB1 Write & PLC CPU Control Alert (`s7comm_plc_security_lab.frasm`)\n\nNegotiates S7 PDU parameters (`setupcomm`), polls 4 bytes from `DB1.DBB0` (`area\n0x84 dbnum 1`), writes to `DB1`, and emits a `plccontrol` Job to test critical OT\nsecurity alerts.\n\n```frameassembly\nhost tia_ws  { ip 10.110.1.15 }\nhost plc_315 { ip 10.110.2.102 }\n\ncompile {\n    tia_ws -> plc_315 tcp syn srcport 51102 dstport 102 win 65535 mss 1460 wait 1ms\n    tia_ws <- plc_315 tcp syn ack win 65535 mss 1460 wait 1ms\n    tia_ws -> plc_315 tcp ack wait 1ms\n    // 1. S7 Setup Communication (Func 0xf0)\n    tia_ws -> plc_315 s7comm rosctr \"job\" setupcomm pduref 100 wait 2ms\n    tia_ws <- plc_315 s7comm rosctr \"ackdata\" setupcomm pduref 100 wait 2ms\n    // 2. Read 4 bytes from Data Block 1 (area 0x84 = DB, dbnum 1, offset 0)\n    tia_ws -> plc_315 s7comm rosctr \"job\" readvar pduref 101 area 0x84 dbnum 1 offset 0 count 4 wait 2ms\n    tia_ws <- plc_315 s7comm rosctr \"ackdata\" readvar pduref 101 count 4 wait 5ms\n    // 3. WriteVar (0x05) + PLCControl (0x28) -> critical OT IDS signatures\n    tia_ws -> plc_315 s7comm rosctr \"job\" writevar pduref 102 area 0x84 dbnum 1 offset 0 count 2 wait 3ms\n    tia_ws <- plc_315 s7comm rosctr \"ackdata\" writevar pduref 102 wait 3ms\n    tia_ws -> plc_315 s7comm rosctr \"job\" plccontrol pduref 103\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show s7comm_plc_security_lab.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly s7comm_plc_security_lab.frasm s7comm_plc_security_lab.pcap\nframeassembly s7comm_plc_security_lab.frasm s7comm_plc_security_lab.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse s7comm_plc_security_lab.pcap s7comm_plc_security_lab_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r s7comm_plc_security_lab.pcap -Y \"s7comm\"\n```\n\n## All `s7comm` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host s7comm [setupcomm | readvar | writevar\n| plccontrol | func \"<text>\"] [rosctr \"<job|ack|ackdata|userdata>\"] [pduref\n<0..65535>] [area <hex_or_str>] [dbnum <0..65535>] [offset <number>] [count\n<0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `setupcomm \\| readvar \\| writevar \\| plccontrol \\| func \"<text>\"` | S7 Parameter Function (`0xf0` Setup, `0x04` ReadVar, `0x05` WriteVar, `0x28` PLCControl) | `setupcomm (0xf0)` | Selects the S7comm Parameter Function code. |\n| `rosctr \"<job\\|ack\\|ackdata\\|userdata>\"` | Remote Operating Service Control type | `\"job\" (0x01)` | Sets `0x01` Job (HMI/engineering request), `0x02` Ack, `0x03` Ack_Data (PLC reply with 2-byte error status), or `0x07` Userdata. |\n| `pduref <0..65535>` | 16-bit PDU Reference ID | `1` | Correlates each PLC `ackdata` response with its initiating `job`. |\n| `area <hex_or_str> \\| dbnum <0..65535>` | `0x84` Data Blocks (`DB`), `0x81` Inputs (`I`), `0x82` Outputs (`Q`), `0x83` Merkers (`M`) + DB number | `area 0x84 (DB), dbnum 1` | Sets the memory area and Data Block number in S7Any item addressing. |\n| `offset <number> \\| count <0..65535>` | Byte offset + item byte count | `offset 0, count 1` | Encodes the 24-bit bit-addressed start offset and 16-bit read/write length. |\n\n## Cross-Layer Options Valid with `s7comm`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 102 (ISO-on-TCP)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 102 (ISO-on-TCP))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Set rosctr \"ackdata\" on <- PLC Replies\n\n- **Avoid:** `wincc_hmi <- s7_plc s7comm readvar pduref 2 count 4`\n- **Valid v3.3.0 Syntax:** `wincc_hmi <- s7_plc s7comm rosctr \"ackdata\" readvar\n  pduref 2 count 4`\n\n`rosctr` defaults to `\"job\"` (a request from HMI to PLC). On `<-` replies from the\nPLC, specify `rosctr \"ackdata\"` so the 12-byte S7 Ack_Data header (with Error\nClass/Code `0x0000`) is written.\n"}
{"id":"pretrain-proto-s7commplus","kind":"protocol_spec","title":"Siemens SIMATIC S7-1200 / S7-1500 S7commPlus OMS Protocol (s7commplus) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/s7commplus","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["s7commplus"],"text":"# s7commplus — Port 102 S7-1200/1500 0x72 OMS+ Symbolic Sessions (`s7commplus`)\n\n> **FrameAssembly v3.3.0** · Protocol 109 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/s7commplus\n\n- **Full Protocol Name:** Siemens SIMATIC S7-1200 / S7-1500 S7commPlus OMS\n  Protocol\n- **Keyword:** `s7commplus`\n- **OSI Layer & Transport:** Layer 7 · TCP 102 (TPKT + COTP + 0x72)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** RFC 1006 (ISO-on-TCP), ISO 8073 COTP, Siemens OMS+ / S7commPlus\n- **Wireshark Display Filter:** `s7comm-plus || cotp`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 102 (TPKT + COTP + 0x72) -> Siemens S7commPlus`\n\n## Overview\n\nModern Siemens S7-1200 and S7-1500 PLCs replaced classic `0x32` `s7comm` with\n`0x72` `s7commplus` on TCP `102` — validate your OT IDS against TIA Portal\n`createobject`, `getmultivariables`, and `setmultivariables` sessions.\n\nSiemens S7commPlus (`s7commplus`) is the modern object-oriented **Object\nManagement System (OMS+)** protocol used by **TIA Portal, WinCC Unified, and\nSIMATIC S7-1200 / S7-1500 PLCs** on **TCP port `102`** (`RFC 1006 TPKT` + `ISO\n8073 COTP`). Unlike classic `s7comm` (`Protocol ID 0x32`), S7commPlus frames begin\nwith **`Protocol ID 0x72`**, a protocol `Version` (`1`, `2`, or `3` with\nTLS/integrity trailer), 16-bit `Data Length`, `Opcode` (`0x31` Request, `0x32`\nResponse, `0x33` Notification), 16-bit `Function Code` (`0x04ca` CreateObject\nsession setup, `0x0542` GetMultiVariables, `0x0552` SetMultiVariables, `0x0586`\nDeleteObject), `Sequence Number`, and `Session ID`.\n\nFrameAssembly wraps `0x72` S7commPlus headers and trailing `0x72 <version> 00 00`\nend-markers inside valid TPKT + COTP DT frames over stateful TCP port `102`.\n\n## Minimal Quickstart (`s7commplus_quickstart.frasm`)\n\n```frameassembly\nhost tia_portal { ip 192.168.10.20 }\nhost s7_1500    { ip 192.168.10.100 }\n\ncompile {\n    tia_portal -> s7_1500 tcp syn srcport 51102 dstport 102 wait 1ms\n    tia_portal <- s7_1500 tcp syn ack wait 1ms\n    tia_portal -> s7_1500 tcp ack wait 1ms\n    tia_portal -> s7_1500 s7commplus version 2 opcode 0x31 func \"createobject\" seqnum 1 sessionid 0 wait 2ms\n    tia_portal <- s7_1500 s7commplus version 2 isresponse func \"createobject\" seqnum 1 sessionid 0x000003e8\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `102` and prepends the 4-byte RFC 1006 `TPKT` (`03\n  00 <len>`) + 3-byte ISO 8073 `COTP DT Data` (`02 f0 80`) headers automatically.\n- Frames the inner `0x72` S7commPlus header, calculates the 16-bit OMS+ data block\n  length, and appends the mandatory 4-byte `0x72 <version> 00 00` trailer.\n- Sets `Opcode = 0x32` (`Response`) automatically whenever `isresponse` or\n  `response` is specified.\n\n## Practical Lab Example: TIA Portal <-> SIMATIC S7-1500 Session: CreateObject, GetMultiVariables & SetMultiVariables (`s7commplus_tia_portal_session.frasm`)\n\nOpens TCP `102` to a SIMATIC S7-1500 CPU, negotiates an S7commPlus session\n(`CreateObject` `0x04ca`), reads symbolic PLC tags (`GetMultiVariables` `0x0542`),\nand executes a tag write (`SetMultiVariables` `0x0552`).\n\n```frameassembly\nhost eng_laptop { ip 10.110.2.15 }\nhost plc_s71516 { ip 10.110.1.50 }\n\ncompile {\n    eng_laptop -> plc_s71516 tcp syn srcport 53102 dstport 102 win 65535 mss 1460 wait 1ms\n    eng_laptop <- plc_s71516 tcp syn ack win 65535 mss 1460 wait 1ms\n    eng_laptop -> plc_s71516 tcp ack wait 1ms\n    // 1. OMS+ Session Establishment: CreateObject (0x04ca) assigns Session ID 0x01000234\n    eng_laptop -> plc_s71516 s7commplus version 3 opcode 0x31 func 0x04ca seqnum 1 sessionid 0 id 0x010d wait 3ms\n    eng_laptop <- plc_s71516 s7commplus version 3 isresponse func 0x04ca seqnum 1 sessionid 0x01000234 wait 5ms\n    // 2. Symbolic Tag Poll: GetMultiVariables (0x0542 / \"read\")\n    eng_laptop -> plc_s71516 s7commplus version 3 func \"read\" seqnum 2 sessionid 0x01000234 id 0x8a0e0001 wait 2ms\n    eng_laptop <- plc_s71516 s7commplus version 3 isresponse func \"read\" seqnum 2 sessionid 0x01000234 wait 10ms\n    // 3. Tag Write: SetMultiVariables (0x0552 / \"write\") -> triggers OT write-policy inspection\n    eng_laptop -> plc_s71516 s7commplus version 3 func \"write\" seqnum 3 sessionid 0x01000234 id 0x8a0e0002 wait 2ms\n    eng_laptop <- plc_s71516 s7commplus version 3 isresponse func \"write\" seqnum 3 sessionid 0x01000234\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show s7commplus_tia_portal_session.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly s7commplus_tia_portal_session.frasm s7commplus_tia_portal_session.pcap\nframeassembly s7commplus_tia_portal_session.frasm s7commplus_tia_portal_session.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse s7commplus_tia_portal_session.pcap s7commplus_tia_portal_session_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r s7commplus_tia_portal_session.pcap -Y \"s7comm-plus || cotp\"\n```\n\n## All `s7commplus` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host s7commplus [version <1..3>] [opcode\n\"<text_or_num>\"] [isresponse | response] [func \"<text_or_num>\"] [seqnum\n<0..65535>] [sessionid <number>] [id <number>] [flags <0..255>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `version <1..3>` | 8-bit S7commPlus Protocol Version (`1`, `2`, or `3`) | `2` | Sets the Version byte immediately following the `0x72` magic byte in both header and trailer. |\n| `opcode \"<text_or_num>\" \\| isresponse \\| response` | 8-bit OMS+ Opcode (`0x31` Request, `0x32` Response, `0x33` Notification) | `0x31 (Request); 0x32 when isresponse/response is set` | Sets the S7commPlus message Opcode byte. |\n| `func \"<text_or_num>\"` | 16-bit Function Code or mnemonic (\"read\",\"write\",\"createobject\",\"deleteobject\",\"explore\") | `0x0542 (GetMultiVariables / read)` | Writes the 16-bit OMS+ Function Code (`0x04ca` CreateObject, `0x04d4` Explore, `0x0542` GetMultiVariables, `0x0552` SetMultiVariables, `0x0586` DeleteObject). |\n| `seqnum <0..65535>` | 16-bit PDU Sequence Number | `1` | Writes the big-endian 2-byte transaction Sequence Number. |\n| `sessionid <number> \\| id <number> \\| flags <0..255>` | 32-bit Session ID, 32-bit Object/Integrity ID, and 8-bit Transport Flags | `sessionid 1, id 0, flags 0x36` | Populates the 32-bit OMS+ Session ID, target Object ID, and transport flags. |\n\n## Cross-Layer Options Valid with `s7commplus`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 102 (TPKT + COTP + 0x72)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 102 (TPKT + COTP + 0x72))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Use s7commplus for S7-1200/S7-1500 (0x72) and s7comm for S7-300/S7-400 (0x32)\n\n- **Valid v3.3.0 Syntax:** `hmi -> s7_1500 s7commplus version 3 func \"read\" seqnum\n  1 sessionid 100`\n\nBoth protocols share TCP port `102` (`TPKT` + `COTP`), but S7-1200/1500 optimized\ndata blocks use `0x72` (`s7commplus`) instead of classic `0x32` (`s7comm`).\n\n### Match seqnum and sessionid on PLC Responses\n\n- **Valid v3.3.0 Syntax:** `hmi -> plc s7commplus func \"read\" seqnum 5 sessionid\n  200\nhmi <- plc s7commplus isresponse func \"read\" seqnum 5 sessionid 200`\n\nOT IDS state engines track `(sessionid, seqnum)` pairs to correlate PLC responses\nand flag injected rogue `SetMultiVariables` requests.\n"}
{"id":"pretrain-proto-ethernetip","kind":"protocol_spec","title":"ODVA EtherNet/IP & Common Industrial Protocol (Rockwell) (ethernetip) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/ethernetip","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ethernetip"],"text":"# ethernetip — Rockwell CIP Sessions (44818) & UDP 2222 I/O (`ethernetip`)\n\n> **FrameAssembly v3.3.0** · Protocol 110 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/ethernetip\n\n- **Full Protocol Name:** ODVA EtherNet/IP & Common Industrial Protocol (Rockwell)\n- **Keyword:** `ethernetip`\n- **OSI Layer & Transport:** Layer 7 · TCP 44818 (Explicit) / UDP 2222 (Implicit\n  I/O)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** ODVA EtherNet/IP, CIP Vol. 1 & Vol. 2\n- **Wireshark Display Filter:** `enip || cip`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 44818 (Explicit) / UDP 2222 (Implicit I/O) (transport tcp|udp) ->\n  EtherNet/IP (CIP)`\n\n## Overview\n\nFactory-floor CIP encapsulation: `ethernetip` uses TCP `44818` for explicit\nsessions (`registersession`, `sendrrdata`) and automatically hops to real-time UDP\n`2222` when you pick `sendunitdata`!\n\nEtherNet/IP (`ethernetip`, ODVA) encapsulates the **Common Industrial Protocol\n(CIP)** used across Rockwell Automation / Allen-Bradley ControlLogix &\nCompactLogix PLCs, Omron controllers, and industrial robots. Explicit session\nmanagement (`registersession`, `listidentity`, `sendrrdata`) runs over **TCP port\n`44818`** (`0xaf12`), while real-time cyclic I/O (`sendunitdata` or `transport\nudp`) runs over **UDP port `2222`**.\n\nFrameAssembly builds the little-endian 24-byte EtherNet/IP Encapsulation Header,\nCommon Packet Format (`CPF`) items, and EPATH-encoded CIP service requests\n(`cipservice`, `cipclass`, `cipinstance`, `cipattr`) automatically.\n\n## Minimal Quickstart (`ethernetip_quickstart.frasm`)\n\n```frameassembly\nhost factory_hmi { ip 192.168.20.10 }\nhost logix_plc   { ip 192.168.20.55 }\n\ncompile {\n    factory_hmi -> logix_plc tcp syn srcport 54818 dstport 44818 wait 1ms\n    factory_hmi <- logix_plc tcp syn ack wait 1ms\n    factory_hmi -> logix_plc tcp ack wait 1ms\n    factory_hmi -> logix_plc ethernetip registersession wait 2ms\n    factory_hmi <- logix_plc ethernetip registersession sessionhandle 0x00010001 wait 2ms\n    factory_hmi -> logix_plc ethernetip sendrrdata sessionhandle 0x00010001 cipservice 0x0e cipclass 0x01 cipinstance 1 cipattr 7\n}\n```\n\n### Automatic Wire Calculations\n\n- Selects TCP port `44818` for explicit encapsulation commands (`registersession`,\n  `listidentity`, `sendrrdata`) and automatically switches to UDP port `2222` on\n  `sendunitdata` or `transport udp`.\n- Encodes the 24-byte little-endian EtherNet/IP Encapsulation Header (`Command`,\n  `Length`, `Session Handle`, `Status`, 8-byte `Sender Context`, `Options`).\n- Builds Common Packet Format (`CPF`) Null/Unconnected Data items and logical\n  EPATH segments (`0x20` Class, `0x24` Instance, `0x30` Attribute) inside\n  `sendrrdata` and `sendunitdata`.\n\n## Practical Lab Example: PLC Discovery (`ListIdentity`), Session Registration, CIP Attribute Read & UDP 2222 I/O (`ethernetip_cip_cell.frasm`)\n\nPerforms a `listidentity` check, registers session `0x00010042` on TCP 44818,\nreads Assembly Instance `100` Attribute `3` (`Get_Attribute_Single` `0x0e`), and\nsends an implicit I/O packet on UDP 2222.\n\n```frameassembly\nhost studio_ws { ip 10.120.10.15 }\nhost clx_plc   { ip 10.120.10.60 }\n\ncompile {\n    studio_ws -> clx_plc tcp syn srcport 51818 dstport 44818 win 65535 mss 1460 wait 1ms\n    studio_ws <- clx_plc tcp syn ack win 65535 mss 1460 wait 1ms\n    studio_ws -> clx_plc tcp ack wait 1ms\n    // 1. ListIdentity (0x0063) + RegisterSession (0x0065)\n    studio_ws -> clx_plc ethernetip listidentity wait 2ms\n    studio_ws -> clx_plc ethernetip registersession context 0x1122334455667788 wait 2ms\n    studio_ws <- clx_plc ethernetip registersession sessionhandle 0x00010042 context 0x1122334455667788 status 0 wait 3ms\n    // 2. SendRRData (0x006f): CIP Get_Attribute_Single (0x0e) on Assembly Object (0x04), Instance 100, Attr 3\n    studio_ws -> clx_plc ethernetip sendrrdata sessionhandle 0x00010042 cipservice 0x0e cipclass 0x04 cipinstance 100 cipattr 3 wait 4ms\n    // 3. Implicit CIP I/O over UDP 2222 + UnRegisterSession\n    studio_ws -> clx_plc ethernetip sendunitdata sessionhandle 0x00010042 cipservice 0x0e cipclass 0x04 cipinstance 150 cipattr 3 transport udp wait 3ms\n    studio_ws -> clx_plc ethernetip unregistersession sessionhandle 0x00010042\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show ethernetip_cip_cell.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly ethernetip_cip_cell.frasm ethernetip_cip_cell.pcap\nframeassembly ethernetip_cip_cell.frasm ethernetip_cip_cell.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse ethernetip_cip_cell.pcap ethernetip_cip_cell_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r ethernetip_cip_cell.pcap -Y \"enip || cip\"\n```\n\n## All `ethernetip` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host ethernetip [nop | listservices |\nlistidentity | listinterfaces | registersession | unregistersession | sendrrdata |\nsendunitdata | cmd \"<text>\"] [sessionhandle <hex_or_num>] [status <number>]\n[context <hex_or_str>] [cipservice <hex_or_num>] [cipclass <hex_or_num>]\n[cipinstance <number>] [cipattr <number>] [transport <tcp|udp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `nop \\| listservices \\| listidentity \\| listinterfaces \\| registersession \\| unregistersession \\| sendrrdata \\| sendunitdata` | EtherNet/IP encapsulation command (or `cmd \"<text>\"`) | `listidentity (0x0063)` | Selects Encapsulation Command `0x0000` NOP, `0x0004` ListServices, `0x0063` ListIdentity, `0x0064` ListInterfaces, `0x0065` RegisterSession, `0x0066` UnRegisterSession, `0x006f` SendRRData, or `0x0070` SendUnitData. |\n| `sessionhandle <hex_or_num> \\| status <number> \\| context <hex_or_str>` | 32-bit Session Handle, 32-bit Status (`0` Success), 64-bit Sender Context | `sessionhandle 0, status 0` | Populates the 24-byte EtherNet/IP Encapsulation Header fields. |\n| `cipservice <hex_or_num>` | CIP Service Code (`0x01` Get_Attributes_All, `0x0e` Get_Attribute_Single, `0x10` Set_Attribute_Single, `0x4c` Read_Tag) | `0x0e (Get_Attribute_Single)` | Sets the CIP Service byte inside `sendrrdata` / `sendunitdata`. |\n| `cipclass <hex_or_num> \\| cipinstance <number> \\| cipattr <number>` | CIP Object Class (`0x01` Identity, `0x04` Assembly, `0x6b` Symbol), Instance, and Attribute | `cipclass 0x01, cipinstance 1, cipattr 1` | Encodes the logical EPATH segments targeting the PLC CIP object. |\n| `transport <tcp\\|udp>` | `tcp` or `udp` | `tcp (44818), or udp (2222) on sendunitdata` | Switches Layer 4 between TCP `44818` and UDP `2222`. |\n\n## Cross-Layer Options Valid with `ethernetip`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 44818 (Explicit) / UDP 2222 (Implicit I/O)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Protocol Keyword Is ethernetip (No Slash)\n\n- **Avoid:** `factory_hmi -> logix_plc ethernet/ip listidentity`\n- **Valid v3.3.0 Syntax:** `factory_hmi -> logix_plc ethernetip listidentity`\n\nSpell ODVA EtherNet/IP as `ethernetip` with no slash or hyphen.\n\n### Wireshark Display Filter Uses enip and cip\n\n- **Valid v3.3.0 Syntax:** `Wireshark display filter: enip || cip`\n\nWireshark dissects the 24-byte encapsulation layer under `enip` and the inner\nCommon Industrial Protocol payload under `cip`.\n"}
{"id":"pretrain-proto-opcua","kind":"protocol_spec","title":"OPC Unified Architecture Binary TCP Protocol (opcua) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/opcua","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["opcua"],"text":"# opcua — Port 4840 Purdue-DMZ Binary Chunks (HEL/ACK/OPN/MSG) (`opcua`)\n\n> **FrameAssembly v3.3.0** · Protocol 111 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/opcua\n\n- **Full Protocol Name:** OPC Unified Architecture Binary TCP Protocol\n- **Keyword:** `opcua`\n- **OSI Layer & Transport:** Layer 7 · TCP 4840\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** IEC 62541-6\n- **Wireshark Display Filter:** `opcua`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 4840 -> OPC UA`\n\n## Overview\n\nThe protocol bridging OT plant networks to IT historians across the industrial DMZ\non TCP `4840` — `opcua` writes little-endian `HEL -> ACK -> OPN -> MSG -> CLO`\nbinary chunks with exact message-size fields.\n\nOPC Unified Architecture (`opcua`, IEC 62541-6) is the cross-vendor Industry 4.0\nstandard used to bridge plant-floor PLCs across the **Purdue Level 3.5 Industrial\nDMZ** to historians, MES systems, and cloud analytics over **TCP port `4840`**.\nEvery OPC UA Binary message begins with an 8-byte header: a 3-character ASCII\n`MessageType` (`\"HEL\"`, `\"ACK\"`, `\"OPN\"`, `\"MSG\"`, `\"CLO\"`, `\"ERR\"`), a\n1-character `ChunkType` (`\"F\"` Final, `\"C\"` Intermediate, `\"A\"` Abort), and a\n**32-bit little-endian `MessageSize`**.\n\nFrameAssembly calculates the little-endian `MessageSize` automatically and encodes\n`\"HEL\"` (`endpointurl`), `\"ACK\"` buffer parameters, `\"OPN\"` secure channel setup,\nand `\"MSG\"` service calls carrying `securechannelid`, `tokenid`, `seqnum`,\n`reqid`, and `nodeid` strings.\n\n## Minimal Quickstart (`opcua_quickstart.frasm`)\n\n```frameassembly\nhost historian { ip 10.130.35.10 }\nhost ua_server { ip 10.130.20.48 }\n\ncompile {\n    historian -> ua_server tcp syn srcport 54840 dstport 4840 wait 1ms\n    historian <- ua_server tcp syn ack wait 1ms\n    historian -> ua_server tcp ack wait 1ms\n    historian -> ua_server opcua msgtype \"HEL\" chunktype \"F\" endpointurl \"opc.tcp://10.130.20.48:4840\" wait 2ms\n    historian <- ua_server opcua msgtype \"ACK\" chunktype \"F\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to TCP destination port `4840` (`psh ack`), `msgtype \"HEL\"`, `chunktype\n  \"F\"`, and calculates the 4-byte little-endian `MessageSize` across the entire\n  OPC UA frame.\n- Encodes IEC 62541-6 receive/send buffer sizes (`65535`) + length-prefixed UTF-8\n  `endpointurl` inside `\"HEL\"` and `\"ACK\"` frames.\n- Encodes `SecureChannelId`, `SecurityTokenId`, `SequenceNumber`, `RequestId`, and\n  ReadService `nodeid` fields inside `\"OPN\"`, `\"MSG\"`, and `\"CLO\"` frames.\n\n## Practical Lab Example: Complete OPC UA Connection (`HEL`/`ACK`), `OpenSecureChannel`, `NodeId` Read & `CLO` (`opcua_idmz_historian.frasm`)\n\nEstablishes an OPC UA Binary TCP 4840 session across an Industrial DMZ, opens\nSecure Channel `1`, reads `\"ns=2;s=Turbine1.RPM\"` via `\"MSG\"`, and closes cleanly\nwith `\"CLO\"`.\n\n```frameassembly\nhost idmz_hist { ip 172.18.35.20 }\nhost plant_ua  { ip 192.168.48.10 }\n\ncompile {\n    idmz_hist -> plant_ua tcp syn srcport 51840 dstport 4840 win 65535 mss 1460 wait 1ms\n    idmz_hist <- plant_ua tcp syn ack win 65535 mss 1460 wait 1ms\n    idmz_hist -> plant_ua tcp ack wait 1ms\n    // 1. Transport Hello / Acknowledge\n    idmz_hist -> plant_ua opcua msgtype \"HEL\" chunktype \"F\" endpointurl \"opc.tcp://192.168.48.10:4840/UA/PlantServer\" wait 2ms\n    idmz_hist <- plant_ua opcua msgtype \"ACK\" chunktype \"F\" wait 2ms\n    // 2. OpenSecureChannel (OPN)\n    idmz_hist -> plant_ua opcua msgtype \"OPN\" chunktype \"F\" securechannelid 0 seqnum 1 reqid 1 wait 2ms\n    idmz_hist <- plant_ua opcua msgtype \"OPN\" chunktype \"F\" securechannelid 1 tokenid 1 seqnum 1 reqid 1 wait 3ms\n    // 3. Service Read Request (MSG) for NodeId + CloseSecureChannel (CLO)\n    idmz_hist -> plant_ua opcua msgtype \"MSG\" chunktype \"F\" securechannelid 1 tokenid 1 seqnum 2 reqid 2 nodeid \"ns=2;s=Turbine1.RPM\" wait 4ms\n    idmz_hist -> plant_ua opcua msgtype \"CLO\" chunktype \"F\" securechannelid 1 tokenid 1 seqnum 3 reqid 3\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show opcua_idmz_historian.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly opcua_idmz_historian.frasm opcua_idmz_historian.pcap\nframeassembly opcua_idmz_historian.frasm opcua_idmz_historian.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse opcua_idmz_historian.pcap opcua_idmz_historian_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r opcua_idmz_historian.pcap -Y \"opcua\"\n```\n\n## All `opcua` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host opcua [msgtype\n\"<HEL|ACK|OPN|MSG|CLO|ERR>\"] [chunktype \"<F|C|A>\"] [securechannelid <number>]\n[tokenid <number>] [seqnum <number>] [reqid <number>] [endpointurl \"<text>\"]\n[nodeid \"<text>\"]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `msgtype \"<HEL\\|ACK\\|OPN\\|MSG\\|CLO\\|ERR>\"` | 3-character ASCII OPC UA message type | `\"HEL\"` | Sets bytes 0..2 (`HEL` Hello, `ACK` Acknowledge, `OPN` OpenSecureChannel, `MSG` Service Message, `CLO` Close, `ERR` Error). |\n| `chunktype \"<F\\|C\\|A>\"` | `\"F\"` Final chunk, `\"C\"` Intermediate chunk, `\"A\"` Abort | `\"F\"` | Sets byte 3 (`IsFinal`) of the 8-byte OPC UA Binary header. |\n| `endpointurl \"<text>\"` | Quoted `opc.tcp://...` endpoint URL on `\"HEL\"` | `\"opc.tcp://localhost:4840\"` | Writes the length-prefixed `EndpointUrl` string inside `\"HEL\"` messages. |\n| `securechannelid <number> \\| tokenid <number> \\| seqnum <number> \\| reqid <number>` | 32-bit little-endian channel, token, sequence, and request IDs | `1` | Populates the Secure Conversation and Sequence headers on `\"OPN\"`, `\"MSG\"`, and `\"CLO\"` frames. |\n| `nodeid \"<text>\"` | Quoted OPC UA NodeId string (`\"ns=2;s=Line1.Pressure\"`) | `Omitted unless set` | Encodes a String `NodeId` inside `\"MSG\"` ReadRequest payloads. |\n\n## Cross-Layer Options Valid with `opcua`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 4840` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 4840)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Keep msgtype and chunktype Uppercase Inside Quotes (\"HEL\", \"F\")\n\n- **Avoid:** `historian -> ua_server opcua hel`\n- **Valid v3.3.0 Syntax:** `historian -> ua_server opcua msgtype \"HEL\" chunktype\n  \"F\"`\n\nOPC UA specifies message types via `msgtype \"<3_CHARS>\"` (`\"HEL\"`, `\"ACK\"`,\n`\"OPN\"`, `\"MSG\"`, `\"CLO\"`, `\"ERR\"`) rather than bare keywords.\n"}
{"id":"pretrain-proto-iec104","kind":"protocol_spec","title":"IEC 60870-5-104 Substation Telecontrol Over TCP/IP (iec104) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/iec104","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["iec104"],"text":"# iec104 — Port 2404 IEC 60870-5-104 Substation I/S/U APDUs (`iec104`)\n\n> **FrameAssembly v3.3.0** · Protocol 112 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/iec104\n\n- **Full Protocol Name:** IEC 60870-5-104 Substation Telecontrol Over TCP/IP\n- **Keyword:** `iec104`\n- **OSI Layer & Transport:** Layer 7 · TCP 2404\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** IEC 60870-5-104, IEC 60870-5-101\n- **Wireshark Display Filter:** `iec60870_104`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 2404 -> IEC 60870-5-104`\n\n## Overview\n\nEuropean and Asian transmission grids run on TCP `2404` (`0x68` APCI start byte):\n`iec104` encodes `startdt`/`testfr` U-frames, `sframe` acknowledgments, and\nIEEE-754 `real` or integer ASDUs (`typeid`, `cot`, `ca`, `ioa`).\n\nIEC 60870-5-104 (`iec104`) is the dominant transmission and distribution\npower-grid SCADA telecontrol protocol across Europe, Asia, and Latin America (and\nnotorious from the 2016 **Industroyer / CrashOverride** Ukraine substation\nincident) on **TCP port `2404`**. Every APDU starts with **`0x68`**, an 8-bit\n`APDU Length`, and 4 **Application Protocol Control Information (APCI)** control\noctets encoding **U-Frames** (`STARTDT act/con`, `STOPDT`, `TESTFR`), **S-Frames**\n(Supervisory `N(R)` acknowledgments), or **I-Frames** (`N(S)`/`N(R)` sequence\nnumbers + an IEC 60870-5-101 **ASDU**: `TypeID`, `VSQ`, `Cause of Transmission\ncot`, 16-bit `Common Address ca`, 24-bit `Information Object Address ioa`, and\ninteger or IEEE 754 `real` telemetry/command values).\n\nFrameAssembly encodes shifted little-endian `(seq << 1)` I/S-frame control fields,\n16-bit `ca`, 24-bit `ioa`, and IEEE 754 single-precision floats (`real 49.98` ->\n`TypeID 13` `M_ME_NC_1` Short Floating Point).\n\n## Minimal Quickstart (`iec104_quickstart.frasm`)\n\n```frameassembly\nhost scada_cc { ip 10.104.1.10 }\nhost sub_rtu  { ip 10.104.2.50 }\n\ncompile {\n    scada_cc -> sub_rtu tcp syn srcport 52404 dstport 2404 wait 1ms\n    scada_cc <- sub_rtu tcp syn ack wait 1ms\n    scada_cc -> sub_rtu tcp ack wait 1ms\n    scada_cc -> sub_rtu iec104 startdt wait 2ms\n    scada_cc <- sub_rtu iec104 startdt confirm wait 5ms\n    scada_cc <- sub_rtu iec104 txseq 0 rxseq 0 typeid 13 cot 3 ca 1 ioa 1001 real 49.98\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `2404` and formats the `0x68` Start Byte + exact\n  `APDU Length` (`4` for U/S-frames, `4 + ASDU_len` for I-frames).\n- Encodes 15-bit `txseq` and `rxseq` shifted left by 1 bit (`seq << 1`) in\n  little-endian APCI octets per IEC 60870-5-104 Section 5.1.\n- Packs 16-bit little-endian Common Address (`ca`), 24-bit little-endian\n  Information Object Address (`ioa`), Quality Descriptor (`QDS = 0x00` Good), and\n  32-bit IEEE 754 little-endian floats when `real` is provided.\n\n## Practical Lab Example: Substation Telecontrol Session: U-Frame STARTDT, Spontaneous 50Hz Float Telemetry, S-Frame & Single Command (`iec104_substation_telecontrol.frasm`)\n\nActivates data transfer (`STARTDT act/con`), streams spontaneous grid frequency\ntelemetry (`TypeID 13`, `49.98 Hz`), acknowledges via `S-Frame`, executes a Single\nCommand (`TypeID 45`, `cot 6` -> `cot 7`), and exchanges `TESTFR` keepalives.\n\n```frameassembly\nhost dispatch_cc { ip 172.26.1.10 }\nhost bay_rtu_04  { ip 172.26.4.40 }\n\ncompile {\n    dispatch_cc -> bay_rtu_04 tcp syn srcport 54404 dstport 2404 wait 1ms\n    dispatch_cc <- bay_rtu_04 tcp syn ack wait 1ms\n    dispatch_cc -> bay_rtu_04 tcp ack wait 1ms\n    // 1. U-Frame STARTDT act (0x07) & STARTDT con (0x0b)\n    dispatch_cc -> bay_rtu_04 iec104 startdt wait 2ms\n    dispatch_cc <- bay_rtu_04 iec104 startdt confirm wait 5ms\n    // 2. I-Frame Spontaneous Measured Float (TypeID 13 M_ME_NC_1, COT 3 Spontaneous, IOA 4001 = 49.98 Hz)\n    dispatch_cc <- bay_rtu_04 iec104 txseq 0 rxseq 0 typeid 13 cot 3 ca 4 ioa 4001 real 49.98 wait 2ms\n    // 3. Supervisory S-Frame acknowledging RTU txseq 0 (rxseq = 1)\n    dispatch_cc -> bay_rtu_04 iec104 sframe rxseq 1 wait 10ms\n    // 4. Breaker Single Command (TypeID 45 C_SC_NA_1, COT 6 Activation -> COT 7 ActivationCon)\n    dispatch_cc -> bay_rtu_04 iec104 txseq 0 rxseq 1 typeid 45 cot 6 ca 4 ioa 6001 value 1 wait 3ms\n    dispatch_cc <- bay_rtu_04 iec104 txseq 1 rxseq 1 typeid 45 cot 7 ca 4 ioa 6001 value 1 wait 15ms\n    // 5. U-Frame TESTFR act & con keepalive\n    dispatch_cc -> bay_rtu_04 iec104 testfr wait 2ms\n    dispatch_cc <- bay_rtu_04 iec104 testfr confirm\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show iec104_substation_telecontrol.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly iec104_substation_telecontrol.frasm iec104_substation_telecontrol.pcap\nframeassembly iec104_substation_telecontrol.frasm iec104_substation_telecontrol.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse iec104_substation_telecontrol.pcap iec104_substation_telecontrol_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r iec104_substation_telecontrol.pcap -Y \"iec60870_104\"\n```\n\n## All `iec104` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host iec104 [startdt | stopdt | testfr |\nsframe | msgtype \"<text>\"] [confirm] [txseq <0..32767>] [rxseq <0..32767>] [typeid\n<0..255>] [cot \"<text_or_num>\"] [ca <0..65535>] [ioa <0..16777215>] [value\n<number>] [real <decimal>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `startdt \\| stopdt \\| testfr \\| sframe \\| msgtype \"<text>\" \\| [confirm]` | APCI frame format (`U-Frame` STARTDT/STOPDT/TESTFR, `S-Frame`, or default `I-Frame` when ASDU fields are present) | `I-Frame (or U-Frame when startdt/stopdt/testfr is set)` | Selects U-Frame (`0x07`/`0x0b` STARTDT, `0x13`/`0x23` STOPDT, `0x43`/`0x83` TESTFR with `confirm`), S-Frame (`0x01`), or I-Frame (`N(S)`/`N(R)` + ASDU). |\n| `txseq <0..32767> \\| rxseq <0..32767>` | 15-bit Send `N(S)` & Receive `N(R)` sequence numbers | `txseq 0, rxseq 0` | Encodes `(txseq << 1)` and `(rxseq << 1)` in APCI control octets 1..4. |\n| `typeid <0..255>` | 8-bit IEC 60870-5-101/104 Type Identification | `13 (M_ME_NC_1 when real is set) or 1 (M_SP_NA_1)` | Sets ASDU byte 0 (`1` Single-Point, `9` Normalized Meas, `13` Short Float, `36` Float w/ CP56Time2a, `45` Single Cmd, `46` Double Cmd, `100` Interrogation). |\n| `cot \"<text_or_num>\"` | Cause of Transmission (`3` Spont, `6` Act, `7` ActCon, `10` ActTerm, `20` Interrogated) | `3 (Spontaneous)` | Writes the 16-bit Cause of Transmission field in the ASDU header. |\n| `ca <0..65535> \\| ioa <0..16777215>` | 16-bit Common Address of ASDU & 24-bit Information Object Address | `ca 1, ioa 1` | Writes the 2-byte little-endian station `CA` and 3-byte little-endian data-point `IOA`. |\n| `value <number> \\| real <decimal>` | Integer state/command byte or IEEE 754 floating-point number (e.g. `49.98`, `-12.5`) | `value 1` | Encodes Single/Double/Measured integer values (`value`) or 4-byte IEEE 754 float + QDS (`real`). |\n\n## Cross-Layer Options Valid with `iec104`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 2404` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 2404)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Combine startdt/testfr with confirm (Not response) for U-Frame Confirmations\n\n- **Avoid:** `cc <- rtu iec104 startdt response`\n- **Valid v3.3.0 Syntax:** `cc <- rtu iec104 startdt confirm`\n\nIEC 60870-5-104 U-Frames pair Activation (`act`) with Confirmation (`con`, enabled\nvia the `confirm` flag keyword).\n\n### Do Not Include typeid/ioa on Pure U-Frames If You Want a 6-Byte APCI Packet\n\n- **Avoid:** `cc -> rtu iec104 startdt ca 1 ioa 1001 real 49.98`\n- **Valid v3.3.0 Syntax:** `cc -> rtu iec104 startdt\ncc <- rtu iec104 typeid 13 cot 3 ca 1 ioa 1001 real 49.98`\n\nReal substations exchange 6-byte U-Frame `STARTDT act` / `STARTDT con` packets\nfirst before transmitting ASDU I-Frames (`ca`, `ioa`, `real`).\n"}
{"id":"pretrain-proto-mms","kind":"protocol_spec","title":"Manufacturing Message Specification (IEC 61850 Station Bus) (mms) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/mms","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["mms"],"text":"# mms — Port 102 ISO 9506 / IEC 61850-8-1 Substation Client/Server (`mms`)\n\n> **FrameAssembly v3.3.0** · Protocol 113 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/mms\n\n- **Full Protocol Name:** Manufacturing Message Specification (IEC 61850 Station\n  Bus)\n- **Keyword:** `mms`\n- **OSI Layer & Transport:** Layer 7 · TCP 102 (TPKT + COTP + OSI\n  Session/Pres/ACSE)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** ISO 9506-1 / 9506-2, IEC 61850-8-1, RFC 1006\n- **Wireshark Display Filter:** `mms`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 102 (TPKT + COTP + OSI Session/Pres/ACSE) -> ISO 9506 MMS (IEC 61850-8-1)`\n\n## Overview\n\nBuilding a valid ISO 9506 MMS packet by hand means nesting seven OSI layers (TPKT\n-> COTP -> Session -> Presentation -> ACSE -> ASN.1 BER MMS) on TCP `102` — `mms`\nassembles the entire IEC 61850-8-1 station-bus stack in one line!\n\nManufacturing Message Specification (`mms`, ISO 9506 / IEC 61850-8-1) is the\nclient-server **station-bus protocol** connecting substation SCADA gateways and\nHMIs to protection **Intelligent Electronic Devices (IEDs)** over **TCP port\n`102`**. Manually crafting valid MMS packets is famously painful because every MMS\nASN.1 BER PDU sits atop a **5-layer ISO/OSI stack**: `RFC 1006 TPKT` -> `ISO 8073\nCOTP` -> `ISO 8327 Session` -> `ISO 8823 Presentation` (+ `ISO 8650 ACSE` on\nInitiate) -> **`ISO 9506 MMS`** (`Initiate-RequestPDU`, `Confirmed-RequestPDU`,\n`Confirmed-ResponsePDU`, `Unconfirmed-PDU` InformationReport, `Conclude`).\n\nFrameAssembly builds the entire TPKT + COTP + OSI Session/Presentation/ACSE\nenvelope automatically so your IEC 61850 Logical Device (`domain \"IED1LD0\"`) and\nLogical Node variable (`item \"MMXU1$MX$PhV\"` or `\"CSWI1$CO$Pos\"`) dissect cleanly\nin Wireshark (`mms`).\n\n## Minimal Quickstart (`mms_quickstart.frasm`)\n\n```frameassembly\nhost station_hmi { ip 10.61.85.10 }\nhost relay_ied01 { ip 10.61.85.51 }\n\ncompile {\n    station_hmi -> relay_ied01 tcp syn srcport 52102 dstport 102 wait 1ms\n    station_hmi <- relay_ied01 tcp syn ack wait 1ms\n    station_hmi -> relay_ied01 tcp ack wait 1ms\n    station_hmi -> relay_ied01 mms read invokeid 1 domain \"IED1LD0\" item \"MMXU1$MX$TotW\" wait 3ms\n    station_hmi <- relay_ied01 mms read isresponse invokeid 1 value 1450\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `102` and constructs the full RFC 1006 `TPKT` +\n  ISO 8073 `COTP DT` + ISO 8327 `Session` + ISO 8823 `Presentation` (+ `ACSE` on\n  `init`/`initack`) stack.\n- Encodes ASN.1 BER `Confirmed-RequestPDU` (`0xa0`), `Confirmed-ResponsePDU`\n  (`0xa1`), `Unconfirmed-PDU` (`0xa3` for `report`), `Initiate-RequestPDU`\n  (`0xa8`), `Initiate-ResponsePDU` (`0xa9`), and `Conclude` (`0x8b`).\n- Wraps `domain` and `item` (`$`-delimited IEC 61850 functional constraint paths\n  like `\"XCBR1$ST$Pos\"`) into `ObjectName :: domain-specific` BER sequences.\n\n## Practical Lab Example: IEC 61850 Substation Bay Workflow: MMS Initiate, GetNameList, MMXU Read, Report & CSWI Write (`mms_iec61850_station_bus.frasm`)\n\nAssociates an IEC 61850 station HMI with Bay Relay `IED01` (`init`/`initack`),\nenumerates `IED01LD0` via `getnamelist`, reads `MMXU1$MX$PhV`, receives a\nspontaneous `RPT` `report`, and writes `CSWI1$CO$Pos`.\n\n```frameassembly\nhost sub_gateway { ip 172.21.61.10 }\nhost feeder_ied1 { ip 172.21.61.101 }\n\ncompile {\n    sub_gateway -> feeder_ied1 tcp syn srcport 54102 dstport 102 wait 1ms\n    sub_gateway <- feeder_ied1 tcp syn ack wait 1ms\n    sub_gateway -> feeder_ied1 tcp ack wait 1ms\n    // 1. OSI ACSE + MMS Initiate Request & Response\n    sub_gateway -> feeder_ied1 mms init wait 3ms\n    sub_gateway <- feeder_ied1 mms initack wait 4ms\n    // 2. GetNameList (InvokeID 1) + Read Phase Voltage MMXU1$MX$PhV (InvokeID 2)\n    sub_gateway -> feeder_ied1 mms getnamelist invokeid 1 domain \"IED1LD0\" wait 2ms\n    sub_gateway <- feeder_ied1 mms getnamelist isresponse invokeid 1 domain \"IED1LD0\" item \"MMXU1\" wait 4ms\n    sub_gateway -> feeder_ied1 mms read invokeid 2 domain \"IED1LD0\" item \"MMXU1$MX$PhV\" wait 2ms\n    sub_gateway <- feeder_ied1 mms read isresponse invokeid 2 value 138000 wait 10ms\n    // 3. Unconfirmed InformationReport from IED (Breaker status change)\n    sub_gateway <- feeder_ied1 mms report domain \"IED1LD0\" item \"XCBR1$ST$Pos\" value 2 wait 5ms\n    // 4. Switch Controller Write (CSWI1$CO$Pos) -> Confirmed Write Response\n    sub_gateway -> feeder_ied1 mms write invokeid 3 domain \"IED1LD0\" item \"CSWI1$CO$Pos\" value 1 wait 2ms\n    sub_gateway <- feeder_ied1 mms write isresponse invokeid 3 value 0\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show mms_iec61850_station_bus.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly mms_iec61850_station_bus.frasm mms_iec61850_station_bus.pcap\nframeassembly mms_iec61850_station_bus.frasm mms_iec61850_station_bus.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse mms_iec61850_station_bus.pcap mms_iec61850_station_bus_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r mms_iec61850_station_bus.pcap -Y \"mms\"\n```\n\n## All `mms` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host mms [init | initack | getnamelist |\nread | write | report | conclude | service \"<text>\"] [isresponse | response]\n[invokeid <number>] [domain \"<text>\"] [item \"<text>\"] [value <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `init \\| initack \\| getnamelist \\| read \\| write \\| report \\| conclude \\| service \"<text>\"` | ISO 9506 MMS Service selector | `read` | Selects `Initiate-RequestPDU` (`init`), `Initiate-ResponsePDU` (`initack`), `GetNameList` (`1`), `Read` (`4`), `Write` (`5`), `InformationReport` (`report`), or `Conclude`. |\n| `isresponse \\| response` | Confirmed-ResponsePDU toggle flag | `Request (Confirmed-RequestPDU 0xa0)` | Switches `read` / `write` / `getnamelist` from `Confirmed-RequestPDU` (`0xa0`) to `Confirmed-ResponsePDU` (`0xa1`). |\n| `invokeid <number>` | 32-bit unsigned MMS `invokeID` | `1` | Encodes the ASN.1 BER integer `invokeID` correlating Confirmed Requests and Confirmed Responses. |\n| `domain \"<text>\" \\| item \"<text>\"` | IEC 61850 Logical Device `domainId` & `$`-separated `itemId` | `domain \"LD0\", item \"LLN0$ST$Mod\"` | Populates the `domain-specific` `(VisibleString domainId, VisibleString itemId)` variable specification. |\n| `value <number>` | Integer `Data` access value (`Read` response, `Write` request, or `InformationReport`) | `0` | Encodes an ASN.1 BER `Data :: integer` / `unsigned` element inside `listOfAccessResult` or `listOfData`. |\n\n## Cross-Layer Options Valid with `mms`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 102 (TPKT + COTP + OSI Session/Pres/ACSE)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 102 (TPKT + COTP + OSI Session/Pres/ACSE))` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Distinguish Station-Bus mms (TCP 102) from Process/Bay-Level goose (L2 0x88b8)\n\n- **Valid v3.3.0 Syntax:** `hmi -> ied mms read invokeid 1 domain \"LD0\" item\n  \"MMXU1$MX$PhV\"\nied -> peer_ied goose appid 0x1000 gocbref \"IED1/LLN0$GO$gcb01\" stnum 2 sqnum 0`\n\nIn IEC 61850 substations, client-server SCADA polling/control uses TCP `102`\n`mms`, whereas sub-4ms relay-to-relay protection trips use Layer 2 multicast\n`goose` (`0x88b8`).\n\n### Add isresponse (or response) When Returning Confirmed-ResponsePDU Frames\n\n- **Valid v3.3.0 Syntax:** `hmi <- ied mms read isresponse invokeid 1 value 230`\n\n`<-` flips the TCP direction (`102 -> client`), while `isresponse` switches the\nASN.1 BER tag from `Confirmed-RequestPDU (0xa0)` to `Confirmed-ResponsePDU\n(0xa1)`.\n"}
{"id":"pretrain-proto-synchrophasor","kind":"protocol_spec","title":"IEEE C37.118.2 PMU / PDC Wide-Area Grid Synchrophasor Telemetry (synchrophasor) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/synchrophasor","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["synchrophasor"],"text":"# synchrophasor — Port 4712 IEEE C37.118 PMU Phasors & CRC-CCITT (`synchrophasor`)\n\n> **FrameAssembly v3.3.0** · Protocol 114 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/synchrophasor\n\n- **Full Protocol Name:** IEEE C37.118.2 PMU / PDC Wide-Area Grid Synchrophasor\n  Telemetry\n- **Keyword:** `synchrophasor`\n- **OSI Layer & Transport:** Layer 7 · TCP 4712 (or UDP 4712/4713 via transport\n  udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** IEEE C37.118.2-2011, IEC/IEEE 60255-118-1\n- **Wireshark Display Filter:** `synphasor`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 4712 (or UDP 4712/4713 via transport udp) (transport tcp|udp) -> IEEE\n  C37.118 Synchrophasor`\n\n## Overview\n\nWide-area grid Phasor Measurement Units stream 50/60 Hz telemetry on port `4712`:\n`synchrophasor` packs the `0xaa` sync byte, `id` code, SOC `timestamp`, `fracsec`,\n`station` name, and trailing CRC-16-CCITT automatically.\n\nIEEE C37.118.2 Synchrophasor (`synchrophasor`) streams GPS/PTP time-synchronized\n**Phasor Measurement Unit (PMU)** voltage/current phase angles, grid frequency\n(`50`/`60` Hz), and Rate of Change of Frequency (`ROCOF`) to **Phasor Data\nConcentrators (PDCs)** at `30`–`120` frames per second on **TCP port `4712` and\nUDP port `4713`**. Every frame starts with a **`0xaa` SYNC byte** (`Type |\nVersion`), 16-bit `FRAMESIZE`, 16-bit `IDCODE` (`id`), 32-bit UTC `SOC`\n(`timestamp`), 32-bit `FRACSEC` (`Time Quality + Fraction of Second`), frame body\n(`Data` `0`, `Header` `1`, `CFG-2` `2`/`3`, or `Command` `4`), and a trailing\n**16-bit `CRC-CCITT` (`0x1021`, init `0xffff`)**.\n\nFrameAssembly computes `FRAMESIZE` and the trailing **IEEE C37.118 CRC-CCITT**\nautomatically across TCP or `transport udp` streams.\n\n## Minimal Quickstart (`synchrophasor_quickstart.frasm`)\n\n```frameassembly\nhost regional_pdc { ip 10.118.1.10 }\nhost sub_pmu_01   { ip 10.118.2.50 }\n\ncompile {\n    regional_pdc -> sub_pmu_01 tcp syn srcport 54712 dstport 4712 wait 1ms\n    regional_pdc <- sub_pmu_01 tcp syn ack wait 1ms\n    regional_pdc -> sub_pmu_01 tcp ack wait 1ms\n    regional_pdc -> sub_pmu_01 synchrophasor cmd \"dataon\" id 101 timestamp 1735689600 wait 3ms\n    regional_pdc <- sub_pmu_01 synchrophasor msgtype \"data\" id 101 timestamp 1735689600 fracsec 0 status 0x0000\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `4712` (`transport udp` switches to UDP `4712`, or\n  pair with `dstport 4713` for spontaneous UDP data streams).\n- Encodes `SYNC = 0xaa00 | (FrameType << 4) | Version` (`0xaa01` Data, `0xaa11`\n  Header, `0xaa31` CFG-2, `0xaa41` Command) and exact 16-bit `FRAMESIZE`.\n- Calculates the big-endian 16-bit `CRC-CCITT` (`poly 0x1021`, `init 0xffff`) over\n  the entire frame unless `crc` is explicitly overridden.\n\n## Practical Lab Example: PMU Configuration Handshake (`CFG-2`) + 60 Hz UDP 4713 Synchrophasor Stream (`synchrophasor_pdc_pmu_stream.frasm`)\n\nRequests PMU `101`’s `CFG-2` descriptor (`station \"SUB_WEST_500KV\"`) and enables\nreal-time transmission over TCP `4712`, then streams consecutive `16.667 ms` UDP\n`4713` phasor frames.\n\n```frameassembly\nhost openpdc_srv { ip 172.27.118.5 }\nhost pmu_500kv   { ip 172.27.118.101 }\n\ncompile {\n    openpdc_srv -> pmu_500kv tcp syn srcport 51712 dstport 4712 wait 1ms\n    openpdc_srv <- pmu_500kv tcp syn ack wait 1ms\n    openpdc_srv -> pmu_500kv tcp ack wait 1ms\n    // 1. PDC requests CFG-2 (0x0005) -> PMU returns 16-byte padded STN \"SUB_WEST_500KV\"\n    openpdc_srv -> pmu_500kv synchrophasor cmd \"sendcfg2\" id 101 timestamp 1735689600 wait 2ms\n    openpdc_srv <- pmu_500kv synchrophasor msgtype \"cfg2\" id 101 station \"SUB_WEST_500KV\" timestamp 1735689600 wait 3ms\n    // 2. PDC sends Turn On Transmission (0x0002)\n    openpdc_srv -> pmu_500kv synchrophasor cmd \"dataon\" id 101 timestamp 1735689600 wait 2ms\n    // 3. PMU streams 60fps (16667us gap) synchrophasor data over UDP 4713 with DSCP EF (46)\n    pmu_500kv -> openpdc_srv synchrophasor msgtype \"data\" id 101 timestamp 1735689601 fracsec 0 status 0x0000 dstport 4713 dscp 46 transport udp wait 16667us\n    pmu_500kv -> openpdc_srv synchrophasor msgtype \"data\" id 101 timestamp 1735689601 fracsec 16667 status 0x0000 dstport 4713 dscp 46 transport udp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show synchrophasor_pdc_pmu_stream.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly synchrophasor_pdc_pmu_stream.frasm synchrophasor_pdc_pmu_stream.pcap\nframeassembly synchrophasor_pdc_pmu_stream.frasm synchrophasor_pdc_pmu_stream.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse synchrophasor_pdc_pmu_stream.pcap synchrophasor_pdc_pmu_stream_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r synchrophasor_pdc_pmu_stream.pcap -Y \"synphasor\"\n```\n\n## All `synchrophasor` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host synchrophasor [msgtype \"<text>\"]\n[version <1..2>] [id <0..65535>] [timestamp <number>] [fracsec <number>] [cmd\n\"<text_or_num>\"] [status <0..65535>] [station \"<text>\"] [crc <0..65535>]\n[transport <tcp|udp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `msgtype \"<text>\" \\| cmd \"<text_or_num>\"` | Frame Type (\"data\",\"header\",\"cfg1\",\"cfg2\",\"cmd\") or 16-bit PDC Command (\"dataoff\",\"dataon\",\"sendhdr\",\"sendcfg1\",\"sendcfg2\") | `msgtype \"data\" (or \"cmd\" when cmd is set)` | Selects C37.118 Frame Type (`0` Data, `1` Header, `2` CFG-1, `3` CFG-2, `4` Command) and Command word (`0x0001` Data Off, `0x0002` Data On, `0x0005` Send CFG-2). |\n| `version <1..2> \\| id <0..65535>` | 4-bit C37.118 Version (`1`=2005, `2`=2011) & 16-bit PMU/PDC `IDCODE` | `version 1, id 1` | Writes the low nibble of `SYNC` byte 1 and bytes 4..5 (`IDCODE`). |\n| `timestamp <number> \\| fracsec <number>` | 32-bit UTC Second-of-Century (`SOC`) & 32-bit `FRACSEC` (Time Quality + 24-bit fraction) | `timestamp 1700000000, fracsec 0` | Writes bytes 6..13 (`SOC` and `FRACSEC`) used by PDCs to time-align phasors across substations. |\n| `status <0..65535> \\| station \"<text>\"` | 16-bit Data Frame `STAT` bitmask & 16-char ASCII `STN` Station Name (on `cfg1`/`cfg2`) | `status 0x0000 (Valid/Locked), station \"PMU_STATION_01\"` | Writes PMU `STAT` flags in Data frames or the space-padded 16-byte `STN` field in Configuration frames. |\n| `crc <0..65535> \\| transport <tcp\\|udp>` | Optional 16-bit CRC-CCITT override & L4 transport selector | `Auto CRC-CCITT, transport tcp` | Replaces the trailing 2-byte `CRC-CCITT` or switches between TCP and UDP. |\n\n## Cross-Layer Options Valid with `synchrophasor`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 4712 (or UDP 4712/4713 via transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Include a CFG-2 Frame Before Data Frames So Wireshark Knows Phasor Counts\n\n- **Valid v3.3.0 Syntax:** `pdc <- pmu synchrophasor msgtype \"cfg2\" id 101 station\n  \"SUB_01\"\npdc <- pmu synchrophasor msgtype \"data\" id 101`\n\nPer IEEE C37.118.2, `Data` frames contain raw packed phasor/analog values whose\nlayout is defined by the preceding `CFG-2` frame for that `id` (`IDCODE`).\n\n### Omit crc for Valid Captures\n\n- **Valid v3.3.0 Syntax:** `pdc -> pmu synchrophasor cmd \"dataon\" id 101`\n\nFrameAssembly computes the exact `0x1021` `CRC-CCITT` automatically unless `crc`\nis passed for negative testing.\n"}
{"id":"pretrain-proto-hartip","kind":"protocol_spec","title":"Highway Addressable Remote Transducer Over IP (Process Field Instruments) (hartip) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/hartip","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["hartip"],"text":"# hartip — Port 5094 FieldComm HART-IP Process Transmitter Gateways (`hartip`)\n\n> **FrameAssembly v3.3.0** · Protocol 115 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/hartip\n\n- **Full Protocol Name:** Highway Addressable Remote Transducer Over IP (Process\n  Field Instruments)\n- **Keyword:** `hartip`\n- **OSI Layer & Transport:** Layer 7 · UDP 5094 (or TCP 5094 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** FieldComm Group HCF_SPEC-085, IEC 62591 (WirelessHART)\n- **Wireshark Display Filter:** `hart_ip`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 5094 (or TCP 5094 via transport tcp) (transport tcp|udp) -> HART-IP (IEC\n  62591)`\n\n## Overview\n\nSmart 4–20 mA pressure and valve transmitters reach IP historians via\nWirelessHART/HART-IP gateways on port `5094` — `hartip` wraps the 8-byte HART-IP\nheader + inner HART token-ring PDU with valid XOR checksums.\n\nHART-IP (`hartip`, FieldComm Group `HCF_SPEC-085` / IEC 62591) bridges 4–20 mA\nsmart process transmitters, **WirelessHART gateways**, and asset management\nsystems (Emerson AMS, Yokogawa PRM, Honeywell FDM) onto refinery and\nchemical-plant IP networks over **UDP or TCP port `5094`**. Every HART-IP packet\nstarts with an **8-byte Header** (`Version = 1`, `Message Type`: `0` Request / `1`\nResponse / `2` Publish, `Message ID`: `0` Session Initiate / `1` Session Close /\n`2` Keep-Alive / `3` Token-Passing PDU Pass-Through, `Status`, `16-bit Sequence\nNumber txid`, and `16-bit Byte Count`).\n\nFrameAssembly encodes Session Initiate (`mode` Master Type + `holdtime` Inactivity\nClose Timer), Keep-Alive, Session Close, and **Message ID `3` HART Token-Passing\nPDU** frames complete with XOR longitudinal parity check byte!\n\n## Minimal Quickstart (`hartip_quickstart.frasm`)\n\n```frameassembly\nhost ams_server { ip 10.94.1.10 }\nhost whart_gw   { ip 10.94.2.50 }\n\ncompile {\n    ams_server -> whart_gw hartip init txid 1 mode 1 holdtime 60000 wait 3ms\n    ams_server <- whart_gw hartip init isresponse txid 1 status 0 mode 1 holdtime 60000 wait 5ms\n    ams_server -> whart_gw hartip msgid 3 txid 2 addr 0 cmd 1 wait 4ms\n    ams_server <- whart_gw hartip msgid 3 isresponse txid 2 status 0 addr 0 cmd 1\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `5094` (`transport tcp` switches to stateful\n  TCP `5094`) and computes the big-endian 16-bit `Byte Count` (including the\n  8-byte header) automatically.\n- Sets `Message Type = 1` (`Response`) whenever `isresponse` or `response` is\n  present (`0` `Request` by default).\n- On `msgid 3` (HART Pass-Through), wraps `addr` (short frame polling address) and\n  `cmd` (`0` Read Unique ID, `1` Read Primary Variable, `3` Read Dynamic\n  Variables) with a valid trailing XOR checksum byte.\n\n## Practical Lab Example: WirelessHART Gateway Session: Initiate, Read Primary Variable (Cmd 1), Keep-Alive & Close (`hartip_process_transmitter_poll.frasm`)\n\nInitiates a Primary Master (`mode 1`) HART-IP session over UDP `5094`, polls\npressure transmitter `addr 1` with Universal Command `3` (Dynamic Variables),\nexchanges a `keepalive`, and closes the session cleanly.\n\n```frameassembly\nhost dcs_ams  { ip 172.20.94.10 }\nhost whart_ap { ip 172.20.94.100 }\n\ncompile {\n    // 1. Session Initiate (Message ID 0): Primary Master (mode 1), 60,000 ms inactivity timer\n    dcs_ams -> whart_ap hartip init txid 100 mode 1 holdtime 60000 wait 2ms\n    dcs_ams <- whart_ap hartip init isresponse txid 100 status 0 mode 1 holdtime 60000 wait 5ms\n    // 2. Pass-Through Token-Passing PDU (Message ID 3): HART Command 3 (Read Dynamic Variables)\n    dcs_ams -> whart_ap hartip msgid 3 txid 101 addr 1 cmd 3 wait 4ms\n    dcs_ams <- whart_ap hartip msgid 3 isresponse txid 101 status 0 addr 1 cmd 3 wait 15ms\n    // 3. Keep-Alive (Message ID 2) & Graceful Session Close (Message ID 1)\n    dcs_ams -> whart_ap hartip keepalive txid 102 wait 2ms\n    dcs_ams <- whart_ap hartip keepalive isresponse txid 102 status 0 wait 5ms\n    dcs_ams -> whart_ap hartip close txid 103 wait 2ms\n    dcs_ams <- whart_ap hartip close isresponse txid 103 status 0\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show hartip_process_transmitter_poll.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly hartip_process_transmitter_poll.frasm hartip_process_transmitter_poll.pcap\nframeassembly hartip_process_transmitter_poll.frasm hartip_process_transmitter_poll.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse hartip_process_transmitter_poll.pcap hartip_process_transmitter_poll_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r hartip_process_transmitter_poll.pcap -Y \"hart_ip\"\n```\n\n## All `hartip` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host hartip [init | close | keepalive |\nmsgid \"<text_or_num>\"] [version <0..255>] [msgtype \"<text_or_num>\"] [isresponse |\nresponse] [status <0..255>] [txid <0..65535>] [mode <0..255>] [holdtime <number>]\n[addr <0..255>] [cmd <0..255>] [transport <udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `init \\| close \\| keepalive \\| msgid \"<text_or_num>\"` | 8-bit HART-IP Message ID (`0` Initiate, `1` Close, `2` Keep-Alive, `3` Token-Passing PDU) | `init (0) or 3 when cmd/addr is set` | Sets byte 2 (`Message ID`) of the 8-byte HART-IP header and formats the matching body. |\n| `msgtype \"<text_or_num>\" \\| isresponse \\| response` | HART-IP Message Type (`0` Request, `1` Response, `2` Publish/Notification, `15` NAK) | `0 (Request); 1 (Response) with isresponse` | Sets byte 1 (`Message Type`) of the HART-IP header. |\n| `version <0..255> \\| status <0..255> \\| txid <0..65535>` | Header Version (`1` plain, `2` TLS/DTLS), Status (`0` Success), and 16-bit Sequence Number | `version 1, status 0, txid 1` | Populates bytes 0, 3, and 4..5 of the 8-byte HART-IP header. |\n| `mode <0..255> \\| holdtime <number>` | Master Type (`1` Primary, `0` Secondary) & 32-bit Inactivity Close Timer (ms) | `mode 1, holdtime 30000` | Writes the 5-byte payload of `Session Initiate` (`Message ID = 0`). |\n| `addr <0..255> \\| cmd <0..255>` | HART polling address & Universal/Practice Command (`0`, `1`, `2`, `3`, `6`, `48`) | `addr 0, cmd 0` | Builds an embedded HART Token-Passing short frame inside `Message ID = 3` with valid XOR parity. |\n| `transport <udp\\|tcp>` | `udp` or `tcp` | `udp` | Switches Layer 4 between UDP `5094` and stateful TCP `5094`. |\n\n## Cross-Layer Options Valid with `hartip`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 5094 (or TCP 5094 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Send Session Initiate (init) Before Pass-Through Commands for Stateful Gateways\n\n- **Valid v3.3.0 Syntax:** `ams -> gw hartip init txid 1 mode 1 holdtime 60000\nams -> gw hartip msgid 3 txid 2 cmd 1`\n\nFieldComm HART-IP servers require an active session (`Message ID 0` Initiate)\nbefore accepting `Message ID 3` HART Pass-Through requests.\n\n### Preserve Matching txid on HART-IP Responses\n\n- **Valid v3.3.0 Syntax:** `ams -> gw hartip keepalive txid 55\nams <- gw hartip keepalive isresponse txid 55`\n\nBytes 4..5 (`Sequence Number`) pair asynchronous HART-IP responses with in-flight\nmaster requests.\n"}
{"id":"pretrain-proto-fins","kind":"protocol_spec","title":"Omron Factory Interface Network Service (NJ/NX/CJ/CS PLC Protocol) (fins) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/fins","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["fins"],"text":"# fins — Port 9600 Omron FINS PLC Memory Area Read & Write Frames (`fins`)\n\n> **FrameAssembly v3.3.0** · Protocol 116 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/fins\n\n- **Full Protocol Name:** Omron Factory Interface Network Service (NJ/NX/CJ/CS PLC\n  Protocol)\n- **Keyword:** `fins`\n- **OSI Layer & Transport:** Layer 7 · UDP 9600 (or TCP 9600 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** Omron W342 / W227 FINS Reference Manual\n- **Wireshark Display Filter:** `omron`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 9600 (or TCP 9600 via transport tcp) (transport tcp|udp) -> Omron FINS`\n\n## Overview\n\nFactory-automation lines running Omron CJ/CS/NJ PLCs speak FINS on port `9600`\n(`area \"dm\"`, `dna`/`da1`/`sna`/`sa1`): add `transport tcp` and FrameAssembly\nwraps the 10-byte FINS header in the `\"FINS\"` TCP magic envelope automatically.\n\nFactory Interface Network Service (`fins`) is Omron’s native industrial PLC\nprotocol across **Sysmac NJ/NX, CJ2, CS1, and CP1 controllers** in automotive\nassembly, packaging, and battery manufacturing lines on **UDP or TCP port\n`9600`**. Every FINS PDU carries a **10-byte FINS Header** (`ICF` Information\nControl Field `0x80` command / `0xc0` response, `RSV`, `GCT` Gateway Count `0x02`,\n`DNA`/`DA1`/`DA2` destination network/node/unit, `SNA`/`SA1`/`SA2` source\nnetwork/node/unit, and `SID` Service ID) followed by a 2-byte `Command Code`\n(`0x0101` Memory Area Read, `0x0102` Memory Area Write, `0x0501` Controller Data\nRead). When `transport tcp` is selected, FrameAssembly also prepends the **16-byte\nASCII `\"FINS\"` (`46 49 4e 53`) TCP framing header** automatically!\n\nFrameAssembly maps Omron memory mnemonics (`area \"DM\"` `0x82`, `\"CIO\"` `0xb0`,\n`\"WR\"` `0xb1`, `\"HR\"` `0xb2`) and response end-codes (`errcode 0x0000`) directly\nto wire bytes.\n\n## Minimal Quickstart (`fins_quickstart.frasm`)\n\n```frameassembly\nhost scada_hmi { ip 192.168.250.10 }\nhost omron_cj2 { ip 192.168.250.1 }\n\ncompile {\n    scada_hmi -> omron_cj2 fins read da1 1 sa1 10 sid 1 area \"DM\" addr 100 count 2 wait 2ms\n    scada_hmi <- omron_cj2 fins read response da1 10 sa1 1 sid 1 errcode 0x0000 value 1250\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `9600`; when `transport tcp` is specified,\n  switches to stateful TCP `9600` and prepends the mandatory 16-byte `\"FINS\"`\n  (`0x46494e53`, `Command = 2`, `Error = 0`) FINS/TCP wrapper.\n- Sets `ICF = 0x80` on commands and `ICF = 0xc0` (plus 2-byte `End Code`\n  `errcode`) automatically when `response` / `isresponse` is present.\n- Translates memory area names (`\"DM\"` -> `0x82`, `\"CIO\"` -> `0xb0`, `\"WR\"` ->\n  `0xb1`, `\"HR\"` -> `0xb2`, `\"AR\"` -> `0xb3`) and writes 16-bit word `addr` + bit\n  `0x00` + 16-bit `count`.\n\n## Practical Lab Example: Packaging Line Omron CJ2M Poll: DM Word Read, Setpoint Write & Controller Read (`fins_omron_dm_read_write.frasm`)\n\nReads 4 Data Memory (`DM100..DM103`) words over UDP `9600`, writes a conveyor\nspeed setpoint (`DM200 = 1500`), and queries Controller Data (`cmd 0x0501`).\n\n```frameassembly\nhost sysmac_ws { ip 10.250.1.25 }\nhost cj2m_cpu  { ip 10.250.1.1 }\n\ncompile {\n    // 1. Memory Area Read (0x0101): Read 4 words starting at DM100 (SID = 10)\n    sysmac_ws -> cj2m_cpu fins read dna 0 da1 1 da2 0 sna 0 sa1 25 sa2 0 sid 10 area \"DM\" addr 100 count 4 wait 2ms\n    sysmac_ws <- cj2m_cpu fins read response dna 0 da1 25 da2 0 sna 0 sa1 1 sa2 0 sid 10 errcode 0x0000 value 420 wait 8ms\n    // 2. Memory Area Write (0x0102): Write setpoint 1500 into DM200 (SID = 11)\n    sysmac_ws -> cj2m_cpu fins write da1 1 sa1 25 sid 11 area \"DM\" addr 200 count 1 value 1500 wait 2ms\n    sysmac_ws <- cj2m_cpu fins write response da1 25 sa1 1 sid 11 errcode 0x0000 wait 10ms\n    // 3. Controller Data Read (0x0501) over FINS/TCP (port 9600)\n    sysmac_ws -> cj2m_cpu tcp syn srcport 54600 dstport 9600 wait 1ms\n    sysmac_ws <- cj2m_cpu tcp syn ack wait 1ms\n    sysmac_ws -> cj2m_cpu tcp ack wait 1ms\n    sysmac_ws -> cj2m_cpu fins cmd 0x0501 da1 1 sa1 25 sid 12 transport tcp wait 2ms\n    sysmac_ws <- cj2m_cpu fins cmd 0x0501 response da1 25 sa1 1 sid 12 errcode 0x0000 transport tcp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show fins_omron_dm_read_write.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly fins_omron_dm_read_write.frasm fins_omron_dm_read_write.pcap\nframeassembly fins_omron_dm_read_write.frasm fins_omron_dm_read_write.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse fins_omron_dm_read_write.pcap fins_omron_dm_read_write_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r fins_omron_dm_read_write.pcap -Y \"omron\"\n```\n\n## All `fins` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host fins [read | write | cmd\n\"<text_or_num>\"] [response | isresponse] [icf <0..255>] [dna <0..255>] [da1\n<0..255>] [da2 <0..255>] [sna <0..255>] [sa1 <0..255>] [sa2 <0..255>] [sid\n<0..255>] [area \"<text_or_num>\"] [addr <0..65535>] [count <0..65535>] [value\n<0..65535>] [errcode <0..65535>] [transport <udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `read \\| write \\| cmd \"<text_or_num>\" \\| [response \\| isresponse]` | 16-bit FINS Command Code (`0x0101` Read, `0x0102` Write, `0x0401` Run, `0x0402` Stop, `0x0501` Controller Info) | `read (0x0101), command (ICF 0x80)` | Sets the 2-byte `(MRC, SRC)` Command Code and toggles `ICF` (`0x80` vs `0xc0` with `response`). |\n| `icf <0..255> \\| sid <0..255>` | 8-bit Information Control Field & 8-bit Service ID | `icf 0x80 (or 0xc0), sid 1` | Writes byte 0 (`ICF`) and byte 9 (`SID` transaction correlation byte) of the 10-byte FINS header. |\n| `dna <0..255> \\| da1 <0..255> \\| da2 <0..255> \\| sna <0..255> \\| sa1 <0..255> \\| sa2 <0..255>` | Destination & Source `(Network, Node, Unit)` FINS routing triples | `dna 0, da1 1, da2 0, sna 0, sa1 10, sa2 0` | Writes bytes 3..8 of the 10-byte FINS header (`da1`/`sa1` typically match the last IPv4 octet). |\n| `area \"<text_or_num>\" \\| addr <0..65535> \\| count <0..65535> \\| value <0..65535>` | Memory Area (\"DM\",\"CIO\",\"WR\",\"HR\",\"AR\" or hex code), 16-bit Word Address, Item Count, and 16-bit Word Value | `area \"DM\" (0x82), addr 0, count 1, value 0` | Populates Memory Area Read/Write request parameters and response/write word payloads. |\n| `errcode <0..65535> \\| transport <udp\\|tcp>` | 16-bit FINS Response End Code (`0x0000` Normal) & L4 transport | `errcode 0x0000, transport udp` | Writes `(MRES, SRES)` in response frames or switches between FINS/UDP and `\"FINS\"`-framed FINS/TCP. |\n\n## Cross-Layer Options Valid with `fins`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 9600 (or TCP 9600 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Swap da1 and sa1 Node Numbers on <- PLC Responses\n\n- **Valid v3.3.0 Syntax:** `hmi -> plc fins read da1 1 sa1 25 sid 1 area \"DM\" addr\n  100\nhmi <- plc fins read response da1 25 sa1 1 sid 1 errcode 0`\n\nOmron PLCs swap the FINS Source `(SNA, SA1, SA2)` and Destination `(DNA, DA1,\nDA2)` node triples while echoing the caller’s `SID`.\n\n### Quote Area Mnemonics Like \"DM\" or \"CIO\"\n\n- **Valid v3.3.0 Syntax:** `hmi -> plc fins read area \"DM\" addr 100 count 2`\n\nQuoting `\"DM\"`, `\"CIO\"`, `\"WR\"`, or `\"HR\"` makes memory-bank strings unmistakable\nnext to strict-lowercase `.frasm` keywords.\n"}
{"id":"pretrain-proto-melsec","kind":"protocol_spec","title":"Mitsubishi Electric MELSEC Communication Protocol (QnA / iQ-R 3E Frame) (melsec) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/melsec","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["melsec"],"text":"# melsec — Port 5000 Mitsubishi MELSEC MC 3E Binary PLC Frames (`melsec`)\n\n> **FrameAssembly v3.3.0** · Protocol 117 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/melsec\n\n- **Full Protocol Name:** Mitsubishi Electric MELSEC Communication Protocol (QnA /\n  iQ-R 3E Frame)\n- **Keyword:** `melsec`\n- **OSI Layer & Transport:** Layer 7 · TCP 5000 (or UDP 5000 via transport udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** Mitsubishi MELSEC Communication Protocol Reference (SH-080008)\n- **Wireshark Display Filter:** `tcp.port == 5000 || udp.port == 5000`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 5000 (or UDP 5000 via transport udp) (transport tcp|udp) -> Mitsubishi\n  MELSEC MC (3E)`\n\n## Overview\n\nSemiconductor and automotive assembly cells rely on Mitsubishi MELSEC iQ-R/Q PLCs\non port `5000` — `melsec` writes little-endian QnA-3E binary `0x5000`/`0xd000`\nsubheaders and device codes (`device \"D\"`, `addr`, `count`, `value`).\n\nMELSEC Communication Protocol (`melsec`, MC Protocol **QnA-compatible 3E Binary\nFrame**) is Mitsubishi Electric’s workhorse PLC protocol across **MELSEC iQ-R,\niQ-F, Q-Series, and L-Series controllers** in semiconductor fabs, EV battery\nplants, and discrete manufacturing on **TCP or UDP port `5000`** (commonly\n`5000`–`5007`). Every 3E Binary request starts with Subheader `50 00` (`d0 00` on\nresponses), `Network No.`, `PC No.` (`0xff` local CPU), little-endian 16-bit\n`Request Destination Module I/O No.` (`0x03ff` own station), `Station No.`,\nlittle-endian 16-bit `Request Data Length`, 16-bit `Monitoring Timer`, 16-bit\n`Command` (`0x0401` Batch Read, `0x1401` Batch Write) + `Subcommand`, 24-bit `Head\nDevice Number` (`addr`), `Device Code` (`D`=`0xa8`, `M`=`0x90`, `X`=`0x9c`,\n`Y`=`0x9d`, `W`=`0xb4`, `R`=`0xaf`), and 16-bit `Number of Device Points`\n(`count`).\n\nFrameAssembly encodes exact little-endian 3E binary frames, 24-bit device\naddresses, and 16-bit `End Code` (`endcode 0x0000`) responses.\n\n## Minimal Quickstart (`melsec_quickstart.frasm`)\n\n```frameassembly\nhost got_hmi  { ip 192.168.3.10 }\nhost iqr_plc  { ip 192.168.3.39 }\n\ncompile {\n    got_hmi -> iqr_plc tcp syn srcport 51500 dstport 5000 wait 1ms\n    got_hmi <- iqr_plc tcp syn ack wait 1ms\n    got_hmi -> iqr_plc tcp ack wait 1ms\n    got_hmi -> iqr_plc melsec read device \"D\" addr 100 count 4 wait 2ms\n    got_hmi <- iqr_plc melsec read response endcode 0x0000 value 2500\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `5000` (`transport udp` switches to UDP `5000`)\n  and writes Subheader `50 00` on requests or `d0 00` on `response`/`isresponse`\n  frames.\n- Computes the little-endian 16-bit `Request / Response Data Length` in bytes 7..8\n  automatically.\n- Maps Mitsubishi device mnemonics (`\"D\"` -> `0xa8`, `\"M\"` -> `0x90`, `\"X\"` ->\n  `0x9c`, `\"Y\"` -> `0x9d`, `\"W\"` -> `0xb4`, `\"R\"` -> `0xaf`, `\"B\"` -> `0xa0`) and\n  packs 3-byte little-endian `addr` values.\n\n## Practical Lab Example: MELSEC iQ-R Cell Line Cycle: Data Register Batch Read (D100), Setpoint Batch Write (D200) & UDP Poll (`melsec_iqr_batch_rw.frasm`)\n\nConnects to an iQ-R PLC on TCP `5000` (`io 0x03ff`, `pc 0xff`), batch-reads\n`D100..D103`, writes a servo target into `D200`, and polls Link Register `W0` over\nUDP `5002` (`transport udp`).\n\n```frameassembly\nhost gx_works3 { ip 10.39.1.15 }\nhost melsec_q  { ip 10.39.1.50 }\n\ncompile {\n    gx_works3 -> melsec_q tcp syn srcport 53500 dstport 5000 wait 1ms\n    gx_works3 <- melsec_q tcp syn ack wait 1ms\n    gx_works3 -> melsec_q tcp ack wait 1ms\n    // 1. 3E Binary Batch Read (0x0401, Subcmd 0x0000 Word): Read 4 words from D100\n    gx_works3 -> melsec_q melsec read network 0 pc 0xff io 0x03ff station 0 timer 16 device \"D\" addr 100 count 4 wait 2ms\n    gx_works3 <- melsec_q melsec read response endcode 0x0000 value 1024 wait 8ms\n    // 2. 3E Binary Batch Write (0x1401): Write word value 3600 to D200\n    gx_works3 -> melsec_q melsec write device \"D\" addr 200 count 1 value 3600 wait 2ms\n    gx_works3 <- melsec_q melsec write response endcode 0x0000 wait 10ms\n    // 3. High-speed UDP 5002 Link Register W0 poll\n    gx_works3 -> melsec_q melsec read dstport 5002 device \"W\" addr 0 count 2 transport udp wait 2ms\n    gx_works3 <- melsec_q melsec read response endcode 0x0000 value 1 transport udp\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show melsec_iqr_batch_rw.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly melsec_iqr_batch_rw.frasm melsec_iqr_batch_rw.pcap\nframeassembly melsec_iqr_batch_rw.frasm melsec_iqr_batch_rw.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse melsec_iqr_batch_rw.pcap melsec_iqr_batch_rw_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r melsec_iqr_batch_rw.pcap -Y \"tcp.port == 5000 || udp.port == 5000\"\n```\n\n## All `melsec` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host melsec [read | write | cmd\n\"<text_or_num>\"] [response | isresponse] [subcmd <0..65535>] [network <0..255>]\n[pc <0..255>] [io <0..65535>] [station <0..255>] [timer <0..65535>] [device\n\"<text_or_num>\"] [addr <0..16777215>] [count <0..65535>] [value <0..65535>]\n[endcode|errcode <0..65535>] [transport <tcp|udp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `read \\| write \\| cmd \"<text_or_num>\" \\| [response \\| isresponse]` | 16-bit MC Command (`0x0401` Batch Read, `0x1401` Batch Write, `0x1001` Remote Run, `0x1002` Remote Stop) | `read (0x0401), request (50 00)` | Sets the 16-bit little-endian Command Code and Subheader (`50 00` vs `d0 00` with `response`). |\n| `subcmd <0..65535>` | 16-bit Subcommand (`0x0000` word units, `0x0001` bit units, `0x0002` iQ-R extended) | `0x0000 (word units)` | Writes bytes 13..14 of the 3E request header. |\n| `network <0..255> \\| pc <0..255> \\| io <0..65535> \\| station <0..255> \\| timer <0..65535>` | 3E Routing Path + Monitoring Timer (in 250 ms units) | `network 0, pc 0xff, io 0x03ff, station 0, timer 16` | Populates bytes 2..6 (Access Route) and bytes 9..10 (CPU Monitoring Timer) of the 3E header. |\n| `device \"<text_or_num>\" \\| addr <0..16777215> \\| count <0..65535> \\| value <0..65535>` | Device Code (\"D\",\"M\",\"X\",\"Y\",\"W\",\"R\",\"B\"), 24-bit Head Address, Point Count, and 16-bit Word Value | `device \"D\" (0xa8), addr 0, count 1, value 0` | Writes the 3-byte little-endian `addr`, 1-byte `Device Code`, 2-byte `count`, and write/read word data. |\n| `endcode <0..65535> \\| errcode <0..65535> \\| transport <tcp\\|udp>` | 16-bit Response End Code (`0x0000` Success) & L4 transport | `endcode 0x0000, transport tcp` | Writes the 2-byte little-endian `End Code` in `d0 00` responses or toggles TCP/UDP. |\n\n## Cross-Layer Options Valid with `melsec`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 5000 (or UDP 5000 via transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Keep io = 0x03ff and pc = 0xff When Addressing the Local CPU Module\n\n- **Valid v3.3.0 Syntax:** `hmi -> plc melsec read network 0 pc 0xff io 0x03ff\n  station 0 device \"D\" addr 100 count 2`\n\nMitsubishi 3E Binary frames default to `network 0`, `pc 0xff`, `io 0x03ff` (own\nstation CPU); changing `io` routes the request to an intelligent function or\nmulti-CPU slot.\n\n### Add response (or isresponse) on <- Replies\n\n- **Valid v3.3.0 Syntax:** `hmi <- plc melsec read response endcode 0x0000 value\n  500`\n\nWithout `response`, the frame emits a `50 00` Request Subheader instead of a `d0\n00` 3E Response Subheader + `End Code`.\n"}
{"id":"pretrain-proto-someip","kind":"protocol_spec","title":"Scalable service-Oriented MiddlewarE over IP & Service Discovery (someip) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/someip","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["someip"],"text":"# someip — Port 30490 AUTOSAR Zonal RPC & Service Discovery (`someip`)\n\n> **FrameAssembly v3.3.0** · Protocol 118 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/someip\n\n- **Full Protocol Name:** Scalable service-Oriented MiddlewarE over IP & Service\n  Discovery\n- **Keyword:** `someip`\n- **OSI Layer & Transport:** Layer 7 · UDP 30490 (or TCP 30490 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** AUTOSAR FO R22-11 SOME/IP Protocol, AUTOSAR SOME/IP-SD\n- **Wireshark Display Filter:** `someip`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 30490 (or TCP 30490 via transport tcp) (transport tcp|udp) -> SOME/IP & SD\n  (AUTOSAR)`\n\n## Overview\n\nModern zonal vehicle Ethernet backbones run AUTOSAR SOME/IP on port `30490` —\n`someip` encodes both 16-byte RPC headers (`serviceid`, `methodid`, `clientid`,\n`sessionid`) and `0xffff8100` Service Discovery IPv4/IPv6 Endpoint Options.\n\nScalable service-Oriented MiddlewarE over IP (`someip`, AUTOSAR) is the\nfoundational in-vehicle Ethernet RPC and pub/sub middleware connecting **ADAS\nradar/camera sensors, zonal gateways, cockpit HPCs, and body ECUs** on **UDP or\nTCP port `30490`**. Standard RPC/event frames carry a 16-byte SOME/IP header\n(`16-bit Service ID`, `16-bit Method/Event ID`, `32-bit Length`, `16-bit Client\nID`, `16-bit Session ID`, `Protocol Version = 1`, `Interface Version`, `Message\nType`, and `Return Code`), while **SOME/IP Service Discovery (`Service ID 0xffff`,\n`Method ID 0x8100`)** dynamically advertises and subscribes to ECU endpoints using\n16-byte Service/Eventgroup Entries and IPv4/IPv6 Endpoint Options.\n\nFrameAssembly encodes both RPC/Event frames and complete **SOME/IP-SD\n(`findservice`, `offerservice`, `subscribe`, `subscribeack`)**\nstructures—computing Entry Array lengths, Option Array lengths, 24-bit SD `TTL`,\nand IPv4/IPv6 Endpoint Options automatically.\n\n## Minimal Quickstart (`someip_quickstart.frasm`)\n\n```frameassembly\nhost adas_ecu  { ip 192.168.10.20 }\nhost zonal_gw  { ip 192.168.10.1 }\n\ncompile {\n    adas_ecu -> zonal_gw someip offerservice sessionid 1 sdservice 0x1234 instanceid 1 majorver 1 sdttl 3 endpointip 192.168.10.20 endpointport 30509 wait 5ms\n    zonal_gw -> adas_ecu someip request dstport 30509 serviceid 0x1234 methodid 0x0001 clientid 0x0010 sessionid 1 payload \"GET-RADAR-TRACKS\" wait 2ms\n    zonal_gw <- adas_ecu someip response serviceid 0x1234 methodid 0x0001 clientid 0x0010 sessionid 1 returncode 0 payload \"TRACKS-OK\"\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `30490` (`transport tcp` switches to stateful\n  TCP) and calculates the 32-bit SOME/IP `Length` field (`8 + payload_len`)\n  automatically.\n- On `findservice`, `offerservice`, `subscribe`, and `subscribeack`, automatically\n  sets outer `Service ID = 0xffff`, `Method ID = 0x8100`, `Message Type = 0x02`\n  (`NOTIFICATION`), SD Flags (`0x80` Reboot bit), 16-byte SD Entry, and IPv4\n  (`0x04`) or IPv6 (`0x06`) Endpoint Option.\n- Encodes `Message Type` (`0x00` REQUEST, `0x01` REQUEST_NO_RETURN, `0x02`\n  NOTIFICATION, `0x80` RESPONSE, `0x81` ERROR) and `Return Code` (`0x00` `E_OK`).\n\n## Practical Lab Example: In-Vehicle 1000BASE-T1 VLAN 10 Flow: SOME/IP-SD Offer, SubscribeAck & Cyclic Radar Event (`someip_adas_sd_and_events.frasm`)\n\nTraces a front radar ECU offering Service `0x2100` over VLAN `10` (`pcp 5`), the\nADAS domain controller subscribing to Eventgroup `1`, receiving\n`SubscribeEventgroupAck`, and consuming a cyclic `0x8001` radar object\nnotification.\n\n```frameassembly\nhost radar_front { ip 10.10.10.41 mac 02:00:5e:10:00:41 }\nhost adas_hpc    { ip 10.10.10.10 mac 02:00:5e:10:00:10 }\n\ncompile {\n    // 1. SOME/IP-SD FindService (0x00) from ADAS HPC -> OfferService (0x01) from Front Radar\n    adas_hpc -> radar_front someip findservice sessionid 1 sdservice 0x2100 instanceid 1 majorver 1 sdttl 3 vlan 10 pcp 5 wait 2ms\n    radar_front -> adas_hpc someip offerservice sessionid 1 sdservice 0x2100 instanceid 1 majorver 1 minorver 2 sdttl 3 endpointip 10.10.10.41 endpointport 30509 vlan 10 pcp 5 wait 3ms\n    // 2. Eventgroup Subscribe (0x06) & SubscribeEventgroupAck (0x07)\n    adas_hpc -> radar_front someip subscribe sessionid 2 sdservice 0x2100 instanceid 1 majorver 1 sdttl 3 endpointip 10.10.10.10 endpointport 30510 vlan 10 pcp 5 wait 2ms\n    radar_front -> adas_hpc someip subscribeack sessionid 2 sdservice 0x2100 instanceid 1 majorver 1 sdttl 3 vlan 10 pcp 5 wait 10ms\n    // 3. Unicast Radar Object Event Notification (Event ID 0x8001 has bit 15 set per AUTOSAR)\n    radar_front -> adas_hpc someip notification srcport 30509 dstport 30510 serviceid 0x2100 methodid 0x8001 clientid 0x0000 sessionid 101 ifacever 1 hexpayload \"000201f4003c\" vlan 10 pcp 6\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show someip_adas_sd_and_events.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly someip_adas_sd_and_events.frasm someip_adas_sd_and_events.pcap\nframeassembly someip_adas_sd_and_events.frasm someip_adas_sd_and_events.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse someip_adas_sd_and_events.pcap someip_adas_sd_and_events_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r someip_adas_sd_and_events.pcap -Y \"someip\"\n```\n\n## All `someip` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host someip [findservice | offerservice |\nsubscribe | subscribeack | request | requestnoreply | notification | response |\nerror | msgtype \"<text_or_num>\"] [serviceid <0..65535>] [methodid <0..65535>]\n[clientid <0..65535>] [sessionid <0..65535>] [protover <0..255>] [ifacever\n<0..255>] [returncode <0..255>] [flags <0..255>] [sdservice <0..65535>]\n[instanceid <0..65535>] [majorver <0..255>] [sdttl <0..16777215>] [minorver\n<number>] [endpointip <ip>] [endpointport <0..65535>] [transport <udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `findservice \\| offerservice \\| subscribe \\| subscribeack \\| request \\| requestnoreply \\| notification \\| response \\| error \\| msgtype \"<text_or_num>\"` | SOME/IP-SD Entry selector or SOME/IP Message Type (`0x00`..`0x81`) | `request (0x00)` | Selects either a full `0xffff:0x8100` SOME/IP-SD frame (`findservice`/`offerservice`/`subscribe`/`subscribeack`) or standard SOME/IP `Message Type`. |\n| `serviceid <0..65535> \\| methodid <0..65535>` | 16-bit Service ID & Method/Event ID (`0x8000+` for Events) | `serviceid 0x1234, methodid 0x0001 (or 0xffff/0x8100 on SD)` | Writes the 32-bit SOME/IP `Message ID` (`Service ID << 16 \\| Method ID`) in bytes 0..3. |\n| `clientid <0..65535> \\| sessionid <0..65535>` | 16-bit Client ID & 16-bit Session ID (`1..65535`) | `clientid 1, sessionid 1` | Writes the 32-bit `Request ID` in bytes 8..11. |\n| `protover <0..255> \\| ifacever <0..255> \\| returncode <0..255>` | 8-bit Protocol Version (`1`), Interface Major Version, and Return Code (`0x00` E_OK) | `protover 1, ifacever 1, returncode 0` | Writes bytes 12, 13, and 15 of the 16-byte SOME/IP header. |\n| `sdservice <0..65535> \\| instanceid <0..65535> \\| majorver <0..255> \\| minorver <number> \\| sdttl <0..16777215>` | SOME/IP-SD 16-byte Service/Eventgroup Entry fields | `sdservice 0x1234, instanceid 1, majorver 1, minorver 0, sdttl 3` | Populates the SOME/IP-SD Entry (`sdttl 0` signifies `StopOfferService` / `StopSubscribeEventgroup`). |\n| `endpointip <ip> \\| endpointport <0..65535> \\| flags <0..255>` | IPv4/IPv6 SD Endpoint Option address + L4 port + 8-bit SD Flags | `Host IP / port 30509 / flags 0x80` | Appends an IPv4 (`12-byte`) or IPv6 (`24-byte`) Endpoint Option to `offerservice` / `subscribe` SD messages. |\n| `transport <udp\\|tcp>` | `udp` or `tcp` | `udp` | Switches Layer 4 transport (and SD Endpoint Option L4-Proto byte `0x11` UDP vs `0x06` TCP). |\n\n## Cross-Layer Options Valid with `someip`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 30490 (or TCP 30490 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Use sdservice (Not serviceid) for the Offered Service Inside SOME/IP-SD\n\n- **Avoid:** `ecu -> gw someip offerservice serviceid 0x2100`\n- **Valid v3.3.0 Syntax:** `ecu -> gw someip offerservice sdservice 0x2100\n  instanceid 1`\n\nSOME/IP-SD frames must keep outer `serviceid = 0xffff` and `methodid = 0x8100` so\nWireshark dissects them as `SOME/IP-SD`; `sdservice` sets the offered Service ID\n*inside* the SD Entry.\n\n### AUTOSAR Event Notifications Set Bit 15 on methodid (0x8001..0xfffe)\n\n- **Valid v3.3.0 Syntax:** `ecu -> gw someip notification serviceid 0x2100\n  methodid 0x8001 payload \"ev\"`\n\nPer AUTOSAR SOME/IP, `0x0000..0x7fff` denote RPC Methods while `0x8000..0xfffe`\ndenote subscribed Events / Field Notifiers.\n"}
{"id":"pretrain-proto-doip","kind":"protocol_spec","title":"Diagnostics over Internet Protocol (Automotive UDS Transport) (doip) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/doip","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["doip"],"text":"# doip — Port 13400 ISO 13400 Vehicle VIN Discovery & UDS Routing (`doip`)\n\n> **FrameAssembly v3.3.0** · Protocol 119 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/doip\n\n- **Full Protocol Name:** Diagnostics over Internet Protocol (Automotive UDS\n  Transport)\n- **Keyword:** `doip`\n- **OSI Layer & Transport:** Layer 7 · TCP 13400 (or UDP 13400 via transport udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** ISO 13400-2:2019, ISO 14229-1 (UDS)\n- **Wireshark Display Filter:** `doip`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 13400 (or UDP 13400 via transport udp) (transport tcp|udp) -> DoIP (ISO\n  13400-2)`\n\n## Overview\n\nOBD-II and ECU flashing over Ethernet on port `13400`: `doip` automatically\ncomputes `invversion = version ^ 0xff` in the 8-byte ISO 13400-2 header for\n`vehiclevin`, `routingreq`, and UDS `diagnostic` frames.\n\nDiagnostics over Internet Protocol (`doip`, ISO 13400-2) replaces legacy CAN\nOBD-II bottlenecks with high-speed Ethernet **ECU flashing,OTA diagnostics, and\nISO 14229 Unified Diagnostic Services (UDS)** on **UDP and TCP port `13400`**.\nEvery DoIP frame starts with an **8-byte Generic Header** (`Protocol Version`,\nbitwise-inverted `Inverse Protocol Version = version ^ 0xff`, `16-bit Payload\nType`, and `32-bit Payload Length`). Testers discover vehicles over UDP `13400`\n(`vehicleid` `0x0001` -> `announcement` `0x0004` carrying 17-byte `VIN`, 16-bit\nLogical Address, 6-byte `EID`, and 6-byte `GID`), then open TCP `13400` for\n`routingreq` (`0x0005`) / `routingresp` (`0x0006`) and UDS `diagnostic` (`0x8001`,\ne.g. `22 F1 90` ReadDataByIdentifier VIN).\n\nFrameAssembly computes `Inverse Protocol Version` (`0x02` -> `0xfd`, `0x03` ->\n`0xfc`) automatically unless explicitly overridden for negative header-NACK tests.\n\n## Minimal Quickstart (`doip_quickstart.frasm`)\n\n```frameassembly\nhost diag_tester { ip 169.254.10.50 }\nhost veh_gateway { ip 169.254.10.1 }\n\ncompile {\n    diag_tester -> veh_gateway doip vehicleid transport udp wait 3ms\n    diag_tester <- veh_gateway doip announcement vin \"WVWZZZ1JZXW000001\" src 0x0100 eid 02:11:22:33:44:55 gid 02:11:22:33:44:55 transport udp\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `13400` (`transport udp` switches to UDP `13400`\n  for ISO 13400-2 vehicle discovery) and computes the 32-bit `Payload Length`\n  automatically.\n- Calculates byte 1 (`Inverse Protocol Version = version ^ 0xff`, e.g. `0x02` ISO\n  13400-2:2012 -> `0xfd`, `0x03` ISO 13400-2:2019 -> `0xfc`) unless `invversion`\n  is explicitly passed.\n- Pads or truncates 17-character ASCII `vin` strings and 6-byte `eid`/`gid`\n  identifiers into the exact 32/33-byte Vehicle Identification Response (`0x0004`)\n  layout.\n\n## Practical Lab Example: End-to-End Automotive DoIP Session: UDP VIN Discovery, TCP Routing Activation & UDS ReadVIN (`doip_uds_diagnostic_session.frasm`)\n\nDiscovers a central vehicle gateway via UDP `13400`, opens stateful TCP `13400`,\nactivates diagnostic routing (`0x10`), sends UDS `ReadDataByIdentifier (0x22 F1\n90)` to ECU `0x0e80 -> 0x0100`, and receives `diagack` + positive UDS `0x62 F1 90`\nresponse.\n\n```frameassembly\nhost tester_pc { ip 169.254.20.99 }\nhost central_gw { ip 169.254.20.10 }\n\ncompile {\n    // 1. UDP 13400 Vehicle Identification Request (0x0001) & Announcement/Response (0x0004)\n    tester_pc -> central_gw doip vehicleid version 3 transport udp wait 2ms\n    tester_pc <- central_gw doip announcement version 3 vin \"5YJ3E1EA7PF000042\" src 0x0100 eid 00:1c:23:aa:bb:cc gid 00:1c:23:aa:bb:cc transport udp wait 5ms\n    // 2. TCP 13400 Handshake + Routing Activation Request (0x0005) & Response (0x0006, code 0x10 = Success)\n    tester_pc -> central_gw tcp syn srcport 53400 dstport 13400 wait 1ms\n    tester_pc <- central_gw tcp syn ack wait 1ms\n    tester_pc -> central_gw tcp ack wait 1ms\n    tester_pc -> central_gw doip routingreq version 3 src 0x0e80 wait 2ms\n    tester_pc <- central_gw doip routingresp version 3 src 0x0e80 dst 0x0100 code 0x10 wait 3ms\n    // 3. DoIP Diagnostic Message (0x8001) carrying ISO 14229 UDS ReadDataByIdentifier (22 F1 90)\n    tester_pc -> central_gw doip diagnostic version 3 src 0x0e80 dst 0x0100 hexpayload \"22f190\" wait 1ms\n    tester_pc <- central_gw doip diagack version 3 src 0x0100 dst 0x0e80 code 0x00 wait 3ms\n    tester_pc <- central_gw doip diagnostic version 3 src 0x0100 dst 0x0e80 hexpayload \"62f19035594a3345314541375046303030303432\"\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show doip_uds_diagnostic_session.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly doip_uds_diagnostic_session.frasm doip_uds_diagnostic_session.pcap\nframeassembly doip_uds_diagnostic_session.frasm doip_uds_diagnostic_session.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse doip_uds_diagnostic_session.pcap doip_uds_diagnostic_session_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r doip_uds_diagnostic_session.pcap -Y \"doip\"\n```\n\n## All `doip` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host doip [routingreq | routingresp |\ndiagnostic | diagack | diagnack | vehicleid | vehicleeid | vehiclevin |\nannouncement | alivecheckreq | alivecheckresp | nack | msgtype \"<text_or_num>\"]\n[version <0..255>] [invversion <0..255>] [src <0..65535>] [dst <0..65535>] [code\n<0..255>] [vin \"<text>\"] [eid <mac_or_hex>] [gid <mac_or_hex>] [transport\n<tcp|udp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `routingreq \\| routingresp \\| diagnostic \\| diagack \\| diagnack \\| vehicleid \\| vehicleeid \\| vehiclevin \\| announcement \\| alivecheckreq \\| alivecheckresp \\| nack \\| msgtype \"<text_or_num>\"` | 16-bit ISO 13400-2 Payload Type keyword or number | `vehicleid (0x0001)` | Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004` Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008` Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK. |\n| `version <0..255> \\| invversion <0..255>` | DoIP Protocol Version (`2` = 2012, `3` = 2019, `0xff` default discovery) & Inverse Version | `version 2, invversion 0xfd (auto version ^ 0xff)` | Writes bytes 0 and 1 of the 8-byte Generic DoIP Header. |\n| `src <0..65535> \\| dst <0..65535>` | 16-bit DoIP Logical Addresses (e.g. `0x0e80` external tester, `0x0100` ECU) | `src 0x0e80, dst 0x0100` | Writes Source/Target Logical Addresses in Routing Activation, Announcement, and UDS `0x8001` messages. |\n| `code <0..255>` | 8-bit Response / ACK / NACK Code (`0x10` Routing Activated, `0x00` Diag ACK OK) | `0x10 on routingresp, 0x00 on diagack/nack` | Sets the status/reason byte in `routingresp`, `diagack`, `diagnack`, or `nack`. |\n| `vin \"<text>\" \\| eid <mac_or_hex> \\| gid <mac_or_hex>` | 17-char ASCII VIN and 6-byte Entity ID / Group ID | `\"00000000000000000\", 00:00:00:00:00:00` | Populates `Vehicle Identification Response / Announcement` (`0x0004`) and `vehiclevin`/`vehicleeid` filters. |\n| `transport <tcp\\|udp>` | `tcp` or `udp` | `tcp` | Switches Layer 4 between TCP `13400` (Routing/Diagnostic) and UDP `13400` (Vehicle Discovery). |\n\n## Cross-Layer Options Valid with `doip`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 13400 (or UDP 13400 via transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Add transport udp on Vehicle Discovery (0x0001..0x0004) Messages\n\n- **Valid v3.3.0 Syntax:** `tester -> gw doip vehicleid transport udp`\n\nBecause DoIP diagnostic sessions run over TCP `13400`, `doip` defaults to `tcp`;\nadd `transport udp` when crafting UDP `13400` `vehicleid` and `announcement`\nframes.\n\n### Pass ISO 14229 UDS Service Bytes via hexpayload on diagnostic Messages\n\n- **Valid v3.3.0 Syntax:** `tester -> gw doip diagnostic src 0x0e80 dst 0x0100\n  hexpayload \"1003\"`\n\nWireshark automatically hands the payload after `src`/`dst` on `0x8001`\n(`diagnostic`) straight to its ISO 14229 `uds` dissector (`10 03` =\nDiagnosticSessionControl Extended).\n"}
{"id":"pretrain-proto-c1222","kind":"protocol_spec","title":"ANSI C12.22 / IEEE 1703 Smart-Meter Utility AMI Application Protocol (c1222) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/c1222","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["c1222"],"text":"# c1222 — Port 1153 ANSI C12.22 / IEEE 1703 Smart Grid AMI Tables (`c1222`)\n\n> **FrameAssembly v3.3.0** · Protocol 120 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/c1222\n\n- **Full Protocol Name:** ANSI C12.22 / IEEE 1703 Smart-Meter Utility AMI\n  Application Protocol\n- **Keyword:** `c1222`\n- **OSI Layer & Transport:** Layer 7 · UDP 1153 (or TCP 1153 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** ANSI C12.22-2012, IEEE 1703, ANSI C12.19 (Tables)\n- **Wireshark Display Filter:** `c1222`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 1153 (or TCP 1153 via transport tcp) (transport tcp|udp) -> ANSI C12.22 (AMI\n  Smart Grid)`\n\n## Overview\n\nUtility smart-meter AMI headends communicate over ANSI C12.22 on port `1153`:\n`c1222` encodes ASN.1 BER ACSE AP-titles (`callingap`, `calledap`) and EPSEM\nC12.19 table reads/writes (`tableid`).\n\nANSI C12.22 (`c1222`, IEEE 1703) transports **ANSI C12.19 smart electric/gas/water\nmeter tables** across utility **Advanced Metering Infrastructure (AMI)** head-end\nservers, field-area mesh collectors, and IPv4/IPv6 smart meters on **UDP or TCP\nport `1153`**. Every C12.22 frame wraps an **ISO 8650 ASN.1 BER ACSE header**\n(`Calling-AP-title` OID, `Called-AP-title` OID, `Calling/Called AP-invocation-id`)\naround an **Extended Protocol Specification for Electric Metering (`EPSEM`)**\npayload (`EPSEM Control` byte, optional `ED-Class`, and PSEM service codes: `0x20`\nIdentify, `0x50` Logon, `0x30` Full Table Read, `0x40` Full Table Write, `0x52`\nLogoff, `0x21` Terminate).\n\nFrameAssembly encodes valid ASN.1 BER ACSE OIDs, BER length octets, and ANSI\nC12.19 `tableid` read/write requests and `<OK>` (`0x00`) responses.\n\n## Minimal Quickstart (`c1222_quickstart.frasm`)\n\n```frameassembly\nhost ami_headend { ip 10.115.1.10 }\nhost smart_meter { ip 10.115.20.45 }\n\ncompile {\n    ami_headend -> smart_meter c1222 read callingap 1.3.6.1.4.1.9999.1 calledap 1.3.6.1.4.1.9999.45 callingid 1 tableid 1 wait 5ms\n    ami_headend <- smart_meter c1222 response callingap 1.3.6.1.4.1.9999.45 calledap 1.3.6.1.4.1.9999.1 callingid 1 value 4820\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `1153` (`transport tcp` switches to stateful\n  TCP `1153`) and formats the outer ASN.1 BER `0x60` (`AARE`/`AARQ` C12.22 ACSE\n  PDU) envelope.\n- Encodes `callingap` and `calledap` dotted OIDs in ASN.1 BER Object Identifier\n  format alongside `callingid` / `calledid` invocation integers.\n- Builds the inner `user-information` (`0xbe`) **EPSEM** frame with `epsemctrl`\n  (`0x80` Cleartext), big-endian 16-bit C12.19 `tableid`, and 1-byte checksum.\n\n## Practical Lab Example: IPv6 Wi-SUN Smart Meter Billing Collection: Identify, Logon, C12.19 Table 23 Read & Logoff (`c1222_ipv6_smart_meter_ami.frasm`)\n\nSimulates an IPv6 utility AMI collector identifying a residential smart meter,\nlogging on, reading ANSI C12.19 Standard Table `23` (Current Register Data), and\nterminating the session.\n\n```frameassembly\nhost collector_v6 { ip 2001:db8:1153::1 }\nhost meter_0042   { ip 2001:db8:1153::42 }\n\ncompile {\n    // 1. EPSEM Identify (0x20) -> <OK> (0x00) Response\n    collector_v6 -> meter_0042 c1222 identify callingap 1.3.6.1.4.1.33500.1 calledap 1.3.6.1.4.1.33500.42 callingid 10 wait 4ms\n    collector_v6 <- meter_0042 c1222 response callingap 1.3.6.1.4.1.33500.42 calledap 1.3.6.1.4.1.33500.1 callingid 10 errcode 0 wait 6ms\n    // 2. EPSEM Logon (0x50) -> <OK>\n    collector_v6 -> meter_0042 c1222 logon callingap 1.3.6.1.4.1.33500.1 calledap 1.3.6.1.4.1.33500.42 callingid 11 wait 4ms\n    collector_v6 <- meter_0042 c1222 ok callingap 1.3.6.1.4.1.33500.42 calledap 1.3.6.1.4.1.33500.1 callingid 11 wait 6ms\n    // 3. Full Read (0x30) of ANSI C12.19 Table 23 (Current Register Data kWh)\n    collector_v6 -> meter_0042 c1222 read callingap 1.3.6.1.4.1.33500.1 calledap 1.3.6.1.4.1.33500.42 callingid 12 tableid 23 wait 5ms\n    collector_v6 <- meter_0042 c1222 response callingap 1.3.6.1.4.1.33500.42 calledap 1.3.6.1.4.1.33500.1 callingid 12 value 12845 wait 6ms\n    // 4. Graceful Terminate (0x21)\n    collector_v6 -> meter_0042 c1222 terminate callingap 1.3.6.1.4.1.33500.1 calledap 1.3.6.1.4.1.33500.42 callingid 13\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show c1222_ipv6_smart_meter_ami.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly c1222_ipv6_smart_meter_ami.frasm c1222_ipv6_smart_meter_ami.pcap\nframeassembly c1222_ipv6_smart_meter_ami.frasm c1222_ipv6_smart_meter_ami.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse c1222_ipv6_smart_meter_ami.pcap c1222_ipv6_smart_meter_ami_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r c1222_ipv6_smart_meter_ami.pcap -Y \"c1222\"\n```\n\n## All `c1222` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host c1222 [read | write | identify | logon\n| logoff | terminate | response | ok | service \"<text_or_num>\"] [callingap <oid>]\n[calledap <oid>] [callingid <number>] [calledid <number>] [epsemctrl <0..255>]\n[edclass <number>] [tableid <0..65535>] [value <0..65535>] [errcode <0..255>]\n[transport <udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `read \\| write \\| identify \\| logon \\| logoff \\| terminate \\| response \\| ok \\| service \"<text_or_num>\"` | EPSEM PSEM Service Code (`0x20` Identify, `0x21` Terminate, `0x30` Read, `0x40` Write, `0x50` Logon, `0x52` Logoff, `0x00` OK) | `read (0x30)` | Selects the EPSEM Request or Response service byte inside the ACSE `user-information` block. |\n| `callingap <oid> \\| calledap <oid>` | Dotted ASN.1 OID (unquoted `1.3.6.1...` or quoted `\"1.3.6.1...\"`) | `1.3.6.1.4.1.9999.1 / 1.3.6.1.4.1.9999.2` | Encodes `Calling-AP-title` (`0xa6`) and `Called-AP-title` (`0xa2`) universal ApTitles. |\n| `callingid <number> \\| calledid <number>` | 32-bit `AP-invocation-id` integers | `callingid 1` | Encodes `Calling-AP-invocation-id` (`0xa8`) and optional `Called-AP-invocation-id` (`0xa4`). |\n| `epsemctrl <0..255> \\| edclass <number>` | 8-bit EPSEM Control byte & optional 32-bit End-Device Class | `epsemctrl 0x80 (Reserved bit, cleartext)` | Writes the EPSEM Control header byte and optional 4-byte `ED-Class` when bit `0x10` is set. |\n| `tableid <0..65535> \\| value <0..65535> \\| errcode <0..255>` | 16-bit ANSI C12.19 Table ID, 16-bit Table Data Word, and 8-bit PSEM Response Code (`0x00` OK) | `tableid 1, value 0, errcode 0` | Populates C12.19 Table Read/Write payloads and `<OK>`/`<ERR>` response codes. |\n| `transport <udp\\|tcp>` | `udp` or `tcp` | `udp` | Switches Layer 4 between connectionless C12.22/UDP (`1153`) and stateful TCP (`1153`). |\n\n## Cross-Layer Options Valid with `c1222`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 1153 (or TCP 1153 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Pass Valid Dotted Numeric OIDs (At Least 2 Arcs) to callingap / calledap\n\n- **Avoid:** `headend -> meter c1222 read callingap \"meter01\"`\n- **Valid v3.3.0 Syntax:** `headend -> meter c1222 read callingap\n  1.3.6.1.4.1.9999.1 calledap 1.3.6.1.4.1.9999.2`\n\nANSI C12.22 `ApTitle` fields are ASN.1 BER `OBJECT IDENTIFIER` values\n(`1.3.6.1...` or `2.16.124...`), not free-form hostnames.\n\n### Swap callingap and calledap on Meter <- Responses\n\n- **Valid v3.3.0 Syntax:** `h -> m c1222 identify callingap 1.3.6.1.4.1.99.1\n  calledap 1.3.6.1.4.1.99.2\nh <- m c1222 ok callingap 1.3.6.1.4.1.99.2 calledap 1.3.6.1.4.1.99.1`\n\nWhen the smart meter responds, its own `ApTitle` becomes `Calling-AP-title` and\nthe head-end’s OID becomes `Called-AP-title`.\n"}
{"id":"pretrain-proto-gesrtp","kind":"protocol_spec","title":"General Electric / Emerson Service Request Transport Protocol (gesrtp) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/gesrtp","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["gesrtp"],"text":"# gesrtp — Port 18245 GE Fanuc / Emerson PacSystems SRTP PLC Ops (`gesrtp`)\n\n> **FrameAssembly v3.3.0** · Protocol 121 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/gesrtp\n\n- **Full Protocol Name:** General Electric / Emerson Service Request Transport\n  Protocol\n- **Keyword:** `gesrtp`\n- **OSI Layer & Transport:** Layer 7 · TCP 18245\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** GE Fanuc / Emerson PACSystems TCP/IP Ethernet Manual (GFK-1541)\n- **Wireshark Display Filter:** `tcp.port == 18245`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 18245 -> GE SRTP (Emerson PACSystems)`\n\n## Overview\n\nEvery GE Fanuc / Emerson PacSystems PLC packet on TCP `18245` is a fixed 56-byte\nlittle-endian SRTP header — `gesrtp` maps register areas (`%R`, `%AI`, `%Q`,\n`%M`), `addr`, `count`, and `value` cleanly.\n\nService Request Transport Protocol (`gesrtp`) is the native Ethernet\nHMI/engineering protocol for **GE Fanuc Series 90-30 / 90-70, VersaMax, and\nEmerson PACSystems RX3i / RX7i PLCs** across power generation, water treatment,\nand rail signaling on **TCP port `18245`**. Every GE SRTP packet is a fixed\n**56-byte header** (plus optional extended payload when length > 6 bytes),\nstarting with a 2-byte `Type` (`0x0000` 56-byte Init -> `0x0100` Init ACK,\n`0x0200` Request -> `0x0300` Piggybacked Response), `Sequence Number`, `Text\nLength`, `Mailbox Source/Dest`, `Packet Type` (`0xc0` Request / `0xd4` ACK), and\n`Service Request Code` (`0x04` Read System Memory, `0x07` Write System Memory,\n`0x43` Return Controller Type) targeting PLC memory segments (`%R`, `%AI`, `%AQ`,\n`%I`, `%Q`, `%M`).\n\nFrameAssembly packs exact 56-byte little-endian GE SRTP frames and memory-segment\nselectors over stateful TCP port `18245`.\n\n## Minimal Quickstart (`gesrtp_quickstart.frasm`)\n\n```frameassembly\nhost ifix_scada { ip 10.182.1.10 }\nhost rx3i_plc   { ip 10.182.1.50 }\n\ncompile {\n    ifix_scada -> rx3i_plc tcp syn srcport 51245 dstport 18245 wait 1ms\n    ifix_scada <- rx3i_plc tcp syn ack wait 1ms\n    ifix_scada -> rx3i_plc tcp ack wait 1ms\n    ifix_scada -> rx3i_plc gesrtp init wait 2ms\n    ifix_scada <- rx3i_plc gesrtp initack wait 3ms\n    ifix_scada -> rx3i_plc gesrtp read seqnum 1 area \"R\" addr 1 count 4 wait 2ms\n    ifix_scada <- rx3i_plc gesrtp response seqnum 1 status 0 value 750\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `18245` (`psh ack`, automatic TCP `seq`/`acknum`\n  across 56-byte headers).\n- Emits the exact 56-byte `0x00` Initialization frame on `init`, `0x01`\n  Initialization ACK on `initack`, `0x02` Service Request on\n  `read`/`write`/`request`, and `0x03` Response on `response`.\n- Maps GE PLC segment selectors (`\"R\"` -> `0x08` `%R` Registers, `\"AI\"` -> `0x0a`\n  `%AI`, `\"AQ\"` -> `0x0c` `%AQ`, `\"I\"` -> `0x10` `%I`, `\"Q\"` -> `0x12` `%Q`, `\"M\"`\n  -> `0x16` `%M`) and writes 0-based little-endian offsets (`addr - 1` when\n  1-based).\n\n## Practical Lab Example: Emerson PACSystems RX3i Turbine Control Poll: Init, %R Register Read & %Q Output Write (`gesrtp_rx3i_plc_session.frasm`)\n\nOpens TCP `18245`, completes the 56-byte SRTP `init`/`initack` handshake, reads 4\n`%R` registers starting at `%R0001`, and writes a valve setpoint to `%R0010`.\n\n```frameassembly\nhost cimplicity { ip 172.19.18.10 }\nhost pac_rx3i   { ip 172.19.18.100 }\n\ncompile {\n    cimplicity -> pac_rx3i tcp syn srcport 53245 dstport 18245 wait 1ms\n    cimplicity <- pac_rx3i tcp syn ack wait 1ms\n    cimplicity -> pac_rx3i tcp ack wait 1ms\n    // 1. 56-byte SRTP Session Initialization (0x00 -> 0x01)\n    cimplicity -> pac_rx3i gesrtp init wait 2ms\n    cimplicity <- pac_rx3i gesrtp initack wait 4ms\n    // 2. Service Request 0x04: Read 4 words from %R0001\n    cimplicity -> pac_rx3i gesrtp read seqnum 1 area \"R\" addr 1 count 4 wait 2ms\n    cimplicity <- pac_rx3i gesrtp response seqnum 1 area \"R\" status 0 value 1800 wait 10ms\n    // 3. Service Request 0x07: Write setpoint 1950 to %R0010\n    cimplicity -> pac_rx3i gesrtp write seqnum 2 area \"R\" addr 10 count 1 value 1950 wait 2ms\n    cimplicity <- pac_rx3i gesrtp response seqnum 2 status 0\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show gesrtp_rx3i_plc_session.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly gesrtp_rx3i_plc_session.frasm gesrtp_rx3i_plc_session.pcap\nframeassembly gesrtp_rx3i_plc_session.frasm gesrtp_rx3i_plc_session.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse gesrtp_rx3i_plc_session.pcap gesrtp_rx3i_plc_session_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r gesrtp_rx3i_plc_session.pcap -Y \"tcp.port == 18245\"\n```\n\n## All `gesrtp` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host gesrtp [init | initack | request |\nresponse | read | write | type \"<text>\"] [seqnum <0..65535>] [func\n\"<text_or_num>\"] [area \"<text_or_num>\"] [addr <0..65535>] [count <0..65535>]\n[value <number>] [status <0..65535>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `init \\| initack \\| request \\| response \\| read \\| write \\| type \"<text>\"` | GE SRTP Packet Type (`init` 0x00, `initack` 0x01, `read`/`write`/`request` 0x02, `response` 0x03) | `read (Type 0x02, Service 0x04)` | Selects byte 0 of the 56-byte GE SRTP header and initializes the Service Request byte (`0x04` Read, `0x07` Write). |\n| `seqnum <0..65535> \\| func \"<text_or_num>\"` | Sequence Number & 8-bit Service Request Code (`0x04` Read, `0x07` Write, `0x21` Program Load, `0x23` Run/Stop, `0x43` Info) | `seqnum 1, func 0x04` | Writes byte 2 (`Sequence Number`) and byte 42 (`Service Request Code`). |\n| `area \"<text_or_num>\" \\| addr <0..65535> \\| count <0..65535>` | Memory Segment (\"R\",\"AI\",\"AQ\",\"I\",\"Q\",\"M\" or hex selector), Register Offset, and Word/Byte Count | `area \"R\" (0x08), addr 1, count 1` | Writes byte 43 (`Memory Type Selector`), bytes 44..45 (`Memory Offset`), and bytes 46..47 (`Length`). |\n| `value <number> \\| status <0..65535>` | Register data value & 16-bit PLC Status word (`0x0000` OK) | `value 0, status 0` | Populates piggybacked/extended data bytes and response status codes. |\n\n## Cross-Layer Options Valid with `gesrtp`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 18245` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 18245)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |\n\n## Common Mistakes & Quick Fixes\n\n### Do Not Confuse Industrial gesrtp (TCP 18245) with Media RTP/SRTP (UDP 5004)\n\n- **Valid v3.3.0 Syntax:** `hmi -> plc gesrtp read seqnum 1 area \"R\" addr 1 count\n  4`\n\nUse `gesrtp` for General Electric / Emerson PACSystems PLC traffic on TCP `18245`\n(and `rtp` for RFC 3550 VoIP audio/video streams on UDP `5004`).\n\n### Include init / initack Before Service Requests in Multi-Packet Captures\n\n- **Valid v3.3.0 Syntax:** `hmi -> plc gesrtp init\nhmi <- plc gesrtp initack\nhmi -> plc gesrtp read seqnum 1 area \"R\" addr 1`\n\nReal GE/Emerson PLCs and stateful OT IDS engines expect the 56-byte `0x00` ->\n`0x01` initialization exchange at the start of every TCP `18245` connection.\n"}
{"id":"pretrain-proto-rocplus","kind":"protocol_spec","title":"Emerson Fisher ROC Plus Oil & Gas Pipeline RTU Protocol (rocplus) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/rocplus","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["rocplus"],"text":"# rocplus — Port 4000 Emerson ROC Plus Oil & Gas Pipeline RTUs (`rocplus`)\n\n> **FrameAssembly v3.3.0** · Protocol 122 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/rocplus\n\n- **Full Protocol Name:** Emerson Fisher ROC Plus Oil & Gas Pipeline RTU Protocol\n- **Keyword:** `rocplus`\n- **OSI Layer & Transport:** Layer 7 · TCP 4000 (or UDP 4000 via transport udp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** Emerson Fisher ROC Plus Protocol Specifications Manual\n  (D301151X012)\n- **Wireshark Display Filter:** `tcp.port == 4000 || udp.port == 4000`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  TCP 4000 (or UDP 4000 via transport udp) (transport tcp|udp) -> Emerson ROC\n  Plus`\n\n## Overview\n\nWellhead and natural-gas custody-transfer RTUs speak Emerson ROC Plus on port\n`4000` — `rocplus` packs unit/group addressing, TLP (`type`, `addr`, `param`)\npoint reads/writes, and reflected CRC-16 trailers.\n\nEmerson Fisher ROC Plus (`rocplus`) is a core **upstream wellhead,\ncustody-transfer flow computer (`FloBoss`), and midstream natural-gas/crude\npipeline RTU (`ROC800`, `FB1000`/`FB2000`)** SCADA protocol on **TCP or UDP port\n`4000`**. Every ROC Plus frame consists of a **6-byte Header** (`Destination\nUnit`/`Destination Group`, `Source Unit`/`Source Group`, `Opcode`, and `Data\nLength`), **Type-Length-Parameter (`TLP`: `Point Type`, `Logical/Point Number\naddr`, `Parameter Number param`)** data bytes, and a trailing **little-endian\nreflected 16-bit CRC-16 (`poly 0xa001`, init `0x0000`)**.\n\nFrameAssembly computes `Data Length` and the trailing **ROC CRC-16 (`0xa001`)**\nautomatically (or lets you override `crc` to test pipeline SCADA gateway error\ncounters).\n\n## Minimal Quickstart (`rocplus_quickstart.frasm`)\n\n```frameassembly\nhost cygnet_host { ip 10.40.1.10 }\nhost roc800_rtu  { ip 10.40.20.1 }\n\ncompile {\n    cygnet_host -> roc800_rtu tcp syn srcport 54000 dstport 4000 wait 1ms\n    cygnet_host <- roc800_rtu tcp syn ack wait 1ms\n    cygnet_host -> roc800_rtu tcp ack wait 1ms\n    cygnet_host -> roc800_rtu rocplus read dst 1 group 2 src 3 type 3 addr 0 param 14 wait 5ms\n    cygnet_host <- roc800_rtu rocplus read isresponse dst 3 group 0 src 1 type 3 addr 0 param 14 value 850\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to stateful TCP port `4000` (`transport udp` switches to UDP `4000`)\n  and calculates byte 5 (`Data Length`) automatically.\n- Maps `read` to ROC Plus Opcode `180` (`Single/Multiple TLP Read`), `write` to\n  Opcode `181` (`TLP Write`), and `error` to Opcode `255` (`Error Indicator`).\n- Appends the exact 2-byte little-endian reflected **ROC CRC-16 (`0xa001`, init\n  `0x0000`)** over Header + Data unless `crc` is overridden.\n\n## Practical Lab Example: Midstream Pipeline Station Poll: ROC800 Analog Pressure TLP Read, Valve Setpoint Write & Error Response (`rocplus_pipeline_rtu_tlp.frasm`)\n\nPolls discharge pressure TLP `(3, 0, 14)` on `ROC800` Unit `1` Group `2`, writes a\nregulator setpoint (`Opcode 181`), and tests an invalid-TLP error response\n(`Opcode 255`).\n\n```frameassembly\nhost pipeline_scada { ip 172.23.40.5 }\nhost station_roc800 { ip 172.23.40.101 }\n\ncompile {\n    pipeline_scada -> station_roc800 tcp syn srcport 52400 dstport 4000 wait 1ms\n    pipeline_scada <- station_roc800 tcp syn ack wait 1ms\n    pipeline_scada -> station_roc800 tcp ack wait 1ms\n    // 1. Opcode 180: Read 1 TLP parameter (Point Type 3 Analog Input, Point 0, Param 14 Filtered EU)\n    pipeline_scada -> station_roc800 rocplus read dst 1 group 2 src 10 type 3 addr 0 param 14 wait 6ms\n    pipeline_scada <- station_roc800 rocplus read isresponse dst 10 group 0 src 1 type 3 addr 0 param 14 value 1120 wait 15ms\n    // 2. Opcode 181: Write TLP Setpoint (Point Type 4 Analog Output, Point 0, Param 2)\n    pipeline_scada -> station_roc800 rocplus write dst 1 group 2 src 10 type 4 addr 0 param 2 value 950 wait 6ms\n    pipeline_scada <- station_roc800 rocplus write isresponse dst 10 group 0 src 1 wait 10ms\n    // 3. Out-of-range TLP poll triggering ROC Error Indicator (Opcode 255)\n    pipeline_scada -> station_roc800 rocplus read dst 1 group 2 src 10 type 99 addr 99 param 99 wait 6ms\n    pipeline_scada <- station_roc800 rocplus error isresponse dst 10 group 0 src 1\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show rocplus_pipeline_rtu_tlp.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly rocplus_pipeline_rtu_tlp.frasm rocplus_pipeline_rtu_tlp.pcap\nframeassembly rocplus_pipeline_rtu_tlp.frasm rocplus_pipeline_rtu_tlp.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse rocplus_pipeline_rtu_tlp.pcap rocplus_pipeline_rtu_tlp_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r rocplus_pipeline_rtu_tlp.pcap -Y \"tcp.port == 4000 || udp.port == 4000\"\n```\n\n## All `rocplus` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host rocplus [read | write | error | opcode\n\"<text_or_num>\" | func \"<text_or_num>\"] [dst <0..255>] [group <0..255>] [src\n<0..255>] [type <0..255>] [addr <0..255>] [param <0..255>] [value <number>]\n[isresponse] [crc <0..65535>] [transport <tcp|udp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `read \\| write \\| error \\| opcode \"<text_or_num>\" \\| func \"<text_or_num>\" \\| [isresponse]` | 8-bit ROC Plus Opcode (`180` Read TLP, `181` Write TLP, `7` Read Clock, `8` Set Clock, `17` Logon, `255` Error) | `read (Opcode 180)` | Sets byte 4 (`Opcode`) of the 6-byte ROC Plus header and formats request vs `isresponse` TLP payloads. |\n| `dst <0..255> \\| group <0..255> \\| src <0..255>` | 8-bit ROC Unit Address (`dst`, `src`) & Device Group (`group`) | `dst 1, group 2, src 3` | Writes bytes 0..3 (`ROC Unit`, `ROC Group`, `Host Unit`, `Host Group`) of the ROC Plus header. |\n| `type <0..255> \\| addr <0..255> \\| param <0..255>` | 3-byte ROC `TLP` (`Point Type`, `Logical/Point Number`, `Parameter Number`) | `type 3, addr 0, param 0` | Encodes the 3-octet `(Type, Location/Number, Parameter)` tuple identifying a specific RTU variable. |\n| `value <number>` | 32-bit little-endian TLP parameter value | `0` | Writes the 4-byte value inside `write` (`181`) requests or `read isresponse` (`180`) replies. |\n| `crc <0..65535> \\| transport <tcp\\|udp>` | Optional 16-bit ROC CRC-16 override & L4 transport | `Auto 0xa001 CRC-16, transport tcp` | Overrides the trailing 2-byte little-endian CRC-16 or switches between TCP `4000` and UDP `4000`. |\n\n## Cross-Layer Options Valid with `rocplus`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 4000 (or UDP 4000 via transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport tcp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Swap dst and src Unit Addresses and Add isresponse on RTU Replies\n\n- **Valid v3.3.0 Syntax:** `host_scada -> rtu rocplus read dst 1 group 2 src 10\n  type 3 addr 0 param 14\nhost_scada <- rtu rocplus read isresponse dst 10 group 0 src 1 type 3 addr 0 param\n14 value 500`\n\nIn ROC Plus, the replying RTU echoes the same `Opcode` (`180` on Read) while\nswapping `(Unit, Group)` addresses and returning the TLP data bytes\n(`isresponse`).\n\n### ROC Plus Addresses (dst, group, src, type, addr, param) Are 8-Bit (0..255)\n\n- **Avoid:** `host_scada -> rtu rocplus read dst 300`\n- **Valid v3.3.0 Syntax:** `host_scada -> rtu rocplus read dst 1 group 2 src 10`\n\nROC unit/group and TLP coordinates are single octets (`0..=255`); combine `dst`\n(`Unit`) and `group` (`Group`) to address up to 65,000 RTUs.\n"}
{"id":"pretrain-proto-bsap","kind":"protocol_spec","title":"Emerson / Bristol Babcock Synchronous Asynchronous Protocol (BSAP/IP) (bsap) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/bsap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["bsap"],"text":"# bsap — Port 1234 Bristol Babcock BSAP Water & Pipeline Telemetry (`bsap`)\n\n> **FrameAssembly v3.3.0** · Protocol 123 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/bsap\n\n- **Full Protocol Name:** Emerson / Bristol Babcock Synchronous Asynchronous\n  Protocol (BSAP/IP)\n- **Keyword:** `bsap`\n- **OSI Layer & Transport:** Layer 7 · UDP 1234 (or TCP 1234 via transport tcp)\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** Emerson OpenBSI / Bristol Babcock ControlWave BSAP IP\n  Specification\n- **Wireshark Display Filter:** `udp.port == 1234 || tcp.port == 1234`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 1234 (or TCP 1234 via transport tcp) (transport tcp|udp) -> Bristol Babcock\n  BSAP`\n\n## Overview\n\nMunicipal water distribution and gas SCADA RTUs using ControlWave / Bristol\nBabcock controllers run BSAP on port `1234` — `bsap` constructs IP RBE headers\nplus Remote Database `poll`, `read`, and `write` frames.\n\nBristol Synchronous Asynchronous Protocol over IP (`bsap`) connects **Emerson\nControlWave, Bristol Babcock Network 3000 / DPC 3330 RTUs, and OpenBSI SCADA\nmasters** across municipal water/wastewater distribution and natural-gas SCADA\nnetworks on **UDP or TCP port `1234`**. BSAP/IP encapsulates Remote Database\nAccess (`RDB` / `NDB`) and poll messages with 16-bit `Destination Address`\n(`dst`), 16-bit `Source Address` (`src`), 8-bit `Sequence Number` (`seqnum`),\nApplication `Function Code` (`poll`, `read` RDB Read, `write` RDB Write), starting\nsignal/list `addr`, `count`, and 32-bit `value` payloads.\n\nFrameAssembly encodes BSAP/IP headers and RDB payloads cleanly over default UDP\n`1234` or stateful TCP `1234` (`transport tcp`).\n\n## Minimal Quickstart (`bsap_quickstart.frasm`)\n\n```frameassembly\nhost openbsi_srv { ip 10.123.1.10 }\nhost cw_rtu_10   { ip 10.123.4.10 }\n\ncompile {\n    openbsi_srv -> cw_rtu_10 bsap read dst 10 src 1 seqnum 1 addr 100 count 2 wait 5ms\n    openbsi_srv <- cw_rtu_10 bsap read isresponse dst 1 src 10 seqnum 1 addr 100 value 420\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `1234` (`transport tcp` switches to stateful\n  TCP `1234`) and calculates the BSAP/IP message length header automatically.\n- Encodes 16-bit BSAP node addresses (`dst`, `src`), 8-bit `seqnum`, and RDB\n  function codes (`poll`, `read`, `write`, plus response flag bit when\n  `isresponse` is set).\n- Packs 16-bit signal `addr`, item `count`, and 32-bit data `value` fields for RDB\n  Read responses and RDB Write commands.\n\n## Practical Lab Example: Water Booster Station ControlWave RTU Cycle: BSAP Poll, Tank Level Read & Pump Setpoint Write (`bsap_controlwave_scada.frasm`)\n\nPolls ControlWave RTU `10` over UDP `1234`, reads reservoir level RDB `addr 200`,\nand issues an RDB `write` (`addr 205`, `value 65`) with RTU acknowledgment.\n\n```frameassembly\nhost water_scada { ip 172.24.12.5 }\nhost booster_rtu { ip 172.24.12.50 }\n\ncompile {\n    // 1. BSAP Node Status Poll (seqnum 1) -> RTU Response\n    water_scada -> booster_rtu bsap poll dst 50 src 1 seqnum 1 wait 4ms\n    water_scada <- booster_rtu bsap poll isresponse dst 1 src 50 seqnum 1 wait 10ms\n    // 2. Remote Database (RDB) Read of Reservoir Tank Level (addr 200, count 2)\n    water_scada -> booster_rtu bsap read dst 50 src 1 seqnum 2 addr 200 count 2 wait 5ms\n    water_scada <- booster_rtu bsap read isresponse dst 1 src 50 seqnum 2 addr 200 value 1840 wait 15ms\n    // 3. RDB Write of Booster Pump VFD Speed Setpoint (addr 205 = 65%)\n    water_scada -> booster_rtu bsap write dst 50 src 1 seqnum 3 addr 205 count 1 value 65 wait 5ms\n    water_scada <- booster_rtu bsap write isresponse dst 1 src 50 seqnum 3 addr 205 value 65\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show bsap_controlwave_scada.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly bsap_controlwave_scada.frasm bsap_controlwave_scada.pcap\nframeassembly bsap_controlwave_scada.frasm bsap_controlwave_scada.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse bsap_controlwave_scada.pcap bsap_controlwave_scada_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r bsap_controlwave_scada.pcap -Y \"udp.port == 1234 || tcp.port == 1234\"\n```\n\n## All `bsap` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host bsap [read | write | poll | func\n\"<text_or_num>\"] [dst <0..65535>] [src <0..65535>] [seqnum <0..255>] [addr\n<0..65535>] [count <0..65535>] [value <number>] [isresponse] [transport\n<udp|tcp>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `read \\| write \\| poll \\| func \"<text_or_num>\" \\| [isresponse]` | BSAP Application Function selector + Response flag | `poll, request` | Selects Poll, RDB Read, RDB Write, or numeric BSAP function byte and toggles response direction. |\n| `dst <0..65535> \\| src <0..65535>` | 16-bit BSAP Destination & Source RTU/Master Node Addresses | `dst 1, src 0` | Writes the 2-byte Destination and Source BSAP node addresses in the BSAP/IP header. |\n| `seqnum <0..255>` | 8-bit BSAP Message Sequence Number (`0..255`) | `1` | Writes the 1-byte transaction Sequence Number echoed by the RTU. |\n| `addr <0..65535> \\| count <0..65535> \\| value <number>` | 16-bit RDB Signal Index/Address, Point Count, and 32-bit Signal Value | `addr 1, count 1, value 0` | Populates RDB Read/Write request lists and data values. |\n| `transport <udp\\|tcp>` | `udp` or `tcp` | `udp` | Switches Layer 4 between BSAP/UDP (`1234`) and BSAP/TCP (`1234`). |\n\n## Cross-Layer Options Valid with `bsap`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 1234 (or TCP 1234 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport <tcp\\|udp\\|sctp>` | `tcp`, `udp`, or `sctp` (dual TCP/UDP + universal L7 SCTP) | `transport udp` | Switches Layer 4 transport between stateful TCP, connectionless UDP, or Castagnoli CRC-32c SCTP association. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n| `seq <number> \\| acknum <number> \\| win\\|window <0..65535> \\| urgent <0..65535> \\| syn \\| ack \\| psh \\| fin \\| rst \\| urg \\| ece \\| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`sackblock`/`tsval`/`tsecr`/`tcpmd5`/`tfo`. |\n\n## Common Mistakes & Quick Fixes\n\n### Swap dst and src BSAP Node IDs on <- RTU Replies\n\n- **Valid v3.3.0 Syntax:** `scada -> rtu bsap read dst 50 src 1 seqnum 2 addr 200\nscada <- rtu bsap read isresponse dst 1 src 50 seqnum 2 addr 200 value 100`\n\nJust like DNP3 and ROC Plus, `<-` swaps Ethernet/IP/UDP addresses automatically,\nwhile `dst` and `src` explicitly set the application-layer BSAP node fields.\n\n### Keep seqnum Within 8-Bit Bounds (0..255)\n\n- **Avoid:** `scada -> rtu bsap poll seqnum 1000`\n- **Valid v3.3.0 Syntax:** `scada -> rtu bsap poll seqnum 1`\n\nBSAP sequence numbers are 1 octet wide (`0..=255`) and wrap modulo 256.\n"}
{"id":"pretrain-proto-knxnetip","kind":"protocol_spec","title":"KNXnet/IP Building Automation Tunneling & Group Telegrams (knxnetip) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/protocols/knxnetip","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["knxnetip"],"text":"# knxnetip — UDP 3671 Smart Building KNXnet/IP Tunneling & cEMI (`knxnetip`)\n\n> **FrameAssembly v3.3.0** · Protocol 124 of 81 · Canonical URL:\n> https://frameassembly-lang.dev/docs/protocols/knxnetip\n\n- **Full Protocol Name:** KNXnet/IP Building Automation Tunneling & Group\n  Telegrams\n- **Keyword:** `knxnetip`\n- **OSI Layer & Transport:** Layer 7 · UDP 3671\n- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6\n- **Standards:** ISO/IEC 14543-3-10, EN 50090, KNX Spec v2.1 (03/08/02/04)\n- **Wireshark Display Filter:** `knxip`\n- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 ->\n  UDP 3671 -> KNXnet/IP (ISO/IEC 14543-3)`\n\n## Overview\n\nCommercial lighting, blinds, and HVAC actuators on smart-building VLANs speak\nKNXnet/IP (`0x0610` magic) on UDP `3671` — `knxnetip` encodes `connect`/`connack`\nchannels and cEMI `read`/`write` telegrams between individual (`src`) and group\n(`dst`) addresses.\n\nKNXnet/IP (`knxnetip`, ISO/IEC 14543-3 / EN 50090) is the international\n**smart-building, hospital HVAC, lighting, blind/access actuator, and data-center\nenvironmental BMS** standard on **UDP port `3671`**. Every KNXnet/IP frame starts\nwith a **6-byte Header** (`Header Length = 0x06`, `Protocol Version = 0x10`,\n`16-bit Service Type Identifier` such as `0x0205` `CONNECT_REQUEST`, `0x0206`\n`CONNECT_RESPONSE`, `0x0209` `DISCONNECT_REQUEST`, `0x0420` `TUNNELLING_REQUEST`,\n`0x0421` `TUNNELLING_ACK`, or `0x0530` `ROUTING_INDICATION`, and `16-bit Total\nLength`) followed by HPAI endpoints, 4-byte Connection Headers (`channel`,\n`seqnum`, `status`), and **Common External Message Interface (`cEMI` `0x11`\n`L_Data.req`)** KNX telegrams (`16-bit Individual Source Address src`, `16-bit\nGroup Destination Address dst`, `GroupValueRead` `0x0000` / `GroupValueWrite`\n`0x0080 | val`).\n\nFrameAssembly packs exact `06 10` KNXnet/IP headers, HPAI endpoint descriptors,\nTunneling Connection Headers, and cEMI group-address telegrams.\n\n## Minimal Quickstart (`knxnetip_quickstart.frasm`)\n\n```frameassembly\nhost bms_server { ip 192.168.50.10 }\nhost knx_gw     { ip 192.168.50.200 }\n\ncompile {\n    bms_server -> knx_gw knxnetip connect wait 2ms\n    bms_server <- knx_gw knxnetip connack channel 1 status 0 wait 4ms\n    bms_server -> knx_gw knxnetip service \"tunnelreq\" channel 1 seqnum 0 src 0x1101 dst 0x0901 write value 1 wait 2ms\n    bms_server <- knx_gw knxnetip service \"tunnelack\" channel 1 seqnum 0 status 0\n}\n```\n\n### Automatic Wire Calculations\n\n- Defaults to UDP destination port `3671`, writes the `06 10` (`Header Len 6,\n  KNXnet/IP v1.0`) preamble, and computes the big-endian 16-bit `Total Length`\n  automatically.\n- Formats dual 8-byte IPv4 UDP `HPAI` (`Host Protocol Address Information`) +\n  4-byte `CRI` (`Tunnel Connection`) descriptors on `connect` (`0x0205`) and\n  `connack` (`0x0206`).\n- Constructs complete 11+-byte **cEMI `L_Data.req` (`0x11`)** payloads inside\n  `TUNNELLING_REQUEST` (`0x0420`) and `ROUTING_INDICATION` (`0x0530`) using 16-bit\n  KNX physical `src` (`Area.Line.Device`) and group `dst` (`Main/Middle/Sub`)\n  addresses.\n\n## Practical Lab Example: Hospital Lighting & HVAC KNXnet/IP Tunneling Session: Connect, GroupValueWrite, GroupValueRead & Disconnect (`knxnetip_bms_tunneling.frasm`)\n\nOpens Tunneling Channel `7` on a KNX/IP interface (`UDP 3671`), switches Zone 1\nlighting ON (`GroupValueWrite` `value 1` to `1/1/1` = `0x0901`), reads room\ntemperature (`GroupValueRead` to `2/0/10` = `0x100a`), and disconnects cleanly.\n\n```frameassembly\nhost bms_ctrl  { ip 10.50.36.10 }\nhost knx_ip_if { ip 10.50.36.71 }\n\ncompile {\n    // 1. CONNECT_REQUEST (0x0205) -> CONNECT_RESPONSE (0x0206) assigning Channel 7, Status E_NO_ERROR (0x00)\n    bms_ctrl -> knx_ip_if knxnetip connect wait 2ms\n    bms_ctrl <- knx_ip_if knxnetip connack channel 7 status 0 wait 5ms\n    // 2. TUNNELLING_REQUEST (0x0420) cEMI GroupValueWrite: 1.1.1 (0x1101) -> 1/1/1 (0x0901) = 1 (ON)\n    bms_ctrl -> knx_ip_if knxnetip service 0x0420 channel 7 seqnum 0 src 0x1101 dst 0x0901 write value 1 wait 2ms\n    bms_ctrl <- knx_ip_if knxnetip service 0x0421 channel 7 seqnum 0 status 0 wait 10ms\n    // 3. TUNNELLING_REQUEST (0x0420) cEMI GroupValueRead: 1.1.1 (0x1101) -> 2/0/10 (0x100a)\n    bms_ctrl -> knx_ip_if knxnetip service 0x0420 channel 7 seqnum 1 src 0x1101 dst 0x100a read wait 2ms\n    bms_ctrl <- knx_ip_if knxnetip service 0x0421 channel 7 seqnum 1 status 0 wait 5ms\n    // 4. DISCONNECT_REQUEST (0x0209) -> DISCONNECT_RESPONSE (0x020a)\n    bms_ctrl -> knx_ip_if knxnetip disconnect channel 7 wait 2ms\n    bms_ctrl <- knx_ip_if knxnetip service 0x020a channel 7 status 0\n}\n```\n\n```bash\n# 1. Eyeball relative timestamps, ports & wire lengths in your terminal\nframeassembly show knxnetip_bms_tunneling.frasm\n\n# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'\nframeassembly knxnetip_bms_tunneling.frasm knxnetip_bms_tunneling.pcap\nframeassembly knxnetip_bms_tunneling.frasm knxnetip_bms_tunneling.pcapng\n\n# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture\nframeassembly reverse knxnetip_bms_tunneling.pcap knxnetip_bms_tunneling_edited.frasm\n\n# 4. Verify dissected protocol fields in tshark\ntshark -r knxnetip_bms_tunneling.pcap -Y \"knxip\"\n```\n\n## All `knxnetip` Keywords & Header Options\n\nPacket line pattern: `src_host -> dst_host knxnetip [connect | connack |\ndisconnect | service \"<text_or_num>\"] [channel <0..255>] [seqnum <0..255>] [status\n<0..255>] [src <0..65535>] [dst <0..65535>] [read | write] [value <number>]`\n\n| Keyword / Option | Accepted Value | Default | Effect on Packet |\n| --- | --- | --- | --- |\n| `connect \\| connack \\| disconnect \\| service \"<text_or_num>\"` | 16-bit KNXnet/IP Service Type Identifier (`0x0205` Connect, `0x0206` ConnResp, `0x0209` Disconnect, `0x020a` DiscResp, `0x0420` TunnelReq, `0x0421` TunnelAck, `0x0530` RoutingInd) | `service 0x0420 (TUNNELLING_REQUEST) when read/write/src/dst set, else connect (0x0205)` | Sets bytes 2..3 of the 6-byte KNXnet/IP header and builds the corresponding connection or cEMI body. |\n| `channel <0..255> \\| seqnum <0..255> \\| status <0..255>` | 8-bit Communication Channel ID, Tunnel Sequence Counter, and Error Status (`0x00` `E_NO_ERROR`, `0x24` `E_NO_MORE_CONNECTIONS`) | `channel 1, seqnum 0, status 0` | Populates the Connection Response Header or 4-byte Tunneling Connection Header. |\n| `src <0..65535> \\| dst <0..65535>` | 16-bit KNX Individual Address `(Area<<12 \\| Line<<8 \\| Dev)` & 3-Level Group Address `(Main<<11 \\| Mid<<8 \\| Sub)` | `src 0x1101 (1.1.1), dst 0x0901 (1/1/1)` | Writes bytes 4..7 of the embedded cEMI `L_Data` frame. |\n| `read \\| write \\| value <number>` | KNX Application Layer APCI (`0x0000` GroupValueRead, `0x0080` GroupValueWrite) + DPT value | `read (GroupValueRead)` | Encodes 6-bit inline DPT1/DPT5 values (`0x80 \\| (val & 0x3f)`) or multi-byte APDU data in the cEMI TPDU. |\n\n## Cross-Layer Options Valid with `knxnetip`\n\n| Option | Range / Format | Default | Effect |\n| --- | --- | --- | --- |\n| `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). |\n| `comment \"<text>\"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |\n| `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. |\n| `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. |\n| `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. |\n| `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. |\n| `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`). |\n| `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. |\n| `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. |\n| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |\n| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |\n| `srcport <0..65535> \\| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), UDP 3671` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |\n| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `UDP (UDP 3671)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |\n| `badchecksum \\| nochecksum` | L4 checksum fault or UDP zero-checksum flag | `Valid RFC checksum / CRC-32c` | `badchecksum` corrupts the L4 checksum for negative firewall/NIC offload tests; `nochecksum` writes `0x0000` in UDP headers. |\n\n## Common Mistakes & Quick Fixes\n\n### Increment Tunneling seqnum by +1 Only After TUNNELLING_ACK Matches the Current seqnum\n\n- **Valid v3.3.0 Syntax:** `c -> gw knxnetip service 0x0420 channel 1 seqnum 0\n  write value 1\nc <- gw knxnetip service 0x0421 channel 1 seqnum 0 status 0`\n\nIn KNXnet/IP Tunneling, `TUNNELLING_ACK (0x0421)` echoes the *exact* `seqnum` of\nthe `TUNNELLING_REQUEST (0x0420)` being acknowledged; the next request increments\n`seqnum` to `1`.\n\n### Pack 3-Level Group Addresses into 16-Bit Hex (Main<<11 | Middle<<8 | Sub)\n\n- **Valid v3.3.0 Syntax:** `c -> gw knxnetip service 0x0420 src 0x1101 dst 0x0901\n  write value 1`\n\nKNX group address `1/1/1` encodes on the wire as `(1 << 11) | (1 << 8) | 1 =\n0x0901`; individual address `1.1.1` encodes as `(1 << 12) | (1 << 8) | 1 =\n0x1101`.\n"}
{"id":"pretrain-examples-hub","kind":"examples_anthology","title":"FrameAssembly by Example — 169 Annotated .frasm Recipes","url":"https://frameassembly-lang.dev/docs/examples","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["arp","vlan","qinq","lldp","stp","lacp","eapol","mpls","cdp","isis","macsec","pfc","pppoe","nsh","profinet","goose","sv","ethercat","icmp","ndp","igmp","mld","gre","vxlan","geneve","ipip","srv6","erspan","ipsec","esp","ah","ikev2","wireguard","ospf","bgp","rip","pim","vrrp","hsrp","glbp","bfd","openflow","rsvp","ldp","bmp","rpkirtr","l2tp","lisp","gtpu","tcp","udp","sctp","snmp1","snmp2","snmp3","dns","mdns","dhcp","ntp","ptp","radius","tacacs","syslog","netflow","ipfix","sflow","http","http2","grpc","websocket","tls","quic","ssh","telnet","tftp","ftp","whois","sip","rtp","rtsp","stun","ssdp","gtpc","pfcp","diameter","ngap","s1ap","smtp","imap","pop3","kerberos","ldap","smb","nfs","iscsi","nvmetcp","rocev2","redis","memcached","mysql","postgres","mqtt","coap","amqp","modbus","bacnet","dnp3","s7comm","s7commplus","ethernetip","opcua","iec104","mms","synchrophasor","hartip","fins","melsec","someip","doip","c1222","gesrtp","rocplus","bsap","knxnetip"],"text":"# FrameAssembly by Example — 169 Annotated `.frasm` Packet Capture Recipes\n\n> **FrameAssembly v3.3.0** · MIT License · Canonical URL:\n> https://frameassembly-lang.dev/docs/examples · Full single-file examples corpus:\n> https://frameassembly-lang.dev/llms-examples.txt\n\nBrowse compilable, RFC-accurate `.frasm` (`text/vnd.frameassembly`) packet capture\nspecifications organized into 12 right-sized domain anthologies across all 81\nLayer 2–7 protocols, dual-stack `flow(a, b)` templates, `transport tcp|udp`\noverrides, nanosecond `.pcapng` bursts, and Scapy / Wireshark / `frameassembly\nreverse` migrations.\n\n## Anthology Index (`01`–`12`)\n\n- **Anthology 01 (Layer 2 · 14 recipes): [Layer 2 Switching, VLAN, QinQ, 802.1X &\n  MPLS\n  Examples](https://frameassembly-lang.dev/docs/examples/l2-switching-vlans-nac)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/l2-switching-vlans-nac.md)) —\n  Rootless Ethernet II switching captures with MAC-only endpoints, 802.1Q VLAN\n  trunks, 802.1ad QinQ double tags, IEEE slow-protocol multicast MACs, 802.1X\n  EAPOL onboarding, and MPLS shim labels.\n- **Anthology 02 (Layer 3 · 14 recipes): [ICMPv4/v6, Dual-Stack Flows,\n  Fragmentation & DiffServ\n  QoS](https://frameassembly-lang.dev/docs/examples/icmp-dual-stack-qos)** ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/icmp-dual-stack-qos.md)) —\n  Reusable IPv4 and IPv6 `flow(src, dst)` reachability checks, Path MTU Discovery\n  (`df`), manual IPv4 fragment offsets (`ipid`, `mf`, `fragoffset`), IPv6 Neighbor\n  Discovery (`ndp`), and IGMP/MLD group joins.\n- **Anthology 03 (Layer 4 · 14 recipes): [Stateful 4-Tuple TCP Streams, Sequence\n  Anomalies &\n  SCTP](https://frameassembly-lang.dev/docs/examples/tcp-handshakes-anomalies)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/tcp-handshakes-anomalies.md))\n  — Automatic 4-tuple `seq` and `acknum` progression, RFC 7323 TCP options (`mss`,\n  `wscale`, `sackperm`, `tsval`/`tsecr`), deliberate retransmissions, ZeroWindow\n  stalls, abnormal scan flags, and Castagnoli CRC-32c SCTP.\n- **Anthology 04 (Layer 3 · 13 recipes): [BGP, OSPF, BFD, VRRP/HSRP, Multicast PIM\n  & OpenFlow\n  Examples](https://frameassembly-lang.dev/docs/examples/routing-bfd-redundancy)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/routing-bfd-redundancy.md)) —\n  Control-plane routing sessions, sub-second BFD failure-detection timers,\n  first-hop gateway redundancy (`vrrp` and `hsrp`), multicast Rendezvous Point\n  joins (`pim`), and SDN `openflow` channels.\n- **Anthology 05 (Layer 3 · 13 recipes): [Data-Center Overlays (VXLAN, GENEVE,\n  GRE) & VPN\n  Tunnels](https://frameassembly-lang.dev/docs/examples/overlays-tunnels-vpns)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/overlays-tunnels-vpns.md)) —\n  Spine-leaf EVPN underlay captures (`vxlan` UDP 4789 and `geneve` UDP 6081),\n  `gre` routing encapsulations, `ikev2` SA/Child-SA exchanges, IPsec\n  `esp`/`ah`/`ipsec` headers, and modern `wireguard` handshakes.\n- **Anthology 06 (Layer 7 · 13 recipes): [DNS (UDP/TCP), mDNS, SSDP, DHCPv4/v6 &\n  Nanosecond Time\n  Sync](https://frameassembly-lang.dev/docs/examples/dns-dhcp-network-timing)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/dns-dhcp-network-timing.md)) —\n  Core DDI address and service resolution (`dns`, `mdns`, `ssdp`, `dhcp` DORA and\n  IPv6 SARR) alongside stratum `ntp` polling and sub-microsecond IEEE 1588 `ptp`\n  `.pcapng` captures.\n- **Anthology 07 (Layer 7 · 13 recipes): [TLS 1.3 SNI, QUIC, HTTP/1.1, HTTP/2,\n  gRPC & WebSocket\n  APIs](https://frameassembly-lang.dev/docs/examples/tls-quic-http-apis)** ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/tls-quic-http-apis.md)) —\n  Modern web, reverse-proxy, WAF, and service-mesh traffic fixtures: TLS 1.3\n  `clienthello` SNI/ALPN, `quic` long/short headers, `http` `hosthdr` REST calls,\n  `http2` streams, `grpc` status trails, and `websocket` frames.\n- **Anthology 08 (Layer 7 · 13 recipes): [PostgreSQL, MySQL, Redis, Memcached,\n  MQTT & AMQP\n  Captures](https://frameassembly-lang.dev/docs/examples/databases-caches-brokers)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/databases-caches-brokers.md))\n  — East-west microservice data-tier segmentation and IoT message-bus traces:\n  `postgres` v3 Wire queries, `mysql` greetings and SQL commands, `redis` RESP\n  arrays, `memcached` TCP/UDP, `mqtt`, and `amqp`.\n- **Anthology 09 (Layer 7 · 14 recipes): [Active Directory (Kerberos, LDAP), AAA,\n  SMB/NFS & Admin\n  Access](https://frameassembly-lang.dev/docs/examples/identity-aaa-storage)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/identity-aaa-storage.md)) —\n  Enterprise identity, NAS storage, and bastion captures: `kerberos` AS/TGS\n  exchanges, `ldap` binds and searches, `radius` & `tacacs` AAA, `smb` & `nfs`\n  shares, plus `ssh`, `telnet`, `ftp`, `tftp`, and `whois`.\n- **Anthology 10 (Layer 7 · 20 recipes): [SIP/RTP VoIP, Mail, Encrypted SNMPv3 USM\n  & Flow\n  Telemetry](https://frameassembly-lang.dev/docs/examples/voip-media-snmp-telemetry)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/voip-media-snmp-telemetry.md))\n  — Voice/media signaling (`sip`, `rtp`, `rtsp`, `stun`), mail relays (`smtp`,\n  `imap`, `pop3`), MIB-free `snmp1`/`snmp2`/encrypted `snmp3` USM traps, `syslog`,\n  and `netflow`/`ipfix`/`sflow` collector streams.\n- **Anthology 11 (Layer 7 · 14 recipes): [Industrial ICS/SCADA & IIoT Captures\n  (Modbus, DNP3, S7comm, OPC\n  UA)](https://frameassembly-lang.dev/docs/examples/industrial-ics-scada-ot)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/industrial-ics-scada-ot.md)) —\n  Purdue-model OT firewall and passive ICS sensor validation across `modbus`,\n  `dnp3` (reflected 0x3d65 CRC-16), Siemens `s7comm`, `opcua`, `bacnet`,\n  `ethernetip` CIP, and constrained `coap`.\n- **Anthology 12 (L2–L7 Cross-Layer · 14 recipes): [Scapy, Wireshark Filter,\n  tcprewrite & PCAP Reverse\n  Migrations](https://frameassembly-lang.dev/docs/examples/scapy-wireshark-migrations)**\n  ([Raw\n  .md](https://frameassembly-lang.dev/docs/examples/scapy-wireshark-migrations.md))\n  — Side-by-side translations from imperative Python/Scapy scripts, `tcprewrite`,\n  `text2pcap` hex dumps, and Wireshark display filters into `.frasm`, plus full\n  L2–L7 PCAP redaction with `frameassembly reverse`.\n\n## Machine-Readable Training, Grammar & Specification Feeds\n\n- **Complete Language & 81-Protocol Reference (`llms-full.txt`)**:\n  https://frameassembly-lang.dev/llms-full.txt\n- **All 169 Annotated Cookbook Examples (`llms-examples.txt`)**:\n  https://frameassembly-lang.dev/llms-examples.txt\n- **ISO/IEC 14977 EBNF Grammar**:\n  https://frameassembly-lang.dev/grammars/grammar.ebnf\n- **llama.cpp / XGrammar GBNF Grammar**:\n  https://frameassembly-lang.dev/grammars/frameassembly.gbnf\n- **Outlines / vLLM / llguidance Lark Grammar**:\n  https://frameassembly-lang.dev/grammars/frameassembly.lark\n- **MLCommons Croissant 1.0 Dataset Manifest**:\n  https://frameassembly-lang.dev/datasets/croissant.json\n"}
{"id":"pretrain-anthology-l2-switching-vlans-nac","kind":"examples_anthology","title":"Layer 2 Switching, VLAN, QinQ, 802.1X & MPLS Examples — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/l2-switching-vlans-nac","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["lldp","stp","lacp","eapol","mpls","icmp","arp","qinq","vlan","tcp","tls"],"text":"# Layer 2 Switching, VLAN, QinQ, 802.1X & MPLS Examples\n\n> **FrameAssembly v3.3.0** · Anthology 01 (Layer 2 · 14 Recipes) · MIT License ·\n> Canonical URL:\n> https://frameassembly-lang.dev/docs/examples/l2-switching-vlans-nac\n\nRootless Ethernet II switching captures with MAC-only endpoints, 802.1Q VLAN\ntrunks, 802.1ad QinQ double tags, IEEE slow-protocol multicast MACs, 802.1X EAPOL\nonboarding, and MPLS shim labels.\n\n## Key Wire & Syntax Takeaways\n\n- Pure Layer 2 protocols (`arp`, `vlan`, `qinq`, `lldp`, `stp`, `lacp`, `eapol`,\n  `mpls`) support MAC-only `host` blocks without IP addresses.\n- IEEE group destination MACs (`01:80:c2:00:00:00`, `01:80:c2:00:00:02`,\n  `01:80:c2:00:00:03`, `01:80:c2:00:00:0e`) and broadcast ARP `ff:ff:ff:ff:ff:ff`\n  populate automatically.\n- `vlan <vid>`, `qinq <svid> innervlan <cvid>`, and `mpls <label>` work both\n  standalone and as cross-layer prefixes on any L3–L7 packet.\n\n## 01.01 · MAC-Only Switch Control-Plane Bundle (LLDP + RSTP + LACP) (`switch_l2_control_plane.frasm`)\n\nPure Layer 2 switching protocols do not require IP addresses on endpoints. This\ncapture declares Cisco dot-quad MAC-only hosts and emits IEEE group-MAC LLDP,\nRapid STP, and LACP frames on a trunk.\n\n- **Protocols:** `lldp`, `stp`, `lacp` (3 Ethernet frames)\n- **Wire Behavior:** Automatically populates IEEE slow/bridge multicast\n  destination MACs (01:80:c2:00:00:0e, 01:80:c2:00:00:00, and 01:80:c2:00:00:02).\n- **Wireshark Filter:** `lldp || stp || slow`\n- **CLI Build:** `frameassembly switch_l2_control_plane.frasm`\n\n```frameassembly\nhost leaf_sw1  { mac 001c.73aa.0001 }\nhost spine_sw1 { mac 001c.73bb.0001 }\n\ncompile {\n    leaf_sw1 -> spine_sw1 lldp chassisid \"leaf-sw1\" portid \"Ethernet49/1\" ttl 120 sysname \"leaf-sw1.dc1\" wait 2ms\n    spine_sw1 -> leaf_sw1 stp rstp rootid \"32768:00:1c:73:bb:00:01\" bridgeid \"32768:00:1c:73:bb:00:01\" portid 0x8001 cost 2000 hellotime 2 wait 2ms\n    leaf_sw1 -> spine_sw1 lacp actorsys 00:1c:73:aa:00:01 actorkey 10 actorport 49 partnersys 00:1c:73:bb:00:01 partnerkey 10 partnerport 1\n}\n```\n\n## 01.02 · IEEE 802.1X Supplicant Onboarding (EAPOL-Start, Identity & Key) (`nac_8021x_eapol_exchange.frasm`)\n\nModels a wired workstation authenticating to a NAC-enabled access switch over\nEtherType 0x888e before receiving an IP lease.\n\n- **Protocols:** `eapol` (5 Ethernet frames)\n- **Wire Behavior:** Targets PAE multicast MAC 01:80:c2:00:00:03 on supplicant\n  frames and steps through EAP-Request/Response Identity (eapmethod 1) and\n  EAP-Success (eapcode 3).\n- **Wireshark Filter:** `eapol || eap`\n- **CLI Build:** `frameassembly nac_8021x_eapol_exchange.frasm`\n\n```frameassembly\nhost corp_laptop { mac 00:24:9b:11:22:33 }\nhost access_sw   { mac 00:1c:73:00:10:01 }\n\ncompile {\n    corp_laptop -> access_sw eapol version 2 start wait 3ms\n    corp_laptop <- access_sw eapol version 2 eappacket eapcode 1 eapid 1 eapmethod 1 wait 2ms\n    corp_laptop -> access_sw eapol version 2 eappacket eapcode 2 eapid 1 eapmethod 1 identity \"host/wkstn-42.corp.internal\" wait 8ms\n    corp_laptop <- access_sw eapol version 2 eappacket eapcode 3 eapid 1 wait 2ms\n    corp_laptop <- access_sw eapol version 2 key\n}\n```\n\n## 01.03 · MPLS L3VPN Shim Label with Traffic-Class QoS Marking (`mpls_l3vpn_exp5.frasm`)\n\nWraps an inter-site ICMP Echo exchange inside a 20-bit MPLS transport label\n(16040) with Traffic Class / EXP 5 for core voice-grade forwarding checks.\n\n- **Protocols:** `mpls`, `icmp` (2 Ethernet frames)\n- **Wire Behavior:** Prepends EtherType 0x8847 with label 16040, exp 5, bos 1, and\n  decremented mplsttl on the return path.\n- **Wireshark Filter:** `mpls.label == 16040`\n- **CLI Build:** `frameassembly mpls_l3vpn_exp5.frasm`\n\n```frameassembly\nhost pe_west { ip 10.254.0.1 mac 00:1c:73:10:00:01 }\nhost pe_east { ip 10.254.0.2 mac 00:1c:73:20:00:02 }\n\ncompile {\n    pe_west -> pe_east mpls 16040 exp 5 bos 1 mplsttl 64 icmp echorequest id 0x0901 seq 1 wait 4ms\n    pe_west <- pe_east mpls 24010 exp 5 bos 1 mplsttl 63 icmp echoreply id 0x0901 seq 1\n}\n```\n\n## 01.04 · Local Subnet ARP Discovery Sweep (`scan_arp_lan_sweep.frasm`)\n\nBroadcasts Layer 2 ARP Who-Has requests across three local subnet IPs, showing two\nonline hosts answering with their MACs and one unused IP staying silent.\n\n- **Protocols:** `arp` (5 Ethernet frames)\n- **Wire Behavior:** arp request automatically sets the Ethernet destination MAC\n  to ff:ff:ff:ff:ff:ff (broadcast), while <- arp reply sends a unicast response\n  straight back to the scanner.\n- **Wireshark Filter:** `arp`\n- **CLI Build:** `frameassembly scan_arp_lan_sweep.frasm`\n\n```frameassembly\n// Technician laptop scanning three local /24 addresses on the same VLAN\nhost tech_laptop { ip 192.168.10.200 mac 00:1a:2b:00:00:aa }\nhost router_gw   { ip 192.168.10.1   mac 00:1c:73:00:00:01 }\nhost nas_box     { ip 192.168.10.50  mac 00:11:32:aa:bb:cc }\nhost unused_ip   { ip 192.168.10.51 }\n\ncompile {\n    // Probe .1 -> Gateway answers with its MAC\n    tech_laptop -> router_gw arp request senderip 192.168.10.200 targetip 192.168.10.1 wait 1ms\n    tech_laptop <- router_gw arp reply senderip 192.168.10.1 targetip 192.168.10.200 wait 2ms\n\n    // Probe .50 -> NAS answers with its MAC\n    tech_laptop -> nas_box arp request senderip 192.168.10.200 targetip 192.168.10.50 wait 1ms\n    tech_laptop <- nas_box arp reply senderip 192.168.10.50 targetip 192.168.10.200 wait 2ms\n\n    // Probe .51 -> No host owns this IP, so no ARP reply comes back\n    tech_laptop -> unused_ip arp request senderip 192.168.10.200 targetip 192.168.10.51\n}\n```\n\n## 01.05 · 802.1ad QinQ Double-Tag VLAN Hopping Trunk Audit (`pentest_qinq_vlan_hop.frasm`)\n\nBuilds an 802.1ad/802.1Q double-tagged frame (outer S-VLAN 100 + inner C-VLAN 20)\nto verify access switch ports drop unexpected outer tags instead of forwarding\ninto a protected VLAN.\n\n- **Protocols:** `qinq`, `vlan`, `icmp` (2 Ethernet frames)\n- **Wire Behavior:** qinq 100 innervlan 20 stacks outer EtherType 0x88a8 (VID 100)\n  ahead of inner EtherType 0x8100 (VID 20) so you can audit trunk native-VLAN\n  hardening.\n- **Wireshark Filter:** `vlan.id == 100 || vlan.id == 20`\n- **CLI Build:** `frameassembly pentest_qinq_vlan_hop.frasm`\n\n```frameassembly\n// Lab test host on VLAN 100 auditing switch isolation toward restricted VLAN 20\nhost audit_port { ip 10.20.0.99 mac 02:aa:bb:cc:dd:01 }\nhost restricted { ip 10.20.0.10 mac 00:1c:73:20:00:10 }\n\ncompile {\n    // 1. Send double-tagged frame (outer S-Tag 100, inner C-Tag 20)\n    audit_port -> restricted qinq 100 innervlan 20 icmp echorequest id 0x1337 seq 1 payload \"vlan-hop-audit\" wait 3ms\n\n    // 2. Simulated misconfigured trunk stripping outer tag and delivering single-tagged VLAN 20 frame\n    audit_port -> restricted vlan 20 icmp echorequest id 0x1337 seq 1 payload \"vlan-hop-audit\"\n}\n```\n\n## 01.06 · Gratuitous ARP Spoof Test & Unauthorized Egress TLS SNI Audit (`pentest_garp_egress_tls.frasm`)\n\nTests switch Dynamic ARP Inspection (DAI) against an unauthorized Gratuitous ARP\nclaim, followed by an egress TLS ClientHello to an unapproved external domain.\n\n- **Protocols:** `arp`, `tcp`, `tls` (5 Ethernet frames)\n- **Wire Behavior:** arp gratuitous broadcasts senderip == targetip to\n  ff:ff:ff:ff:ff:ff—ideal for verifying DAI port-shutdown rules in a isolated lab.\n- **Wireshark Filter:** `arp.isgratuitous || tls.handshake.extensions_server_name`\n- **CLI Build:** `frameassembly pentest_garp_egress_tls.frasm`\n\n```frameassembly\n// Rogue lab device, default gateway IP, and external cloud endpoint\nhost rogue_box   { ip 10.20.5.99 mac 02:de:ad:be:ef:99 }\nhost vlan_gw     { ip 10.20.5.1  mac 00:1c:73:05:00:01 }\nhost ext_storage { ip 198.51.100.77 }\n\ncompile {\n    // 1. Gratuitous ARP announcement claiming the gateway's 10.20.5.1 IP (tests switch DAI)\n    rogue_box -> vlan_gw arp gratuitous senderip 10.20.5.1 sendermac 02:de:ad:be:ef:99 wait 5ms\n\n    // 2. Outbound TCP 443 + TLS ClientHello to test egress SNI filtering / DLP alerts\n    rogue_box -> ext_storage tcp syn srcport 54900 dstport 443 win 65535 mss 1460 wait 2ms\n    rogue_box <- ext_storage tcp syn ack win 65535 mss 1460 wait 2ms\n    rogue_box -> ext_storage tcp ack wait 1ms\n    rogue_box -> ext_storage tls clienthello sni \"unapproved-drop.example.net\" alpn \"h2\"\n}\n```\n\n## 01.07 · ARP / GARP (`arp`): VLAN-Tagged ARP Resolution Followed by Gratuitous ARP VIP Takeover (`arp_garp_failover.frasm`)\n\nSimulates a workstation resolving its default gateway on VLAN 10, followed by a\nstandby router broadcasting an RFC 5227 Gratuitous ARP announcement during a\nvirtual IP takeover.\n\n- **Protocols:** `arp`, `vlan` (3 Ethernet frames)\n- **Wire Behavior:** Sets Ethernet II EtherType to `0x0806` and broadcasts\n  `request` frames to destination MAC `ff:ff:ff:ff:ff:ff` unless `dstmac` is\n  overridden. Populates Hardware Type `1` (Ethernet), Protocol Type `0x0800`\n  (IPv4), `hlen=6`, `plen=4`, and `opcode=1` (`request`).\n- **Wireshark Filter:** `arp`\n- **CLI Build:** `frameassembly show arp_garp_failover.frasm`\n\n```frameassembly\nhost workstation { ip 10.10.10.50 mac 00:1b:21:10:00:50 }\nhost rtr_active  { ip 10.10.10.1  mac 00:00:5e:00:01:01 }\nhost rtr_standby { ip 10.10.10.2  mac 00:1b:21:10:00:02 }\n\ncompile {\n    // 1. Broadcast ARP Who-Has on VLAN 10\n    workstation -> rtr_active arp request vlan 10 pcp 3 wait 1ms\n    // 2. Unicast ARP Is-At reply from active gateway\n    workstation <- rtr_active arp reply vlan 10 wait 5ms\n    // 3. Standby router takes over VIP 10.10.10.1 and broadcasts GARP\n    rtr_standby -> workstation arp gratuitous sendermac 00:00:5e:00:01:01 senderip 10.10.10.1 vlan 10\n}\n```\n\n## 01.08 · 802.1Q VLAN (`vlan`): Multi-VLAN Trunk Capture Mixing Standalone L2 Probes & Voice/Routing CoS (`vlan_trunk_qos.frasm`)\n\nDemonstrates standalone MAC-only 802.1Q frames alongside VLAN-tagged ARP, VoIP RTP\n(`pcp 5`, `dscp 46`), and network-control OSPF (`pcp 6`) traffic on a single\nswitch trunk.\n\n- **Protocols:** `vlan` (5 Ethernet frames)\n- **Wire Behavior:** Inserts outer TPID `0x8100` and packs `pcp` (3 bits), `dei`\n  (1 bit), and `vid` (12 bits) into the big-endian 16-bit Tag Control Information\n  (TCI) word. Emits default inner EtherType `0x0800` when used standalone\n  (overridable via `ethertype <0..65535>`) or preserves the exact inner protocol\n  EtherType (`0x0806`, `0x0800`, `0x86dd`, `0x8847`) when used as a cross-layer\n  modifier.\n- **Wireshark Filter:** `vlan`\n- **CLI Build:** `frameassembly show vlan_trunk_qos.frasm`\n\n```frameassembly\nhost sw_leaf  { mac 00:1c:73:10:00:01 }\nhost sw_spine { mac 00:1c:73:20:00:01 }\nhost phone_01 { ip 10.50.20.11 mac 00:1c:73:50:00:11 }\nhost pbx_core { ip 10.50.20.10 mac 00:1c:73:50:00:10 }\n\ncompile {\n    // Standalone L2 VLAN probe on management VLAN 99\n    sw_leaf -> sw_spine vlan 99 pcp 2 dei 0 ethertype 0x88b5 payload \"trunk-health\" wait 1ms\n    // Voice VLAN 20: ARP + CoS 5 / EF RTP media packet\n    phone_01 -> pbx_core arp request vlan 20 pcp 5 wait 1ms\n    phone_01 <- pbx_core arp reply vlan 20 pcp 5 wait 2ms\n    phone_01 -> pbx_core rtp pt 0 seq 1 timestamp 160 ssrc 0x10203040 vlan 20 pcp 5 dscp 46 payload \"g711-ulaw-sample\" wait 2ms\n    // Routing VLAN 30: Priority 6 OSPF Hello\n    phone_01 -> pbx_core ospf hello routerid 10.50.20.11 areaid 0 vlan 30 pcp 6\n}\n```\n\n## 01.09 · 802.1ad QinQ (`qinq`): Provider NNI Trunk Carrying Multiple Customer C-VLANs Inside S-VLAN 1200 (`qinq_metro_nni.frasm`)\n\nModels a Metro Ethernet provider trunk (`S-VLAN 1200`) carrying two distinct\ncustomer tenants: Tenant A (`innervlan 100`) running BGP peering and Tenant B\n(`innervlan 200`) running ICMPv6.\n\n- **Protocols:** `qinq`, `tcp` (6 Ethernet frames)\n- **Wire Behavior:** Always writes two complete 4-byte VLAN tags: outer TPID\n  `0x88a8` (S-VLAN, default `100`) followed immediately by inner TPID `0x8100`\n  (C-VLAN, default `innervlan 1`). Applies `pcp` (`0..7`) and `dei` (`0|1`)\n  cleanly to the tag control headers and preserves the inner payload EtherType\n  (`0x0800` IPv4, `0x86dd` IPv6, `0x0806` ARP).\n- **Wireshark Filter:** `vlan.etype == 0x88a8 || vlan`\n- **CLI Build:** `frameassembly show qinq_metro_nni.frasm`\n\n```frameassembly\nhost ce_v4_a { ip 172.20.0.1 mac 00:1b:21:c1:00:01 }\nhost ce_v4_b { ip 172.20.0.2 mac 00:1b:21:c1:00:02 }\nhost ce_v6_a { ip 2001:db8:200::1 mac 00:1b:21:c2:00:01 }\nhost ce_v6_b { ip 2001:db8:200::2 mac 00:1b:21:c2:00:02 }\n\ncompile {\n    // Tenant A: eBGP Keepalive inside S-VLAN 1200 / C-VLAN 100\n    ce_v4_a -> ce_v4_b tcp syn srcport 51179 dstport 179 win 65535 mss 1452 qinq 1200 innervlan 100 pcp 6 wait 1ms\n    ce_v4_a <- ce_v4_b tcp syn ack win 65535 mss 1452 qinq 1200 innervlan 100 pcp 6 wait 1ms\n    ce_v4_a -> ce_v4_b tcp ack qinq 1200 innervlan 100 pcp 6 wait 1ms\n    ce_v4_a -> ce_v4_b bgp keepalive qinq 1200 innervlan 100 pcp 6 wait 3ms\n    // Tenant B: IPv6 Echo inside S-VLAN 1200 / C-VLAN 200\n    ce_v6_a -> ce_v6_b icmp echorequest id 42 seq 1 qinq 1200 innervlan 200 pcp 3 wait 1ms\n    ce_v6_a <- ce_v6_b icmp echoreply id 42 seq 1 qinq 1200 innervlan 200 pcp 3\n}\n```\n\n## 01.10 · LLDP (`lldp`): Bidirectional Leaf-Spine LLDP Neighbor Exchange Plus Shutdown Frame (`lldp_leaf_spine.frasm`)\n\nCaptures mutual LLDP advertisements between an Arista-class spine and an access\nswitch, followed by an IEEE 802.1AB `ttl 0` neighbor withdrawal frame.\n\n- **Protocols:** `lldp` (3 Ethernet frames)\n- **Wire Behavior:** Sets Ethernet II EtherType to `0x88cc` and defaults the\n  destination MAC to IEEE nearest-bridge multicast `01:80:c2:00:00:0e`. Encodes\n  TLV 1 (Chassis ID, subtype `4` MAC or `7` Locally Assigned), TLV 2 (Port ID,\n  subtype `5` Interface Name), and TLV 3 (16-bit `ttl`, default `120` seconds)\n  with exact 7-bit type + 9-bit length bitfields.\n- **Wireshark Filter:** `lldp`\n- **CLI Build:** `frameassembly show lldp_leaf_spine.frasm`\n\n```frameassembly\nhost leaf_01  { mac 00:1c:73:11:22:01 }\nhost spine_01 { mac 00:1c:73:99:88:01 }\n\ncompile {\n    leaf_01 -> spine_01 lldp chassisid \"leaf-01.dc1\" portid \"Ethernet49/1\" ttl 120 sysname \"leaf-01.dc1.internal\" sysdesc \"EOS 4.32.1F\" wait 5ms\n    spine_01 -> leaf_01 lldp chassisid \"spine-01.dc1\" portid \"Ethernet1/1\" ttl 120 sysname \"spine-01.dc1.internal\" sysdesc \"EOS 4.32.1F\" wait 10ms\n    // Graceful LLDP port shutdown advertisement (TTL = 0)\n    leaf_01 -> spine_01 lldp chassisid \"leaf-01.dc1\" portid \"Ethernet49/1\" ttl 0\n}\n```\n\n## 01.11 · STP / RSTP (`stp`): Normal Root RSTP Heartbeat Followed by Rogue Superior BPDU Attack (`stp_rogue_root_audit.frasm`)\n\nCaptures a legitimate distribution switch sending RSTP BPDUs (`priority 32768`),\nfollowed by a rogue access device advertising priority `4096` (`cost 0`) to\ntrigger Root Guard / BPDU Guard.\n\n- **Protocols:** `stp` (3 Ethernet frames)\n- **Wire Behavior:** Addresses Ethernet destination to IEEE Bridge Group multicast\n  `01:80:c2:00:00:00` and writes the exact IEEE 802.3 Payload Length field instead\n  of an Ethernet II EtherType. Prepends the 3-byte LLC header (`0x42 0x42 0x03`)\n  and Protocol Identifier `0x0000` ahead of the Configuration or RSTP BPDU.\n- **Wireshark Filter:** `stp`\n- **CLI Build:** `frameassembly show stp_rogue_root_audit.frasm`\n\n```frameassembly\nhost dist_root  { mac 00:1c:73:01:00:01 }\nhost access_sw  { mac 00:1c:73:02:00:10 }\nhost rogue_port { mac 00:50:56:99:99:99 }\n\ncompile {\n    // Legitimate RSTP Proposal/Learning-Forwarding BPDU from distribution root\n    dist_root -> access_sw stp rstp rootid \"32768:00:1c:73:01:00:01\" bridgeid \"32768:00:1c:73:01:00:01\" portid 0x8001 cost 0 flags 0x3c wait 2s\n    // Downstream access switch relaying root path cost 20000\n    access_sw -> rogue_port stp rstp rootid \"32768:00:1c:73:01:00:01\" bridgeid \"32768:00:1c:73:02:00:10\" portid 0x8018 cost 20000 flags 0x3c wait 500ms\n    // Rogue device injecting a superior Root ID (priority 4096, cost 0)\n    rogue_port -> access_sw stp rstp rootid \"4096:00:50:56:99:99:99\" bridgeid \"4096:00:50:56:99:99:99\" portid 0x8001 cost 0 flags 0x0e\n}\n```\n\n## 01.12 · LACP (`lacp`): LACP Port-Channel Bring-Up From Unsynced Defaulted to Active Distributing (`lacp_negotiation.frasm`)\n\nModels a Linux bond interface and Top-of-Rack switch negotiating Port-Channel 10\n(`key 10`) from initial unsynced discovery (`actorstate 0x45`) to full `0x3f`\nFast-LACP Collecting/Distributing sync.\n\n- **Protocols:** `lacp` (4 Ethernet frames)\n- **Wire Behavior:** Sets Ethernet II EtherType to Slow Protocols `0x8809`,\n  destination MAC to `01:80:c2:00:00:02`, Subtype `0x01` (LACP), and Version\n  `0x01`. Builds the exact 110-byte LACPDU body: Actor TLV (`0x01`, 20B), Partner\n  TLV (`0x02`, 20B), Collector TLV (`0x03`, 16B, MaxDelay `0x8000`), Terminator\n  TLV (`0x00`), and 50 zero-pad octets.\n- **Wireshark Filter:** `lacp`\n- **CLI Build:** `frameassembly show lacp_negotiation.frasm`\n\n```frameassembly\nhost srv_bond0 { mac 00:1b:21:44:55:01 }\nhost tor_leaf1 { mac 00:1c:73:88:99:01 }\n\ncompile {\n    // 1. Initial server LACPDU: Active + ShortTimeout + Aggregatable + Defaulted (0x47)\n    srv_bond0 -> tor_leaf1 lacp actorkey 10 actorport 1 actorstate 0x47 partnerkey 0 partnerport 0 partnerstate 0x00 wait 5ms\n    // 2. Switch replies recognizing server Actor as Partner and setting In-Sync (0x0f)\n    tor_leaf1 -> srv_bond0 lacp actorkey 10 actorport 49 actorstate 0x0f partnersys 00:1b:21:44:55:01 partnerkey 10 partnerport 1 partnerstate 0x47 wait 5ms\n    // 3. Both sides enter Active + Fast + Aggregatable + Sync + Collecting + Distributing (0x3f)\n    srv_bond0 -> tor_leaf1 lacp actorkey 10 actorport 1 actorstate 0x3f partnersys 00:1c:73:88:99:01 partnerkey 10 partnerport 49 partnerstate 0x0f wait 2ms\n    tor_leaf1 -> srv_bond0 lacp actorkey 10 actorport 49 actorstate 0x3f partnersys 00:1b:21:44:55:01 partnerkey 10 partnerport 1 partnerstate 0x3f\n}\n```\n\n## 01.13 · 802.1X EAPOL (`eapol`): Full IEEE 802.1X Supplicant Onboarding With Upstream RADIUS Verification (`eapol_8021x_nac.frasm`)\n\nTraces a workstation sending `EAPOL-Start`, answering an `EAP-Request/Identity`\nchallenge, triggering an upstream `RADIUS Access-Request/Accept` on the switch,\nand receiving `EAP-Success`.\n\n- **Protocols:** `eapol` (6 Ethernet frames)\n- **Wire Behavior:** Sets Ethernet II EtherType to `0x888e` and defaults\n  destination MAC to the IEEE 802.1X PAE group address `01:80:c2:00:00:03`. Writes\n  the 4-byte EAPOL header (`Protocol Version` default `2`, `Packet Type`, and\n  exact 16-bit `Packet Body Length`).\n- **Wireshark Filter:** `eapol || eap`\n- **CLI Build:** `frameassembly show eapol_8021x_nac.frasm`\n\n```frameassembly\nhost laptop    { mac 00:1b:21:55:66:77 }\nhost access_sw { ip 10.20.0.2  mac 00:1c:73:00:01:02 }\nhost radius_srv { ip 10.20.0.50 mac 00:50:56:00:00:50 }\n\ncompile {\n    // 1. Supplicant initiates 802.1X on physical switch port\n    laptop -> access_sw eapol start version 2 wait 2ms\n    // 2. Switch Authenticator requests EAP Identity (eapcode 1 = Request, eapmethod 1 = Identity)\n    access_sw -> laptop eapol eappacket version 2 eapcode 1 eapid 1 eapmethod 1 dstmac 00:1b:21:55:66:77 wait 3ms\n    // 3. Supplicant responds with corporate identity\n    laptop -> access_sw eapol eappacket version 2 eapcode 2 eapid 1 eapmethod 1 identity \"corp\\\\jdoe\" wait 2ms\n    // 4. Switch forwards authentication upstream to RADIUS AAA server\n    access_sw -> radius_srv radius accessrequest id 10 user \"corp\\\\jdoe\" nasip 10.20.0.2 wait 4ms\n    access_sw <- radius_srv radius accessaccept id 10 framedip 10.20.100.45 wait 2ms\n    // 5. Switch grants port access with EAP-Success (eapcode 3)\n    access_sw -> laptop eapol eappacket version 2 eapcode 3 eapid 1 dstmac 00:1b:21:55:66:77\n}\n```\n\n## 01.14 · MPLS (`mpls`): SR-MPLS L3VPN Core Transit Over 802.1Q Sub-Interfaces (`mpls_sr_l3vpn.frasm`)\n\nModels two Provider Edge routers exchanging MPLS-labeled BGP control traffic, VoIP\nEF traffic (`exp 5`), and dual-stack IPv6 customer probes across VLAN 400.\n\n- **Protocols:** `mpls`, `vlan`, `tcp` (6 Ethernet frames)\n- **Wire Behavior:** Sets Ethernet II (or inner VLAN/QinQ) EtherType to `0x8847`\n  (MPLS Unicast). Automatically sets `bos 0` on outer transit/transport labels and\n  `bos 1` on the innermost service label unless `bos` is explicitly overridden.\n- **Wireshark Filter:** `mpls`\n- **CLI Build:** `frameassembly show mpls_sr_l3vpn.frasm`\n\n```frameassembly\nhost pe1_v4 { ip 10.100.1.10 mac 00:1c:73:10:01:01 }\nhost pe2_v4 { ip 10.100.2.20 mac 00:1c:73:20:02:02 }\nhost ce1_v6 { ip 2001:db8:50::10 mac 00:1c:73:10:01:01 }\nhost ce2_v6 { ip 2001:db8:60::20 mac 00:1c:73:20:02:02 }\n\ncompile {\n    // 1. Standalone 2-label SR-MPLS OAM probe over VLAN 400 (outer Node SID 16001, inner VPN label 24010)\n    pe1_v4 -> pe2_v4 mpls 16001 mpls 24010 exp 6 mplsttl 64 vlan 400 payload \"sr-oam-ping\" wait 2ms\n    // 2. L3VPN IPv4 HTTPS TLS ClientHello inside outer label 16002 + inner VPN label 24010\n    pe1_v4 -> pe2_v4 tcp syn srcport 52443 dstport 443 win 65535 mss 1440 vlan 400 mpls 16002 mpls 24010 exp 4 mplsttl 63 wait 1ms\n    pe1_v4 <- pe2_v4 tcp syn ack win 65535 mss 1440 vlan 400 mpls 16001 mpls 24020 exp 4 mplsttl 63 wait 1ms\n    pe1_v4 -> pe2_v4 tcp ack vlan 400 mpls 16002 mpls 24010 exp 4 mplsttl 63 wait 1ms\n    pe1_v4 -> pe2_v4 tls clienthello sni \"erp.vrf-prod.internal\" alpn \"h2\" vlan 400 mpls 16002 mpls 24010 exp 4 mplsttl 63 wait 2ms\n    // 3. 6VPE IPv6 ICMPv6 Echo inside MPLS label stack (16002 -> 24055)\n    ce1_v6 -> ce2_v6 icmp echorequest id 9 seq 1 vlan 400 mpls 16002 mpls 24055 tc 5 mplsttl 62\n}\n```\n"}
{"id":"pretrain-anthology-icmp-dual-stack-qos","kind":"examples_anthology","title":"ICMPv4/v6, Dual-Stack Flows, Fragmentation & DiffServ QoS — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/icmp-dual-stack-qos","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["icmp","udp","ndp","tcp","http","igmp","mld","vlan"],"text":"# ICMPv4/v6, Dual-Stack Flows, Fragmentation & DiffServ QoS\n\n> **FrameAssembly v3.3.0** · Anthology 02 (Layer 3 · 14 Recipes) · MIT License ·\n> Canonical URL: https://frameassembly-lang.dev/docs/examples/icmp-dual-stack-qos\n\nReusable IPv4 and IPv6 `flow(src, dst)` reachability checks, Path MTU Discovery\n(`df`), manual IPv4 fragment offsets (`ipid`, `mf`, `fragoffset`), IPv6 Neighbor\nDiscovery (`ndp`), and IGMP/MLD group joins.\n\n## Key Wire & Syntax Takeaways\n\n- Define one `flow name(a, b)` block and invoke it over IPv4 and IPv6 host pairs\n  so `icmp` morphs cleanly between IPv4 Proto 1 and IPv6 Next Header 58.\n- `igmp` validates IPv4 endpoints exclusively, whereas `ndp` and `mld` validate\n  IPv6 endpoints and RFC multicast MACs (`33:33:xx:xx:xx:xx`).\n- Unified `ttl`, `dscp`, and `ecn` modifiers work identically across IPv4 TOS and\n  IPv6 Traffic Class headers.\n\n## 02.01 · Dual-Stack IPv4 & IPv6 Reachability via Parameterized flow(a, b) (`dual_stack_icmp_flow.frasm`)\n\nReuses a single flow(src, dst) definition across both IPv4 and IPv6 host pairs so\nprotocol builders automatically morph from IPv4 ICMP (Proto 1) to IPv6 ICMPv6\n(Next Header 58).\n\n- **Protocols:** `icmp` (2 Ethernet frames)\n- **Wire Behavior:** flowlabel 0x12345 applies to the IPv6 header and is cleanly\n  ignored when the same flow runs over IPv4 endpoints.\n- **Wireshark Filter:** `icmp || icmpv6`\n- **CLI Build:** `frameassembly dual_stack_icmp_flow.frasm`\n\n```frameassembly\nhost probe_v4 { ip 10.20.1.10 }\nhost core_v4  { ip 10.20.1.1 }\nhost probe_v6 { ip 2001:db8:20::10 }\nhost core_v6  { ip 2001:db8:20::1 }\n\nflow reachability_check(src, dst) {\n    src -> dst icmp echorequest id 0x4200 seq 1 dscp 46 ecn 2 flowlabel 0x12345 wait 2ms\n    src <- dst icmp echoreply id 0x4200 seq 1 dscp 46 ecn 2 flowlabel 0x12345 wait 5ms\n}\n\ncompile {\n    reachability_check(probe_v4, core_v4)\n    reachability_check(probe_v6, core_v6)\n}\n```\n\n## 02.02 · IPv4 Multi-Fragment Reassembly Test (ipid, mf & fragoffset) (`ipv4_fragment_reassembly.frasm`)\n\nEmits two correlated IPv4 UDP fragments sharing ipid 0x7788 to verify firewall\nfragment-reassembly engines and Suricata defrag thresholds.\n\n- **Protocols:** `udp` (2 Ethernet frames)\n- **Wire Behavior:** Fragment 1 sets More-Fragments (mf) with fragoffset 0;\n  Fragment 2 clears mf and sets fragoffset 2 (16-byte offset in 8-byte units).\n- **Wireshark Filter:** `ip.id == 0x7788`\n- **CLI Build:** `frameassembly ipv4_fragment_reassembly.frasm`\n\n```frameassembly\nhost sender_box { ip 172.16.30.10 }\nhost dpi_sensor { ip 172.16.30.50 }\n\ncompile {\n    sender_box -> dpi_sensor udp srcport 54100 dstport 9000 ipid 0x7788 mf fragoffset 0 payload \"FRAGMENT-PART-01\" wait 1ms\n    sender_box -> dpi_sensor udp srcport 54100 dstport 9000 ipid 0x7788 fragoffset 2 payload \"FRAGMENT-PART-02\"\n}\n```\n\n## 02.03 · UDP Traceroute Hop Expiration (TTL=1 Time Exceeded + Port Unreachable) (`traceroute_ttl_hops.frasm`)\n\nReproduces a classic Unix UDP traceroute across an intermediate router hop (TTL=1\n-> ICMP Time Exceeded) followed by arrival at the target host (TTL=2 -> ICMP Port\nUnreachable).\n\n- **Protocols:** `udp`, `icmp` (4 Ethernet frames)\n- **Wire Behavior:** ICMP Type 11 Code 0 marks transit TTL expiry; ICMP Type 3\n  Code 3 signals the final destination port 33435.\n- **Wireshark Filter:** `udp.port >= 33434 || icmp`\n- **CLI Build:** `frameassembly traceroute_ttl_hops.frasm`\n\n```frameassembly\nhost workstation { ip 10.10.0.25 }\nhost hop1_router { ip 10.10.0.1 }\nhost dest_server { ip 10.90.0.40 }\n\ncompile {\n    workstation -> dest_server udp srcport 51200 dstport 33434 ttl 1 payload \"probe-hop-1\" wait 2ms\n    hop1_router -> workstation icmp timeexceeded type 11 code 0 wait 5ms\n    workstation -> dest_server udp srcport 51200 dstport 33435 ttl 2 payload \"probe-hop-2\" wait 3ms\n    dest_server -> workstation icmp destunreach type 3 code 3\n}\n```\n\n## 02.04 · IPv6 Router Discovery & Neighbor Solicitation / Advertisement (NDP) (`ipv6_ndp_slaac_resolution.frasm`)\n\nCaptures IPv6 Router Solicitation, Router Advertisement, and link-layer Neighbor\nSolicitation / Advertisement with Hop Limit 255.\n\n- **Protocols:** `ndp` (4 Ethernet frames)\n- **Wire Behavior:** ndp automatically sets IPv6 Hop Limit to 255 per RFC 4861 so\n  router anti-spoofing checks pass.\n- **Wireshark Filter:** `icmpv6`\n- **CLI Build:** `frameassembly ipv6_ndp_slaac_resolution.frasm`\n\n```frameassembly\nhost host_v6   { ip fe80::21a:2bff:fe3c:4d5e mac 00:1a:2b:3c:4d:5e }\nhost router_v6 { ip fe80::1                   mac 00:1c:73:00:00:01 }\n\ncompile {\n    host_v6 -> router_v6 ndp routersolicit slla 00:1a:2b:3c:4d:5e wait 3ms\n    host_v6 <- router_v6 ndp routeradvert routerlifetime 1800 slla 00:1c:73:00:00:01 wait 5ms\n    host_v6 -> router_v6 ndp neighborsolicit target fe80::1 slla 00:1a:2b:3c:4d:5e wait 1ms\n    host_v6 <- router_v6 ndp neighboradvert target fe80::1 tlla 00:1c:73:00:00:01\n}\n```\n\n## 02.05 · Path MTU Discovery Check (IPv4 DF Bit + ICMP Fragmentation Needed) (`fw_pmtud_df_check.frasm`)\n\nChecks that an edge firewall permits ICMP Type 3 Code 4 (Fragmentation Needed)\nwhen a Don't-Fragment (df) HTTPS segment hits a lower-MTU IPSec or GRE tunnel.\n\n- **Protocols:** `tcp`, `http`, `icmp` (5 Ethernet frames)\n- **Wire Behavior:** Blocking ICMP Type 3 Code 4 causes classic \"pings work, but\n  HTTPS hangs\" tickets. Use df on IPv4 packets to set the Don't-Fragment bit\n  cleanly.\n- **Wireshark Filter:** `ip.flags.df == 1 || (icmp.type == 3 && icmp.code == 4)`\n- **CLI Build:** `frameassembly fw_pmtud_df_check.frasm`\n\n```frameassembly\n// Branch client, VPN tunnel router (1400-byte MTU), and remote web server\nhost branch_client { ip 10.25.1.15 }\nhost vpn_router    { ip 10.25.1.1 }\nhost remote_web    { ip 10.90.5.80 }\n\ncompile {\n    // 1. Normal TCP 3-way handshake succeeds (small 60-byte packets pass any MTU)\n    branch_client -> remote_web tcp syn srcport 54210 dstport 80 win 65535 mss 1460 df wait 2ms\n    branch_client <- remote_web tcp syn ack win 65535 mss 1460 df wait 2ms\n    branch_client -> remote_web tcp ack df wait 1ms\n\n    // 2. Client sends HTTP request with Don't-Fragment (df) flag set\n    branch_client -> remote_web http post uri \"/upload\" hosthdr \"files.corp.internal\" body \"large-unfragmentable-payload-block\" df wait 2ms\n\n    // 3. Tunnel router notifies client to lower its packet size (ICMP Type 3, Code 4)\n    vpn_router -> branch_client icmp destunreach type 3 code 4\n}\n```\n\n## 02.06 · ICMP Ping Sweep (Live Replies vs. Host Unreachable) (`scan_icmp_ping_sweep.frasm`)\n\nPings three subnet targets in sequence: two active servers answer with Echo Reply,\nwhile the router reports Host Unreachable (Type 3, Code 1) for a dead address.\n\n- **Protocols:** `icmp` (6 Ethernet frames)\n- **Wire Behavior:** Use this capture in Wireshark training to compare fast\n  sub-millisecond LAN replies against router-generated ICMP Destination\n  Unreachable responses.\n- **Wireshark Filter:** `icmp`\n- **CLI Build:** `frameassembly scan_icmp_ping_sweep.frasm`\n\n```frameassembly\n// Admin workstation, branch router, and three target IPs\nhost admin_pc   { ip 10.12.0.50 }\nhost branch_rtr { ip 10.12.10.1 }\nhost dns_01     { ip 10.12.10.10 }\nhost print_01   { ip 10.12.10.20 }\nhost offline_pc { ip 10.12.10.99 }\n\ncompile {\n    // Target 1 (.10): Online DNS server replies in 1ms\n    admin_pc -> dns_01 icmp echorequest id 300 seq 1 wait 1ms\n    admin_pc <- dns_01 icmp echoreply id 300 seq 1 wait 3ms\n\n    // Target 2 (.20): Online printer replies in 2ms\n    admin_pc -> print_01 icmp echorequest id 300 seq 2 wait 2ms\n    admin_pc <- print_01 icmp echoreply id 300 seq 2 wait 3ms\n\n    // Target 3 (.99): Offline host -> Router returns ICMP Host Unreachable (Type 3, Code 1)\n    admin_pc -> offline_pc icmp echorequest id 300 seq 3 wait 15ms\n    branch_rtr -> admin_pc icmp destunreach type 3 code 1\n}\n```\n\n## 02.07 · Minimal Two-Block ICMP / ICMPv6 (`icmp`) Quickstart (`icmp_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Internet Control Message\nProtocol v4 & Dual-Stack ICMPv6 (IP Proto 1 (v4) / NextHdr 58 (v6), Dual-Stack\nMorphing (v4/v6)).\n\n- **Protocols:** `icmp` (2 Ethernet frames)\n- **Wire Behavior:** Automatically selects IPv4 Protocol `1` (`0x0800`) over IPv4\n  endpoints or ICMPv6 Next Header `58` (`0x86dd`) over IPv6 endpoints.\n- **Wireshark Filter:** `icmp || icmpv6`\n- **CLI Build:** `frameassembly icmp_quickstart.frasm`\n\n```frameassembly\nhost client { ip 10.0.0.10 }\nhost router { ip 10.0.0.1 }\n\ncompile {\n    client -> router icmp echorequest wait 2ms\n    client <- router icmp echoreply\n}\n```\n\n## 02.08 · Minimal Two-Block IPv6 NDP (`ndp`) Quickstart (`ndp_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for IPv6 Neighbor Discovery\nProtocol (ICMPv6 NextHdr 58 (Hop Limit 255), IPv6-Only).\n\n- **Protocols:** `ndp` (2 Ethernet frames)\n- **Wire Behavior:** Enforces IPv6 Hop Limit `255` (`ttl 255`) by default in\n  accordance with RFC 4861 §6.1.2 / §7.1.1.\n- **Wireshark Filter:** `icmpv6.type >= 133 && icmpv6.type <= 137`\n- **CLI Build:** `frameassembly ndp_quickstart.frasm`\n\n```frameassembly\nhost host_v6   { ip 2001:db8:cafe::25 mac 00:1b:21:aa:00:25 }\nhost router_v6 { ip 2001:db8:cafe::1  mac 00:1c:73:bb:00:01 }\n\ncompile {\n    host_v6 -> router_v6 ndp neighborsolicit target 2001:db8:cafe::1 slla 00:1b:21:aa:00:25 wait 1ms\n    host_v6 <- router_v6 ndp neighboradvert target 2001:db8:cafe::1 tlla 00:1c:73:bb:00:01\n}\n```\n\n## 02.09 · Minimal Two-Block IGMPv1/v2/v3 (`igmp`) Quickstart (`igmp_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Internet Group Management\nProtocol v1, v2 & v3 (IPv4 Proto 2 (TTL 1), IPv4-Only).\n\n- **Protocols:** `igmp` (2 Ethernet frames)\n- **Wire Behavior:** Encapsulates inside IPv4 Protocol `2` with link-local `ttl 1`\n  by default.\n- **Wireshark Filter:** `igmp`\n- **CLI Build:** `frameassembly igmp_quickstart.frasm`\n\n```frameassembly\nhost querier  { ip 10.20.1.1 }\nhost receiver { ip 10.20.1.55 }\n\ncompile {\n    querier -> receiver igmp v2 query group 224.0.0.1 maxresp 100 wait 5ms\n    receiver -> querier igmp v2 report group 239.1.1.10\n}\n```\n\n## 02.10 · Minimal Two-Block IPv6 MLD (`mld`) Quickstart (`mld_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Multicast Listener\nDiscovery v1 & v2 (IPv6) (ICMPv6 NextHdr 58 (Hop Limit 1), IPv6-Only).\n\n- **Protocols:** `mld` (2 Ethernet frames)\n- **Wire Behavior:** Sets IPv6 Next Header to `58` (ICMPv6) and defaults Hop Limit\n  (`ttl`) to `1` per RFC 2710.\n- **Wireshark Filter:** `icmpv6.type >= 130 && icmpv6.type <= 132`\n- **CLI Build:** `frameassembly mld_quickstart.frasm`\n\n```frameassembly\nhost rtr_v6  { ip fe80::1 }\nhost node_v6 { ip fe80::25 }\n\ncompile {\n    rtr_v6 -> node_v6 mld query maxrespdelay 10000 wait 3ms\n    node_v6 -> rtr_v6 mld report multicastaddr ff02::1:ff00:25\n}\n```\n\n## 02.11 · ICMP / ICMPv6 (`icmp`): Dual-Stack Echo Flow Plus IPv4 Fragmentation-Needed & Traceroute TTL Expiry (`icmp_dualstack_pmtud.frasm`)\n\nReuses a `ping_test(src, dst)` flow across IPv4 and IPv6 hosts, then sends a\nrouter Time Exceeded (`ttl 1`) and Fragmentation Needed (`destunreach code 4`)\nreply.\n\n- **Protocols:** `icmp` (5 Ethernet frames)\n- **Wire Behavior:** Automatically selects IPv4 Protocol `1` (`0x0800`) over IPv4\n  endpoints or ICMPv6 Next Header `58` (`0x86dd`) over IPv6 endpoints. Translates\n  `echorequest` (`8` v4 / `128` v6), `echoreply` (`0` v4 / `129` v6),\n  `destunreach` (`3` v4 / `1` v6), `timeexceeded` (`11` v4 / `3` v6), and\n  `redirect` (`5` v4 / `137` v6).\n- **Wireshark Filter:** `icmp || icmpv6`\n- **CLI Build:** `frameassembly show icmp_dualstack_pmtud.frasm`\n\n```frameassembly\nhost app_v4  { ip 10.10.0.25 }\nhost edge_v4 { ip 10.10.0.1 }\nhost app_v6  { ip 2001:db8:10::25 }\nhost edge_v6 { ip 2001:db8:10::1 }\n\nflow ping_test(src, dst) {\n    src -> dst icmp echorequest id 0x2026 seq 1 payload \"healthcheck-probe\" wait 1ms\n    src <- dst icmp echoreply id 0x2026 seq 1 payload \"healthcheck-probe\" wait 2ms\n}\n\ncompile {\n    ping_test(app_v4, edge_v4)\n    ping_test(app_v6, edge_v6)\n    // Traceroute hop 1 expiry + PMTUD Fragmentation Needed (Type 3, Code 4)\n    app_v4 -> edge_v4 icmp echorequest id 0x2026 seq 2 ttl 1 df wait 1ms\n    app_v4 <- edge_v4 icmp timeexceeded code 0 wait 2ms\n    app_v4 <- edge_v4 icmp destunreach code 4\n}\n```\n\n## 02.12 · IPv6 NDP (`ndp`): IPv6 SLAAC Router Discovery Followed by Neighbor Solicitation & Advertisement (`ndp_slaac_discovery.frasm`)\n\nModels a dual-interface IPv6 leaf node soliciting an upstream router\n(`routersolicit` -> `routeradvert`) before resolving next-hop MAC reachability\n(`neighborsolicit` -> `neighboradvert`).\n\n- **Protocols:** `ndp`, `vlan` (4 Ethernet frames)\n- **Wire Behavior:** Enforces IPv6 Hop Limit `255` (`ttl 255`) by default in\n  accordance with RFC 4861 §6.1.2 / §7.1.1. Encodes exact ICMPv6 message bodies\n  for `routersolicit` (`133`), `routeradvert` (`134`, `routerlifetime 1800`),\n  `neighborsolicit` (`135`), `neighboradvert` (`136`, Solicited + Override flags\n  set), and `redirect` (`137`).\n- **Wireshark Filter:** `icmpv6.type >= 133 && icmpv6.type <= 137`\n- **CLI Build:** `frameassembly show ndp_slaac_discovery.frasm`\n\n```frameassembly\nhost leaf_node { ip fe80::1b21:ff:feaa:10 mac 00:1b:21:aa:00:10 }\nhost core_rtr  { ip fe80::1c73:ff:febb:01 mac 00:1c:73:bb:00:01 }\n\ncompile {\n    // 1. Host sends Router Solicitation with Source Link-Layer Address (SLLA)\n    leaf_node -> core_rtr ndp routersolicit slla 00:1b:21:aa:00:10 vlan 100 wait 2ms\n    // 2. Router replies with Router Advertisement (30-minute router lifetime)\n    core_rtr -> leaf_node ndp routeradvert routerlifetime 1800 slla 00:1c:73:bb:00:01 vlan 100 wait 5ms\n    // 3. Neighbor Solicitation & Solicited+Override Neighbor Advertisement\n    leaf_node -> core_rtr ndp neighborsolicit target fe80::1c73:ff:febb:01 slla 00:1b:21:aa:00:10 vlan 100 wait 1ms\n    leaf_node <- core_rtr ndp neighboradvert target fe80::1c73:ff:febb:01 tlla 00:1c:73:bb:00:01 vlan 100\n}\n```\n\n## 02.13 · IGMPv1/v2/v3 (`igmp`): VLAN-Tagged IGMPv2 Query,IGMPv3 Receiver Join, and IGMPv2 Fast Leave (`igmp_snooping_vlan.frasm`)\n\nDemonstrates a multicast router polling VLAN 50, one receiver joining\n`239.255.10.1` via IGMPv3, and a second receiver joining and leaving via IGMPv2.\n\n- **Protocols:** `igmp`, `vlan` (4 Ethernet frames)\n- **Wire Behavior:** Encapsulates inside IPv4 Protocol `2` with link-local `ttl 1`\n  by default. Maps version + operation cleanly onto wire Type codes: `0x11`\n  (`query`, 8B in v1/v2 or 12B in v3), `0x12` (`v1 report`), `0x16` (`v2 report`),\n  `0x17` (`v2 leave`), and `0x22` (`v3 report` with `MODE_IS_EXCLUDE` Group\n  Record).\n- **Wireshark Filter:** `igmp`\n- **CLI Build:** `frameassembly show igmp_snooping_vlan.frasm`\n\n```frameassembly\nhost mcast_rtr { ip 10.50.0.1 }\nhost all_hosts { ip 224.0.0.1 }\nhost decoder_1 { ip 10.50.0.21 }\nhost decoder_2 { ip 10.50.0.22 }\n\ncompile {\n    // 1. General Query to 224.0.0.1 (auto-derives MAC 01:00:5e:00:00:01)\n    mcast_rtr -> all_hosts igmp v2 query group 0.0.0.0 maxresp 100 vlan 50 wait 4ms\n    // 2. Receiver 1 sends IGMPv3 Membership Report for 239.255.10.1\n    decoder_1 -> mcast_rtr igmp v3 report group 239.255.10.1 vlan 50 wait 3ms\n    // 3. Receiver 2 joins and then leaves 239.255.10.2 via IGMPv2\n    decoder_2 -> mcast_rtr igmp v2 report group 239.255.10.2 vlan 50 wait 20ms\n    decoder_2 -> mcast_rtr igmp v2 leave group 239.255.10.2 vlan 50\n}\n```\n\n## 02.14 · IPv6 MLD (`mld`): Link-Local MLD General Query, Solicited-Node Join, and Listener Done (`mld_snooping_ipv6.frasm`)\n\nSimulates an IPv6 multicast router querying all link-local nodes (`ff02::1`), a\nsubscriber reporting membership in `ff05::100`, and cleanly departing with `mld\ndone`.\n\n- **Protocols:** `mld`, `vlan` (3 Ethernet frames)\n- **Wire Behavior:** Sets IPv6 Next Header to `58` (ICMPv6) and defaults Hop Limit\n  (`ttl`) to `1` per RFC 2710. Encodes ICMPv6 Type `130` (`query`), `131`\n  (`report`), or `132` (`done`), 16-bit `Maximum Response Delay` (milliseconds),\n  and 128-bit `Multicast Address`.\n- **Wireshark Filter:** `icmpv6.type >= 130 && icmpv6.type <= 132`\n- **CLI Build:** `frameassembly show mld_snooping_ipv6.frasm`\n\n```frameassembly\nhost querier_v6 { ip fe80::1c73:1 }\nhost all_nodes  { ip ff02::1 }\nhost all_rtrs   { ip ff02::2 }\nhost listener   { ip fe80::1b21:50 }\n\ncompile {\n    // 1. General MLD Query to ff02::1 (multicastaddr :: = all groups, 10000ms max delay)\n    querier_v6 -> all_nodes mld query multicastaddr :: maxrespdelay 10000 vlan 200 wait 4ms\n    // 2. Host joins site-local multicast stream ff05::100\n    listener -> querier_v6 mld report multicastaddr ff05::100 maxrespdelay 0 vlan 200 wait 25ms\n    // 3. Host sends MLD Done to all-routers multicast ff02::2 upon leaving\n    listener -> all_rtrs mld done multicastaddr ff05::100 vlan 200\n}\n```\n"}
{"id":"pretrain-anthology-tcp-handshakes-anomalies","kind":"examples_anthology","title":"Stateful 4-Tuple TCP Streams, Sequence Anomalies & SCTP — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/tcp-handshakes-anomalies","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","sctp","icmp","http","udp"],"text":"# Stateful 4-Tuple TCP Streams, Sequence Anomalies & SCTP\n\n> **FrameAssembly v3.3.0** · Anthology 03 (Layer 4 · 14 Recipes) · MIT License ·\n> Canonical URL:\n> https://frameassembly-lang.dev/docs/examples/tcp-handshakes-anomalies\n\nAutomatic 4-tuple `seq` and `acknum` progression, RFC 7323 TCP options (`mss`,\n`wscale`, `sackperm`, `tsval`/`tsecr`), deliberate retransmissions, ZeroWindow\nstalls, abnormal scan flags, and Castagnoli CRC-32c SCTP.\n\n## Key Wire & Syntax Takeaways\n\n- Set `srcport` and `dstport` once on the opening `tcp syn`; `<-` replies swap\n  ports automatically and payload frames advance `seq` by byte length.\n- Explicit `seq <u32>` or `acknum <u32>` overrides re-anchor connection state to\n  reproduce RTO retransmissions, out-of-order segments, or ZeroWindow stalls.\n- `sctp` computes hardware-polynomial Castagnoli CRC-32c checksums across 4-way\n  cookie handshakes, DATA chunks, heartbeats, and shutdowns.\n\n## 03.01 · Full TCP Lifecycle: RFC 7323 Window Scale, SACK, Timestamps & 4-Way FIN (`tcp_rfc7323_full_lifecycle.frasm`)\n\nDemonstrates a complete TCP connection from SYN option negotiation (mss, wscale,\nsackperm, tsval/tsecr) through bidirectional payload transfer and clean 4-way\nFIN-ACK close.\n\n- **Protocols:** `tcp` (9 Ethernet frames)\n- **Wire Behavior:** FrameAssembly advances each direction seq by +1 on syn,\n  +payload_len on data segments, and +1 on fin automatically.\n- **Wireshark Filter:** `tcp.port == 8443`\n- **CLI Build:** `frameassembly tcp_rfc7323_full_lifecycle.frasm`\n\n```frameassembly\nhost app_client { ip 10.30.1.15 }\nhost api_srv    { ip 10.30.2.80 }\n\ncompile {\n    app_client -> api_srv tcp syn srcport 52843 dstport 8443 win 65535 mss 1460 wscale 7 sackperm tsval 1000 tsecr 0 wait 1ms\n    app_client <- api_srv tcp syn ack win 65535 mss 1460 wscale 7 sackperm tsval 4000 tsecr 1000 wait 1ms\n    app_client -> api_srv tcp ack tsval 1001 tsecr 4000 wait 2ms\n    app_client -> api_srv tcp psh ack tsval 1003 tsecr 4000 payload \"PING-API-V1\" wait 2ms\n    app_client <- api_srv tcp psh ack tsval 4002 tsecr 1003 payload \"PONG-API-OK\" wait 2ms\n    app_client -> api_srv tcp fin ack tsval 1005 tsecr 4002 wait 1ms\n    app_client <- api_srv tcp ack tsval 4003 tsecr 1005 wait 1ms\n    app_client <- api_srv tcp fin ack tsval 4004 tsecr 1005 wait 1ms\n    app_client -> api_srv tcp ack tsval 1006 tsecr 4004\n}\n```\n\n## 03.02 · Out-of-Order TCP Segment Arrival & Gap Fill for DPI Stream Reassembly (`tcp_out_of_order_reassembly.frasm`)\n\nDeliberately transmits bytes 9..16 (seq 1009) ahead of bytes 1..8 (seq 1001) to\nverify IDS/IPS TCP stream reassemblers reconstruct split signatures properly.\n\n- **Protocols:** `tcp` (6 Ethernet frames)\n- **Wire Behavior:** Explicit seq overrides let you transmit segments out of\n  sequence while keeping checksums valid.\n- **Wireshark Filter:** `tcp.analysis.out_of_order || tcp.port == 9090`\n- **CLI Build:** `frameassembly tcp_out_of_order_reassembly.frasm`\n\n```frameassembly\nhost sender { ip 10.40.10.11 }\nhost sensor { ip 10.40.10.22 }\n\ncompile {\n    sender -> sensor tcp syn srcport 54090 dstport 9090 seq 1000 win 65535 mss 1460 wait 1ms\n    sender <- sensor tcp syn ack seq 5000 acknum 1001 win 65535 mss 1460 wait 1ms\n    sender -> sensor tcp ack seq 1001 acknum 5001 wait 1ms\n    // Send second 8-byte chunk first (seq 1009), then backfill missing gap (seq 1001)\n    sender -> sensor tcp psh ack seq 1009 acknum 5001 payload \"CHUNK-02\" wait 3ms\n    sender -> sensor tcp psh ack seq 1001 acknum 5001 payload \"CHUNK-01\" wait 2ms\n    sender <- sensor tcp ack seq 5001 acknum 1017\n}\n```\n\n## 03.03 · Dual-Stack IPv4 + IPv6 Stateful TCP Handshake Template (`tcp_dual_stack_template.frasm`)\n\nValidates load-balancer VIP listener readiness across both IPv4 and IPv6 frontends\nusing one parameterized flow(c, s).\n\n- **Protocols:** `tcp` (6 Ethernet frames)\n- **Wire Behavior:** Each 4-tuple maintains an independent TCP sequence state\n  table across IPv4 and IPv6 invocations.\n- **Wireshark Filter:** `tcp.port == 443`\n- **CLI Build:** `frameassembly tcp_dual_stack_template.frasm`\n\n```frameassembly\nhost edge_c4 { ip 198.51.100.12 }\nhost vip_s4  { ip 203.0.113.10 }\nhost edge_c6 { ip 2001:db8:100::12 }\nhost vip_s6  { ip 2001:db8:200::10 }\n\nflow lb_health_probe(c, s) {\n    c -> s tcp syn srcport 53443 dstport 443 win 65535 mss 1440 sackperm wait 1ms\n    c <- s tcp syn ack win 65535 mss 1440 sackperm wait 1ms\n    c -> s tcp ack wait 1ms\n    c -> s tcp fin ack wait 1ms\n    c <- s tcp fin ack wait 1ms\n    c -> s tcp ack\n}\n\ncompile {\n    lb_health_probe(edge_c4, vip_s4)\n    lb_health_probe(edge_c6, vip_s6)\n}\n```\n\n## 03.04 · Telecom SCTP 4-Way Cookie Handshake, S1AP Data, Heartbeat & Shutdown (`sctp_telecom_4way_lifecycle.frasm`)\n\nBuilds a complete RFC 4960 SCTP association on port 36412 (LTE S1AP) with\nCastagnoli CRC-32c checksums.\n\n- **Protocols:** `sctp` (10 Ethernet frames)\n- **Wire Behavior:** Calculates hardware-polynomial SCTP CRC-32c over every INIT,\n  INIT-ACK, COOKIE-ECHO, DATA, SACK, HEARTBEAT, and SHUTDOWN chunk.\n- **Wireshark Filter:** `sctp`\n- **CLI Build:** `frameassembly sctp_telecom_4way_lifecycle.frasm`\n\n```frameassembly\nhost enodeb { ip 10.60.1.10 }\nhost mme_01 { ip 10.60.2.20 }\n\ncompile {\n    enodeb -> mme_01 sctp init srcport 36412 dstport 36412 vtag 0 tsn 1000 wait 1ms\n    enodeb <- mme_01 sctp initack vtag 0x11223344 tsn 2000 wait 1ms\n    enodeb -> mme_01 sctp cookieecho vtag 0x11223344 wait 1ms\n    enodeb <- mme_01 sctp cookieack vtag 0x55667788 wait 2ms\n    enodeb -> mme_01 sctp data vtag 0x11223344 tsn 1000 stream 0 ssn 0 ppid 18 payload \"S1SetupRequest\" wait 2ms\n    enodeb <- mme_01 sctp sack vtag 0x55667788 tsn 1000 wait 10ms\n    enodeb -> mme_01 sctp heartbeat vtag 0x11223344 wait 1ms\n    enodeb <- mme_01 sctp heartbeatack vtag 0x55667788 wait 2ms\n    enodeb -> mme_01 sctp shutdown vtag 0x11223344 wait 1ms\n    enodeb <- mme_01 sctp shutdownack vtag 0x55667788\n}\n```\n\n## 03.05 · Blocked Management SSH Policy (TCP RST + ICMP Admin Prohibited) (`fw_ssh_deny_policy.frasm`)\n\nSimulates a firewall rejecting unauthorized user-VLAN SSH attempts into the\nout-of-band switch management subnet using both TCP RST-ACK and ICMP Type 3 Code\n13.\n\n- **Protocols:** `tcp`, `icmp` (4 Ethernet frames)\n- **Wire Behavior:** Great for verifying SIEM alerts on blocked management-plane\n  access and training helpdesk techs to tell the difference between a firewall\n  Reset and a silent drop.\n- **Wireshark Filter:** `tcp.port == 22 || icmp.code == 13`\n- **CLI Build:** `frameassembly fw_ssh_deny_policy.frasm`\n\n```frameassembly\n// User workstation, internal firewall interface, and protected core switch\nhost user_laptop { ip 10.10.40.85 }\nhost mgmt_fw     { ip 10.10.40.1 }\nhost core_sw     { ip 10.99.0.10 }\n\ncompile {\n    // Attempt #1: Workstation tries TCP 22 (SSH) -> Rejected inline with TCP RST-ACK\n    user_laptop -> core_sw tcp syn srcport 53110 dstport 22 win 65535 mss 1460 wait 1ms\n    user_laptop <- core_sw tcp rst ack wait 10ms\n\n    // Attempt #2: Workstation retries TCP 22 -> Firewall returns ICMP Admin Prohibited (Type 3, Code 13)\n    user_laptop -> core_sw tcp syn srcport 53111 dstport 22 win 65535 mss 1460 wait 2ms\n    mgmt_fw -> user_laptop icmp destunreach type 3 code 13\n}\n```\n\n## 03.06 · TCP SYN Half-Open Port Scan (Ports 22, 80, 443, 3389) (`scan_tcp_syn_ports.frasm`)\n\nModels an Nmap-style -sS half-open port check across SSH (22), HTTP (80), HTTPS\n(443), and RDP (3389), contrasting open SYN-ACK ports against closed RST-ACK\nports.\n\n- **Protocols:** `tcp` (10 Ethernet frames)\n- **Wire Behavior:** In a half-open SYN scan, the scanner immediately sends tcp\n  rst after receiving syn ack instead of completing the 3rd handshake packet.\n- **Wireshark Filter:** `tcp.flags.syn == 1 || tcp.flags.reset == 1`\n- **CLI Build:** `frameassembly scan_tcp_syn_ports.frasm`\n\n```frameassembly\n// Vulnerability scanner checking common TCP ports on a Linux web server\nhost scanner { ip 10.10.99.10 }\nhost web_srv { ip 10.10.20.40 }\n\ncompile {\n    // Port 22 (SSH) -> Open: server sends SYN-ACK, scanner tears down with RST\n    scanner -> web_srv tcp syn srcport 55001 dstport 22 win 1024 mss 1460 wait 1ms\n    scanner <- web_srv tcp syn ack win 65535 mss 1460 wait 1ms\n    scanner -> web_srv tcp rst wait 2ms\n\n    // Port 80 (HTTP) -> Closed: server replies immediately with RST-ACK\n    scanner -> web_srv tcp syn srcport 55002 dstport 80 win 1024 mss 1460 wait 1ms\n    scanner <- web_srv tcp rst ack wait 2ms\n\n    // Port 443 (HTTPS) -> Open: server sends SYN-ACK, scanner tears down with RST\n    scanner -> web_srv tcp syn srcport 55003 dstport 443 win 1024 mss 1460 wait 1ms\n    scanner <- web_srv tcp syn ack win 65535 mss 1460 wait 1ms\n    scanner -> web_srv tcp rst wait 2ms\n\n    // Port 3389 (RDP) -> Closed: server replies with RST-ACK\n    scanner -> web_srv tcp syn srcport 55004 dstport 3389 win 1024 mss 1460 wait 1ms\n    scanner <- web_srv tcp rst ack\n}\n```\n\n## 03.07 · TCP Xmas (FIN+PSH+URG), SYN+FIN & Stealth FIN Scan for IDS Validation (`pentest_ids_xmas_scan.frasm`)\n\nCrafts abnormal TCP flag combinations (Xmas FIN+PSH+URG, illegal SYN+FIN, and\nunsolicited stealth FIN probe) to verify Suricata, Snort, or Zeek scan-detection\nrules fire in the lab.\n\n- **Protocols:** `tcp` (5 Ethernet frames)\n- **Wire Behavior:** Replay against Suricata (suricata -r\n  pentest_ids_xmas_scan.pcap) during purple-team validation without running live\n  scanner binaries on production segments.\n- **Wireshark Filter:** `tcp.flags == 0x029 || tcp.flags == 0x003 || tcp.flags ==\n  0x001`\n- **CLI Build:** `frameassembly pentest_ids_xmas_scan.frasm`\n\n```frameassembly\n// Authorized purple-team host testing IDS/IPS abnormal TCP flag signatures\nhost red_lab_box { ip 172.18.99.50 }\nhost dmz_target  { ip 172.18.10.25 }\n\ncompile {\n    // 1. TCP Xmas Scan: lights up FIN + PSH + URG simultaneously on port 443\n    red_lab_box -> dmz_target tcp fin psh urg srcport 56101 dstport 443 win 1024 urgent 0 wait 2ms\n    red_lab_box <- dmz_target tcp rst ack wait 4ms\n\n    // 2. Illegal SYN + FIN combination: tests stateless ACL bypass rules on port 80\n    red_lab_box -> dmz_target tcp syn fin srcport 56102 dstport 80 win 1024 wait 2ms\n    red_lab_box <- dmz_target tcp rst ack wait 4ms\n\n    // 3. TCP FIN Stealth Scan (-sF): unsolicited lone FIN segment with custom seq 5000 on port 22\n    red_lab_box -> dmz_target tcp fin srcport 56103 dstport 22 seq 5000 win 1024\n}\n```\n\n## 03.08 · Application Stall: TCP Zero-Window & Retransmission (`troubleshoot_zero_window.frasm`)\n\nDemonstrates the difference between a network packet drop (manual seq\nretransmission) and an overloaded server advertising TCP win 0 (\"buffer full,\npause sending\").\n\n- **Protocols:** `tcp`, `http` (7 Ethernet frames)\n- **Wire Behavior:** When application teams blame the network for slow transfers,\n  TCP ZeroWindow in Wireshark proves the receiving server paused the sender\n  because its socket buffer filled up.\n- **Wireshark Filter:** `tcp.analysis.zero_window || tcp.analysis.retransmission`\n- **CLI Build:** `frameassembly troubleshoot_zero_window.frasm`\n\n```frameassembly\n// Client uploading report data to a busy backend web server\nhost client_pc { ip 10.10.15.30 }\nhost busy_srv  { ip 10.10.80.40 }\n\ncompile {\n    // 1. Establish TCP connection on port 8080\n    client_pc -> busy_srv tcp syn srcport 51800 dstport 8080 win 65535 mss 1460 wait 1ms\n    client_pc <- busy_srv tcp syn ack win 65535 mss 1460 wait 1ms\n    client_pc -> busy_srv tcp ack wait 1ms\n\n    // 2. Client sends HTTP POST; packet drops on WAN, so client retransmits same seq 1001 after 200ms\n    client_pc -> busy_srv http post uri \"/ingest\" hosthdr \"reports.corp.local\" body \"batch-01-payload\" wait 200ms\n    client_pc -> busy_srv seq 1001 http post uri \"/ingest\" hosthdr \"reports.corp.local\" body \"batch-01-payload\" wait 2ms\n\n    // 3. Overloaded server ACKs the data with win 0 (TCP ZeroWindow: socket buffer exhausted!)\n    client_pc <- busy_srv tcp ack win 0 wait 150ms\n\n    // 4. Server drains buffer and sends Window Update (win 32768) so transfer can resume\n    client_pc <- busy_srv tcp ack win 32768\n}\n```\n\n## 03.09 · Minimal Two-Block TCP & RFC 7323 (`tcp`) Quickstart (`tcp_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Transmission Control\nProtocol & RFC 7323 Options (IP Proto 6 (Default dstport 80), Dual-Stack\nIPv4/IPv6).\n\n- **Protocols:** `tcp` (3 Ethernet frames)\n- **Wire Behavior:** Tracks 4-tuple `(src_ip, dst_ip, src_port, dst_port)`\n  sequence state starting at `seq 1000`—advancing `seq` by `+1` for `syn`/`fin`\n  and `+payload_len` for data without manual arithmetic.\n- **Wireshark Filter:** `tcp`\n- **CLI Build:** `frameassembly tcp_quickstart.frasm`\n\n```frameassembly\nhost client { ip 10.10.1.15 }\nhost server { ip 10.10.1.80 }\n\ncompile {\n    client -> server tcp syn srcport 52400 dstport 443 win 65535 mss 1460 wscale 7 sackperm wait 1ms\n    client <- server tcp syn ack win 65535 mss 1460 wscale 7 sackperm wait 1ms\n    client -> server tcp ack\n}\n```\n\n## 03.10 · Minimal Two-Block UDP (`udp`) Quickstart (`udp_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for User Datagram Protocol\n(IP Proto 17 (Default dstport 80), Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `udp` (2 Ethernet frames)\n- **Wire Behavior:** Computes the 16-bit UDP Length (`8 + payload bytes`) and\n  outer IPv4 Total Length / IPv6 Payload Length automatically.\n- **Wireshark Filter:** `udp`\n- **CLI Build:** `frameassembly udp_quickstart.frasm`\n\n```frameassembly\nhost sensor  { ip 10.20.0.15 }\nhost gateway { ip 10.20.0.1 }\n\ncompile {\n    sensor -> gateway udp srcport 53100 dstport 9000 payload \"ping:seq=1\" wait 2ms\n    sensor <- gateway udp payload \"pong:seq=1\"\n}\n```\n\n## 03.11 · Minimal Two-Block SCTP (CRC-32c) (`sctp`) Quickstart (`sctp_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Stream Control\nTransmission Protocol (IP Proto 132 (38412 NGAP / 36412 S1AP), Dual-Stack\nIPv4/IPv6).\n\n- **Protocols:** `sctp` (3 Ethernet frames)\n- **Wire Behavior:** Computes the 32-bit reflected Castagnoli CRC-32c checksum\n  across the 12-byte SCTP Common Header and all padded chunk bytes.\n- **Wireshark Filter:** `sctp`\n- **CLI Build:** `frameassembly sctp_quickstart.frasm`\n\n```frameassembly\nhost gnb_01 { ip 10.50.1.10 }\nhost amf_01 { ip 10.50.1.20 }\n\ncompile {\n    gnb_01 -> amf_01 sctp init srcport 38412 dstport 38412 vtag 0 tsn 1000 wait 1ms\n    gnb_01 <- amf_01 sctp initack vtag 0x11223344 tsn 2000 wait 1ms\n    gnb_01 -> amf_01 sctp data vtag 0x22334455 tsn 1001 stream 0 ssn 0 ppid 60 hexpayload \"0015000900000100\"\n}\n```\n\n## 03.12 · TCP & RFC 7323 (`tcp`): Full Lifecycle: RFC 7323 Handshake, ECN-Capable Data Exchange & Graceful FIN Close (`tcp_rfc7323_lifecycle.frasm`)\n\nCaptures a complete 7-packet TCP lifecycle with RFC 7323 timestamps\n(`tsval`/`tsecr`), selective ACK permission (`sackperm`), payload push (`psh\nack`), and 4-way `fin ack` teardown.\n\n- **Protocols:** `tcp` (8 Ethernet frames)\n- **Wire Behavior:** Tracks 4-tuple `(src_ip, dst_ip, src_port, dst_port)`\n  sequence state starting at `seq 1000`—advancing `seq` by `+1` for `syn`/`fin`\n  and `+payload_len` for data without manual arithmetic. Remembers `srcport 52400`\n  and `dstport 443` from the opening `syn` so `<-` and `->` follow-up frames swap\n  `443 <-> 52400` automatically.\n- **Wireshark Filter:** `tcp`\n- **CLI Build:** `frameassembly show tcp_rfc7323_lifecycle.frasm`\n\n```frameassembly\nhost app_client { ip 172.16.20.10 }\nhost api_origin { ip 172.16.20.90 }\n\ncompile {\n    // 1. 3-way handshake negotiating MSS 1460, Window Scale 7, SACK, and Timestamps\n    app_client -> api_origin tcp syn srcport 54110 dstport 8443 win 65535 mss 1460 wscale 7 sackperm tsval 1000 tsecr 0 wait 1ms\n    app_client <- api_origin tcp syn ack win 65535 mss 1460 wscale 7 sackperm tsval 5000 tsecr 1000 wait 1ms\n    app_client -> api_origin tcp ack tsval 1001 tsecr 5000 wait 2ms\n    // 2. Bidirectional application payload (seq/acknum advance automatically by byte length)\n    app_client -> api_origin tcp psh ack tsval 1003 tsecr 5000 payload \"PING /healthz\\r\\n\" wait 2ms\n    app_client <- api_origin tcp psh ack tsval 5002 tsecr 1003 payload \"200 OK\\r\\n\" wait 3ms\n    // 3. Clean 3-packet FIN/ACK session close\n    app_client -> api_origin tcp fin ack tsval 1006 tsecr 5002 wait 1ms\n    app_client <- api_origin tcp fin ack tsval 5003 tsecr 1007 wait 1ms\n    app_client -> api_origin tcp ack tsval 1007 tsecr 5004\n}\n```\n\n## 03.13 · UDP (`udp`): Dual-Stack Custom Binary Telemetry Feed with QoS Marking (`udp_dualstack_binary.frasm`)\n\nUses a reusable `flow(tx, rx)` template to emit identical hex-encoded binary UDP\nframes marked `dscp 46` (EF) over both IPv4 and IPv6 endpoints.\n\n- **Protocols:** `udp` (3 Ethernet frames)\n- **Wire Behavior:** Computes the 16-bit UDP Length (`8 + payload bytes`) and\n  outer IPv4 Total Length / IPv6 Payload Length automatically. Calculates the\n  ones'-complement pseudo-header checksum over IPv4 or IPv6 addresses, converting\n  `0x0000` to `0xffff` per RFC 768 / RFC 8200.\n- **Wireshark Filter:** `udp`\n- **CLI Build:** `frameassembly show udp_dualstack_binary.frasm`\n\n```frameassembly\nhost feed_v4 { ip 192.0.2.10 }\nhost recv_v4 { ip 192.0.2.20 }\nhost feed_v6 { ip 2001:db8:feed::10 }\nhost recv_v6 { ip 2001:db8:feed::20 }\n\nflow telemetry_burst(tx, rx) {\n    tx -> rx udp srcport 55100 dstport 19500 dscp 46 hexpayload \"cafebabe00010008deadbeef\" wait 500us\n    tx -> rx udp dscp 46 hexpayload \"cafebabe0002000801020304\" wait 1ms\n    tx <- rx udp dscp 46 payload \"ACK:2\"\n}\n\ncompile {\n    telemetry_burst(feed_v4, recv_v4)\n    telemetry_burst(feed_v6, recv_v6)\n}\n```\n\n## 03.14 · SCTP (CRC-32c) (`sctp`): Complete 5G N2 NGAP SCTP 4-Way Handshake, Data Transfer & Heartbeat (`sctp_5g_ngap_association.frasm`)\n\nModels a 5G gNodeB establishing a full 4-way cookie handshake with an AMF on port\n38412, transmitting an NGAP Setup Request (`ppid 60`), receiving `sack`, and\nexchanging `heartbeat` / `heartbeatack`.\n\n- **Protocols:** `sctp` (8 Ethernet frames)\n- **Wire Behavior:** Computes the 32-bit reflected Castagnoli CRC-32c checksum\n  across the 12-byte SCTP Common Header and all padded chunk bytes. Pads chunk\n  payloads to 4-byte alignment per RFC 9260 while recording the exact unpadded\n  length inside the Chunk Length field.\n- **Wireshark Filter:** `sctp`\n- **CLI Build:** `frameassembly show sctp_5g_ngap_association.frasm`\n\n```frameassembly\nhost gnb_du { ip 172.20.10.11 }\nhost core_amf { ip 172.20.10.50 }\n\ncompile {\n    // 1. RFC 9260 4-way association handshake (INIT must carry vtag 0)\n    gnb_du -> core_amf sctp init srcport 38412 dstport 38412 vtag 0 tsn 1000 dscp 46 wait 1ms\n    gnb_du <- core_amf sctp initack vtag 0xa1b2c3d4 tsn 5000 dscp 46 wait 1ms\n    gnb_du -> core_amf sctp cookieecho vtag 0x55667788 dscp 46 wait 1ms\n    gnb_du <- core_amf sctp cookieack vtag 0xa1b2c3d4 dscp 46 wait 2ms\n    // 2. NGAP payload over Stream 0 (PPID 60 = 3GPP NGAP) + SACK acknowledgment\n    gnb_du -> core_amf sctp data vtag 0x55667788 tsn 1000 stream 0 ssn 0 ppid 60 dscp 46 hexpayload \"00150014000002001b00080000f110000001\" wait 1ms\n    gnb_du <- core_amf sctp sack vtag 0xa1b2c3d4 tsn 1000 dscp 46 wait 5ms\n    // 3. Path liveness probe\n    gnb_du -> core_amf sctp heartbeat vtag 0x55667788 wait 1ms\n    gnb_du <- core_amf sctp heartbeatack vtag 0xa1b2c3d4\n}\n```\n"}
{"id":"pretrain-anthology-routing-bfd-redundancy","kind":"examples_anthology","title":"BGP, OSPF, BFD, VRRP/HSRP, Multicast PIM & OpenFlow Examples — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/routing-bfd-redundancy","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","bgp","bfd","vlan","vrrp","hsrp","ospf","rip","pim","openflow"],"text":"# BGP, OSPF, BFD, VRRP/HSRP, Multicast PIM & OpenFlow Examples\n\n> **FrameAssembly v3.3.0** · Anthology 04 (Layer 3 · 13 Recipes) · MIT License ·\n> Canonical URL:\n> https://frameassembly-lang.dev/docs/examples/routing-bfd-redundancy\n\nControl-plane routing sessions, sub-second BFD failure-detection timers, first-hop\ngateway redundancy (`vrrp` and `hsrp`), multicast Rendezvous Point joins (`pim`),\nand SDN `openflow` channels.\n\n## Key Wire & Syntax Takeaways\n\n- `bgp` and `openflow` share the stateful 4-tuple TCP engine on ports 179 and\n  6653, prepending protocol markers and length headers automatically.\n- Link-local control protocols (`ospf`, `vrrp`, `bfd` multihop/single-hop) pair\n  naturally with `ttl 1` or `ttl 255` GTSM security checks and `dscp 48` (CS6).\n- Multicast destinations (`224.0.0.5`, `224.0.0.18`, `224.0.0.2`) derive RFC 1112\n  `01:00:5e:xx:xx:xx` Ethernet MACs automatically.\n\n## 04.01 · eBGP Session Bring-Up Paired with 50ms BFD Echo Liveness (`ebgp_with_bfd_timers.frasm`)\n\nEstablishes an eBGP session on TCP 179 (AS 65001 <-> AS 65002), exchanges an IPv4\nprefix update, and runs rapid UDP 3784 BFD control packets alongside it.\n\n- **Protocols:** `tcp`, `bgp`, `bfd` (10 Ethernet frames)\n- **Wire Behavior:** Combines stateful TCP 179 BGP framing (marker, OPEN,\n  KEEPALIVE, UPDATE) with UDP 3784 BFD state 3 (Up) timers.\n- **Wireshark Filter:** `bgp || bfd`\n- **CLI Build:** `frameassembly ebgp_with_bfd_timers.frasm`\n\n```frameassembly\nhost edge_rtr1 { ip 198.51.100.1 }\nhost isp_rtr2  { ip 198.51.100.2 }\n\ncompile {\n    edge_rtr1 -> isp_rtr2 tcp syn srcport 54179 dstport 179 ttl 1 dscp 48 wait 1ms\n    edge_rtr1 <- isp_rtr2 tcp syn ack ttl 1 dscp 48 wait 1ms\n    edge_rtr1 -> isp_rtr2 tcp ack ttl 1 dscp 48 wait 1ms\n    edge_rtr1 -> isp_rtr2 bgp open asn 65001 holdtime 90 bgpid 198.51.100.1 ttl 1 dscp 48 wait 2ms\n    edge_rtr1 <- isp_rtr2 bgp open asn 65002 holdtime 90 bgpid 198.51.100.2 ttl 1 dscp 48 wait 2ms\n    edge_rtr1 -> isp_rtr2 bgp keepalive ttl 1 dscp 48 wait 1ms\n    edge_rtr1 <- isp_rtr2 bgp keepalive ttl 1 dscp 48 wait 2ms\n    edge_rtr1 -> isp_rtr2 bgp update prefix \"203.0.113.0/24\" nexthop 198.51.100.1 asn 65001 ttl 1 dscp 48 wait 5ms\n    edge_rtr1 -> isp_rtr2 bfd state 3 diag 0 mydisc 0x1001 yourdisc 0x2002 mintx 50000 minrx 50000 mult 3 ttl 255 wait 50ms\n    edge_rtr1 <- isp_rtr2 bfd state 3 diag 0 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 mult 3 ttl 255\n}\n```\n\n## 04.02 · First-Hop Gateway Redundancy Comparison (VRRPv3 + HSRPv1) (`fhrp_vrrp_and_hsrp.frasm`)\n\nModels active/standby gateway heartbeats on two VLANs—VLAN 10 running standard\nVRRP (IP Proto 112) and VLAN 20 running Cisco HSRP (UDP 1985).\n\n- **Protocols:** `vlan`, `vrrp`, `hsrp` (2 Ethernet frames)\n- **Wire Behavior:** VRRP sets TTL=255 automatically; HSRP validates hellotime 3\n  (u8 seconds) and active state 16.\n- **Wireshark Filter:** `vrrp || hsrp`\n- **CLI Build:** `frameassembly fhrp_vrrp_and_hsrp.frasm`\n\n```frameassembly\nhost core_gw_a  { ip 10.10.0.2 mac 00:00:5e:00:01:0a }\nhost vrrp_mcast { ip 224.0.0.18 }\nhost dist_gw_a  { ip 10.20.0.2 mac 00:00:0c:07:ac:14 }\nhost hsrp_mcast { ip 224.0.0.2 }\n\ncompile {\n    core_gw_a -> vrrp_mcast vlan 10 vrrp vrid 10 priority 120 advint 1 vip 10.10.0.1 wait 5ms\n    dist_gw_a -> hsrp_mcast vlan 20 hsrp group 20 priority 110 state 16 hellotime 3 vip 10.20.0.1\n}\n```\n\n## 04.03 · Minimal Two-Block BGP-4 / 4-Byte ASN (`bgp`) Quickstart (`bgp_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Border Gateway Protocol 4\n& 4-Byte ASN Capability (TCP 179, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `bgp` (3 Ethernet frames)\n- **Wire Behavior:** Tracks TCP sequence and acknowledgment numbers automatically\n  on port `179` (`psh ack` flags set by default) and prepends the 16-byte `ff..ff`\n  BGP marker.\n- **Wireshark Filter:** `bgp`\n- **CLI Build:** `frameassembly bgp_quickstart.frasm`\n\n```frameassembly\nhost spine_01 { ip 10.255.0.1 }\nhost leaf_01  { ip 10.255.0.2 }\n\ncompile {\n    spine_01 -> leaf_01 bgp open asn 65001 holdtime 90 bgpid 10.255.0.1 wait 2ms\n    spine_01 <- leaf_01 bgp open asn 65101 holdtime 90 bgpid 10.255.0.2 wait 2ms\n    spine_01 -> leaf_01 bgp keepalive\n}\n```\n\n## 04.04 · Minimal Two-Block OSPFv2 / OSPFv3 (`ospf`) Quickstart (`ospf_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Open Shortest Path First\n— OSPFv2 & Dual-Stack OSPFv3 (IP Proto 89 (TTL 1), Dual-Stack Morphing (v4/v6)).\n\n- **Protocols:** `ospf` (1 Ethernet frame)\n- **Wire Behavior:** Selects OSPFv2 (24B header, IPv4 Proto `89`) over IPv4 hosts\n  or OSPFv3 (16B header, IPv6 Next Header `89`, IPv6 pseudo-header checksum) over\n  IPv6 hosts.\n- **Wireshark Filter:** `ospf`\n- **CLI Build:** `frameassembly ospf_quickstart.frasm`\n\n```frameassembly\nhost rtr_a { ip 10.0.0.1 }\nhost rtr_b { ip 10.0.0.2 }\n\ncompile {\n    rtr_a -> rtr_b ospf hello routerid 1.1.1.1 areaid 0\n}\n```\n\n## 04.05 · Minimal Two-Block BFD (`bfd`) Quickstart (`bfd_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Bidirectional Forwarding\nDetection Control Packet (UDP 3784 (Multihop 4784, TTL 255), Dual-Stack\nIPv4/IPv6).\n\n- **Protocols:** `bfd` (2 Ethernet frames)\n- **Wire Behavior:** Defaults UDP `srcport` to RFC 5881 range (`49152+`),\n  `dstport` to `3784`, and IP `ttl` / Hop Limit to `255`.\n- **Wireshark Filter:** `bfd`\n- **CLI Build:** `frameassembly bfd_quickstart.frasm`\n\n```frameassembly\nhost rtr_leaf  { ip 172.16.0.1 }\nhost rtr_spine { ip 172.16.0.2 }\n\ncompile {\n    rtr_leaf -> rtr_spine bfd state 3 mydisc 101 yourdisc 202 mintx 50000 minrx 50000 mult 3 wait 50ms\n    rtr_leaf <- rtr_spine bfd state 3 mydisc 202 yourdisc 101 mintx 50000 minrx 50000 mult 3\n}\n```\n\n## 04.06 · OSPFv2 / OSPFv3 (`ospf`): Full OSPF Adjacency Synchronization Plus OSPFv3 IPv6 Backbone Hello (`ospf_adjacency_v2_v3.frasm`)\n\nWalks two core routers through OSPFv2 `hello`, `dbd`, `lsr`, `lsu`, and `lsack`\nexchange on Area 0, followed by an OSPFv3 IPv6 Hello using 32-bit `routerid`.\n\n- **Protocols:** `ospf` (7 Ethernet frames)\n- **Wire Behavior:** Selects OSPFv2 (24B header, IPv4 Proto `89`) over IPv4 hosts\n  or OSPFv3 (16B header, IPv6 Next Header `89`, IPv6 pseudo-header checksum) over\n  IPv6 hosts. Defaults IP `ttl` / Hop Limit to `1` and derives multicast\n  destination MACs automatically when sending to `224.0.0.5` / `224.0.0.6` or\n  `ff02::5` / `ff02::6`.\n- **Wireshark Filter:** `ospf`\n- **CLI Build:** `frameassembly show ospf_adjacency_v2_v3.frasm`\n\n```frameassembly\nhost core_1_v4 { ip 172.16.0.1 }\nhost core_2_v4 { ip 172.16.0.2 }\nhost allspf_v6 { ip ff02::5 }\nhost core_1_v6 { ip fe80::1c73:1 }\n\ncompile {\n    // 1. OSPFv2 Area 0 adjacency bring-up and LSA exchange\n    core_1_v4 -> core_2_v4 ospf hello routerid 1.1.1.1 areaid 0 hellointerval 10 deadinterval 40 priority 100 dscp 48 wait 2ms\n    core_1_v4 <- core_2_v4 ospf hello routerid 2.2.2.2 areaid 0 hellointerval 10 deadinterval 40 priority 1 dscp 48 wait 2ms\n    core_1_v4 -> core_2_v4 ospf dbd routerid 1.1.1.1 areaid 0 dscp 48 wait 1ms\n    core_1_v4 <- core_2_v4 ospf lsr routerid 2.2.2.2 areaid 0 dscp 48 wait 1ms\n    core_1_v4 -> core_2_v4 ospf lsu routerid 1.1.1.1 areaid 0 dscp 48 wait 1ms\n    core_1_v4 <- core_2_v4 ospf lsack routerid 2.2.2.2 areaid 0 dscp 48 wait 4ms\n    // 2. OSPFv3 over IPv6 multicast ff02::5 (routerid stays 32-bit dotted-quad!)\n    core_1_v6 -> allspf_v6 ospf hello routerid 1.1.1.1 areaid 0.0.0.0 hellointerval 10 deadinterval 40\n}\n```\n\n## 04.07 · BGP-4 / 4-Byte ASN (`bgp`): Stateful TCP Handshake + 4-Byte ASN eBGP Peering & Route Advertisement (`bgp_4byte_asn_session.frasm`)\n\nEstablishes a GTSM-protected (`ttl 255`) TCP 179 session between two 4-byte ASN\nswitches (`4200000001` and `4200000101`), exchanges `OPEN` + `KEEPALIVE`, and\nadvertises `10.100.0.0/16`.\n\n- **Protocols:** `bgp`, `tcp` (8 Ethernet frames)\n- **Wire Behavior:** Tracks TCP sequence and acknowledgment numbers automatically\n  on port `179` (`psh ack` flags set by default) and prepends the 16-byte `ff..ff`\n  BGP marker. On `bgp open` with `asn > 65535`, writes `AS_TRANS` (`23456`) in the\n  16-bit My AS field and encodes Optional Parameter `2` (Capabilities) ->\n  Capability `65` (4-octet AS) with the full 32-bit `asn`.\n- **Wireshark Filter:** `bgp`\n- **CLI Build:** `frameassembly show bgp_4byte_asn_session.frasm`\n\n```frameassembly\nhost leaf_tor  { ip 172.16.255.1 }\nhost spine_agg { ip 172.16.255.2 }\n\ncompile {\n    // 1. Stateful TCP 3-way handshake on port 179 with GTSM (ttl 255) and CS6 (dscp 48)\n    leaf_tor -> spine_agg tcp syn srcport 53179 dstport 179 win 65535 mss 1460 ttl 255 dscp 48 wait 1ms\n    leaf_tor <- spine_agg tcp syn ack win 65535 mss 1460 ttl 255 dscp 48 wait 1ms\n    leaf_tor -> spine_agg tcp ack ttl 255 dscp 48 wait 1ms\n    // 2. 4-Byte ASN OPEN negotiation (auto-encodes AS_TRANS 23456 + Capability 65)\n    leaf_tor -> spine_agg bgp open asn 4200000101 holdtime 90 bgpid 10.0.1.1 ttl 255 dscp 48 wait 2ms\n    leaf_tor <- spine_agg bgp open asn 4200000001 holdtime 90 bgpid 10.0.0.1 ttl 255 dscp 48 wait 2ms\n    leaf_tor -> spine_agg bgp keepalive ttl 255 dscp 48 wait 1ms\n    leaf_tor <- spine_agg bgp keepalive ttl 255 dscp 48 wait 2ms\n    // 3. Advertise tenant CIDR 10.100.0.0/16 via BGP UPDATE\n    leaf_tor -> spine_agg bgp update asn 4200000101 prefix \"10.100.0.0/16\" nexthop 172.16.255.1 ttl 255 dscp 48\n}\n```\n\n## 04.08 · RIPv2 / RIPng (`rip`): RIPv2 Multicast Update, Route Poisoning (Metric 16), and IPv6 RIPng (`rip_v2_ripng.frasm`)\n\nShows a branch router advertising `10.50.10.0` (`metric 2`), subsequently\npoisoning the route (`metric 16`) upon link loss, and advertising an IPv6 prefix\nover RIPng (`ff02::9`).\n\n- **Protocols:** `rip` (3 Ethernet frames)\n- **Wire Behavior:** Selects RIPv2 on UDP `520 -> 520` over IPv4 hosts or RIPng on\n  UDP `521 -> 521` over IPv6 hosts. Populates Address Family Identifier `2`\n  (`AF_INET`), `255.255.255.0` default mask, Route Tag, Next Hop, and Metric in\n  RIPv2—or 128-bit IPv6 prefix + prefix-length + 8-bit metric in RIPng.\n- **Wireshark Filter:** `rip || ripng`\n- **CLI Build:** `frameassembly show rip_v2_ripng.frasm`\n\n```frameassembly\nhost rtr_branch { ip 172.16.10.2 }\nhost rip_mcast  { ip 224.0.0.9 }\nhost rtr6_a     { ip fe80::10:1 }\nhost ripng_all  { ip ff02::9 }\n\ncompile {\n    // 1. Periodic RIPv2 multicast advertisement (metric 2, route tag 65010)\n    rtr_branch -> rip_mcast rip response prefix 10.50.10.0 nexthop 0.0.0.0 metric 2 tag 65010 ttl 2 wait 10ms\n    // 2. Triggered route-poison update (metric 16 = infinity / unreachable)\n    rtr_branch -> rip_mcast rip response prefix 10.50.10.0 nexthop 0.0.0.0 metric 16 tag 65010 ttl 2 wait 5ms\n    // 3. IPv6 RIPng advertisement on UDP 521 -> 521 to ff02::9\n    rtr6_a -> ripng_all rip response prefix 2001:db8:50:: metric 1 tag 100 ttl 255\n}\n```\n\n## 04.09 · PIM-SM (`pim`): End-to-End Multicast Control Plane: IGMPv3 Join + PIM Hello, Join/Prune & Register (`pim_multicast_tree.frasm`)\n\nCombines a receiver `igmp v3 report` with upstream `pim hello`, `(S,G)`\n`joinprune`, and First-Hop `pim register` signaling to the Rendezvous Point.\n\n- **Protocols:** `pim` (4 Ethernet frames)\n- **Wire Behavior:** Encapsulates over IPv4 Protocol `103` or IPv6 Next Header\n  `103` with PIM Version `2` (`0x20`). Computes full-message checksums (including\n  IPv6 pseudo-header on v6) for `hello` and `joinprune`, while restricting\n  `register` checksums to the 8-byte PIMv2 header per RFC 7761 §4.9.\n- **Wireshark Filter:** `pim`\n- **CLI Build:** `frameassembly show pim_multicast_tree.frasm`\n\n```frameassembly\nhost receiver_01 { ip 10.40.1.50 }\nhost lhr_router  { ip 10.40.1.1 }\nhost pim_mcast   { ip 224.0.0.13 }\nhost core_rp     { ip 172.16.255.1 }\n\ncompile {\n    // 1. PIMv2 Hello on multicast 224.0.0.13 electing DR (drpriority 200)\n    lhr_router -> pim_mcast pim hello holdtime 105 drpriority 200 ttl 1 dscp 48 wait 2ms\n    // 2. Receiver joins SSM channel 232.10.10.5 on LAN\n    receiver_01 -> lhr_router igmp v3 report group 232.10.10.5 wait 2ms\n    // 3. Last-Hop Router sends PIM Join/Prune upstream toward source 10.10.5.100\n    lhr_router -> core_rp pim joinprune group 232.10.10.5 source 10.10.5.100 holdtime 210 dscp 48 wait 3ms\n    // 4. Unicast PIM Register encapsulated to Rendezvous Point\n    lhr_router -> core_rp pim register group 239.20.20.1 source 10.40.1.50 rp 172.16.255.1 ttl 64 dscp 48\n}\n```\n\n## 04.10 · VRRPv2 / VRRPv3 (`vrrp`): Graceful VRRP Master Shutdown (Priority 0), Backup Takeover & VRRPv3 IPv6 (`vrrp_failover_v2_v3.frasm`)\n\nTraces VRID 10 on VLAN 10 where the primary router sends a `priority 0` release,\nthe backup router assumes mastership + sends GARP, alongside an IPv6 VRRPv3\nadvertisement.\n\n- **Protocols:** `vrrp`, `vlan` (5 Ethernet frames)\n- **Wire Behavior:** Sets IPv4 Protocol / IPv6 Next Header to `112` and defaults\n  `ttl` / Hop Limit to `255` per RFC 3768 / RFC 5798. Selects VRRPv2 (`version 2`)\n  over IPv4 and VRRPv3 (`version 3`, 12-bit centisecond `Max Adver Int` +\n  pseudo-header checksum) over IPv6 automatically.\n- **Wireshark Filter:** `vrrp`\n- **CLI Build:** `frameassembly show vrrp_failover_v2_v3.frasm`\n\n```frameassembly\nhost rtr_pri   { ip 10.10.10.2 mac 00:00:5e:00:01:0a }\nhost rtr_bkp   { ip 10.10.10.3 mac 00:00:5e:00:01:0a }\nhost vrrp_v4   { ip 224.0.0.18 }\nhost rtr6_pri  { ip fe80::10:2 mac 00:00:5e:00:02:0a }\nhost vrrp_v6   { ip ff02::12 }\n\ncompile {\n    // 1. Primary router steady-state VRRPv2 heartbeat (VRID 10, Priority 150)\n    rtr_pri -> vrrp_v4 vrrp vrid 10 priority 150 advint 1 vip 10.10.10.1 vlan 10 pcp 6 wait 5ms\n    // 2. Primary router initiates graceful shutdown (Priority 0 triggers immediate takeover)\n    rtr_pri -> vrrp_v4 vrrp vrid 10 priority 0 advint 1 vip 10.10.10.1 vlan 10 pcp 6 wait 2ms\n    // 3. Backup router promotes to Master (Priority 120) and broadcasts GARP for VIP\n    rtr_bkp -> vrrp_v4 vrrp vrid 10 priority 120 advint 1 vip 10.10.10.1 vlan 10 pcp 6 wait 1ms\n    rtr_bkp -> vrrp_v4 arp gratuitous sendermac 00:00:5e:00:01:0a senderip 10.10.10.1 vlan 10 wait 3ms\n    // 4. Dual-stack VRRPv3 over IPv6 (advint 100 = 100 centiseconds = 1.00s)\n    rtr6_pri -> vrrp_v6 vrrp version 3 vrid 10 priority 150 advint 100 vip fe80::10:1 vlan 10\n}\n```\n\n## 04.11 · HSRPv1 / HSRPv2 (`hsrp`): Campus VLAN 20 Active/Standby HSRP Pair Plus HSRPv2 IPv6 Gateway (`hsrp_active_standby.frasm`)\n\nModels two distribution switches exchanging Active (`state 16`, `priority 110`)\nand Standby (`state 8`, `priority 100`) HSRPv1 Hellos on VLAN 20 alongside an IPv6\nHSRPv2 Active router.\n\n- **Protocols:** `hsrp`, `vlan` (3 Ethernet frames)\n- **Wire Behavior:** Defaults UDP source and destination ports to `1985 -> 1985`\n  on IPv4 (HSRPv1) or `2029 -> 2029` on IPv6 (HSRPv2 TLV). Zero-pads or truncates\n  `auth` cleanly into the fixed 8-byte RFC 2281 Authentication Data field (default\n  `\"cisco\\0\\0\\0\"`).\n- **Wireshark Filter:** `hsrp || hsrp2`\n- **CLI Build:** `frameassembly show hsrp_active_standby.frasm`\n\n```frameassembly\nhost dist_a   { ip 10.20.20.2 mac 00:00:0c:07:ac:14 }\nhost dist_b   { ip 10.20.20.3 mac 00:1c:73:20:00:03 }\nhost hsrp_v4  { ip 224.0.0.2 }\nhost dist6_a  { ip fe80::20:2 mac 00:05:73:a0:00:14 }\nhost hsrp_v6  { ip ff02::66 }\n\ncompile {\n    // 1. Active router (state 16, priority 110, virtual MAC 00:00:0c:07:ac:14 for group 20)\n    dist_a -> hsrp_v4 hsrp group 20 priority 110 state 16 hellotime 3 holdtime 10 auth \"corpkey1\" vip 10.20.20.1 vlan 20 ttl 1 dscp 48 wait 3ms\n    // 2. Standby router (state 8, priority 100) monitoring Active peer\n    dist_b -> hsrp_v4 hsrp group 20 priority 100 state 8 hellotime 3 holdtime 10 auth \"corpkey1\" vip 10.20.20.1 vlan 20 ttl 1 dscp 48 wait 5ms\n    // 3. HSRPv2 over IPv6 on UDP 2029 -> ff02::66\n    dist6_a -> hsrp_v6 hsrp group 20 priority 110 state 16 hellotime 3 holdtime 10 vip 2001:db8:20::1 vlan 20 ttl 255\n}\n```\n\n## 04.12 · BFD (`bfd`): BFD 3-Way Session Bring-Up (Down -> Init -> Up) & Detection Timeout (`bfd_state_machine.frasm`)\n\nTraces two routers negotiating a 50ms (`50000` us * `mult 3` = `150ms` detection)\nBFD session from `Down` (`1`) through `Init` (`2`) to `Up` (`3`), followed by a\n`diag 1` timeout.\n\n- **Protocols:** `bfd` (5 Ethernet frames)\n- **Wire Behavior:** Defaults UDP `srcport` to RFC 5881 range (`49152+`),\n  `dstport` to `3784`, and IP `ttl` / Hop Limit to `255`. Bit-packs Version (`1`),\n  `diag` (`0..31`), `state` (`0..3`), `mult` (default `3`), `Length = 24`,\n  `mydisc`, `yourdisc`, `mintx` (`100000` us), `minrx` (`100000` us), and Echo RX\n  interval.\n- **Wireshark Filter:** `bfd`\n- **CLI Build:** `frameassembly show bfd_state_machine.frasm`\n\n```frameassembly\nhost pe_north { ip 10.255.1.1 }\nhost pe_south { ip 10.255.1.2 }\n\ncompile {\n    // 1. Initial Down packet (state 1, yourdisc 0 = peer unknown, slow 1s timer)\n    pe_north -> pe_south bfd state 1 diag 0 mydisc 0x1001 yourdisc 0 mintx 1000000 minrx 1000000 mult 3 dscp 48 wait 2ms\n    // 2. Peer sees 0x1001 and transitions to Init (state 2)\n    pe_north <- pe_south bfd state 2 diag 0 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 mult 3 dscp 48 wait 2ms\n    // 3. Both peers reach Up (state 3) at 50ms (50,000 us) intervals\n    pe_north -> pe_south bfd state 3 diag 0 mydisc 0x1001 yourdisc 0x2002 mintx 50000 minrx 50000 mult 3 dscp 48 wait 50ms\n    pe_north <- pe_south bfd state 3 diag 0 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 mult 3 dscp 48 wait 150ms\n    // 4. Link failure detected: state 1 (Down), diag 1 (Control Detection Time Expired)\n    pe_north -> pe_south bfd state 1 diag 1 mydisc 0x1001 yourdisc 0x2002 mintx 1000000 minrx 1000000 mult 3 dscp 48\n}\n```\n\n## 04.13 · OpenFlow SDN (`openflow`): Complete OpenFlow 1.3 Switch Onboarding, Packet-In Miss & FlowMod Programming (`openflow_sdn_pipeline.frasm`)\n\nWalks through TCP 6653 connection establishment, OpenFlow 1.3 `HELLO` +\n`FEATURES_REPLY`, a switch table-miss `PACKET_IN`, controller `FLOW_MOD`\ninstallation in Table 0, and `ECHO` heartbeat.\n\n- **Protocols:** `openflow`, `tcp` (12 Ethernet frames)\n- **Wire Behavior:** Defaults to IANA OpenFlow port TCP `6653`, Version `4`\n  (`0x04` = OpenFlow 1.3), and shares stateful 4-tuple TCP `seq`/`acknum`\n  progression. Computes the exact 16-bit big-endian OpenFlow `length` field across\n  both 8-byte header-only messages (`hello`, `featuresreq`, `echoreq`) and\n  structured bodies (`32B` `featuresreply`, `56B` `flowmod`).\n- **Wireshark Filter:** `openflow_v4 || openflow`\n- **CLI Build:** `frameassembly show openflow_sdn_pipeline.frasm`\n\n```frameassembly\nhost controller { ip 10.90.0.10 }\nhost leaf_ovs   { ip 10.90.0.51 }\n\ncompile {\n    // 1. TCP handshake on port 6653\n    leaf_ovs -> controller tcp syn srcport 54653 dstport 6653 win 65535 mss 1460 wait 1ms\n    leaf_ovs <- controller tcp syn ack win 65535 mss 1460 wait 1ms\n    leaf_ovs -> controller tcp ack wait 1ms\n    // 2. OpenFlow 1.3 (version 4) Hello & Features negotiation\n    leaf_ovs -> controller openflow hello version 4 xid 10 wait 1ms\n    leaf_ovs <- controller openflow hello version 4 xid 10 wait 1ms\n    leaf_ovs <- controller openflow featuresreq version 4 xid 11 wait 1ms\n    leaf_ovs -> controller openflow featuresreply version 4 xid 11 dpid 0x0000001c73aa0051 wait 3ms\n    // 3. Table-miss PacketIn triggers FlowMod rule installation + PacketOut\n    leaf_ovs -> controller openflow packetin version 4 xid 0 tableid 0 wait 2ms\n    leaf_ovs <- controller openflow flowmod version 4 xid 12 tableid 0 priority 1000 wait 1ms\n    leaf_ovs <- controller openflow packetout version 4 xid 13 wait 5ms\n    // 4. Liveness Echo Request / Reply\n    leaf_ovs <- controller openflow echoreq version 4 xid 99 wait 1ms\n    leaf_ovs -> controller openflow echoreply version 4 xid 99\n}\n```\n"}
{"id":"pretrain-anthology-overlays-tunnels-vpns","kind":"examples_anthology","title":"Data-Center Overlays (VXLAN, GENEVE, GRE) & VPN Tunnels — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/overlays-tunnels-vpns","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["wireguard","vxlan","geneve","ikev2","gre","vlan","ipsec","esp","ah"],"text":"# Data-Center Overlays (VXLAN, GENEVE, GRE) & VPN Tunnels\n\n> **FrameAssembly v3.3.0** · Anthology 05 (Layer 3 · 13 Recipes) · MIT License ·\n> Canonical URL:\n> https://frameassembly-lang.dev/docs/examples/overlays-tunnels-vpns\n\nSpine-leaf EVPN underlay captures (`vxlan` UDP 4789 and `geneve` UDP 6081), `gre`\nrouting encapsulations, `ikev2` SA/Child-SA exchanges, IPsec `esp`/`ah`/`ipsec`\nheaders, and modern `wireguard` handshakes.\n\n## Key Wire & Syntax Takeaways\n\n- `vxlan` (UDP 4789) and `geneve` (UDP 6081) encode 24-bit VNIs and combine\n  cleanly with `df` and `dscp` to verify underlay jumbo-MTU policies.\n- `ikev2` switches automatically from UDP 500 on `sainit` to NAT-T UDP 4500 when\n  needed, pairing with `esp`, `ah`, and `ipsec` SPI sequence traces.\n- `wireguard` encodes little-endian Noise_IKpsk2 initiation, response, cookie, and\n  transport data frames over both IPv4 and IPv6 UDP 51820.\n\n## 05.01 · IPv6 WireGuard Noise_IKpsk2 Handshake, Cookie Reply & Transport Data (`wireguard_ipv6_tunnel.frasm`)\n\nRuns a complete WireGuard tunnel handshake (initiation, response, cookie, and\nencrypted data transport) over IPv6 UDP port 51820.\n\n- **Protocols:** `wireguard` (5 Ethernet frames)\n- **Wire Behavior:** Encodes little-endian WireGuard message types (1 Initiation,\n  2 Response, 3 Cookie, 4 Data) with sender, receiver, and nonce counter fields.\n- **Wireshark Filter:** `wg`\n- **CLI Build:** `frameassembly wireguard_ipv6_tunnel.frasm`\n\n```frameassembly\nhost roadwarrior { ip 2001:db8:50::25 }\nhost wg_hub      { ip 2001:db8:50::1 }\n\ncompile {\n    roadwarrior -> wg_hub wireguard initiation sender 0x0a0b0c0d wait 3ms\n    roadwarrior <- wg_hub wireguard response sender 0x11223344 receiver 0x0a0b0c0d wait 2ms\n    roadwarrior -> wg_hub wireguard data receiver 0x11223344 counter 0 wait 2ms\n    roadwarrior <- wg_hub wireguard data receiver 0x0a0b0c0d counter 0 wait 5ms\n    roadwarrior <- wg_hub wireguard cookie receiver 0x0a0b0c0d\n}\n```\n\n## 05.02 · Data-Center Spine-Leaf Underlay Check (VXLAN UDP 4789 + GENEVE UDP 6081) (`dc_vxlan_and_geneve_vteps.frasm`)\n\nVerifies jumbo-MTU spine ACLs and hardware VTEP tunnel offload across both VXLAN\n(VNI 10100) and OVN/NSX GENEVE (VNI 20200 with TLV metadata).\n\n- **Protocols:** `vxlan`, `geneve` (3 Ethernet frames)\n- **Wire Behavior:** Sets DF bit on outer IPv4 underlay headers and encodes 24-bit\n  VNIs on UDP 4789 and UDP 6081.\n- **Wireshark Filter:** `vxlan || geneve`\n- **CLI Build:** `frameassembly dc_vxlan_and_geneve_vteps.frasm`\n\n```frameassembly\nhost vtep_rack01 { ip 10.250.1.11 }\nhost vtep_rack08 { ip 10.250.1.18 }\n\ncompile {\n    vtep_rack01 -> vtep_rack08 vxlan vni 10100 df dscp 18 payload \"evpn-l2vni-10100-frame\" wait 2ms\n    vtep_rack01 <- vtep_rack08 vxlan vni 10100 df dscp 18 payload \"evpn-l2vni-10100-reply\" wait 3ms\n    vtep_rack01 -> vtep_rack08 geneve vni 20200 optclass 0x0102 opttype 1 df payload \"ovn-geneve-metadata\"\n}\n```\n\n## 05.03 · Minimal Two-Block VXLAN (`vxlan`) Quickstart (`vxlan_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Virtual eXtensible Local\nArea Network Overlay (UDP 4789 (VNI 1), Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `vxlan` (1 Ethernet frame)\n- **Wire Behavior:** Wraps the packet in UDP `dstport 4789` with ephemeral outer\n  `srcport` and computes the outer IPv4/IPv6 + UDP checksums.\n- **Wireshark Filter:** `vxlan`\n- **CLI Build:** `frameassembly vxlan_quickstart.frasm`\n\n```frameassembly\nhost vtep_leaf1 { ip 172.16.0.11 }\nhost vtep_leaf2 { ip 172.16.0.12 }\n\ncompile {\n    vtep_leaf1 -> vtep_leaf2 vxlan vni 10100\n}\n```\n\n## 05.04 · Minimal Two-Block IKEv2 (`ikev2`) Quickstart (`ikev2_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Internet Key Exchange\nProtocol Version 2 (UDP 500 -> 500 (NAT-T 4500), Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `ikev2` (2 Ethernet frames)\n- **Wire Behavior:** Defaults both `srcport` and `dstport` to IANA IKE port `500`\n  (avoiding ephemeral `49152` source ports blocked by strict VPN ACLs).\n- **Wireshark Filter:** `isakmp`\n- **CLI Build:** `frameassembly ikev2_quickstart.frasm`\n\n```frameassembly\nhost initiator { ip 198.51.100.10 }\nhost responder { ip 203.0.113.20 }\n\ncompile {\n    initiator -> responder ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 msgid 0 wait 3ms\n    initiator <- responder ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 flags 0x20 msgid 0\n}\n```\n\n## 05.05 · Minimal Two-Block WireGuard (`wireguard`) Quickstart (`wireguard_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for WireGuard Noise_IK Secure\nNetwork Tunnel (UDP 51820, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `wireguard` (2 Ethernet frames)\n- **Wire Behavior:** Defaults UDP `dstport` to `51820` and writes the 4-byte\n  WireGuard message header (`Type` `1..4` followed by three mandatory `0x00`\n  reserved bytes).\n- **Wireshark Filter:** `wg`\n- **CLI Build:** `frameassembly wireguard_quickstart.frasm`\n\n```frameassembly\nhost wg_laptop { ip 198.51.100.42 }\nhost wg_relay  { ip 203.0.113.10 }\n\ncompile {\n    wg_laptop -> wg_relay wireguard initiation sender 0x01020304 wait 2ms\n    wg_laptop <- wg_relay wireguard response sender 0x0a0b0c0d receiver 0x01020304\n}\n```\n\n## 05.06 · GRE / NVGRE (`gre`): Keyed Dual-Stack GRE Tunnel Sequence & Transparent Ethernet Bridging (GRETAP) (`gre_overlay_lab.frasm`)\n\nDemonstrates an RFC 2890 keyed + checksummed GRE tunnel exchange over IPv4\nfollowed by an IPv6 outer GRETAP (`greproto 0x6558`) overlay frame.\n\n- **Protocols:** `gre` (4 Ethernet frames)\n- **Wire Behavior:** Sets outer IPv4 Protocol or IPv6 Next Header to `47` and\n  defaults `greproto` to `0x0800` (IPv4) with an inner probe header when `payload`\n  is omitted. Dynamically toggles GRE header flag bits (`0x8000` for `checksum`,\n  `0x2000` for `grekey`/`key`, `0x1000` for `greseq`) and inserts only the active\n  32-bit extension words in RFC 2890 order (`Checksum+Reserved1`, `Key`,\n  `Sequence`).\n- **Wireshark Filter:** `gre`\n- **CLI Build:** `frameassembly show gre_overlay_lab.frasm`\n\n```frameassembly\nhost edge_a_v4 { ip 172.16.100.1 }\nhost edge_b_v4 { ip 172.16.100.2 }\nhost vtep_a_v6 { ip 2001:db8:47::1 }\nhost vtep_b_v6 { ip 2001:db8:47::2 }\n\ncompile {\n    // 1. Minimal 4-byte RFC 2784 GRE keepalive\n    edge_a_v4 -> edge_b_v4 gre payload \"keepalive-1\" wait 2ms\n    // 2. Full 16-byte GRE header (C=1, K=1, S=1) with tunnel key 5000\n    edge_a_v4 -> edge_b_v4 gre grekey 5000 greseq 10 checksum dscp 46 payload \"wan-voice-tunnel\" wait 2ms\n    edge_a_v4 <- edge_b_v4 gre grekey 5000 greseq 1 checksum dscp 46 payload \"wan-voice-reply\" wait 3ms\n    // 3. GRE over IPv6 carrying Transparent Ethernet Bridging (0x6558)\n    vtep_a_v6 -> vtep_b_v6 gre grekey 0x00102000 greproto 0x6558 hexpayload \"ffffffffffff001b21aa00010806\"\n}\n```\n\n## 05.07 · VXLAN (`vxlan`): Multi-Tenant EVPN-VXLAN Underlay Carrying L2VNI 10100 & L3VNI 50000 (`vxlan_evpn_fabric.frasm`)\n\nSimulates leaf VTEPs exchanging multi-tenant VXLAN traffic across ECMP UDP source\nports, plus an IPv6 underlay VXLAN encapsulation.\n\n- **Protocols:** `vxlan`, `vlan` (3 Ethernet frames)\n- **Wire Behavior:** Wraps the packet in UDP `dstport 4789` with ephemeral outer\n  `srcport` and computes the outer IPv4/IPv6 + UDP checksums. Writes the 8-byte\n  RFC 7348 VXLAN header (`08 00 00 00 <24-bit VNI> 00`) with the mandatory `I` bit\n  (`0x08`) set.\n- **Wireshark Filter:** `vxlan`\n- **CLI Build:** `frameassembly show vxlan_evpn_fabric.frasm`\n\n```frameassembly\nhost leaf1_vtep { ip 10.255.0.11 mac 00:1c:73:aa:00:11 }\nhost leaf2_vtep { ip 10.255.0.12 mac 00:1c:73:aa:00:12 }\nhost vtep6_a    { ip 2001:db8:255::11 }\nhost vtep6_b    { ip 2001:db8:255::12 }\n\ncompile {\n    // Tenant A L2VNI 10100 with outer UDP entropy port 52101 and underlay VLAN 4090\n    leaf1_vtep -> leaf2_vtep vxlan vni 10100 srcport 52101 vlan 4090 dscp 26 wait 1ms\n    // Tenant B Symmetric IRB L3VNI 50000 with different ECMP hash port 58420\n    leaf2_vtep -> leaf1_vtep vxlan vnid 50000 srcport 58420 vlan 4090 dscp 46 wait 2ms\n    // IPv6 underlay VXLAN on legacy Linux port 8472\n    vtep6_a -> vtep6_b vxlan vni 20200 dstport 8472 flowlabel 0x33445\n}\n```\n\n## 05.08 · GENEVE (`geneve`): Kubernetes OVN & Cilium GENEVE Overlay With Security Identity TLVs (`geneve_cni_tlvs.frasm`)\n\nModels pod-to-pod overlay packets carrying OVN (`0x0102`) and Cilium (`0x0104`)\noption classes, plus a Layer 3 IPv6 inner payload (`protocoltype 0x86dd`).\n\n- **Protocols:** `geneve` (3 Ethernet frames)\n- **Wire Behavior:** Encapsulates over UDP `dstport 6081` with computed IPv4/IPv6\n  and UDP pseudo-header checksums. Writes the 8-byte RFC 8926 GENEVE base header\n  (`Ver=0`, dynamic `OptLen` in 4-byte words, `Protocol Type=0x6558` TEB, and\n  24-bit `VNI`).\n- **Wireshark Filter:** `geneve`\n- **CLI Build:** `frameassembly show geneve_cni_tlvs.frasm`\n\n```frameassembly\nhost node_az1 { ip 10.128.1.10 }\nhost node_az2 { ip 10.128.2.20 }\n\ncompile {\n    // 1. OVN-Kubernetes pod egress carrying Option Class 0x0102\n    node_az1 -> node_az2 geneve vni 4010 optclass 0x0102 opttype 1 srcport 55100 wait 1ms\n    // 2. Cilium return packet carrying Option Class 0x0104\n    node_az1 <- node_az2 geneve vni 4010 optclass 0x0104 opttype 2 srcport 59200 wait 2ms\n    // 3. Direct L3 IPv4 payload inside GENEVE (protocoltype 0x0800) for GWLB appliance test\n    node_az1 -> node_az2 geneve vni 100 optclass 0x0108 opttype 1 protocoltype 0x0800\n}\n```\n\n## 05.09 · IPsec (ESP Alias) (`ipsec`): IKEv2 Tunnel Bring-Up Followed by Bidirectional IPsec Data Frames (`ipsec_site_to_site.frasm`)\n\nPairs an `ikev2` `SA_INIT` + `IKE_AUTH` negotiation on UDP 500 with encrypted\n`ipsec` tunnel-mode (`nextheader 4`) data packets in both directions.\n\n- **Protocols:** `ipsec` (6 Ethernet frames)\n- **Wire Behavior:** Sets outer IPv4 Protocol or IPv6 Next Header to `50` (ESP).\n  Encodes the 4-byte `spi` (default `0x00000100`), 4-byte ESP `seq` (default `1`),\n  8-byte `iv`, block-aligned ciphertext + 2-byte ESP trailer (`Pad Length` +\n  `nextheader`), and 12-byte `icv` authentication tag.\n- **Wireshark Filter:** `esp`\n- **CLI Build:** `frameassembly show ipsec_site_to_site.frasm`\n\n```frameassembly\nhost gw_west { ip 198.51.100.10 }\nhost gw_east { ip 203.0.113.20 }\n\ncompile {\n    // 1. IKEv2 SA_INIT and IKE_AUTH key exchange on UDP 500\n    gw_west -> gw_east ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 msgid 0 nextheader 33 wait 3ms\n    gw_west <- gw_east ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 flags 0x20 wait 3ms\n    gw_west -> gw_east ikev2 auth initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 msgid 1 nextheader 46 wait 4ms\n    // 2. Bidirectional IPsec ESP tunnel frames (outbound SPI 0x1001, inbound SPI 0x2002)\n    gw_west -> gw_east ipsec spi 0x00001001 seq 1 iv \"0102030405060708\" icv \"aabbccddeeff001122334455\" nextheader 4 wait 1ms\n    gw_west -> gw_east ipsec spi 0x00001001 seq 2 iv \"090a0b0c0d0e0f10\" icv \"112233445566778899aabbcc\" nextheader 4 wait 2ms\n    gw_west <- gw_east ipsec spi 0x00002002 seq 1 iv \"f1f2f3f4f5f6f7f8\" icv \"99887766554433221100ffaa\" nextheader 4\n}\n```\n\n## 05.10 · IPsec ESP (`esp`): Dual-Stack IPv4 & IPv6 ESP Security Associations With DiffServ QoS (`esp_dualstack_vpn.frasm`)\n\nEmits unidirectional outbound and inbound ESP Security Associations across both\nIPv4 and IPv6 WAN endpoints with preserved DiffServ markings.\n\n- **Protocols:** `esp` (3 Ethernet frames)\n- **Wire Behavior:** Emits IPv4 Protocol `50` or IPv6 Next Header `50` with\n  computed outer IPv4 header checksum and exact payload length. Aligns ciphertext\n  + padding + 2-byte trailer (`Pad Length`, `Next Header`) cleanly to cipher block\n  boundaries before appending the `icv`.\n- **Wireshark Filter:** `esp`\n- **CLI Build:** `frameassembly show esp_dualstack_vpn.frasm`\n\n```frameassembly\nhost hub_v4    { ip 198.51.100.1 }\nhost spoke_v4  { ip 203.0.113.50 }\nhost hub_v6    { ip 2001:db8:100::1 }\nhost spoke_v6  { ip 2001:db8:200::50 }\n\ncompile {\n    // IPv4 ESP tunnel (SPI 0x1010 -> 0x2020) with Expedited Forwarding (dscp 46)\n    spoke_v4 -> hub_v4 esp spi 0x00001010 seq 101 iv \"1011121314151617\" icv \"a1a2a3a4a5a6a7a8a9aaabac\" nextheader 4 dscp 46 df wait 1ms\n    spoke_v4 <- hub_v4 esp spi 0x00002020 seq 88 iv \"2021222324252627\" icv \"b1b2b3b4b5b6b7b8b9babbbc\" nextheader 4 dscp 46 df wait 3ms\n    // IPv6 ESP tunnel (Next Header 50, inner Next Header 41 = IPv6-in-IPv6)\n    spoke_v6 -> hub_v6 esp spi 0x00061010 seq 1 iv \"3031323334353637\" icv \"c1c2c3c4c5c6c7c8c9cacbcc\" nextheader 41 flowlabel 0x50001\n}\n```\n\n## 05.11 · IPsec AH (`ah`): Authenticated Dual-Stack Router Peering Using IPsec AH (Protocol 51) (`ah_authenticated_peering.frasm`)\n\nEmits bidirectional IPv4 and IPv6 RFC 4302 Authentication Header packets\ndemonstrating 32-bit vs 64-bit ICV alignment.\n\n- **Protocols:** `ah` (3 Ethernet frames)\n- **Wire Behavior:** Sets outer IPv4 Protocol or IPv6 Next Header to `51`\n  (Authentication Header). Computes RFC 4302 `Payload Len = (total_ah_bytes / 4) -\n  2` automatically and zero-pads `icv` to 4-byte (IPv4) or 8-byte (IPv6)\n  alignment.\n- **Wireshark Filter:** `ah`\n- **CLI Build:** `frameassembly show ah_authenticated_peering.frasm`\n\n```frameassembly\nhost core_a_v4 { ip 172.16.51.1 }\nhost core_b_v4 { ip 172.16.51.2 }\nhost core_a_v6 { ip 2001:db8:51::1 }\nhost core_b_v6 { ip 2001:db8:51::2 }\n\ncompile {\n    // IPv4 AH (24-byte header: Payload Len = 4, 12-byte 96-bit ICV)\n    core_a_v4 -> core_b_v4 ah spi 0x00002001 seq 1 nextheader 59 icv \"00112233445566778899aabb\" payload \"cleartext-signed-v4\" wait 2ms\n    core_a_v4 <- core_b_v4 ah spi 0x00002002 seq 1 nextheader 59 icv \"aabbccddeeff001122334455\" payload \"cleartext-ack-v4\" wait 3ms\n    // IPv6 AH (aligned to 8-octet boundary per RFC 4302 §2.2)\n    core_a_v6 -> core_b_v6 ah spi 0x00062001 seq 1 nextheader 59 icv \"0102030405060708090a0b0c\" payload \"cleartext-signed-v6\"\n}\n```\n\n## 05.12 · IKEv2 (`ikev2`): IKEv2 SA_INIT on UDP 500 Floating to NAT-Traversal UDP 4500 + DPD Check (`ikev2_natt_dpd.frasm`)\n\nTraces a complete IKEv2 phase: `SA_INIT` on UDP `500`, NAT-T port float to UDP\n`4500` for encrypted `IKE_AUTH` (`nextpayload 46`), and an `INFORMATIONAL` Dead\nPeer Detection exchange.\n\n- **Protocols:** `ikev2` (6 Ethernet frames)\n- **Wire Behavior:** Defaults both `srcport` and `dstport` to IANA IKE port `500`\n  (avoiding ephemeral `49152` source ports blocked by strict VPN ACLs). Writes the\n  28-byte RFC 7296 IKEv2 header (`Version 0x20`, exact 32-bit `Length`, 64-bit\n  SPIs) and defaults `responderspi` to `0` on `sainit` requests.\n- **Wireshark Filter:** `isakmp`\n- **CLI Build:** `frameassembly show ikev2_natt_dpd.frasm`\n\n```frameassembly\nhost branch_fw { ip 198.51.100.15 }\nhost cloud_vpn { ip 203.0.113.99 }\n\ncompile {\n    // 1. IKE_SA_INIT on UDP 500 -> 500 (Next Payload 33 = Security Association)\n    branch_fw -> cloud_vpn ikev2 sainit initiatorspi 0x9080706050403020 responderspi 0 msgid 0 flags 0x08 nextpayload 33 wait 4ms\n    branch_fw <- cloud_vpn ikev2 sainit initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 0 flags 0x20 nextpayload 33 wait 4ms\n    // 2. Float to UDP 4500 for IKE_AUTH (Next Payload 46 = Encrypted & Authenticated SK)\n    branch_fw -> cloud_vpn ikev2 auth srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 1 flags 0x08 nextpayload 46 wait 5ms\n    branch_fw <- cloud_vpn ikev2 auth srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 1 flags 0x20 nextpayload 46 wait 50ms\n    // 3. INFORMATIONAL Dead Peer Detection (DPD) liveness check\n    branch_fw -> cloud_vpn ikev2 informational srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 2 flags 0x08 nextpayload 46 wait 3ms\n    branch_fw <- cloud_vpn ikev2 informational srcport 4500 dstport 4500 initiatorspi 0x9080706050403020 responderspi 0x0102030405060708 msgid 2 flags 0x20 nextpayload 46\n}\n```\n\n## 05.13 · WireGuard (`wireguard`): Full 1-RTT Noise_IK Handshake, Transport Data Stream, and Under-Load Cookie (`wireguard_handshake_data.frasm`)\n\nCaptures a WireGuard initiator completing a 1-RTT handshake (`initiation` +\n`response`), exchanging encrypted `data` frames with incrementing counters, and\nhandling a `cookie` challenge.\n\n- **Protocols:** `wireguard` (7 Ethernet frames)\n- **Wire Behavior:** Defaults UDP `dstport` to `51820` and writes the 4-byte\n  WireGuard message header (`Type` `1..4` followed by three mandatory `0x00`\n  reserved bytes). Emits exact-length handshake structures: `148` bytes for\n  `initiation` (`Type 1`), `92` bytes for `response` (`Type 2`), and `64` bytes\n  for `cookie` (`Type 3`).\n- **Wireshark Filter:** `wg`\n- **CLI Build:** `frameassembly show wireguard_handshake_data.frasm`\n\n```frameassembly\nhost roadwarrior { ip 198.51.100.88 }\nhost corp_wg_gw  { ip 203.0.113.5 }\n\ncompile {\n    // 1. Optional DoS Cookie Reply challenge (64 bytes, Type 3)\n    roadwarrior -> corp_wg_gw wireguard initiation sender 0x11112222 wait 2ms\n    roadwarrior <- corp_wg_gw wireguard cookie receiver 0x11112222 wait 3ms\n    // 2. Full 1-RTT Noise_IKpsk2 Handshake (148B Initiation -> 92B Response)\n    roadwarrior -> corp_wg_gw wireguard initiation sender 0x33334444 wait 2ms\n    roadwarrior <- corp_wg_gw wireguard response sender 0xaaaabbbb receiver 0x33334444 wait 2ms\n    // 3. Encrypted Transport Data packets (Type 4) swapping receiver indices\n    roadwarrior -> corp_wg_gw wireguard data receiver 0xaaaabbbb counter 0 payload \"inner-ipv4-syn\" wait 1ms\n    roadwarrior <- corp_wg_gw wireguard data receiver 0x33334444 counter 0 payload \"inner-ipv4-synack\" wait 1ms\n    roadwarrior -> corp_wg_gw wireguard data receiver 0xaaaabbbb counter 1 payload \"inner-ipv4-ack\"\n}\n```\n"}
{"id":"pretrain-anthology-dns-dhcp-network-timing","kind":"examples_anthology","title":"DNS (UDP/TCP), mDNS, SSDP, DHCPv4/v6 & Nanosecond Time Sync — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/dns-dhcp-network-timing","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","dns","dhcp","ptp","ntp","udp","icmp","mdns","vlan","ssdp"],"text":"# DNS (UDP/TCP), mDNS, SSDP, DHCPv4/v6 & Nanosecond Time Sync\n\n> **FrameAssembly v3.3.0** · Anthology 06 (Layer 7 · 13 Recipes) · MIT License ·\n> Canonical URL:\n> https://frameassembly-lang.dev/docs/examples/dns-dhcp-network-timing\n\nCore DDI address and service resolution (`dns`, `mdns`, `ssdp`, `dhcp` DORA and\nIPv6 SARR) alongside stratum `ntp` polling and sub-microsecond IEEE 1588 `ptp`\n`.pcapng` captures.\n\n## Key Wire & Syntax Takeaways\n\n- Adding `transport tcp` to `dns` switches from UDP 53 to stateful TCP 53 and\n  prepends the RFC 1035 2-byte message length automatically.\n- `dhcp` adapts ports by IP family and message role: UDP `68 <-> 67` on IPv4 DORA\n  vs. UDP `546 <-> 547` on IPv6 Solicit/Advertise/Request/Reply.\n- `ptp` separates event messages (UDP 319) from general messages (UDP 320) and\n  preserves 1ns `wait` precision when compiled to `.pcapng`.\n\n## 06.01 · DNS over TCP Port 53 Zone Transfer Check (transport tcp) (`dns_tcp_zone_transfer.frasm`)\n\nTests firewall rules that mistakenly allow UDP 53 while blocking TCP 53 (required\nfor truncated responses >512B, DNSSEC, and AXFR transfers).\n\n- **Protocols:** `tcp`, `dns` (5 Ethernet frames)\n- **Wire Behavior:** Adding transport tcp to dns prepends the mandatory RFC 1035\n  2-byte big-endian TCP message-length prefix automatically.\n- **Wireshark Filter:** `dns && tcp.port == 53`\n- **CLI Build:** `frameassembly dns_tcp_zone_transfer.frasm`\n\n```frameassembly\nhost ns_secondary { ip 10.53.0.12 }\nhost ns_primary   { ip 10.53.0.11 }\n\ncompile {\n    ns_secondary -> ns_primary tcp syn srcport 53053 dstport 53 win 65535 mss 1460 wait 1ms\n    ns_secondary <- ns_primary tcp syn ack win 65535 mss 1460 wait 1ms\n    ns_secondary -> ns_primary tcp ack wait 1ms\n    ns_secondary -> ns_primary dns query txid 0x8801 qname \"prod.corp.internal\" qtype \"AXFR\" transport tcp wait 3ms\n    ns_secondary <- ns_primary dns response txid 0x8801 qname \"prod.corp.internal\" qtype \"A\" rdata \"10.53.10.20\" ansttl 3600 transport tcp\n}\n```\n\n## 06.02 · Stateful DHCPv6 Four-Packet SARR Lease (Solicit, Advertise, Request, Reply) (`dhcpv6_sarr_lease.frasm`)\n\nExercises IPv6 DHCPv6 client-to-relay/server port flipping (UDP 546 <-> 547)\nacross Solicit, Advertise, Request, and Reply.\n\n- **Protocols:** `dhcp` (4 Ethernet frames)\n- **Wire Behavior:** Over IPv6 endpoints, dhcp automatically switches from BOOTP\n  (68/67) to RFC 8415 DHCPv6 (546/547).\n- **Wireshark Filter:** `dhcpv6`\n- **CLI Build:** `frameassembly dhcpv6_sarr_lease.frasm`\n\n```frameassembly\nhost client_v6 { ip fe80::250:56ff:feaa:0010 mac 00:50:56:aa:00:10 }\nhost dhcp_v6   { ip fe80::1                   mac 00:1c:73:00:00:53 }\n\ncompile {\n    client_v6 -> dhcp_v6 dhcp solicit txid 0x102030 wait 3ms\n    client_v6 <- dhcp_v6 dhcp advertise txid 0x102030 wait 2ms\n    client_v6 -> dhcp_v6 dhcp request txid 0x102031 wait 2ms\n    client_v6 <- dhcp_v6 dhcp reply txid 0x102031\n}\n```\n\n## 06.03 · Nanosecond IEEE 1588 PTPv2 Two-Step Sync Burst (.pcapng Output) (`ptpv2_nanosecond_sync.frasm`)\n\nEmits a grandmaster PTPv2 Sync (UDP 319), Follow_Up (UDP 320), Delay_Req (UDP\n319), and Delay_Resp (UDP 320) spaced at sub-microsecond 250ns intervals.\n\n- **Protocols:** `ptp` (4 Ethernet frames)\n- **Wire Behavior:** Compile to .pcapng so IfTsResol(9) preserves exact\n  1-nanosecond timestamps on UDP ports 319 and 320.\n- **Wireshark Filter:** `ptp`\n- **CLI Build:** `frameassembly ptpv2_nanosecond_sync.frasm\n  ptpv2_nanosecond_sync.pcapng`\n\n```frameassembly\nhost gm_clock    { ip 10.158.0.1 mac 00:1c:73:15:88:01 }\nhost boundary_sw { ip 10.158.0.2 mac 00:1c:73:00:15:88 }\n\ncompile {\n    gm_clock -> boundary_sw ptp sync domain 24 seqid 900 clockid \"001c73fffe000001\" dscp 46 wait 250ns\n    gm_clock -> boundary_sw ptp followup domain 24 seqid 900 clockid \"001c73fffe000001\" dscp 46 wait 500ns\n    boundary_sw -> gm_clock ptp delayreq domain 24 seqid 45 clockid \"001c73fffe001588\" dscp 46 wait 250ns\n    boundary_sw <- gm_clock ptp delayresp domain 24 seqid 45 clockid \"001c73fffe000001\" dscp 46\n}\n```\n\n## 06.04 · UDP Service Probe (DNS 53, NTP 123 & Closed Port ICMP Unreachable) (`scan_udp_services.frasm`)\n\nProbes UDP 53 (DNS), UDP 123 (NTP), and closed UDP 1900 on an infrastructure host\nto show open UDP protocol replies vs. ICMP Port Unreachable (Type 3, Code 3).\n\n- **Protocols:** `dns`, `ntp`, `udp`, `icmp` (6 Ethernet frames)\n- **Wire Behavior:** Closed UDP ports do not send TCP RSTs—instead, the target OS\n  sends an ICMP Destination Unreachable (Code 3: Port Unreachable) packet.\n- **Wireshark Filter:** `dns || ntp || udp.port == 1900 || icmp`\n- **CLI Build:** `frameassembly scan_udp_services.frasm`\n\n```frameassembly\n// Audit host checking active UDP services on an internal infrastructure server\nhost audit_pc  { ip 10.15.0.25 }\nhost infra_srv { ip 10.15.1.10 }\n\ncompile {\n    // 1. UDP 53 (DNS) -> Open: answers standard A-record query\n    audit_pc -> infra_srv dns query txid 0x1001 qname \"ns1.corp.local\" qtype \"A\" wait 2ms\n    audit_pc <- infra_srv dns response txid 0x1001 qname \"ns1.corp.local\" qtype \"A\" rdata \"10.15.1.10\" wait 3ms\n\n    // 2. UDP 123 (NTP) -> Open: answers client mode 3 poll with server mode 4 stratum 2\n    audit_pc -> infra_srv ntp vn 4 mode 3 poll 6 wait 2ms\n    audit_pc <- infra_srv ntp vn 4 mode 4 stratum 2 refid \"GPS\" wait 3ms\n\n    // 3. UDP 1900 -> Closed: server OS returns ICMP Port Unreachable (Type 3, Code 3)\n    audit_pc -> infra_srv udp srcport 55200 dstport 1900 payload \"M-SEARCH\" wait 2ms\n    infra_srv -> audit_pc icmp destunreach type 3 code 3\n}\n```\n\n## 06.05 · Minimal Two-Block DNS (UDP/TCP) (`dns`) Quickstart (`dns_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Domain Name System over\nUDP or TCP (UDP 53 (or TCP 53 via transport tcp), Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `dns` (2 Ethernet frames)\n- **Wire Behavior:** Encodes dotted `qname` strings into RFC 1035 length-prefixed\n  labels (`\\x03api...\\x00`) and validates RFC label (`<= 63`B) and total length\n  (`<= 253`B) limits at compile time.\n- **Wireshark Filter:** `dns`\n- **CLI Build:** `frameassembly dns_quickstart.frasm`\n\n```frameassembly\nhost stub_client { ip 10.10.0.25 }\nhost dns_resolv  { ip 10.10.0.53 }\n\ncompile {\n    stub_client -> dns_resolv dns query txid 0x4a12 qname \"api.frameassembly.internal\" qtype \"A\" wait 2ms\n    stub_client <- dns_resolv dns response txid 0x4a12 qname \"api.frameassembly.internal\" qtype \"A\" rdata \"10.10.50.80\" ansttl 300\n}\n```\n\n## 06.06 · Minimal Two-Block DHCPv4 / DHCPv6 (`dhcp`) Quickstart (`dhcp_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Dynamic Host\nConfiguration Protocol — DHCPv4 & DHCPv6 (UDP 68/67 (DHCPv4) · UDP 546/547\n(DHCPv6), Dual-Stack Morphing (v4/v6)).\n\n- **Protocols:** `dhcp` (2 Ethernet frames)\n- **Wire Behavior:** Selects UDP `68 -> 67` for client messages (`discover`,\n  `request`, `release`) and UDP `67 -> 68` for server messages (`offer`, `ack`) on\n  IPv4—or UDP `546 <-> 547` on IPv6.\n- **Wireshark Filter:** `dhcp || dhcpv6`\n- **CLI Build:** `frameassembly dhcp_quickstart.frasm`\n\n```frameassembly\nhost client_pc { ip 0.0.0.0 mac 00:1b:21:44:55:66 }\nhost dhcp_srv  { ip 10.10.10.1 mac 00:1b:21:00:00:01 }\n\ncompile {\n    client_pc -> dhcp_srv dhcp discover xid 0x3903f326 chaddr 00:1b:21:44:55:66 hostname \"eng-laptop-04\" wait 2ms\n    client_pc <- dhcp_srv dhcp offer xid 0x3903f326 yiaddr 10.10.10.150 siaddr 10.10.10.1 chaddr 00:1b:21:44:55:66 subnetmask 255.255.255.0 router 10.10.10.1 dnsserver 10.10.10.53 leasetime 86400\n}\n```\n\n## 06.07 · Minimal Two-Block PTPv2 (IEEE 1588) (`ptp`) Quickstart (`ptp_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for IEEE 1588 Precision Time\nProtocol v2 (UDP 319 (Event) / UDP 320 (General), Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `ptp` (2 Ethernet frames)\n- **Wire Behavior:** Routes time-critical Event messages (`sync`, `delayreq`) to\n  UDP `319` and General messages (`followup`, `delayresp`, `announce`) to UDP\n  `320` automatically.\n- **Wireshark Filter:** `ptp`\n- **CLI Build:** `frameassembly ptp_quickstart.frasm`\n\n```frameassembly\nhost grandmaster { ip 10.60.1.1 }\nhost boundary_sw { ip 10.60.1.10 }\n\ncompile {\n    grandmaster -> boundary_sw ptp sync domain 0 seqid 100 clockid \"001c73fffe000001\" wait 200us\n    grandmaster -> boundary_sw ptp followup domain 0 seqid 100 clockid \"001c73fffe000001\"\n}\n```\n\n## 06.08 · DNS (UDP/TCP) (`dns`): UDP A/AAAA + NXDOMAIN Lookups Followed by Stateful DNS-over-TCP SRV Resolution (`dns_udp_and_tcp_lab.frasm`)\n\nCaptures standard UDP `AAAA` and `NXDOMAIN` (`rcode 3`) queries, then establishes\na TCP 53 session to resolve an Active Directory `_kerberos._tcp` lookup via\n`transport tcp`.\n\n- **Protocols:** `dns`, `tcp` (9 Ethernet frames)\n- **Wire Behavior:** Encodes dotted `qname` strings into RFC 1035 length-prefixed\n  labels (`\\x03api...\\x00`) and validates RFC label (`<= 63`B) and total length\n  (`<= 253`B) limits at compile time. Sets DNS flags (`QR=0, RD=1` `0x0100` on\n  `query`; `QR=1, RD=1, RA=1` `0x8180 | rcode` on `response`) and appends\n  compressed `0xc00c` Answer RRs when `rdata` is provided.\n- **Wireshark Filter:** `dns`\n- **CLI Build:** `frameassembly show dns_udp_and_tcp_lab.frasm`\n\n```frameassembly\nhost workstation { ip 172.16.10.45 }\nhost corp_dns    { ip 172.16.10.10 }\n\ncompile {\n    // 1. Standard UDP IPv6 AAAA lookup\n    workstation -> corp_dns dns query txid 0x1001 srcport 53110 qname \"git.corp.internal\" qtype \"AAAA\" wait 1ms\n    workstation <- corp_dns dns response txid 0x1001 qname \"git.corp.internal\" qtype \"AAAA\" rdata \"2001:db8:10::443\" ansttl 120 wait 3ms\n    // 2. Non-existent domain returning NXDOMAIN (rcode 3)\n    workstation -> corp_dns dns query txid 0x1002 srcport 53111 qname \"missing-svc.corp.internal\" qtype \"A\" wait 1ms\n    workstation <- corp_dns dns response txid 0x1002 qname \"missing-svc.corp.internal\" qtype \"A\" rcode 3 wait 4ms\n    // 3. RFC 1035 DNS-over-TCP on port 53 (auto-prefixes 2-byte TCP length field)\n    workstation -> corp_dns tcp syn srcport 54053 dstport 53 win 65535 mss 1460 wait 1ms\n    workstation <- corp_dns tcp syn ack win 65535 mss 1460 wait 1ms\n    workstation -> corp_dns tcp ack wait 1ms\n    workstation -> corp_dns dns query txid 0x2001 qname \"dc01.corp.internal\" qtype \"TXT\" transport tcp wait 1ms\n    workstation <- corp_dns dns response txid 0x2001 qname \"dc01.corp.internal\" qtype \"TXT\" rdata \"v=spf1 ip4:172.16.0.0/16 -all\" ansttl 3600 transport tcp\n}\n```\n\n## 06.09 · mDNS (Zero-Conf) (`mdns`): Dual-Stack DNS-SD Service Browse (`PTR`) and Host Address Announcement (`AAAA`) (`mdns_ipv6_matter_discovery.frasm`)\n\nDiscovers `_matterc._udp.local` commissioning nodes and announces an IPv6\nlink-local service record over VLAN 30.\n\n- **Protocols:** `mdns`, `vlan` (3 Ethernet frames)\n- **Wire Behavior:** Overrides the L3 destination IP to link-local multicast\n  `224.0.0.251` (IPv4) or `ff02::fb` (IPv6) with matching multicast Ethernet MAC\n  (`01:00:5e:00:00:fb` / `33:33:00:00:00:fb`). Fixes both UDP source and\n  destination ports to `5353 -> 5353` and defaults `txid` to `0` per RFC 6762.\n- **Wireshark Filter:** `mdns`\n- **CLI Build:** `frameassembly show mdns_ipv6_matter_discovery.frasm`\n\n```frameassembly\nhost controller { ip fe80::10 mac 00:1c:73:aa:00:10 }\nhost sensor_hub { ip fe80::55 mac 00:1c:73:aa:00:55 }\n\ncompile {\n    // 1. Multicast browse query to ff02::fb on UDP 5353 -> 5353\n    controller -> sensor_hub mdns query qname \"_matter._tcp.local\" qtype \"PTR\" vlan 30 ttl 255 wait 2ms\n    // 2. Hub announces PTR instance and AAAA address record\n    sensor_hub -> controller mdns response qname \"_matter._tcp.local\" qtype \"PTR\" rdata \"hub-01._matter._tcp.local\" ansttl 4500 vlan 30 ttl 255 wait 1ms\n    sensor_hub -> controller mdns response qname \"hub-01.local\" qtype \"AAAA\" rdata \"fe80::55\" ansttl 120 vlan 30 ttl 255\n}\n```\n\n## 06.10 · DHCPv4 / DHCPv6 (`dhcp`): Complete 4-Step DHCPv4 DORA Lease Workflow + DHCPv6 SARR Exchange (`dhcp_v4_dora_and_v6_sarr.frasm`)\n\nCaptures a full 4-frame IPv4 `discover -> offer -> request -> ack` cycle on VLAN\n10 followed by a 4-frame IPv6 `solicit -> advertise -> request -> reply` exchange.\n\n- **Protocols:** `dhcp`, `vlan` (8 Ethernet frames)\n- **Wire Behavior:** Selects UDP `68 -> 67` for client messages (`discover`,\n  `request`, `release`) and UDP `67 -> 68` for server messages (`offer`, `ack`) on\n  IPv4—or UDP `546 <-> 547` on IPv6. Writes the 4-byte RFC 2132 DHCP magic cookie\n  (`0x63825363`), packs every specified option TLV (`1`, `3`, `6`, `12`, `51`,\n  `53`), and terminates with Option `255` (`0xff`).\n- **Wireshark Filter:** `dhcp || dhcpv6`\n- **CLI Build:** `frameassembly show dhcp_v4_dora_and_v6_sarr.frasm`\n\n```frameassembly\nhost phone_v4 { ip 0.0.0.0 mac 00:50:56:aa:10:01 }\nhost srv_v4   { ip 10.20.10.1 mac 00:50:56:aa:00:01 }\nhost host_v6  { ip fe80::25 mac 00:50:56:bb:10:25 }\nhost srv_v6   { ip fe80::1 mac 00:50:56:bb:00:01 }\n\ncompile {\n    // 1. DHCPv4 DORA on VLAN 10 (UDP 68 <-> 67)\n    phone_v4 -> srv_v4 dhcp discover xid 0x77889900 chaddr 00:50:56:aa:10:01 hostname \"voip-desk-12\" vlan 10 wait 2ms\n    phone_v4 <- srv_v4 dhcp offer xid 0x77889900 yiaddr 10.20.10.112 siaddr 10.20.10.1 chaddr 00:50:56:aa:10:01 subnetmask 255.255.255.0 router 10.20.10.1 dnsserver 10.20.10.53 leasetime 43200 vlan 10 wait 1ms\n    phone_v4 -> srv_v4 dhcp request xid 0x77889900 chaddr 00:50:56:aa:10:01 hostname \"voip-desk-12\" vlan 10 wait 1ms\n    phone_v4 <- srv_v4 dhcp ack xid 0x77889900 yiaddr 10.20.10.112 siaddr 10.20.10.1 chaddr 00:50:56:aa:10:01 subnetmask 255.255.255.0 router 10.20.10.1 dnsserver 10.20.10.53 leasetime 43200 vlan 10 wait 5ms\n    // 2. DHCPv6 SARR over IPv6 link-local endpoints (UDP 546 <-> 547)\n    host_v6 -> srv_v6 dhcp solicit xid 0x00a1b2c3 dnsserver 2001:db8:20::53 wait 2ms\n    host_v6 <- srv_v6 dhcp advertise xid 0x00a1b2c3 dnsserver 2001:db8:20::53 wait 1ms\n    host_v6 -> srv_v6 dhcp request xid 0x00a1b2c3 wait 1ms\n    host_v6 <- srv_v6 dhcp reply xid 0x00a1b2c3 dnsserver 2001:db8:20::53\n}\n```\n\n## 06.11 · NTPv4 (`ntp`): Stratum 1 Synchronization + Kiss-o'-Death Rate-Limit & Mode 6 Audit Probe (`ntp_sync_and_security_audit.frasm`)\n\nCaptures normal NTPv4 client/server clock sync, a `stratum 0 refid \"RATE\"`\nKiss-o'-Death response, and a blocked `mode 6` control query for IDS testing.\n\n- **Protocols:** `ntp` (4 Ethernet frames)\n- **Wire Behavior:** Packs the first byte `(li << 6) | (vn << 3) | mode` cleanly\n  (`0x23` for `li 0 vn 4 mode 3` client; `0x24` for `mode 4` server) inside a\n  48-byte RFC 5905 header. Zero-pads 4-character ASCII `refid` strings (`\"GPS\\0\"`,\n  `\"PPS\\0\"`, `\"RATE\"`) for Stratum 0/1 servers.\n- **Wireshark Filter:** `ntp`\n- **CLI Build:** `frameassembly show ntp_sync_and_security_audit.frasm`\n\n```frameassembly\nhost branch_rtr { ip 172.16.30.1 }\nhost ntp_core   { ip 172.16.30.123 }\n\ncompile {\n    // 1. Standard NTPv4 Client (mode 3) -> Stratum 1 GPS Server (mode 4)\n    branch_rtr -> ntp_core ntp vn 4 mode 3 poll 6 precision -18 dscp 48 wait 2ms\n    branch_rtr <- ntp_core ntp li 0 vn 4 mode 4 stratum 1 poll 6 precision -24 refid \"GPS\" txtimestamp 0xe9b4d01080000000 dscp 48 wait 5ms\n    // 2. RFC 5905 Kiss-o'-Death (stratum 0, li 3, refid \"RATE\")\n    branch_rtr <- ntp_core ntp li 3 vn 4 mode 4 stratum 0 refid \"RATE\" wait 5ms\n    // 3. Mode 6 NTP Control query probe (tested against perimeter IDS/firewall)\n    branch_rtr -> ntp_core ntp vn 2 mode 6\n}\n```\n\n## 06.12 · PTPv2 (IEEE 1588) (`ptp`): Complete Two-Step IEEE 1588v2 Grandmaster <-> Ordinary Clock Exchange (.pcapng Ready) (`ptp_twostep_grandmaster.frasm`)\n\nExecutes a 5-frame PTPv2 `announce -> sync -> followup -> delayreq -> delayresp`\ncycle with sub-millisecond `wait` intervals ideal for `.pcapng` nanosecond export.\n\n- **Protocols:** `ptp` (5 Ethernet frames)\n- **Wire Behavior:** Routes time-critical Event messages (`sync`, `delayreq`) to\n  UDP `319` and General messages (`followup`, `delayresp`, `announce`) to UDP\n  `320` automatically. Computes exact IEEE 1588-2008 `messageLength` (`44` bytes\n  for `sync`/`followup`/`delayreq`, `54` bytes for `delayresp`, `64` bytes for\n  `announce`) and sets `twoStepFlag` on `sync`.\n- **Wireshark Filter:** `ptp`\n- **CLI Build:** `frameassembly show ptp_twostep_grandmaster.frasm`\n\n```frameassembly\nhost gm_clock    { ip 172.22.0.1 }\nhost media_node  { ip 172.22.0.45 }\n\ncompile {\n    // 1. Grandmaster announces BMCA hierarchy on UDP 320 (domain 127 = SMPTE ST 2059-2)\n    gm_clock -> media_node ptp announce domain 127 seqid 500 clockid \"ec4670fffe010203\" dscp 46 wait 500us\n    // 2. Two-step Sync (UDP 319) + Follow_Up (UDP 320) with matching seqid 501\n    gm_clock -> media_node ptp sync domain 127 seqid 501 clockid \"ec4670fffe010203\" dscp 46 wait 120us\n    gm_clock -> media_node ptp followup domain 127 seqid 501 clockid \"ec4670fffe010203\" dscp 46 wait 250us\n    // 3. Slave measures reverse path delay via Delay_Req (UDP 319) -> Delay_Resp (UDP 320)\n    media_node -> gm_clock ptp delayreq domain 127 seqid 88 clockid \"001b21fffeaa0045\" dscp 46 wait 180us\n    media_node <- gm_clock ptp delayresp domain 127 seqid 88 clockid \"ec4670fffe010203\" dscp 46\n}\n```\n\n## 06.13 · SSDP (UPnP) (`ssdp`): IoT Gateway SSDP M-SEARCH Sweep & UPnP IGD Alive Notification (`ssdp_upnp_audit.frasm`)\n\nSends a multicast `msearch` looking for UPnP Internet Gateway Devices, followed by\na router `notify` advertisement pointing to its XML description URL.\n\n- **Protocols:** `ssdp` (2 Ethernet frames)\n- **Wire Behavior:** Defaults UDP destination port to `1900` and automatically\n  derives the RFC 1112 multicast MAC `01:00:5e:7f:ff:fa` when sending to\n  `239.255.255.250`. Formats `M-SEARCH * HTTP/1.1\n` with `HOST`, `MAN: \"ssdp:discover\"`, `MX`, and `ST` headers on `msearch`\npackets.\n- **Wireshark Filter:** `ssdp`\n- **CLI Build:** `frameassembly show ssdp_upnp_audit.frasm`\n\n```frameassembly\nhost scanner   { ip 192.168.10.55 }\nhost upnp_grp  { ip 239.255.255.250 }\nhost rogue_rtr { ip 192.168.10.254 }\n\ncompile {\n    scanner -> upnp_grp ssdp msearch hosthdr \"239.255.255.250:1900\" man \"\\\"ssdp:discover\\\"\" mx 2 st \"urn:schemas-upnp-org:device:InternetGatewayDevice:1\" wait 5ms\n    rogue_rtr -> upnp_grp ssdp notify hosthdr \"239.255.255.250:1900\" nt \"urn:schemas-upnp-org:device:InternetGatewayDevice:1\" nts \"ssdp:alive\" usn \"uuid:f81d4fae-7dec::upnp:rootdevice\" location \"http://192.168.10.254:49152/rootDesc.xml\"\n}\n```\n"}
{"id":"pretrain-anthology-tls-quic-http-apis","kind":"examples_anthology","title":"TLS 1.3 SNI, QUIC, HTTP/1.1, HTTP/2, gRPC & WebSocket APIs — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/tls-quic-http-apis","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","http","grpc","vlan","tls","http2","quic","websocket"],"text":"# TLS 1.3 SNI, QUIC, HTTP/1.1, HTTP/2, gRPC & WebSocket APIs\n\n> **FrameAssembly v3.3.0** · Anthology 07 (Layer 7 · 13 Recipes) · MIT License ·\n> Canonical URL: https://frameassembly-lang.dev/docs/examples/tls-quic-http-apis\n\nModern web, reverse-proxy, WAF, and service-mesh traffic fixtures: TLS 1.3\n`clienthello` SNI/ALPN, `quic` long/short headers, `http` `hosthdr` REST calls,\n`http2` streams, `grpc` status trails, and `websocket` frames.\n\n## Key Wire & Syntax Takeaways\n\n- Use `hosthdr \"<domain>\"` on `http` and `ssdp` frames (`host` is reserved for\n  top-level endpoint declarations).\n- `tls clienthello` populates SNI and ALPN extensions cleanly over a 3-way TCP\n  handshake so NGFW application-ID rules trigger reliably.\n- `http2`, `grpc`, and `websocket` frame binary stream identifiers, length\n  prefixes, and masking bits on top of stateful TCP.\n\n## 07.01 · HTTP/1.1 API Authentication & Rate-Limit Response (429 Too Many Requests) (`http_api_ratelimit_429.frasm`)\n\nTests WAF and API-gateway rules with repeatable custom header key/value pairs,\nJSON POST bodies, and HTTP 429 rate-limit replies.\n\n- **Protocols:** `tcp`, `http` (7 Ethernet frames)\n- **Wire Behavior:** Uses hosthdr for the HTTP Host header and computes\n  Content-Length automatically from body.\n- **Wireshark Filter:** `http`\n- **CLI Build:** `frameassembly http_api_ratelimit_429.frasm`\n\n```frameassembly\nhost api_client { ip 10.42.10.15 }\nhost waf_edge   { ip 10.42.90.80 }\n\ncompile {\n    api_client -> waf_edge tcp syn srcport 51080 dstport 80 win 65535 mss 1460 wait 1ms\n    api_client <- waf_edge tcp syn ack win 65535 mss 1460 wait 1ms\n    api_client -> waf_edge tcp ack wait 1ms\n    api_client -> waf_edge http post uri \"/v2/tokens\" hosthdr \"auth.corp.internal\" contenttype \"application/json\" header \"X-Request-Id\" \"req-9012\" body \"{\\\"grant\\\":\\\"client_credentials\\\"}\" wait 2ms\n    api_client <- waf_edge http status 200 reason \"OK\" contenttype \"application/json\" body \"{\\\"active\\\":true}\" wait 3ms\n    api_client -> waf_edge http post uri \"/v2/tokens\" hosthdr \"auth.corp.internal\" contenttype \"application/json\" header \"X-Request-Id\" \"req-9013\" body \"{\\\"grant\\\":\\\"client_credentials\\\"}\" wait 2ms\n    api_client <- waf_edge http status 429 reason \"Too Many Requests\" header \"Retry-After\" \"60\" body \"{\\\"error\\\":\\\"rate_limited\\\"}\"\n}\n```\n\n## 07.02 · Service-Mesh gRPC Unary Call & Status Code Verification (TCP 50051) (`service_mesh_grpc_check.frasm`)\n\nEstablishes a TCP 50051 channel between two Kubernetes pods and exercises a unary\ngRPC call returning grpcstatus 0 (OK) followed by grpcstatus 14 (UNAVAILABLE).\n\n- **Protocols:** `tcp`, `grpc` (7 Ethernet frames)\n- **Wire Behavior:** Builds HTTP/2 HEADERS + length-prefixed gRPC data + trailing\n  grpc-status frames over stateful TCP.\n- **Wireshark Filter:** `http2 || grpc || tcp.port == 50051`\n- **CLI Build:** `frameassembly service_mesh_grpc_check.frasm`\n\n```frameassembly\nhost checkout_pod { ip 10.244.1.18 }\nhost ledger_pod   { ip 10.244.2.44 }\n\ncompile {\n    checkout_pod -> ledger_pod tcp syn srcport 55051 dstport 50051 win 65535 mss 1460 wait 1ms\n    checkout_pod <- ledger_pod tcp syn ack win 65535 mss 1460 wait 1ms\n    checkout_pod -> ledger_pod tcp ack wait 1ms\n    checkout_pod -> ledger_pod grpc service \"ledger.v1.LedgerService\" method \"ReserveFunds\" streamid 1 payload \"order-8841\" wait 2ms\n    checkout_pod <- ledger_pod grpc service \"ledger.v1.LedgerService\" method \"ReserveFunds\" streamid 1 grpcstatus 0 wait 4ms\n    checkout_pod -> ledger_pod grpc service \"ledger.v1.LedgerService\" method \"CommitBatch\" streamid 3 payload \"batch-99\" wait 2ms\n    checkout_pod <- ledger_pod grpc service \"ledger.v1.LedgerService\" method \"CommitBatch\" streamid 3 grpcstatus 14\n}\n```\n\n## 07.03 · Stateful VLAN 20 HTTPS Permit Check (`fw_vlan20_https_permit.frasm`)\n\nVerifies an inter-VLAN firewall rule permits branch workstations on VLAN 20 to\ncomplete a 3-way TCP handshake and TLS 1.3 negotiation to an internal portal on\nport 443.\n\n- **Protocols:** `vlan`, `tcp`, `tls` (5 Ethernet frames)\n- **Wire Behavior:** Stateful firewalls drop lone TLS packets without a prior SYN\n  -> SYN-ACK -> ACK exchange. Specify srcport and dstport once on the opening syn\n  line and FrameAssembly tracks ports and sequence numbers automatically.\n- **Wireshark Filter:** `vlan.id == 20 && tcp.port == 443`\n- **CLI Build:** `frameassembly fw_vlan20_https_permit.frasm`\n\n```frameassembly\n// Devices on Branch VLAN 20 and Internal Portal Subnet\nhost branch_pc  { ip 10.20.10.25 }\nhost portal_srv { ip 10.20.90.80 }\n\ncompile {\n    // 1. Open TCP port 443 with an 802.1Q VLAN 20 tag (0x8100)\n    branch_pc -> portal_srv vlan 20 tcp syn srcport 51240 dstport 443 win 65535 mss 1460 wait 1ms\n    branch_pc <- portal_srv vlan 20 tcp syn ack win 65535 mss 1460 wait 1ms\n    branch_pc -> portal_srv vlan 20 tcp ack wait 1ms\n\n    // 2. Send TLS ClientHello with SNI so NGFW application control can inspect the hostname\n    branch_pc -> portal_srv vlan 20 tls clienthello sni \"portal.corp.internal\" alpn \"h2\" wait 2ms\n\n    // 3. Server completes TLS 1.3 ServerHello (0x1301 = TLS_AES_128_GCM_SHA256)\n    branch_pc <- portal_srv vlan 20 tls serverhello ciphersuite 0x1301\n}\n```\n\n## 07.04 · Minimal Two-Block HTTP/1.1 (`http`) Quickstart (`http_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Hypertext Transfer\nProtocol HTTP/1.1 (TCP 80, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `http` (5 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `80` with `psh ack` flags\n  and advances TCP `seq` by the exact HTTP header + body byte count.\n- **Wireshark Filter:** `http`\n- **CLI Build:** `frameassembly http_quickstart.frasm`\n\n```frameassembly\nhost client  { ip 10.10.1.20 }\nhost web_srv { ip 10.10.1.80 }\n\ncompile {\n    client -> web_srv tcp syn srcport 52100 dstport 80 wait 1ms\n    client <- web_srv tcp syn ack wait 1ms\n    client -> web_srv tcp ack wait 1ms\n    client -> web_srv http get uri \"/healthz\" hosthdr \"api.corp.internal\" useragent \"kube-probe/1.30\" wait 2ms\n    client <- web_srv http status 200 reason \"OK\" contenttype \"application/json\" body \"{\\\"status\\\":\\\"healthy\\\"}\"\n}\n```\n\n## 07.05 · Minimal Two-Block HTTP/2 (`http2`) Quickstart (`http2_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Hypertext Transfer\nProtocol Version 2 Binary Framing (TCP 443, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `http2` (4 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `443` (`psh ack`) and keeps\n  TCP `seq` / `acknum` synchronized across multiplexed frames.\n- **Wireshark Filter:** `http2`\n- **CLI Build:** `frameassembly http2_quickstart.frasm`\n\n```frameassembly\nhost app_client { ip 10.20.1.10 }\nhost api_gw     { ip 10.20.1.44 }\n\ncompile {\n    app_client -> api_gw http2 preface dstport 8080 wait 1ms\n    app_client <- api_gw http2 settings wait 1ms\n    app_client -> api_gw http2 headers streamid 1 wait 1ms\n    app_client <- api_gw http2 data streamid 1 payload \"{\\\"ok\\\":true}\"\n}\n```\n\n## 07.06 · Minimal Two-Block TLS 1.2 / 1.3 (`tls`) Quickstart (`tls_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Transport Layer Security\nRecord & Handshake Layer (TCP 443, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `tls` (5 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `443` (`psh ack`), TLS\n  record version `0x0303` (RFC 8446 compatibility layer), and TLS 1.3 cipher suite\n  `0x1301` (`TLS_AES_128_GCM_SHA256`).\n- **Wireshark Filter:** `tls`\n- **CLI Build:** `frameassembly tls_quickstart.frasm`\n\n```frameassembly\nhost workstation { ip 10.10.5.20 }\nhost https_edge  { ip 198.51.100.44 }\n\ncompile {\n    workstation -> https_edge tcp syn srcport 53443 dstport 443 wait 1ms\n    workstation <- https_edge tcp syn ack wait 1ms\n    workstation -> https_edge tcp ack wait 1ms\n    workstation -> https_edge tls clienthello sni \"portal.corp.internal\" ciphersuite 0x1301 alpn \"h2\" wait 2ms\n    workstation <- https_edge tls serverhello ciphersuite 0x1301\n}\n```\n\n## 07.07 · Minimal Two-Block QUIC (HTTP/3) (`quic`) Quickstart (`quic_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for QUIC v1 & v2 Encrypted\nUDP Transport (UDP 443, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `quic` (2 Ethernet frames)\n- **Wire Behavior:** Defaults to UDP destination port `443`, QUIC v1 (`version 1`\n  `0x00000001`), and sets the mandatory Fixed Bit (`0x40`) in byte 0.\n- **Wireshark Filter:** `quic`\n- **CLI Build:** `frameassembly quic_quickstart.frasm`\n\n```frameassembly\nhost browser { ip 10.20.4.15 }\nhost cdn_vip { ip 198.51.100.44 }\n\ncompile {\n    browser -> cdn_vip quic initial version 1 dcid 0x1122334455667788 scid 0xaabbccddeeff0011 pktnum 1 wait 2ms\n    browser <- cdn_vip quic handshake version 1 dcid 0xaabbccddeeff0011 scid 0x1122334455667788 pktnum 1\n}\n```\n\n## 07.08 · HTTP/1.1 (`http`): REST API JSON Webhook POST + WAF 403 Block Scenario (`http_api_waf_test.frasm`)\n\nCompletes a TCP handshake on port 8080, sends an authenticated JSON `POST` request\nwith custom HTTP headers, and captures a `403 Forbidden` gateway response.\n\n- **Protocols:** `http`, `tcp` (7 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `80` with `psh ack` flags\n  and advances TCP `seq` by the exact HTTP header + body byte count. Computes and\n  inserts `Content-Length: <bytes>` automatically whenever `body` is present,\n  formatting all header lines with standard `\n` CRLF terminators.\n- **Wireshark Filter:** `http`\n- **CLI Build:** `frameassembly show http_api_waf_test.frasm`\n\n```frameassembly\nhost ext_client { ip 198.51.100.45 }\nhost waf_proxy  { ip 172.16.20.80 }\n\ncompile {\n    // 1. Complete TCP 3-way handshake on port 8080 (so Suricata stream engine tracks state)\n    ext_client -> waf_proxy tcp syn srcport 54320 dstport 8080 win 65535 mss 1460 wait 1ms\n    ext_client <- waf_proxy tcp syn ack win 65535 mss 1460 wait 1ms\n    ext_client -> waf_proxy tcp ack wait 1ms\n    // 2. HTTP POST with custom headers and JSON body\n    ext_client -> waf_proxy http post uri \"/v1/login\" hosthdr \"portal.example.com\" useragent \"Mozilla/5.0\" contenttype \"application/json\" header \"X-Request-ID\" \"req-9041\" header \"X-Forwarded-For\" \"203.0.113.9\" body \"{\\\"user\\\":\\\"admin\\\"}\" wait 3ms\n    // 3. WAF blocks request with HTTP 403 Forbidden + TCP FIN\n    ext_client <- waf_proxy http status 403 reason \"Forbidden\" contenttype \"application/json\" body \"{\\\"error\\\":\\\"blocked_by_policy\\\"}\" wait 1ms\n    ext_client <- waf_proxy tcp fin ack wait 1ms\n    ext_client -> waf_proxy tcp ack\n}\n```\n\n## 07.09 · HTTP/2 (`http2`): Cleartext h2c Connection Preface, Stream 1 Request, PING & Graceful GOAWAY (`http2_multiplexed_session.frasm`)\n\nEstablishes a TCP port 8080 connection, exchanges HTTP/2 connection prefaces,\nserves a Stream 1 request/data exchange, tests liveness with `ping`, and closes\ncleanly via `goaway`.\n\n- **Protocols:** `http2`, `tcp` (11 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `443` (`psh ack`) and keeps\n  TCP `seq` / `acknum` synchronized across multiplexed frames. Enforces RFC 9113\n  frame size rules automatically: 24-byte magic string + `SETTINGS` on `preface`,\n  8-byte payload on `ping` (`streamid 0`), 4-byte window increment on\n  `windowupdate`, and 8-byte `last_stream_id + error_code` on `goaway`.\n- **Wireshark Filter:** `http2`\n- **CLI Build:** `frameassembly show http2_multiplexed_session.frasm`\n\n```frameassembly\nhost mesh_sidecar { ip 172.16.30.11 }\nhost upstream_svc { ip 172.16.30.80 }\n\ncompile {\n    mesh_sidecar -> upstream_svc tcp syn srcport 53080 dstport 8080 win 65535 mss 1460 wait 1ms\n    mesh_sidecar <- upstream_svc tcp syn ack win 65535 mss 1460 wait 1ms\n    mesh_sidecar -> upstream_svc tcp ack wait 1ms\n    // 1. Client magic preface + server SETTINGS\n    mesh_sidecar -> upstream_svc http2 preface wait 1ms\n    mesh_sidecar <- upstream_svc http2 settings wait 1ms\n    // 2. Stream 1 request headers + response data + flow-control window update\n    mesh_sidecar -> upstream_svc http2 headers streamid 1 wait 2ms\n    mesh_sidecar <- upstream_svc http2 headers streamid 1 wait 1ms\n    mesh_sidecar <- upstream_svc http2 data streamid 1 payload \"{\\\"items\\\":[]}\" wait 1ms\n    mesh_sidecar -> upstream_svc http2 windowupdate streamid 0 wait 5ms\n    // 3. Keepalive PING & graceful connection drain (GOAWAY on stream 0)\n    mesh_sidecar -> upstream_svc http2 ping streamid 0 wait 2ms\n    mesh_sidecar <- upstream_svc http2 goaway streamid 0\n}\n```\n\n## 07.10 · gRPC (`grpc`): gNMI Router Telemetry Subscription + Backend UNAVAILABLE Failover (`grpc_service_mesh_lab.frasm`)\n\nOpens a TCP 50051 connection, invokes a `telemetry.Collector/Export` RPC\nsucceeding with `grpcstatus 0`, and captures a second call returning `grpcstatus\n14` (`UNAVAILABLE`).\n\n- **Protocols:** `grpc`, `tcp` (7 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `50051` (`psh ack`) and\n  formats HTTP/2 `HEADERS` (`:method POST`, `:path /<service>/<method>`,\n  `content-type: application/grpc`). Wraps request payloads in the 5-byte gRPC\n  Length-Prefixed-Message header (`Compressed-Flag = 0` + 32-bit big-endian\n  message length).\n- **Wireshark Filter:** `grpc || http2`\n- **CLI Build:** `frameassembly show grpc_service_mesh_lab.frasm`\n\n```frameassembly\nhost edge_agent { ip 172.16.40.12 }\nhost mesh_gw    { ip 172.16.40.50 }\n\ncompile {\n    edge_agent -> mesh_gw tcp syn srcport 55051 dstport 50051 win 65535 mss 1460 wait 1ms\n    edge_agent <- mesh_gw tcp syn ack win 65535 mss 1460 wait 1ms\n    edge_agent -> mesh_gw tcp ack wait 1ms\n    // 1. Healthy gRPC Export call -> OK (0)\n    edge_agent -> mesh_gw grpc service \"telemetry.Collector\" method \"Export\" wait 2ms\n    edge_agent <- mesh_gw grpc grpcstatus 0 wait 4ms\n    // 2. Upstream maintenance -> UNAVAILABLE (14)\n    edge_agent -> mesh_gw grpc service \"auth.TokenVerifier\" method \"Validate\" wait 2ms\n    edge_agent <- mesh_gw grpc grpcstatus 14\n}\n```\n\n## 07.11 · WebSocket (`websocket`): Full HTTP 101 Upgrade Handshake Into Masked WebSocket Stream & Close (`websocket_upgrade_session.frasm`)\n\nPerforms a TCP handshake + HTTP `101 Switching Protocols` WebSocket upgrade so\nWireshark and Suricata track the protocol switch, then exchanges masked client\nJSON, server events, `ping`/`pong`, and `close`.\n\n- **Protocols:** `websocket`, `tcp` (10 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `80` (`psh ack`), `text`\n  frame (`opcode 0x1`), and `finbit 1` (complete unfragmented message). Encodes\n  RFC 6455 extended 16-bit (`126`) or 64-bit (`127`) payload lengths automatically\n  when payloads exceed 125 bytes.\n- **Wireshark Filter:** `websocket`\n- **CLI Build:** `frameassembly show websocket_upgrade_session.frasm`\n\n```frameassembly\nhost dashboard_ui { ip 172.16.10.25 }\nhost realtime_gw  { ip 172.16.10.80 }\n\ncompile {\n    // 1. TCP 3-way handshake + HTTP 101 WebSocket Upgrade\n    dashboard_ui -> realtime_gw tcp syn srcport 52800 dstport 80 win 65535 mss 1460 wait 1ms\n    dashboard_ui <- realtime_gw tcp syn ack win 65535 mss 1460 wait 1ms\n    dashboard_ui -> realtime_gw tcp ack wait 1ms\n    dashboard_ui -> realtime_gw http get uri \"/ws\" hosthdr \"noc.corp.internal\" header \"Upgrade\" \"websocket\" header \"Connection\" \"Upgrade\" header \"Sec-WebSocket-Version\" \"13\" header \"Sec-WebSocket-Key\" \"dGhlIHNhbXBsZSBub25jZQ==\" wait 2ms\n    dashboard_ui <- realtime_gw http status 101 reason \"Switching Protocols\" header \"Upgrade\" \"websocket\" header \"Connection\" \"Upgrade\" wait 2ms\n    // 2. Masked client text frame + unmasked server push + Ping/Pong + Close\n    dashboard_ui -> realtime_gw websocket text maskkey 0x12345678 payload \"{\\\"op\\\":\\\"subscribe\\\",\\\"channel\\\":\\\"bgp\\\"}\" wait 2ms\n    dashboard_ui <- realtime_gw websocket text payload \"{\\\"peer\\\":\\\"10.0.0.2\\\",\\\"state\\\":\\\"Established\\\"}\" wait 10ms\n    dashboard_ui <- realtime_gw websocket ping payload \"hb\" wait 1ms\n    dashboard_ui -> realtime_gw websocket pong maskkey 0xabcdef01 payload \"hb\" wait 5ms\n    dashboard_ui -> realtime_gw websocket close maskkey 0x11223344\n}\n```\n\n## 07.12 · TLS 1.2 / 1.3 (`tls`): Full TLS 1.3 Handshake (`sni` + `alpn \"h2\"`), Encrypted AppData & Alert Teardown (`tls13_sni_handshake.frasm`)\n\nCompletes a TCP 443 handshake, negotiates `TLS_CHACHA20_POLY1305_SHA256`\n(`0x1303`) with SNI and ALPN, exchanges encrypted Application Data records, and\ncloses with a TLS `alert`.\n\n- **Protocols:** `tls`, `tcp` (11 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `443` (`psh ack`), TLS\n  record version `0x0303` (RFC 8446 compatibility layer), and TLS 1.3 cipher suite\n  `0x1301` (`TLS_AES_128_GCM_SHA256`). Automatically encodes Extension `0x0000`\n  (`server_name` when `sni` is set), Extension `0x002b` (`supported_versions`\n  advertising TLS 1.3 `0x0304` + TLS 1.2 `0x0303`), and Extension `0x0010` (`alpn`\n  when `alpn` is set).\n- **Wireshark Filter:** `tls`\n- **CLI Build:** `frameassembly show tls13_sni_handshake.frasm`\n\n```frameassembly\nhost branch_pc { ip 172.16.12.34 }\nhost saas_gw   { ip 203.0.113.100 }\n\ncompile {\n    branch_pc -> saas_gw tcp syn srcport 54443 dstport 443 win 65535 mss 1460 sackperm wait 1ms\n    branch_pc <- saas_gw tcp syn ack win 65535 mss 1460 sackperm wait 1ms\n    branch_pc -> saas_gw tcp ack wait 1ms\n    // 1. TLS 1.3 ClientHello + ServerHello + Encrypted Handshake / AppData\n    branch_pc -> saas_gw tls clienthello sni \"api.saas-vendor.example\" ciphersuite 0x1303 alpn \"h2\" wait 2ms\n    branch_pc <- saas_gw tls serverhello ciphersuite 0x1303 wait 1ms\n    branch_pc <- saas_gw tls certificate wait 1ms\n    branch_pc <- saas_gw tls finished wait 1ms\n    branch_pc -> saas_gw tls finished wait 2ms\n    // 2. Encrypted TLS Record Type 23 (Application Data) + Record Type 21 (Alert)\n    branch_pc -> saas_gw tls appdata hexpayload \"9f4a1c880021bc773310aa55\" wait 3ms\n    branch_pc <- saas_gw tls appdata hexpayload \"41e82209ff12008ac491bb02\" wait 5ms\n    branch_pc -> saas_gw tls alert\n}\n```\n\n## 07.13 · QUIC (HTTP/3) (`quic`): QUIC v1 Retry Token Challenge, Handshake & 1-RTT Connection Migration (`quic_connection_migration.frasm`)\n\nShows a server challenging an initial client packet with `retry`, completing the\nQUIC handshake, and maintaining the same `dcid` across a NAT source-port rebind on\n`short` packets.\n\n- **Protocols:** `quic` (6 Ethernet frames)\n- **Wire Behavior:** Defaults to UDP destination port `443`, QUIC v1 (`version 1`\n  `0x00000001`), and sets the mandatory Fixed Bit (`0x40`) in byte 0. Encodes\n  8-byte `dcid` and `scid` Connection IDs plus RFC 9000 variable-length integer\n  payload lengths automatically on Long Header packets.\n- **Wireshark Filter:** `quic`\n- **CLI Build:** `frameassembly show quic_connection_migration.frasm`\n\n```frameassembly\nhost mobile_app { ip 198.51.100.70 }\nhost edge_pop   { ip 203.0.113.44 }\n\ncompile {\n    // 1. Initial attempt -> Server sends stateless Retry token\n    mobile_app -> edge_pop quic initial srcport 51443 dcid 0x0102030405060708 scid 0x1111222233334444 pktnum 0 wait 2ms\n    mobile_app <- edge_pop quic retry dcid 0x1111222233334444 scid 0x9999888877776666 token \"addr-verified-tok\" wait 2ms\n    // 2. Client resends Initial with token + Handshake completion\n    mobile_app -> edge_pop quic initial dcid 0x9999888877776666 scid 0x1111222233334444 token \"addr-verified-tok\" pktnum 1 wait 2ms\n    mobile_app <- edge_pop quic handshake dcid 0x1111222233334444 scid 0x9999888877776666 pktnum 1 wait 3ms\n    // 3. 1-RTT Short Header packets (client migrates from srcport 51443 -> 60222 keeping dcid)\n    mobile_app -> edge_pop quic short dcid 0x9999888877776666 pktnum 2 payload \"h3-stream-frame-1\" wait 5ms\n    mobile_app -> edge_pop quic short srcport 60222 dstport 443 dcid 0x9999888877776666 pktnum 3 payload \"h3-migrated-port\"\n}\n```\n"}
{"id":"pretrain-anthology-databases-caches-brokers","kind":"examples_anthology","title":"PostgreSQL, MySQL, Redis, Memcached, MQTT & AMQP Captures — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/databases-caches-brokers","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","postgres","mqtt","vlan","mysql","redis","memcached","amqp"],"text":"# PostgreSQL, MySQL, Redis, Memcached, MQTT & AMQP Captures\n\n> **FrameAssembly v3.3.0** · Anthology 08 (Layer 7 · 13 Recipes) · MIT License ·\n> Canonical URL:\n> https://frameassembly-lang.dev/docs/examples/databases-caches-brokers\n\nEast-west microservice data-tier segmentation and IoT message-bus traces:\n`postgres` v3 Wire queries, `mysql` greetings and SQL commands, `redis` RESP\narrays, `memcached` TCP/UDP, `mqtt`, and `amqp`.\n\n## Key Wire & Syntax Takeaways\n\n- `postgres`, `mysql`, and `redis` build authentic binary/RESP wire messages on\n  TCP 5432, 3306, and 6379 for zero-trust east-west ACL testing.\n- `memcached` is one of the 9 dual-transport protocols, supporting default UDP\n  11211 (8-byte request ID header) or `transport tcp`.\n- `mqtt` (TCP 1883) and `amqp` (TCP 5672) encode variable-length broker frames for\n  industrial and cloud pub/sub telemetry validation.\n\n## 08.01 · Dual-Stack IPv4 + IPv6 PostgreSQL Read-Replica Health Flow (`postgres_dual_stack_replica.frasm`)\n\nRuns an identical PostgreSQL v3 startup, authentication, and SQL readiness probe\nacross IPv4 and IPv6 database subnets via flow(app, db).\n\n- **Protocols:** `tcp`, `postgres` (9 Ethernet frames)\n- **Wire Behavior:** Encodes big-endian PostgreSQL StartupMessage (196608 = v3.0),\n  AuthenticationOk, Query (\"Q\"), CommandComplete (\"C\"), and ReadyForQuery (\"Z\").\n- **Wireshark Filter:** `pgsql`\n- **CLI Build:** `frameassembly postgres_dual_stack_replica.frasm`\n\n```frameassembly\nhost api_v4 { ip 10.50.1.10 }\nhost pg_v4  { ip 10.50.2.54 }\nhost api_v6 { ip 2001:db8:50:1::10 }\nhost pg_v6  { ip 2001:db8:50:2::54 }\n\nflow pg_replica_check(app, db) {\n    app -> db tcp syn srcport 54320 dstport 5432 win 65535 mss 1440 wait 1ms\n    app <- db tcp syn ack win 65535 mss 1440 wait 1ms\n    app -> db tcp ack wait 1ms\n    app -> db postgres startup user \"health_ro\" db \"analytics\" wait 1ms\n    app <- db postgres authok wait 1ms\n    app <- db postgres readyforquery wait 1ms\n    app -> db postgres query sql \"SELECT pg_is_in_recovery();\" wait 2ms\n    app <- db postgres commandcomplete wait 1ms\n    app <- db postgres readyforquery\n}\n\ncompile {\n    pg_replica_check(api_v4, pg_v4)\n    pg_replica_check(api_v6, pg_v6)\n}\n```\n\n## 08.02 · MQTT v3.1.1 Broker Connect, Topic Subscribe & QoS 1 Publish / PubAck (`mqtt_qos1_sensor_bus.frasm`)\n\nModels an edge gateway connecting to an internal MQTT broker on TCP 1883,\nsubscribing to command topics, and publishing QoS 1 sensor telemetry.\n\n- **Protocols:** `tcp`, `mqtt` (11 Ethernet frames)\n- **Wire Behavior:** Encodes variable-byte MQTT Remaining Length headers across\n  CONNECT, CONNACK, SUBSCRIBE, SUBACK, PUBLISH, PUBACK, and PINGREQ/PINGRESP.\n- **Wireshark Filter:** `mqtt`\n- **CLI Build:** `frameassembly mqtt_qos1_sensor_bus.frasm`\n\n```frameassembly\nhost edge_gw     { ip 10.75.10.22 }\nhost mqtt_broker { ip 10.75.0.18 }\n\ncompile {\n    edge_gw -> mqtt_broker tcp syn srcport 51883 dstport 1883 win 65535 mss 1460 wait 1ms\n    edge_gw <- mqtt_broker tcp syn ack win 65535 mss 1460 wait 1ms\n    edge_gw -> mqtt_broker tcp ack wait 1ms\n    edge_gw -> mqtt_broker mqtt connect clientid \"gw-line04\" wait 2ms\n    edge_gw <- mqtt_broker mqtt connack returncode 0 wait 2ms\n    edge_gw -> mqtt_broker mqtt subscribe pktid 10 topic \"plant/line04/cmd/#\" qos 1 wait 2ms\n    edge_gw <- mqtt_broker mqtt suback pktid 10 qos 1 wait 3ms\n    edge_gw -> mqtt_broker mqtt publish pktid 11 topic \"plant/line04/temp\" qos 1 payload \"{\\\"c\\\":64.5}\" wait 2ms\n    edge_gw <- mqtt_broker mqtt puback pktid 11 wait 10ms\n    edge_gw -> mqtt_broker mqtt pingreq wait 1ms\n    edge_gw <- mqtt_broker mqtt pingresp\n}\n```\n\n## 08.03 · DMZ Web App to Internal PostgreSQL (TCP 5432) Segmentation Check (`fw_dmz_postgres_5432.frasm`)\n\nTests a narrow East-West firewall rule allowing a DMZ web server to authenticate\nand run a health query against an internal PostgreSQL database on TCP port 5432.\n\n- **Protocols:** `vlan`, `tcp`, `postgres` (8 Ethernet frames)\n- **Wire Behavior:** Feed this .pcap into Suricata or firewall packet-tracer tools\n  to confirm deep-packet inspection recognizes valid PostgreSQL wire framing over\n  VLAN 50.\n- **Wireshark Filter:** `vlan.id == 50 && tcp.port == 5432`\n- **CLI Build:** `frameassembly fw_dmz_postgres_5432.frasm`\n\n```frameassembly\n// DMZ application node and internal database host\nhost dmz_app { ip 172.16.50.20 }\nhost prod_db { ip 10.50.20.40 }\n\ncompile {\n    // 1. Complete 3-way TCP handshake on PostgreSQL port 5432 (VLAN 50)\n    dmz_app -> prod_db vlan 50 tcp syn srcport 52400 dstport 5432 win 65535 mss 1460 wait 1ms\n    dmz_app <- prod_db vlan 50 tcp syn ack win 65535 mss 1460 wait 1ms\n    dmz_app -> prod_db vlan 50 tcp ack wait 1ms\n\n    // 2. PostgreSQL v3.0 startup, auth OK, and lightweight SQL check\n    dmz_app -> prod_db vlan 50 postgres startup user \"app_svc\" db \"orders\" wait 1ms\n    dmz_app <- prod_db vlan 50 postgres authok wait 1ms\n    dmz_app -> prod_db vlan 50 postgres query sql \"SELECT 1;\" wait 2ms\n    dmz_app <- prod_db vlan 50 postgres commandcomplete wait 1ms\n    dmz_app <- prod_db vlan 50 postgres readyforquery\n}\n```\n\n## 08.04 · Minimal Two-Block PostgreSQL (`postgres`) Quickstart (`postgres_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for PostgreSQL\nFrontend/Backend Wire Protocol v3.0 (TCP 5432, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `postgres` (7 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `5432` (`psh ack`) and\n  writes Protocol Version `3.0` (`0x00030000`) inside `startup` frames.\n- **Wireshark Filter:** `pgsql`\n- **CLI Build:** `frameassembly postgres_quickstart.frasm`\n\n```frameassembly\nhost app_pod { ip 10.50.10.12 }\nhost pg_db   { ip 10.50.20.54 }\n\ncompile {\n    app_pod -> pg_db tcp syn srcport 55432 dstport 5432 wait 1ms\n    app_pod <- pg_db tcp syn ack wait 1ms\n    app_pod -> pg_db tcp ack wait 1ms\n    app_pod -> pg_db postgres startup user \"app_ro\" db \"inventory\" wait 2ms\n    app_pod <- pg_db postgres authok wait 1ms\n    app_pod <- pg_db postgres readyforquery wait 2ms\n    app_pod -> pg_db postgres query sql \"SELECT sku, qty FROM stock WHERE qty < 10;\"\n}\n```\n\n## 08.05 · Minimal Two-Block MySQL / MariaDB (`mysql`) Quickstart (`mysql_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for MySQL & MariaDB Wire\nProtocol v10 (TCP 3306, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `mysql` (6 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `3306` (`psh ack`) and\n  computes the 3-byte little-endian MySQL packet length automatically.\n- **Wireshark Filter:** `mysql`\n- **CLI Build:** `frameassembly mysql_quickstart.frasm`\n\n```frameassembly\nhost app_srv  { ip 10.50.1.20 }\nhost mysql_db { ip 10.50.2.33 }\n\ncompile {\n    app_srv -> mysql_db tcp syn srcport 53306 dstport 3306 wait 1ms\n    app_srv <- mysql_db tcp syn ack wait 1ms\n    app_srv -> mysql_db tcp ack wait 1ms\n    app_srv <- mysql_db mysql greeting serverversion \"8.0.36\" wait 2ms\n    app_srv -> mysql_db mysql login user \"app_rw\" db \"orders\" wait 2ms\n    app_srv <- mysql_db mysql ok\n}\n```\n\n## 08.06 · Minimal Two-Block Redis (RESP) (`redis`) Quickstart (`redis_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Redis Serialization\nProtocol Cache & Broker (TCP 6379, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `redis` (5 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `6379` (`psh ack`) and\n  formats exact `*N\n$<len>\n...` RESP multibulk wire arrays.\n- **Wireshark Filter:** `redis || tcp.port == 6379`\n- **CLI Build:** `frameassembly redis_quickstart.frasm`\n\n```frameassembly\nhost api_pod   { ip 10.44.1.12 }\nhost redis_primary { ip 10.44.2.10 }\n\ncompile {\n    api_pod -> redis_primary tcp syn srcport 51637 dstport 6379 wait 1ms\n    api_pod <- redis_primary tcp syn ack wait 1ms\n    api_pod -> redis_primary tcp ack wait 1ms\n    api_pod -> redis_primary redis set key \"session:4821\" value \"active\" wait 1ms\n    api_pod <- redis_primary redis replytype \"ok\" value \"OK\"\n}\n```\n\n## 08.07 · Minimal Two-Block MQTT (`mqtt`) Quickstart (`mqtt_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Message Queuing Telemetry\nTransport (IoT & IIoT) (TCP 1883 (or transport udp), Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `mqtt` (6 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `1883` (`psh ack`) and\n  encodes the multi-byte variable-length `Remaining Length` field per OASIS MQTT\n  §2.2.3.\n- **Wireshark Filter:** `mqtt`\n- **CLI Build:** `frameassembly mqtt_quickstart.frasm`\n\n```frameassembly\nhost edge_gw { ip 10.60.10.25 }\nhost broker  { ip 10.60.10.10 }\n\ncompile {\n    edge_gw -> broker tcp syn srcport 51883 dstport 1883 wait 1ms\n    edge_gw <- broker tcp syn ack wait 1ms\n    edge_gw -> broker tcp ack wait 1ms\n    edge_gw -> broker mqtt connect clientid \"gw-rack04\" keepalive 60 wait 2ms\n    edge_gw <- broker mqtt connack returncode 0 wait 2ms\n    edge_gw -> broker mqtt publish topic \"dc1/rack04/kw\" qos 0 retain payload \"4.85\"\n}\n```\n\n## 08.08 · PostgreSQL (`postgres`): Full PostgreSQL v3.0 Startup, SQL Query Lifecycle & ErrorResponse (`postgres_session_audit.frasm`)\n\nCompletes a TCP 5432 handshake, authenticates via `startup` -> `authok` ->\n`readyforquery`, runs an audit query (`commandcomplete` + `readyforquery`), and\ntriggers an `errorresponse` on a restricted table.\n\n- **Protocols:** `postgres`, `tcp` (11 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `5432` (`psh ack`) and\n  writes Protocol Version `3.0` (`0x00030000`) inside `startup` frames. Computes\n  the 32-bit big-endian self-inclusive length (`4 + body_bytes`) on every `'R'`,\n  `'Q'`, `'C'`, `'Z'`, and `'E'` message.\n- **Wireshark Filter:** `pgsql`\n- **CLI Build:** `frameassembly show postgres_session_audit.frasm`\n\n```frameassembly\nhost api_svc { ip 172.16.54.15 }\nhost pg_pri  { ip 172.16.54.100 }\n\ncompile {\n    api_svc -> pg_pri tcp syn srcport 51432 dstport 5432 win 65535 mss 1460 wait 1ms\n    api_svc <- pg_pri tcp syn ack win 65535 mss 1460 wait 1ms\n    api_svc -> pg_pri tcp ack wait 1ms\n    // 1. Client-first StartupMessage -> AuthenticationOk + ReadyForQuery ('I')\n    api_svc -> pg_pri postgres startup user \"reporting_ro\" db \"analytics\" wait 2ms\n    api_svc <- pg_pri postgres authok wait 1ms\n    api_svc <- pg_pri postgres readyforquery wait 2ms\n    // 2. Authorized SELECT query -> CommandComplete + ReadyForQuery\n    api_svc -> pg_pri postgres query sql \"SELECT count(*) FROM daily_events;\" wait 3ms\n    api_svc <- pg_pri postgres commandcomplete wait 1ms\n    api_svc <- pg_pri postgres readyforquery wait 4ms\n    // 3. Unauthorized write attempt -> ErrorResponse ('E')\n    api_svc -> pg_pri postgres query sql \"DROP TABLE audit_trail;\" wait 2ms\n    api_svc <- pg_pri postgres errorresponse\n}\n```\n\n## 08.09 · MySQL / MariaDB (`mysql`): Blocked `root` Login (`errcode 1045`) + Authorized Application SQL Session (`mysql_dam_audit.frasm`)\n\nShows a rejected `root` login returning MySQL Error `1045`, followed by an\nauthorized `app_ro` connection running a `SELECT` query.\n\n- **Protocols:** `mysql`, `tcp` (14 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `3306` (`psh ack`) and\n  computes the 3-byte little-endian MySQL packet length automatically. Encodes\n  NUL-terminated server version, thread ID, auth-plugin-data salt, and capability\n  flags inside `greeting` so Wireshark recognizes the session as MySQL.\n- **Wireshark Filter:** `mysql`\n- **CLI Build:** `frameassembly show mysql_dam_audit.frasm`\n\n```frameassembly\nhost web_node { ip 172.16.50.15 }\nhost db_main  { ip 172.16.60.10 }\n\ncompile {\n    // 1. Unauthorized root login attempt -> MySQL Error 1045\n    web_node -> db_main tcp syn srcport 54306 dstport 3306 win 65535 mss 1460 wait 1ms\n    web_node <- db_main tcp syn ack win 65535 mss 1460 wait 1ms\n    web_node -> db_main tcp ack wait 1ms\n    web_node <- db_main mysql greeting serverversion \"8.0.37-commercial\" wait 2ms\n    web_node -> db_main mysql login user \"root\" db \"mysql\" wait 2ms\n    web_node <- db_main mysql err errcode 1045 wait 5ms\n    // 2. Authorized query on a second connection\n    web_node -> db_main tcp syn srcport 54307 dstport 3306 win 65535 mss 1460 wait 1ms\n    web_node <- db_main tcp syn ack win 65535 mss 1460 wait 1ms\n    web_node -> db_main tcp ack wait 1ms\n    web_node <- db_main mysql greeting serverversion \"8.0.37-commercial\" wait 1ms\n    web_node -> db_main mysql login user \"app_ro\" db \"billing\" wait 1ms\n    web_node <- db_main mysql ok wait 2ms\n    web_node -> db_main mysql query sql \"SELECT invoice_id, total_cents FROM invoices WHERE paid = 0 LIMIT 25\" wait 3ms\n    web_node <- db_main mysql ok\n}\n```\n\n## 08.10 · Redis (RESP) (`redis`): Blocked Unauthenticated `CONFIG` Probe (`-NOAUTH`) + Authenticated Cache Read/Write (`redis_security_audit.frasm`)\n\nTests an unauthenticated command rejected with `-NOAUTH Authentication required.`,\nfollowed by `AUTH`, `SET`, and bulk `GET`.\n\n- **Protocols:** `redis`, `tcp` (11 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `6379` (`psh ack`) and\n  formats exact `*N\n$<len>\n...` RESP multibulk wire arrays. Emits `+OK\n` (`replytype \"ok\"`), `-ERR ...\n` (`replytype \"err\"`), `:<num>\n` (`replytype \"integer\"`), or `$<len>\n<value>\n` (`replytype \"bulk\"`) on server responses.\n- **Wireshark Filter:** `redis || tcp.port == 6379`\n- **CLI Build:** `frameassembly show redis_security_audit.frasm`\n\n```frameassembly\nhost app_worker { ip 172.16.44.20 }\nhost cache_node { ip 172.16.44.63 }\n\ncompile {\n    app_worker -> cache_node tcp syn srcport 52637 dstport 6379 win 65535 mss 1460 wait 1ms\n    app_worker <- cache_node tcp syn ack win 65535 mss 1460 wait 1ms\n    app_worker -> cache_node tcp ack wait 1ms\n    // 1. Unauthenticated probe rejected with RESP error (-)\n    app_worker -> cache_node redis cmd \"INFO\" wait 1ms\n    app_worker <- cache_node redis replytype \"err\" value \"NOAUTH Authentication required.\" wait 3ms\n    // 2. Authenticate + SET + GET\n    app_worker -> cache_node redis cmd \"AUTH\" args \"LabCacheToken2026\" wait 1ms\n    app_worker <- cache_node redis replytype \"ok\" value \"OK\" wait 1ms\n    app_worker -> cache_node redis set key \"ratelimit:198.51.100.9\" value \"42\" wait 1ms\n    app_worker <- cache_node redis replytype \"ok\" value \"OK\" wait 1ms\n    app_worker -> cache_node redis get key \"ratelimit:198.51.100.9\" wait 1ms\n    app_worker <- cache_node redis replytype \"bulk\" value \"42\"\n}\n```\n\n## 08.11 · Memcached (`memcached`): UDP 11211 `stats` Amplification Audit + TCP ASCII & Binary Cache Operations (`memcached_udp_and_tcp.frasm`)\n\nTests a UDP 11211 `stats` probe, then opens a TCP 11211 session exercising both\nASCII `set`/`get` and Binary (`opcode 0x00`) `get`.\n\n- **Protocols:** `memcached`, `tcp` (6 Ethernet frames)\n- **Wire Behavior:** Prepends the mandatory 8-byte Memcached UDP frame header\n  (`Request ID`, `Seq 0`, `Total Datagrams 1`, `Reserved 0`) automatically on UDP\n  `11211`, and omits it cleanly when `transport tcp` is set. Formats exact\n  `<byte_len>\n<value>\n` blocks on ASCII `set` commands.\n- **Wireshark Filter:** `memcache`\n- **CLI Build:** `frameassembly show memcached_udp_and_tcp.frasm`\n\n```frameassembly\nhost auditor   { ip 172.16.45.10 }\nhost memcache  { ip 172.16.45.112 }\n\ncompile {\n    // 1. UDP 11211 amplification audit probe (with 8-byte UDP header)\n    auditor -> memcache memcached cmd \"stats\" wait 4ms\n    // 2. Authorized internal TCP 11211 session (ASCII + Binary)\n    auditor -> memcache tcp syn srcport 53211 dstport 11211 win 65535 mss 1460 wait 1ms\n    auditor <- memcache tcp syn ack win 65535 mss 1460 wait 1ms\n    auditor -> memcache tcp ack wait 1ms\n    auditor -> memcache memcached set key \"cfg:feature_x\" value \"enabled\" flags 0 exptime 600 transport tcp wait 2ms\n    auditor -> memcache memcached get key \"cfg:feature_x\" opcode 0x00 opaque 0x99 transport tcp\n}\n```\n\n## 08.12 · MQTT (`mqtt`): IIoT Gateway Connect, Wildcard Topic Subscribe, QoS 1 Publish & Keepalive Ping (`mqtt_iiot_telemetry.frasm`)\n\nConnects an industrial gateway to TCP 1883, subscribes to control commands,\npublishes a `qos 1` retained sensor reading acknowledged via `puback`, and\nexchanges `pingreq`/`pingresp`.\n\n- **Protocols:** `mqtt`, `tcp` (12 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `1883` (`psh ack`) and\n  encodes the multi-byte variable-length `Remaining Length` field per OASIS MQTT\n  §2.2.3. Encodes the `\"MQTT\"` Protocol Level `4` header inside `connect`, and\n  includes the 2-byte Packet Identifier (`pktid`) automatically on `qos 1` / `qos\n  2` `publish`, `puback`, `subscribe`, and `suback` packets.\n- **Wireshark Filter:** `mqtt`\n- **CLI Build:** `frameassembly show mqtt_iiot_telemetry.frasm`\n\n```frameassembly\nhost plc_gw      { ip 192.168.80.21 }\nhost mqtt_broker { ip 192.168.80.10 }\n\ncompile {\n    plc_gw -> mqtt_broker tcp syn srcport 52883 dstport 1883 win 65535 mss 1460 wait 1ms\n    plc_gw <- mqtt_broker tcp syn ack win 65535 mss 1460 wait 1ms\n    plc_gw -> mqtt_broker tcp ack wait 1ms\n    plc_gw -> mqtt_broker mqtt connect clientid \"line2-plc-gw\" keepalive 30 wait 2ms\n    plc_gw <- mqtt_broker mqtt connack returncode 0 wait 2ms\n    // 1. Subscribe to actuator commands (pktid 1)\n    plc_gw -> mqtt_broker mqtt subscribe pktid 1 topic \"plant1/line2/cmd\" qos 1 wait 2ms\n    plc_gw <- mqtt_broker mqtt suback pktid 1 wait 3ms\n    // 2. Publish QoS 1 retained telemetry (pktid 2 -> puback)\n    plc_gw -> mqtt_broker mqtt publish topic \"plant1/line2/pressure_bar\" qos 1 retain pktid 2 payload \"{\\\"bar\\\":6.42}\" wait 2ms\n    plc_gw <- mqtt_broker mqtt puback pktid 2 wait 10ms\n    // 3. Keepalive heartbeat + clean disconnect\n    plc_gw -> mqtt_broker mqtt pingreq wait 1ms\n    plc_gw <- mqtt_broker mqtt pingresp wait 2ms\n    plc_gw -> mqtt_broker mqtt disconnect\n}\n```\n\n## 08.13 · AMQP 0-9-1 (`amqp`): Full RabbitMQ Connection Startup, Channel Open, Publish, Deliver & Heartbeat (`amqp_rabbitmq_flow.frasm`)\n\nWalks through TCP 5672 connection startup, opening Channel 1, publishing an audit\nevent to `\"sec.events\"`, delivering to a worker, and sending a Channel 0\nheartbeat.\n\n- **Protocols:** `amqp`, `tcp` (9 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `5672` (`psh ack`) and\n  appends the mandatory `0xce` frame-end octet to every AMQP 0-9-1 frame. Emits\n  the exact 8-byte `AMQP\\x00\\x00\\x09\\x01` connection header on `protocolheader` so\n  Wireshark locks onto the AMQP dissector.\n- **Wireshark Filter:** `amqp`\n- **CLI Build:** `frameassembly show amqp_rabbitmq_flow.frasm`\n\n```frameassembly\nhost auth_svc { ip 172.16.65.10 }\nhost mq_node  { ip 172.16.65.56 }\n\ncompile {\n    auth_svc -> mq_node tcp syn srcport 51672 dstport 5672 win 65535 mss 1460 wait 1ms\n    auth_svc <- mq_node tcp syn ack win 65535 mss 1460 wait 1ms\n    auth_svc -> mq_node tcp ack wait 1ms\n    auth_svc -> mq_node amqp protocolheader wait 1ms\n    auth_svc <- mq_node amqp connectionstart channel 0 wait 2ms\n    auth_svc -> mq_node amqp channelopen channel 1 wait 2ms\n    auth_svc -> mq_node amqp basicpublish channel 1 exchange \"sec.events\" routingkey \"login.mfa\" payload \"{\\\"user\\\":\\\"netadmin\\\"}\" wait 3ms\n    auth_svc <- mq_node amqp basicdeliver channel 1 exchange \"sec.events\" routingkey \"login.mfa\" payload \"{\\\"user\\\":\\\"netadmin\\\"}\" wait 10ms\n    auth_svc <- mq_node amqp heartbeat channel 0\n}\n```\n"}
{"id":"pretrain-anthology-identity-aaa-storage","kind":"examples_anthology","title":"Active Directory (Kerberos, LDAP), AAA, SMB/NFS & Admin Access — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/identity-aaa-storage","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","kerberos","radius","smb","ldap","tacacs","nfs","ssh","telnet","ftp","tftp","whois"],"text":"# Active Directory (Kerberos, LDAP), AAA, SMB/NFS & Admin Access\n\n> **FrameAssembly v3.3.0** · Anthology 09 (Layer 7 · 14 Recipes) · MIT License ·\n> Canonical URL: https://frameassembly-lang.dev/docs/examples/identity-aaa-storage\n\nEnterprise identity, NAS storage, and bastion captures: `kerberos` AS/TGS\nexchanges, `ldap` binds and searches, `radius` & `tacacs` AAA, `smb` & `nfs`\nshares, plus `ssh`, `telnet`, `ftp`, `tftp`, and `whois`.\n\n## Key Wire & Syntax Takeaways\n\n- `kerberos` and `nfs` support `transport tcp` and `transport udp`, automatically\n  adding RFC record-marking headers when carried over TCP.\n- `radius` automatically selects UDP 1812 for `access*` authentication packets and\n  UDP 1813 for `accounting*` packets.\n- `smb` (TCP 445 NetBIOS-less framing) and `ldap` (ASN.1 BER on TCP 389) let blue\n  teams test lateral-movement detections offline.\n\n## 09.01 · Active Directory Kerberos AS-REQ / TGS-REQ over TCP Port 88 (transport tcp) (`kerberos_tcp88_ticket_flow.frasm`)\n\nEnterprise Windows tickets carrying large PAC group memberships exceed UDP MTU and\nswitch to TCP port 88. This trace validates TCP 88 KDC rules.\n\n- **Protocols:** `tcp`, `kerberos` (7 Ethernet frames)\n- **Wire Behavior:** transport tcp on kerberos prepends the 4-byte RFC 4120\n  record-length header over stateful TCP 88.\n- **Wireshark Filter:** `kerberos && tcp.port == 88`\n- **CLI Build:** `frameassembly kerberos_tcp88_ticket_flow.frasm`\n\n```frameassembly\nhost domain_pc { ip 10.10.30.45 }\nhost dc01_kdc  { ip 10.10.0.10 }\n\ncompile {\n    domain_pc -> dc01_kdc tcp syn srcport 52088 dstport 88 win 65535 mss 1460 wait 1ms\n    domain_pc <- dc01_kdc tcp syn ack win 65535 mss 1460 wait 1ms\n    domain_pc -> dc01_kdc tcp ack wait 1ms\n    domain_pc -> dc01_kdc kerberos asreq realm \"CORP.EXAMPLE.COM\" cname \"alice\" sname \"krbtgt/CORP.EXAMPLE.COM\" etype 18 transport tcp wait 2ms\n    domain_pc <- dc01_kdc kerberos asrep realm \"CORP.EXAMPLE.COM\" cname \"alice\" sname \"krbtgt/CORP.EXAMPLE.COM\" etype 18 transport tcp wait 2ms\n    domain_pc -> dc01_kdc kerberos tgsreq realm \"CORP.EXAMPLE.COM\" cname \"alice\" sname \"cifs/filesrv01.corp.example.com\" etype 18 transport tcp wait 2ms\n    domain_pc <- dc01_kdc kerberos tgsrep realm \"CORP.EXAMPLE.COM\" cname \"alice\" sname \"cifs/filesrv01.corp.example.com\" etype 18 transport tcp\n}\n```\n\n## 09.02 · RADIUS 802.1X Access-Challenge / Accept (UDP 1812) + Accounting (UDP 1813) (`radius_auth_and_accounting.frasm`)\n\nVerifies NAC firewall rules for both RADIUS authentication (UDP 1812) and session\naccounting start/response (UDP 1813).\n\n- **Protocols:** `radius` (6 Ethernet frames)\n- **Wire Behavior:** FrameAssembly automatically selects UDP 1812 on access*\n  messages and switches to UDP 1813 on accounting* messages.\n- **Wireshark Filter:** `radius`\n- **CLI Build:** `frameassembly radius_auth_and_accounting.frasm`\n\n```frameassembly\nhost edge_sw { ip 10.20.0.5 }\nhost ise_psn { ip 10.20.100.10 }\n\ncompile {\n    edge_sw -> ise_psn radius accessrequest id 10 user \"mchen\" nasip 10.20.0.5 servicetype 2 wait 3ms\n    edge_sw <- ise_psn radius accesschallenge id 10 wait 3ms\n    edge_sw -> ise_psn radius accessrequest id 11 user \"mchen\" nasip 10.20.0.5 wait 4ms\n    edge_sw <- ise_psn radius accessaccept id 11 framedip 10.20.40.88 wait 5ms\n    edge_sw -> ise_psn radius accountingrequest id 20 user \"mchen\" nasip 10.20.0.5 framedip 10.20.40.88 wait 2ms\n    edge_sw <- ise_psn radius accountingresponse id 20\n}\n```\n\n## 09.03 · Active Directory RC4 Kerberoasting + ADMIN$ SMB Lateral Check (`pentest_ad_kerberos_smb.frasm`)\n\nSimulates an RC4-HMAC (etype 23) Kerberos service ticket request on port 88\nfollowed by an SMB2 ADMIN$ share connection on TCP 445 to validate SOC\nlateral-movement alerts.\n\n- **Protocols:** `kerberos`, `tcp`, `smb` (10 Ethernet frames)\n- **Wire Behavior:** Lets blue-team and SOC engineers verify Zeek kerberos.log /\n  smb_mapping.log and SIEM correlation rules safely without touching a live Domain\n  Controller.\n- **Wireshark Filter:** `kerberos || smb2`\n- **CLI Build:** `frameassembly pentest_ad_kerberos_smb.frasm`\n\n```frameassembly\n// Lab workstation, Active Directory KDC, and Windows member server\nhost lab_wkstn { ip 10.10.20.44 }\nhost ad_dc01   { ip 10.10.0.10 }\nhost file_srv  { ip 10.10.1.45 }\n\ncompile {\n    // Phase 1: Request SQL SPN ticket downgraded to RC4-HMAC (etype 23 = Kerberoasting test)\n    lab_wkstn -> ad_dc01 kerberos tgsreq realm \"CORP.INTERNAL\" cname \"svc_test\" sname \"MSSQLSvc/sql01.corp.internal:1433\" etype 23 wait 2ms\n    lab_wkstn <- ad_dc01 kerberos tgsrep realm \"CORP.INTERNAL\" cname \"svc_test\" sname \"MSSQLSvc/sql01.corp.internal:1433\" etype 23 wait 5ms\n\n    // Phase 2: Open TCP 445 to member server and connect to administrative share ADMIN$\n    lab_wkstn -> file_srv tcp syn srcport 52445 dstport 445 win 65535 mss 1460 wait 1ms\n    lab_wkstn <- file_srv tcp syn ack win 65535 mss 1460 wait 1ms\n    lab_wkstn -> file_srv tcp ack wait 1ms\n    lab_wkstn -> file_srv smb negotiate msgid 0 wait 1ms\n    lab_wkstn <- file_srv smb negotiate msgid 0 status 0 wait 1ms\n    lab_wkstn -> file_srv smb sessionsetup msgid 1 sessionid 0x2001 wait 1ms\n    lab_wkstn <- file_srv smb sessionsetup msgid 1 sessionid 0x2001 status 0 wait 1ms\n    lab_wkstn -> file_srv smb treeconnect msgid 2 sessionid 0x2001 share \"\\\\file_srv\\ADMIN$\"\n}\n```\n\n## 09.04 · Kerberos v5 (`kerberos`): AES256 TGT Login Over TCP 88 + RC4 (`etype 23`) Kerberoasting Detection Lab (`kerberos_ad_detection_lab.frasm`)\n\nModels a normal Windows workstation obtaining an AES256 TGT over TCP port 88,\nfollowed by an RC4 (`etype 23`) `tgsreq`/`tgsrep` SPN ticket request to trigger\nSOC Kerberoasting signatures.\n\n- **Protocols:** `kerberos`, `tcp` (7 Ethernet frames)\n- **Wire Behavior:** Encodes valid ASN.1 DER RFC 4120 `APPLICATION` tags (`10`\n  AS-REQ, `11` AS-REP, `12` TGS-REQ, `13` TGS-REP, `30` KRB-ERROR) with `pvno =\n  5`. Splits slash-separated SPNs like `\"MSSQLSvc/db01.corp.internal:1433\"` into\n  multi-component `PrincipalName` ASN.1 sequences automatically.\n- **Wireshark Filter:** `kerberos`\n- **CLI Build:** `frameassembly show kerberos_ad_detection_lab.frasm`\n\n```frameassembly\nhost wkstn_14 { ip 172.16.20.14 }\nhost dc01_ad  { ip 172.16.1.10 }\n\ncompile {\n    // 1. Normal Active Directory TGT exchange over TCP port 88 (etype 18 = AES256)\n    wkstn_14 -> dc01_ad tcp syn srcport 53088 dstport 88 win 65535 mss 1460 wait 1ms\n    wkstn_14 <- dc01_ad tcp syn ack win 65535 mss 1460 wait 1ms\n    wkstn_14 -> dc01_ad tcp ack wait 1ms\n    wkstn_14 -> dc01_ad kerberos asreq realm \"CORP.INTERNAL\" cname \"alice\" sname \"krbtgt/CORP.INTERNAL\" etype 18 transport tcp wait 2ms\n    wkstn_14 <- dc01_ad kerberos asrep realm \"CORP.INTERNAL\" cname \"alice\" etype 18 transport tcp wait 5ms\n    // 2. Suspicious RC4-HMAC (etype 23) Service Ticket Request for SQL SPN (Kerberoasting test)\n    wkstn_14 -> dc01_ad kerberos tgsreq realm \"CORP.INTERNAL\" cname \"alice\" sname \"MSSQLSvc/db-prod.corp.internal:1433\" etype 23 transport tcp wait 2ms\n    wkstn_14 <- dc01_ad kerberos tgsrep realm \"CORP.INTERNAL\" cname \"alice\" sname \"MSSQLSvc/db-prod.corp.internal:1433\" etype 23 transport tcp\n}\n```\n\n## 09.05 · LDAPv3 (`ldap`): AD Bind Failure (`49`), Authorized Bind, Privileged Group Search & Unbind (`ldap_ad_search_audit.frasm`)\n\nCaptures a rejected bind (`resultcode 49`), a successful bind (`resultcode 0`), an\n`(adminCount=1)` privileged-account search returning an entry + `searchdone`, and\na clean `unbindreq`.\n\n- **Protocols:** `ldap`, `tcp` (11 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `389` (`psh ack`) and wraps\n  every operation in an ASN.1 BER `SEQUENCE` (`0x30`) with exact definite-length\n  tags. Encodes RFC 4511 protocolOp tags (`0x60` BindRequest, `0x61` BindResponse,\n  `0x63` SearchRequest, `0x64` SearchResultEntry, `0x65` SearchResultDone, `0x42`\n  UnbindRequest).\n- **Wireshark Filter:** `ldap`\n- **CLI Build:** `frameassembly show ldap_ad_search_audit.frasm`\n\n```frameassembly\nhost jump_ws { ip 172.16.30.44 }\nhost ad_dc   { ip 172.16.1.10 }\n\ncompile {\n    jump_ws -> ad_dc tcp syn srcport 52389 dstport 389 win 65535 mss 1460 wait 1ms\n    jump_ws <- ad_dc tcp syn ack win 65535 mss 1460 wait 1ms\n    jump_ws -> ad_dc tcp ack wait 1ms\n    // 1. Failed Simple Bind -> resultcode 49 (invalidCredentials)\n    jump_ws -> ad_dc ldap bindreq msgid 1 basedn \"cn=backup_ro,dc=corp,dc=internal\" wait 2ms\n    jump_ws <- ad_dc ldap bindres msgid 1 resultcode 49 wait 5ms\n    // 2. Successful Bind -> Search privileged accounts -> Unbind\n    jump_ws -> ad_dc ldap bindreq msgid 2 basedn \"cn=backup_ro,dc=corp,dc=internal\" wait 2ms\n    jump_ws <- ad_dc ldap bindres msgid 2 resultcode 0 wait 2ms\n    jump_ws -> ad_dc ldap searchreq msgid 3 basedn \"dc=corp,dc=internal\" filter \"(adminCount=1)\" wait 3ms\n    jump_ws <- ad_dc ldap searchentry msgid 3 basedn \"cn=Domain Admins,cn=Users,dc=corp,dc=internal\" wait 1ms\n    jump_ws <- ad_dc ldap searchdone msgid 3 resultcode 0 wait 2ms\n    jump_ws -> ad_dc ldap unbindreq msgid 4\n}\n```\n\n## 09.06 · RADIUS (`radius`): MFA Challenge, VPN IP Assignment & RADIUS Accounting Start (`radius_vpn_mfa_accounting.frasm`)\n\nWalks through a VPN gateway sending an Access-Request, handling an MFA\nAccess-Challenge, receiving an Access-Accept with an assigned client IP, and\nlogging an Accounting-Request on UDP 1813.\n\n- **Protocols:** `radius` (6 Ethernet frames)\n- **Wire Behavior:** Picks UDP destination port `1812` for `accessrequest`,\n  `accessaccept`, `accessreject`, and `accesschallenge`, or UDP `1813` for\n  `accountingrequest` and `accountingresponse`. Calculates the exact 16-bit RADIUS\n  Length across the 20-byte header and all included AVP attributes, and reverses\n  UDP ports automatically on `<-` replies.\n- **Wireshark Filter:** `radius`\n- **CLI Build:** `frameassembly show radius_vpn_mfa_accounting.frasm`\n\n```frameassembly\nhost vpn_gw    { ip 172.16.1.5 }\nhost radius_01 { ip 172.16.10.20 }\n\ncompile {\n    // 1. Initial VPN login + MFA Access-Challenge on UDP 1812\n    vpn_gw -> radius_01 radius accessrequest id 10 user \"oncall.netops\" nasip 172.16.1.5 servicetype 2 wait 2ms\n    vpn_gw <- radius_01 radius accesschallenge id 10 wait 15ms\n    // 2. Second factor approved -> Access-Accept assigns Framed-IP 10.250.0.25\n    vpn_gw -> radius_01 radius accessrequest id 11 user \"oncall.netops\" nasip 172.16.1.5 servicetype 2 wait 2ms\n    vpn_gw <- radius_01 radius accessaccept id 11 framedip 10.250.0.25 wait 5ms\n    // 3. Session accounting record on UDP 1813\n    vpn_gw -> radius_01 radius accountingrequest id 12 user \"oncall.netops\" nasip 172.16.1.5 framedip 10.250.0.25 wait 2ms\n    vpn_gw <- radius_01 radius accountingresponse id 12\n}\n```\n\n## 09.07 · TACACS+ (`tacacs`): Full TCP 49 Handshake + TACACS+ Admin Login & Command Accounting (`tacacs_admin_session.frasm`)\n\nOpens a TCP port 49 session from a spine router to a TACACS+ server, completes an\nauthentication prompt/reply pair, and sends a command accounting record.\n\n- **Protocols:** `tacacs`, `tcp` (8 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `49` (`psh ack`), TACACS+\n  version `0xc0`, and calculates the 32-bit payload `length` field automatically.\n  Treats `seq` (`0..255`) on a `tacacs` line as the 1-byte TACACS+ `seq_no` (`1`\n  client start, `2` server reply, `3` client continue) without breaking the outer\n  32-bit TCP sequence number.\n- **Wireshark Filter:** `tacplus`\n- **CLI Build:** `frameassembly show tacacs_admin_session.frasm`\n\n```frameassembly\nhost spine_rtr  { ip 172.20.0.1 }\nhost tacacs_aaa { ip 172.20.0.49 }\n\ncompile {\n    // 1. TCP 3-way handshake on port 49\n    spine_rtr -> tacacs_aaa tcp syn srcport 51049 dstport 49 win 65535 mss 1460 wait 1ms\n    spine_rtr <- tacacs_aaa tcp syn ack win 65535 mss 1460 wait 1ms\n    spine_rtr -> tacacs_aaa tcp ack wait 1ms\n    // 2. TACACS+ Authentication conversation (odd seq = router, even seq = server)\n    spine_rtr -> tacacs_aaa tacacs authen seq 1 flags 1 sessionid 0x44001122 user \"secops\" data \"vty0\" wait 2ms\n    spine_rtr <- tacacs_aaa tacacs authen seq 2 flags 1 sessionid 0x44001122 data \"Password: \" wait 5ms\n    spine_rtr -> tacacs_aaa tacacs authen seq 3 flags 1 sessionid 0x44001122 user \"secops\" data \"LabPass!\" wait 2ms\n    // 3. Command authorization & accounting\n    spine_rtr -> tacacs_aaa tacacs author seq 1 flags 1 sessionid 0x44001123 user \"secops\" data \"cmd=configure\" wait 2ms\n    spine_rtr -> tacacs_aaa tacacs acct seq 1 flags 1 sessionid 0x44001124 user \"secops\" data \"task_id=42\"\n}\n```\n\n## 09.08 · SMB2 / SMB3 (`smb`): SMB2 Login Failure (`0xc000006d`) + Administrative `ADMIN$` Named-Pipe Access (`smb_lateral_movement_lab.frasm`)\n\nCompletes TCP 445 setup, captures a failed `sessionsetup`, then connects to\n`\\\\srv01\\ADMIN$` and opens a remote file handle (`create` + `read` + `close`).\n\n- **Protocols:** `smb`, `tcp` (14 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `445` (`psh ack`) and\n  prepends the 4-byte big-endian NetBIOS Session length header (`0x00` + 24-bit\n  size). Builds the full 64-byte `þSMB` header (`StructureSize = 64`, `Command`,\n  `NTSTATUS`, `MessageId`, `TreeId`, `SessionId`) and sets the Server-to-Client\n  flag on `<-` replies.\n- **Wireshark Filter:** `smb2`\n- **CLI Build:** `frameassembly show smb_lateral_movement_lab.frasm`\n\n```frameassembly\nhost admin_pc { ip 172.16.20.55 }\nhost srv_01   { ip 172.16.10.45 }\n\ncompile {\n    admin_pc -> srv_01 tcp syn srcport 52445 dstport 445 win 65535 mss 1460 wait 1ms\n    admin_pc <- srv_01 tcp syn ack win 65535 mss 1460 wait 1ms\n    admin_pc -> srv_01 tcp ack wait 1ms\n    // 1. SMB2 Negotiate + Failed SessionSetup (STATUS_LOGON_FAILURE = 0xc000006d)\n    admin_pc -> srv_01 smb negotiate msgid 0 wait 1ms\n    admin_pc <- srv_01 smb negotiate msgid 0 status 0 wait 1ms\n    admin_pc -> srv_01 smb sessionsetup msgid 1 wait 2ms\n    admin_pc <- srv_01 smb sessionsetup msgid 1 status 0xc000006d wait 5ms\n    // 2. Successful SessionSetup + ADMIN$ TreeConnect + Create/Read/Close\n    admin_pc -> srv_01 smb sessionsetup msgid 2 sessionid 0x400001 wait 1ms\n    admin_pc <- srv_01 smb sessionsetup msgid 2 sessionid 0x400001 status 0 wait 1ms\n    admin_pc -> srv_01 smb treeconnect msgid 3 sessionid 0x400001 share \"\\\\\\\\srv_01\\\\ADMIN$\" wait 2ms\n    admin_pc <- srv_01 smb treeconnect msgid 3 sessionid 0x400001 treeid 1 status 0 wait 1ms\n    admin_pc -> srv_01 smb create msgid 4 sessionid 0x400001 treeid 1 filename \"System32\\\\drivers\\\\etc\\\\hosts\" wait 2ms\n    admin_pc <- srv_01 smb create msgid 4 sessionid 0x400001 treeid 1 status 0 wait 1ms\n    admin_pc -> srv_01 smb treedisconnect msgid 5 sessionid 0x400001 treeid 1\n}\n```\n\n## 09.09 · NFSv3 / v4 (`nfs`): NFSv4 TCP 2049 Export Lookup + Legacy NFSv3 UDP Probe (`nfs_storage_audit.frasm`)\n\nOpens TCP port 2049 from a privileged source port (`srcport 850`) to mount\n`/exports/backups`, then tests a legacy NFSv3 `NULL` ping over UDP 2049.\n\n- **Protocols:** `nfs`, `tcp` (5 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `2049` (`vers 4`, RPC\n  Program `100003`) and prepends the 4-byte ONC RPC Record Marking header\n  (`0x80000000 | length`) over TCP (omitting it cleanly when `transport udp` is\n  selected). Aligns `tag` and `path` UTF-8 strings to 4-byte XDR boundaries per\n  RFC 4506.\n- **Wireshark Filter:** `nfs || rpc`\n- **CLI Build:** `frameassembly show nfs_storage_audit.frasm`\n\n```frameassembly\nhost worker_01 { ip 172.16.40.25 }\nhost netapp_01 { ip 172.16.40.200 }\n\ncompile {\n    // 1. Stateful NFSv4 COMPOUND over TCP 2049 from privileged port 850 (< 1024)\n    worker_01 -> netapp_01 tcp syn srcport 850 dstport 2049 win 65535 mss 1460 wait 1ms\n    worker_01 <- netapp_01 tcp syn ack win 65535 mss 1460 wait 1ms\n    worker_01 -> netapp_01 tcp ack wait 1ms\n    worker_01 -> netapp_01 nfs vers 4 compound xid 0x7001 tag \"mount-backups\" path \"/exports/backups\" wait 3ms\n    // 2. Legacy NFSv3 NULL RPC check over UDP 2049\n    worker_01 -> netapp_01 nfs vers 3 proc \"NULL\" xid 0x7002 transport udp\n}\n```\n\n## 09.10 · SSH-2 (`ssh`): Complete SSH-2 Banner Exchange, KEXINIT Negotiation & NEWKEYS Cutover (`ssh_handshake_audit.frasm`)\n\nEstablishes a TCP 22 session between an admin workstation and a Linux server,\nexchanges version banners, negotiates keys via `kexinit`, activates encryption\nwith `newkeys`, and sends encrypted session data.\n\n- **Protocols:** `ssh`, `tcp` (9 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `22` (`psh ack`) and appends\n  standard RFC 4253 `\n` terminators to `banner` strings. Computes RFC 4253 binary packet framing\n(`4-byte packet_length`, `1-byte padding_length`, payload, and 8-byte block\npadding) automatically on `kexinit`, `newkeys`, and `msgcode` packets.\n- **Wireshark Filter:** `ssh`\n- **CLI Build:** `frameassembly show ssh_handshake_audit.frasm`\n\n```frameassembly\nhost admin_ws  { ip 172.16.99.10 }\nhost linux_srv { ip 172.16.10.22 }\n\ncompile {\n    admin_ws -> linux_srv tcp syn srcport 53220 dstport 22 win 65535 mss 1460 wait 1ms\n    admin_ws <- linux_srv tcp syn ack win 65535 mss 1460 wait 1ms\n    admin_ws -> linux_srv tcp ack wait 1ms\n    // 1. Cleartext RFC 4253 §4.2 protocol version exchange\n    admin_ws -> linux_srv ssh banner \"SSH-2.0-OpenSSH_9.7p1\" wait 1ms\n    admin_ws <- linux_srv ssh banner \"SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13\" wait 2ms\n    // 2. Binary KEXINIT (msgcode 20) + NEWKEYS (msgcode 21)\n    admin_ws -> linux_srv ssh kexinit cookie \"0102030405060708\" wait 1ms\n    admin_ws <- linux_srv ssh kexinit cookie \"aabbccddeeff0011\" wait 2ms\n    admin_ws -> linux_srv ssh newkeys wait 1ms\n    admin_ws <- linux_srv ssh newkeys\n}\n```\n\n## 09.11 · Telnet (`telnet`): Legacy OT RTU Telnet Login Detection Scenario (`telnet_cleartext_audit.frasm`)\n\nModels a TCP 23 connection to a legacy serial-to-Ethernet terminal server,\nnegotiating Echo/Suppress-Go-Ahead options and sending a `show running-config`\ncommand.\n\n- **Protocols:** `telnet`, `tcp` (9 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `23` (`psh ack`) and tracks\n  TCP sequence numbers automatically. Prefixes every `will` (`251`), `wont`\n  (`252`), `do` (`253`), and `dont` (`254`) option with the `0xff` IAC escape\n  byte.\n- **Wireshark Filter:** `telnet`\n- **CLI Build:** `frameassembly show telnet_cleartext_audit.frasm`\n\n```frameassembly\nhost eng_laptop { ip 192.168.50.15 }\nhost rtu_gw     { ip 192.168.50.200 }\n\ncompile {\n    eng_laptop -> rtu_gw tcp syn srcport 50123 dstport 23 win 65535 mss 1460 wait 1ms\n    eng_laptop <- rtu_gw tcp syn ack win 65535 mss 1460 wait 1ms\n    eng_laptop -> rtu_gw tcp ack wait 1ms\n    eng_laptop <- rtu_gw telnet will 1 do 24 wait 2ms\n    eng_laptop <- rtu_gw telnet will 3 data \"RTU-GW01 login: \" wait 5ms\n    eng_laptop -> rtu_gw telnet do 1 wont 24 wait 2ms\n    eng_laptop -> rtu_gw telnet do 3 data \"maint\\r\\n\" wait 3ms\n    eng_laptop <- rtu_gw telnet data \"Password: \" wait 5ms\n    eng_laptop -> rtu_gw telnet data \"show version\\r\\n\"\n}\n```\n\n## 09.12 · FTP (`ftp`): FTP Banner, Failed Brute-Force Login (`530`) & Successful Passive Retrieval (`ftp_login_and_pasv.frasm`)\n\nCompletes a TCP 21 handshake, tests a failed `530 Login incorrect` attempt, then\nlogs in cleanly and enters `PASV` mode to retrieve an archive.\n\n- **Protocols:** `ftp`, `tcp` (15 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `21` (`psh ack`) and\n  terminates every command or reply with standard `\n` CRLF. Formats `<code_num> <reply>\n` automatically when `code` is provided, or `<cmd> <arg>\n` for client requests.\n- **Wireshark Filter:** `ftp`\n- **CLI Build:** `frameassembly show ftp_login_and_pasv.frasm`\n\n```frameassembly\nhost branch_host { ip 172.16.20.35 }\nhost dmz_ftp     { ip 172.16.100.21 }\n\ncompile {\n    branch_host -> dmz_ftp tcp syn srcport 52121 dstport 21 win 65535 mss 1460 wait 1ms\n    branch_host <- dmz_ftp tcp syn ack win 65535 mss 1460 wait 1ms\n    branch_host -> dmz_ftp tcp ack wait 1ms\n    branch_host <- dmz_ftp ftp code 220 reply \"DMZ Archive FTP Ready\" wait 2ms\n    // 1. Rejected login attempt -> 530 Login incorrect\n    branch_host -> dmz_ftp ftp cmd \"USER\" arg \"admin\" wait 1ms\n    branch_host <- dmz_ftp ftp code 331 reply \"Password required for admin\" wait 2ms\n    branch_host -> dmz_ftp ftp cmd \"PASS\" arg \"wrongpass\" wait 5ms\n    branch_host <- dmz_ftp ftp code 530 reply \"Login incorrect.\" wait 5ms\n    // 2. Authorized backup user + PASV + RETR\n    branch_host -> dmz_ftp ftp cmd \"USER\" arg \"svc_backup\" wait 1ms\n    branch_host <- dmz_ftp ftp code 331 reply \"Password required\" wait 1ms\n    branch_host -> dmz_ftp ftp cmd \"PASS\" arg \"LabOnlyToken99\" wait 2ms\n    branch_host <- dmz_ftp ftp code 230 reply \"User logged in, proceed.\" wait 2ms\n    branch_host -> dmz_ftp ftp cmd \"PASV\" wait 1ms\n    branch_host <- dmz_ftp ftp code 227 reply \"Entering Passive Mode (172,16,100,21,195,80).\" wait 1ms\n    branch_host -> dmz_ftp ftp cmd \"RETR\" arg \"daily-config.tar.gz\"\n}\n```\n\n## 09.13 · TFTP (`tftp`): PXE Bootloader Download + Missing Config File Error (`tftp_pxe_boot.frasm`)\n\nRequests `pxelinux.0` in binary `\"octet\"` mode, transfers Block 1 with TFTP `ack`,\nand then requests a missing board config returning RFC 1350 Error Code `1`.\n\n- **Protocols:** `tftp` (5 Ethernet frames)\n- **Wire Behavior:** Defaults UDP destination port to `69` and writes\n  NUL-terminated (`0x00`) `filename` and transfer `mode` (`\"octet\"` or\n  `\"netascii\"`) strings on `rrq`/`wrq`. Encodes 2-byte big-endian Opcode + 2-byte\n  `block` number on `data` (`3`) and `ack` (`4`) packets.\n- **Wireshark Filter:** `tftp`\n- **CLI Build:** `frameassembly show tftp_pxe_boot.frasm`\n\n```frameassembly\nhost pxe_host { ip 172.16.50.101 }\nhost boot_srv { ip 172.16.50.10 }\n\ncompile {\n    // 1. Successful Read Request (RRQ) + Block 1 transfer\n    pxe_host -> boot_srv tftp rrq filename \"pxelinux.0\" mode \"octet\" wait 2ms\n    pxe_host <- boot_srv tftp data block 1 hexpayload \"7f454c46020101000000000000000000\" wait 1ms\n    pxe_host -> boot_srv tftp ack block 1 wait 4ms\n    // 2. Missing profile returns TFTP Error (Opcode 5, Error Code 1 = File not found)\n    pxe_host -> boot_srv tftp rrq filename \"pxelinux.cfg/default\" mode \"octet\" wait 2ms\n    pxe_host <- boot_srv tftp error errcode 1 errmsg \"File not found\"\n}\n```\n\n## 09.14 · WHOIS (`whois`): Full TCP 43 WHOIS Lookup & Clean FIN Teardown (`whois_soc_enrichment.frasm`)\n\nOpens TCP port 43 from a SOC automation host, queries `suspicious-login.example`,\nreceives registrar metadata, and closes the TCP session cleanly per RFC 3912.\n\n- **Protocols:** `whois`, `tcp` (8 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `43` (`psh ack`) and appends\n  `\n` to `domain` on `query` frames. Formats standard multi-line `Domain Name:\n<domain>\nRegistrar: <registrar>\n` directory output on `response` frames.\n- **Wireshark Filter:** `whois`\n- **CLI Build:** `frameassembly show whois_soc_enrichment.frasm`\n\n```frameassembly\nhost soc_bot  { ip 172.16.80.12 }\nhost rir_node { ip 198.51.100.43 }\n\ncompile {\n    soc_bot -> rir_node tcp syn srcport 54043 dstport 43 win 65535 mss 1460 wait 1ms\n    soc_bot <- rir_node tcp syn ack win 65535 mss 1460 wait 1ms\n    soc_bot -> rir_node tcp ack wait 1ms\n    soc_bot -> rir_node whois query domain \"suspicious-login.example\" wait 4ms\n    soc_bot <- rir_node whois response domain \"suspicious-login.example\" registrar \"Example Registrar LLC\" wait 1ms\n    soc_bot <- rir_node tcp fin ack wait 1ms\n    soc_bot -> rir_node tcp fin ack wait 1ms\n    soc_bot <- rir_node tcp ack\n}\n```\n"}
{"id":"pretrain-anthology-voip-media-snmp-telemetry","kind":"examples_anthology","title":"SIP/RTP VoIP, Mail, Encrypted SNMPv3 USM & Flow Telemetry — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/voip-media-snmp-telemetry","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","sip","rtp","syslog","snmp2","snmp3","vlan","rtsp","stun","smtp","imap","pop3","snmp1","netflow","ipfix","sflow"],"text":"# SIP/RTP VoIP, Mail, Encrypted SNMPv3 USM & Flow Telemetry\n\n> **FrameAssembly v3.3.0** · Anthology 10 (Layer 7 · 20 Recipes) · MIT License ·\n> Canonical URL:\n> https://frameassembly-lang.dev/docs/examples/voip-media-snmp-telemetry\n\nVoice/media signaling (`sip`, `rtp`, `rtsp`, `stun`), mail relays (`smtp`, `imap`,\n`pop3`), MIB-free `snmp1`/`snmp2`/encrypted `snmp3` USM traps, `syslog`, and\n`netflow`/`ipfix`/`sflow` collector streams.\n\n## Key Wire & Syntax Takeaways\n\n- `snmp3` performs native RFC 3414/3826/7860 USM key localization\n  (`md5`/`sha1`/`sha256` + `des`/`aes`) from even-length `engineid` hex without\n  MIB files.\n- `sip` and `syslog` accept `transport tcp` for reliable enterprise trunks and\n  SIEM collectors; `rtsp` uses `transporthdr` for its L7 `Transport:` header.\n- `netflow` (UDP 2055), `ipfix` (UDP 4739), and `sflow` (UDP 6343) generate\n  collector-ready flow records with configurable byte/packet counters.\n\n## 10.01 · SIP Trunk Call Setup over TCP 5060 + Bidirectional G.711 RTP Stream (`voip_sip_tcp_rtp_call.frasm`)\n\nCombines SIP signaling over TCP (transport tcp, DSCP CS3 = 24) with a\nbidirectional 20ms G.711 mu-law RTP audio stream (DSCP EF = 46) and clean BYE\nteardown.\n\n- **Protocols:** `tcp`, `sip`, `rtp` (8 Ethernet frames)\n- **Wire Behavior:** sip accepts transport tcp for enterprise SBC trunks while rtp\n  carries 160-sample (20ms) timestamp increments.\n- **Wireshark Filter:** `sip || rtp`\n- **CLI Build:** `frameassembly voip_sip_tcp_rtp_call.frasm`\n\n```frameassembly\nhost ip_phone { ip 10.80.10.25 }\nhost sbc_gw   { ip 10.80.1.10 }\n\ncompile {\n    ip_phone -> sbc_gw tcp syn srcport 51060 dstport 5060 dscp 24 wait 1ms\n    ip_phone <- sbc_gw tcp syn ack dscp 24 wait 1ms\n    ip_phone -> sbc_gw tcp ack dscp 24 wait 1ms\n    ip_phone -> sbc_gw sip invite uri \"sip:+14155550199@sbc.corp.internal\" from \"sip:ext204@corp.internal\" to \"sip:+14155550199@sbc.corp.internal\" callid \"call-7741@10.80.10.25\" cseq 1 dscp 24 transport tcp wait 4ms\n    ip_phone <- sbc_gw sip status 200 reason \"OK\" callid \"call-7741@10.80.10.25\" cseq 1 dscp 24 transport tcp wait 10ms\n    ip_phone -> sbc_gw rtp srcport 16384 dstport 24000 pt 0 seq 100 timestamp 160 ssrc 0x11223344 marker 1 dscp 46 payload \"g711-ulaw-frame-1\" wait 20ms\n    ip_phone <- sbc_gw rtp srcport 24000 dstport 16384 pt 0 seq 500 timestamp 160 ssrc 0x99887766 marker 1 dscp 46 payload \"g711-ulaw-reply-1\" wait 20ms\n    ip_phone -> sbc_gw sip bye uri \"sip:+14155550199@sbc.corp.internal\" callid \"call-7741@10.80.10.25\" cseq 2 dscp 24 transport tcp\n}\n```\n\n## 10.02 · Reliable Syslog Forwarding over TCP Port 514 (transport tcp) (`syslog_tcp_siem_forwarder.frasm`)\n\nVerifies TCP-based SIEM log-collector ingestion on port 514 when compliance\npolicies forbid lossy UDP Syslog.\n\n- **Protocols:** `tcp`, `syslog` (4 Ethernet frames)\n- **Wire Behavior:** transport tcp switches syslog from UDP 514 onto stateful TCP\n  514.\n- **Wireshark Filter:** `syslog && tcp.port == 514`\n- **CLI Build:** `frameassembly syslog_tcp_siem_forwarder.frasm`\n\n```frameassembly\nhost fw_edge  { ip 10.90.1.1 }\nhost siem_ing { ip 10.90.50.20 }\n\ncompile {\n    fw_edge -> siem_ing tcp syn srcport 53514 dstport 514 win 65535 mss 1460 wait 1ms\n    fw_edge <- siem_ing tcp syn ack win 65535 mss 1460 wait 1ms\n    fw_edge -> siem_ing tcp ack wait 1ms\n    fw_edge -> siem_ing syslog facility 4 severity 2 hostname \"fw-edge-01\" app \"policy-engine\" procid \"2048\" msg \"Denied TCP 198.51.100.99:44112 -> 10.90.10.5:22\" transport tcp\n}\n```\n\n## 10.03 · SNMPv2c Switch Uplink linkDown Trap (UDP 162) (`snmpv2c_linkdown_trap.frasm`)\n\nSends a standard SNMPv2c linkDown trap on UDP port 162 carrying sysUpTime,\nsnmpTrapOID.0, interface name Gi1/0/24, and operational state varbinds.\n\n- **Protocols:** `snmp2` (2 Ethernet frames)\n- **Wire Behavior:** No vendor MIB files are needed: 1.3.6.1.6.3.1.1.4.1.0 is\n  snmpTrapOID.0, and oidval 1.3.6.1.6.3.1.1.5.3 identifies standard linkDown (use\n  .5.4 for linkUp).\n- **Wireshark Filter:** `snmp && udp.port == 162`\n- **CLI Build:** `frameassembly snmpv2c_linkdown_trap.frasm`\n\n```frameassembly\n// Access switch sending a Trapv2-PDU to your monitoring server\nhost access_sw { ip 10.30.2.14 }\nhost nms_srv   { ip 10.30.0.100 }\n\ncompile {\n    // SNMPv2c linkDown (.5.3) trap for uplink Gi1/0/24 (ifIndex 24, ifOperStatus 2 = down)\n    access_sw -> nms_srv snmp2 trap community \"noc-traps\" reqid 401 sysuptime 245000 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.2.2.1.2.24 string \"Gi1/0/24\" varbind 1.3.6.1.2.1.2.2.1.8.24 int 2 wait 500ms\n\n    // Recovery: SNMPv2c linkUp (.5.4) trap 500ms later (ifOperStatus 1 = up)\n    access_sw -> nms_srv snmp2 trap community \"noc-traps\" reqid 402 sysuptime 245050 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.4 varbind 1.3.6.1.2.1.2.2.1.2.24 string \"Gi1/0/24\" varbind 1.3.6.1.2.1.2.2.1.8.24 int 1\n}\n```\n\n## 10.04 · Encrypted SNMPv3 authPriv Trap (SHA-256 + AES-128) (`snmpv3_authpriv_trap.frasm`)\n\nGenerates a fully authenticated and AES-128-encrypted SNMPv3 USM trap so NOC teams\ncan verify Zabbix, PRTG, Checkmk, or snmptrapd decryption keys safely.\n\n- **Protocols:** `snmp3` (1 Ethernet frame)\n- **Wire Behavior:** Enter user \"noc-secops\", engineid \"80001f888001020304\",\n  SHA-256 pass \"AuthPass2026!\", and AES pass \"PrivPass2026!\" in Wireshark ->\n  Preferences -> Protocols -> SNMP -> Users Table to decrypt.\n- **Wireshark Filter:** `snmp && udp.port == 162`\n- **CLI Build:** `frameassembly snmpv3_authpriv_trap.frasm`\n\n```frameassembly\n// Core distribution switch and SNMPv3 trap collector\nhost core_sw { ip 10.40.1.1 }\nhost nms_srv { ip 10.40.1.100 }\n\ncompile {\n    // Encrypted SNMPv3 USM trap (HMAC-SHA-256 auth + AES-128-CFB encryption) on UDP 162\n    // engineid must be an even-length hex string matching your snmptrapd createUser -e setting\n    core_sw -> nms_srv snmp3 trap user \"noc-secops\" engineid \"80001f888001020304\" engineboots 5 enginetime 1840 auth sha256 \"AuthPass2026!\" priv aes \"PrivPass2026!\" sysuptime 360000 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.2.2.1.2.1 string \"TenGigE0/1/0\"\n}\n```\n\n## 10.05 · Acknowledged SNMPv3 Inform + NMS Response (`snmpv3_inform_ack.frasm`)\n\nModels a confirmed SNMPv3 InformRequest on UDP 162 and the matching Response-PDU\nreturned by the NMS collector so router retry queues clear cleanly.\n\n- **Protocols:** `snmp3` (2 Ethernet frames)\n- **Wire Behavior:** Unlike fire-and-forget traps, an SNMP inform expects a\n  response with the same reqid; use <- so the NMS reply automatically flips UDP\n  ports (162 -> 49152).\n- **Wireshark Filter:** `snmp`\n- **CLI Build:** `frameassembly snmpv3_inform_ack.frasm`\n\n```frameassembly\n// WAN edge router sending a confirmed SNMPv3 Inform to the central NMS\nhost wan_rtr { ip 172.20.0.1 }\nhost nms_srv { ip 172.20.0.50 }\n\ncompile {\n    // 1. Router sends encrypted SNMPv3 Inform (reqid 910) reporting BGP neighbor loss\n    wan_rtr -> nms_srv snmp3 inform user \"wan-ops\" engineid \"80001f8880aabbccdd\" engineboots 8 enginetime 4200 auth sha256 \"WanAuthKey99!\" priv aes \"WanPrivKey99!\" reqid 910 sysuptime 980000 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.2.1.15.7.2 varbind 1.3.6.1.2.1.15.3.1.7.1 string \"198.51.100.1\" wait 4ms\n\n    // 2. NMS acknowledges receipt with matching reqid 910 so router stops retransmitting\n    wan_rtr <- nms_srv snmp3 response user \"wan-ops\" engineid \"80001f8880aabbccdd\" engineboots 8 enginetime 4200 auth sha256 \"WanAuthKey99!\" priv aes \"WanPrivKey99!\" reqid 910 varbind 1.3.6.1.2.1.15.3.1.7.1 string \"198.51.100.1\"\n}\n```\n\n## 10.06 · Rack UPS On-Battery Trap + Syslog Alert Correlation (`ups_battery_trap_syslog.frasm`)\n\nCombines an RFC 5424 critical Syslog event (UDP 514) with an SNMPv2c UPS\nbattery-power trap (UDP 162) to test NOC event deduplication and paging rules.\n\n- **Protocols:** `syslog`, `snmp2` (2 Ethernet frames)\n- **Wire Behavior:** Handy for testing Graylog/Splunk + Zabbix alert correlation\n  without flipping the breaker on the server-room PDU.\n- **Wireshark Filter:** `syslog || snmp`\n- **CLI Build:** `frameassembly ups_battery_trap_syslog.frasm`\n\n```frameassembly\n// Rack UPS management card and NOC monitoring collector\nhost rack_ups { ip 10.40.10.15 }\nhost noc_srv  { ip 10.40.1.100 }\n\ncompile {\n    // 1. Critical Syslog alert (facility 16 = local0, severity 2 = critical) on UDP 514\n    rack_ups -> noc_srv syslog facility 16 severity 2 hostname \"ups-row-b02\" app \"POWER\" msg \"Utility AC lost: switched to battery (est runtime 18 min)\" wait 3ms\n\n    // 2. Matching SNMPv2c UPS on-battery trap (1.3.6.1.2.1.33.2.1 = upsTrapOnBattery) on UDP 162\n    rack_ups -> noc_srv snmp2 trap community \"dc-facilities\" reqid 77 sysuptime 864000 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.2.1.33.2.1 varbind 1.3.6.1.2.1.33.1.2.3.0 int 18\n}\n```\n\n## 10.07 · SIP (VoIP) (`sip`): Complete VoIP Call Setup (`INVITE` + SDP), `RTP` Audio & `BYE` Hangup (`sip_rtp_voip_call.frasm`)\n\nEstablishes a SIP call with an `application/sdp` offer on VLAN 30, streams G.711\n`rtp` voice packets with `dscp 46` (EF), and hangs up cleanly via `bye` + `200\nOK`.\n\n- **Protocols:** `sip`, `vlan` (8 Ethernet frames)\n- **Wire Behavior:** Defaults to UDP `5060` (`SIP/2.0/UDP`) or switches `Via` and\n  Layer 4 to TCP `5060` (`SIP/2.0/TCP`) when `transport tcp` is added. Generates\n  mandatory RFC 3261 headers (`Via` with `branch=z9hG4bK...`, `From`, `To`,\n  `Call-ID`, `CSeq`, `Max-Forwards: 70`, `Contact`, and exact `Content-Length`).\n- **Wireshark Filter:** `sip`\n- **CLI Build:** `frameassembly show sip_rtp_voip_call.frasm`\n\n```frameassembly\nhost phone_a { ip 172.16.30.101 }\nhost sbc_01  { ip 172.16.30.10 }\n\ncompile {\n    // 1. SIP INVITE with SDP offer + 180 Ringing + 200 OK + SIP ACK\n    phone_a -> sbc_01 sip invite uri \"sip:2050@voice.internal\" from \"sip:1010@voice.internal\" to \"sip:2050@voice.internal\" callid \"voip-8801\" cseq 1 contenttype \"application/sdp\" body \"v=0\\r\\no=- 1 1 IN IP4 172.16.30.101\\r\\ns=-\\r\\nc=IN IP4 172.16.30.101\\r\\nt=0 0\\r\\nm=audio 5004 RTP/AVP 0\\r\\n\" vlan 30 dscp 24 wait 2ms\n    phone_a <- sbc_01 sip status 180 reason \"Ringing\" callid \"voip-8801\" cseq 1 vlan 30 dscp 24 wait 20ms\n    phone_a <- sbc_01 sip status 200 reason \"OK\" callid \"voip-8801\" cseq 1 vlan 30 dscp 24 wait 2ms\n    phone_a -> sbc_01 sip ack uri \"sip:2050@voice.internal\" callid \"voip-8801\" cseq 1 vlan 30 dscp 24 wait 5ms\n    // 2. Bidirectional G.711 PCMU RTP audio (DSCP 46 Expedited Forwarding)\n    phone_a -> sbc_01 rtp pt 0 seq 1 timestamp 160 ssrc 0x11223344 marker 1 payload \"g711-audio-1\" vlan 30 dscp 46 wait 20ms\n    phone_a <- sbc_01 rtp pt 0 seq 1 timestamp 160 ssrc 0x55667788 marker 1 payload \"g711-reply-1\" vlan 30 dscp 46 wait 20ms\n    // 3. Call hangup (BYE -> 200 OK)\n    phone_a -> sbc_01 sip bye uri \"sip:2050@voice.internal\" callid \"voip-8801\" cseq 2 vlan 30 dscp 24 wait 2ms\n    phone_a <- sbc_01 sip status 200 reason \"OK\" callid \"voip-8801\" cseq 2 vlan 30 dscp 24\n}\n```\n\n## 10.08 · RTP (Media) (`rtp`): G.711 VoIP Stream With Simulated WAN Jitter & Single-Packet Drop (`rtp_qos_jitter_lab.frasm`)\n\nEmits a G.711 PCMU (`pt 0`, 8 kHz = `+160` timestamp ticks per `20ms`) voice burst\ncontaining a skipped sequence number (`seq 3` dropped) and a `55ms` jitter spike.\n\n- **Protocols:** `rtp` (4 Ethernet frames)\n- **Wire Behavior:** Defaults to UDP destination port `5004` and writes RTP\n  Version `2` (`0x80`) in the upper bits of byte 0. Packs the 1-bit `marker` and\n  7-bit Payload Type (`pt`) cleanly into byte 1 (`(marker << 7) | pt`).\n- **Wireshark Filter:** `rtp`\n- **CLI Build:** `frameassembly show rtp_qos_jitter_lab.frasm`\n\n```frameassembly\nhost branch_phone { ip 172.16.30.21 }\nhost hq_gateway   { ip 172.16.1.10 }\n\ncompile {\n    // Normal 20ms pacing (+160 samples at 8000 Hz)\n    branch_phone -> hq_gateway rtp srcport 16384 dstport 16400 pt 0 seq 1 timestamp 160 ssrc 0xdeadbeef marker 1 dscp 46 payload \"audio-pkt-1\" wait 20ms\n    branch_phone -> hq_gateway rtp pt 0 seq 2 timestamp 320 ssrc 0xdeadbeef marker 0 dscp 46 payload \"audio-pkt-2\" wait 55ms\n    // seq 3 intentionally omitted to test 1-packet loss + 55ms jitter detection!\n    branch_phone -> hq_gateway rtp pt 0 seq 4 timestamp 640 ssrc 0xdeadbeef marker 0 dscp 46 payload \"audio-pkt-4\" wait 5ms\n    branch_phone -> hq_gateway rtp pt 0 seq 5 timestamp 800 ssrc 0xdeadbeef marker 0 dscp 46 payload \"audio-pkt-5\"\n}\n```\n\n## 10.09 · RTSP (`rtsp`): Full IP Camera RTSP Setup, PLAY, RTP Video Frame & TEARDOWN (`rtsp_camera_session.frasm`)\n\nWalks through TCP 554 connection setup, `DESCRIBE`, `SETUP`\n(`client_port=5004-5005`), `PLAY`, an H.264 `rtp pt 96` packet from the camera,\nand `TEARDOWN`.\n\n- **Protocols:** `rtsp`, `tcp` (11 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `554` (`psh ack`) and writes\n  `\n`-terminated `RTSP/1.0` lines with `CSeq`. Switches from an RTSP client request to\nan `RTSP/1.0 <status> OK` server reply whenever `status` is set.\n- **Wireshark Filter:** `rtsp`\n- **CLI Build:** `frameassembly show rtsp_camera_session.frasm`\n\n```frameassembly\nhost vms_nvr  { ip 192.168.60.10 }\nhost gate_cam { ip 192.168.60.105 }\n\ncompile {\n    vms_nvr -> gate_cam tcp syn srcport 51554 dstport 554 win 65535 mss 1460 wait 1ms\n    vms_nvr <- gate_cam tcp syn ack win 65535 mss 1460 wait 1ms\n    vms_nvr -> gate_cam tcp ack wait 1ms\n    vms_nvr -> gate_cam rtsp describe uri \"rtsp://192.168.60.105/h264\" cseq 1 wait 2ms\n    vms_nvr <- gate_cam rtsp status 200 cseq 1 wait 2ms\n    vms_nvr -> gate_cam rtsp setup uri \"rtsp://192.168.60.105/h264/trackID=1\" cseq 2 transporthdr \"RTP/AVP;unicast;client_port=5004-5005\" wait 2ms\n    vms_nvr <- gate_cam rtsp status 200 cseq 2 transporthdr \"RTP/AVP;unicast;client_port=5004-5005;server_port=8000-8001\" session \"98112233\" wait 2ms\n    vms_nvr -> gate_cam rtsp play uri \"rtsp://192.168.60.105/h264\" cseq 3 session \"98112233\" wait 2ms\n    vms_nvr <- gate_cam rtsp status 200 cseq 3 session \"98112233\" wait 5ms\n    // Camera sends H.264 RTP packet (pt 96) to client port 5004\n    gate_cam -> vms_nvr rtp srcport 8000 dstport 5004 pt 96 seq 1 timestamp 90000 ssrc 0xcafebabe marker 1 payload \"h264-nal-idr\" wait 10ms\n    vms_nvr -> gate_cam rtsp teardown uri \"rtsp://192.168.60.105/h264\" cseq 4 session \"98112233\"\n}\n```\n\n## 10.10 · STUN (NAT) (`stun`): Dual-Stack IPv4 & IPv6 WebRTC ICE STUN Discovery + Error Response (`stun_webrtc_ice.frasm`)\n\nPerforms an IPv4 STUN check on port 19302, an IPv6 STUN check on port 3478, and a\n`bindingerror` (`0x0111`) test.\n\n- **Protocols:** `stun` (5 Ethernet frames)\n- **Wire Behavior:** Defaults to UDP destination port `3478` and writes the\n  mandatory RFC 5389 magic cookie `0x2112a442` in bytes 4..7. XOR-encodes IPv4\n  (`32-bit ^ 0x2112a442`) and IPv6 (`128-bit ^ (0x2112a442 || txid)`)\n  `xormappedaddr` attributes (`0x0020`) automatically.\n- **Wireshark Filter:** `stun`\n- **CLI Build:** `frameassembly show stun_webrtc_ice.frasm`\n\n```frameassembly\nhost client_v4 { ip 172.16.10.25 }\nhost stun_v4   { ip 198.51.100.10 }\nhost client_v6 { ip 2001:db8:10::25 }\nhost stun_v6   { ip 2001:db8:99::3478 }\n\ncompile {\n    // 1. WebRTC UDP 19302 STUN check returning NAT public IPv4 203.0.113.50\n    client_v4 -> stun_v4 stun bindingrequest dstport 19302 txid 0xa1b2c3d4 software \"Chromium-ICE\" wait 2ms\n    client_v4 <- stun_v4 stun bindingresponse txid 0xa1b2c3d4 xormappedaddr 203.0.113.50 software \"coturn-4.6\" wait 4ms\n    // 2. IPv6 STUN Binding check + Error response\n    client_v6 -> stun_v6 stun bindingrequest txid 0x55667788 wait 2ms\n    client_v6 <- stun_v6 stun bindingresponse txid 0x55667788 xormappedaddr 2001:db8:10::25 wait 3ms\n    client_v4 <- stun_v4 stun bindingerror txid 0x99990000\n}\n```\n\n## 10.11 · SMTP (`smtp`): Complete End-to-End RFC 5321 Email Delivery Transaction (`smtp_full_envelope.frasm`)\n\nWalks through a full TCP 25 session from `220` banner and `EHLO` through `MAIL\nFROM`, `RCPT TO`, `DATA` (`354`), message headers/body, `250 Queued`, and `QUIT`.\n\n- **Protocols:** `smtp`, `tcp` (16 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `25` (`psh ack`; use\n  `dstport 587` for submission) and terminates SMTP lines with `\n`. Formats `MAIL FROM:<...>` (`mailfrom`) and `RCPT TO:<...>` (`rcptto`) cleanly\nand terminates `body` payloads with `\n.\n` when needed.\n- **Wireshark Filter:** `smtp`\n- **CLI Build:** `frameassembly show smtp_full_envelope.frasm`\n\n```frameassembly\nhost alert_bot { ip 172.16.15.20 }\nhost smtp_relay { ip 172.16.15.25 }\n\ncompile {\n    alert_bot -> smtp_relay tcp syn srcport 52025 dstport 25 win 65535 mss 1460 wait 1ms\n    alert_bot <- smtp_relay tcp syn ack win 65535 mss 1460 wait 1ms\n    alert_bot -> smtp_relay tcp ack wait 1ms\n    alert_bot <- smtp_relay smtp code 220 reply \"relay.corp.internal ESMTP\" wait 2ms\n    alert_bot -> smtp_relay smtp ehlo \"alert-bot.corp.internal\" wait 1ms\n    alert_bot <- smtp_relay smtp code 250 reply \"PIPELINING\" wait 1ms\n    alert_bot -> smtp_relay smtp mailfrom \"<noc-alerts@corp.internal>\" wait 1ms\n    alert_bot <- smtp_relay smtp code 250 reply \"2.1.0 Ok\" wait 1ms\n    alert_bot -> smtp_relay smtp rcptto \"<oncall@corp.internal>\" wait 1ms\n    alert_bot <- smtp_relay smtp code 250 reply \"2.1.5 Ok\" wait 1ms\n    alert_bot -> smtp_relay smtp data wait 1ms\n    alert_bot <- smtp_relay smtp code 354 reply \"End data with <CR><LF>.<CR><LF>\" wait 2ms\n    alert_bot -> smtp_relay smtp body \"Subject: Core Link Down\\r\\nFrom: noc-alerts@corp.internal\\r\\n\\r\\nGi1/0/49 went down.\\r\\n.\" wait 2ms\n    alert_bot <- smtp_relay smtp code 250 reply \"2.0.0 Ok: queued as 9F4A1\" wait 1ms\n    alert_bot -> smtp_relay smtp quit wait 1ms\n    alert_bot <- smtp_relay smtp code 221 reply \"2.0.0 Bye\"\n}\n```\n\n## 10.12 · IMAP4 (`imap`): Cleartext IMAP Login Failure Followed by Authorized Inbox Selection (`imap_login_audit.frasm`)\n\nCaptures an untagged server greeting, a failed `A01 LOGIN` returning `NO`, and an\nauthorized `A02 LOGIN` + `A03 SELECT INBOX`.\n\n- **Protocols:** `imap`, `tcp` (10 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `143` (`psh ack`) and\n  appends `\n` to every IMAP command or response line. Formats `<tag> <cmd> <arg>\n` on client requests and `<tag> <status> <response>\n` when `status` or `response` is provided.\n- **Wireshark Filter:** `imap`\n- **CLI Build:** `frameassembly show imap_login_audit.frasm`\n\n```frameassembly\nhost laptop   { ip 172.16.25.44 }\nhost mail_box { ip 172.16.25.10 }\n\ncompile {\n    laptop -> mail_box tcp syn srcport 52143 dstport 143 win 65535 mss 1460 wait 1ms\n    laptop <- mail_box tcp syn ack win 65535 mss 1460 wait 1ms\n    laptop -> mail_box tcp ack wait 1ms\n    laptop <- mail_box imap tag \"*\" status \"OK\" response \"IMAP4rev1 Service Ready\" wait 2ms\n    // 1. Failed login -> tagged NO\n    laptop -> mail_box imap tag \"A01\" cmd \"LOGIN\" arg \"jdoe WrongPass1\" wait 3ms\n    laptop <- mail_box imap tag \"A01\" status \"NO\" response \"LOGIN failed.\" wait 5ms\n    // 2. Valid login + SELECT INBOX\n    laptop -> mail_box imap tag \"A02\" cmd \"LOGIN\" arg \"jdoe LabPass2026\" wait 2ms\n    laptop <- mail_box imap tag \"A02\" status \"OK\" response \"LOGIN completed\" wait 2ms\n    laptop -> mail_box imap tag \"A03\" cmd \"SELECT\" arg \"INBOX\" wait 2ms\n    laptop <- mail_box imap tag \"A03\" status \"OK\" response \"[READ-WRITE] SELECT completed\"\n}\n```\n\n## 10.13 · POP3 (`pop3`): POP3 Failed Login (`-ERR`) + Successful Mailbox `STAT` & `QUIT` (`pop3_session_audit.frasm`)\n\nEstablishes a TCP 110 session, captures a rejected password attempt (`err`), then\ncompletes `USER` -> `PASS` -> `STAT` -> `QUIT`.\n\n- **Protocols:** `pop3`, `tcp` (16 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `110` (`psh ack`) and\n  appends `\n` per RFC 1939. Formats `+OK <response>\n` on `ok` and `-ERR <response>\n` on `err`.\n- **Wireshark Filter:** `pop`\n- **CLI Build:** `frameassembly show pop3_session_audit.frasm`\n\n```frameassembly\nhost workstation { ip 172.16.16.40 }\nhost legacy_mail { ip 172.16.16.110 }\n\ncompile {\n    workstation -> legacy_mail tcp syn srcport 52110 dstport 110 win 65535 mss 1460 wait 1ms\n    workstation <- legacy_mail tcp syn ack win 65535 mss 1460 wait 1ms\n    workstation -> legacy_mail tcp ack wait 1ms\n    workstation <- legacy_mail pop3 ok response \"Dovecot POP3 ready.\" wait 2ms\n    workstation -> legacy_mail pop3 cmd \"USER\" arg \"ops_scanner\" wait 1ms\n    workstation <- legacy_mail pop3 ok response \"Pass required\" wait 1ms\n    workstation -> legacy_mail pop3 cmd \"PASS\" arg \"BadPass1\" wait 4ms\n    workstation <- legacy_mail pop3 err response \"[AUTH] Authentication failed.\" wait 5ms\n    workstation -> legacy_mail pop3 cmd \"USER\" arg \"ops_scanner\" wait 1ms\n    workstation <- legacy_mail pop3 ok wait 1ms\n    workstation -> legacy_mail pop3 cmd \"PASS\" arg \"LabPass99\" wait 2ms\n    workstation <- legacy_mail pop3 ok response \"Logged in.\" wait 1ms\n    workstation -> legacy_mail pop3 cmd \"STAT\" wait 1ms\n    workstation <- legacy_mail pop3 ok response \"3 4096\" wait 1ms\n    workstation -> legacy_mail pop3 cmd \"QUIT\" wait 1ms\n    workstation <- legacy_mail pop3 ok response \"Logging out.\"\n}\n```\n\n## 10.14 · SNMPv1 (`snmp1`): SNMPv1 System MIB Poll (`sysDescr.0` / `sysName.0`) + ColdStart & Enterprise Traps (`snmp1_poll_and_traps.frasm`)\n\nPolls `sysDescr.0` on UDP 161, returns a multi-varbind `response`, and emits both\na standard `gentrap 0` (`coldStart`) and an `enterpriseSpecific` (`gentrap 6`)\nhardware alarm trap on UDP 162.\n\n- **Protocols:** `snmp1` (4 Ethernet frames)\n- **Wire Behavior:** Selects UDP `dstport 162` automatically for `trap` (the\n  default PDU) and UDP `161` (with `161 -> ephemeral` port reversal on `<-\n  response`) for `get`, `getnext`, `set`, and `response`. Encodes dotted numeric\n  OIDs (`1.3.6.1.4.1.318` or `.1.3.6.1...`) into compact ASN.1 BER base-128 VLQ\n  octets (`0x2b 0x06 0x01 ...`) and computes nested SEQUENCE lengths.\n- **Wireshark Filter:** `snmp`\n- **CLI Build:** `frameassembly show snmp1_poll_and_traps.frasm`\n\n```frameassembly\nhost poller   { ip 172.16.40.10 }\nhost legacy_sw { ip 172.16.40.25 }\n\ncompile {\n    // 1. Poll sysDescr.0 (1.3.6.1.2.1.1.1.0) on UDP 161\n    poller -> legacy_sw snmp1 get community \"ops-ro\" reqid 1001 oid 1.3.6.1.2.1.1.1.0 wait 2ms\n    poller <- legacy_sw snmp1 response community \"ops-ro\" reqid 1001 varbind 1.3.6.1.2.1.1.1.0 string \"Managed L2 Switch v4.2\" varbind 1.3.6.1.2.1.1.3.0 timeticks 8640000 wait 5ms\n    // 2. Generic coldStart trap (gentrap 0, spectrap 0) on UDP 162\n    legacy_sw -> poller snmp1 trap community \"ops-ro\" enterprise 1.3.6.1.4.1.9.1.516 agentip 172.16.40.25 gentrap 0 spectrap 0 sysuptime 120 wait 2ms\n    // 3. Enterprise-specific PSU fault trap (gentrap 6, spectrap 42) with typed varbinds\n    legacy_sw -> poller snmp1 trap community \"ops-ro\" enterprise 1.3.6.1.4.1.9.9.13 gentrap 6 spectrap 42 sysuptime 45000 varbind 1.3.6.1.2.1.1.5.0 string \"sw-idf-03\" varbind 1.3.6.1.4.1.9.9.13.1.5.1.3.1 int 4\n}\n```\n\n## 10.15 · SNMPv2c (`snmp2`): ifXTable 64-Bit Counter Walk + Acknowledged SNMPv2c LinkDown Inform (`snmp2_getbulk_and_inform.frasm`)\n\nWalks 64-bit high-capacity interface counters via `getbulk` on UDP 161, then\ndelivers a reliable `snmp2 inform` (`linkDown` `1.3.6.1.6.3.1.1.5.3`) on UDP 162\nwith manager `response` acknowledgment.\n\n- **Protocols:** `snmp2` (4 Ethernet frames)\n- **Wire Behavior:** Encodes `GetBulkRequest` (`0xa5`) overloading the BER\n  error-status and error-index slots with `nonrepeaters` (default `0`) and\n  `maxrepetitions` (default `10`) per RFC 3416. Automatically prepends\n  `1.3.6.1.2.1.1.3.0` (`sysUpTime.0` `TimeTicks`) on `trap` (`0xa7`), `inform`\n  (`0xa6`), and `report` (`0xa8`) when `sysuptime` is specified.\n- **Wireshark Filter:** `snmp`\n- **CLI Build:** `frameassembly show snmp2_getbulk_and_inform.frasm`\n\n```frameassembly\nhost nms_poller { ip 10.30.10.20 }\nhost dist_sw    { ip 10.30.10.1 }\n\ncompile {\n    // 1. High-capacity 64-bit interface counter bulk poll on UDP 161\n    nms_poller -> dist_sw snmp2 getbulk community \"infra-ro\" reqid 2001 nonrepeaters 1 maxrepetitions 5 varbind 1.3.6.1.2.1.1.3.0 null varbind 1.3.6.1.2.1.31.1.1.1.6 null wait 2ms\n    nms_poller <- dist_sw snmp2 response community \"infra-ro\" reqid 2001 varbind 1.3.6.1.2.1.1.3.0 timeticks 43200000 varbind 1.3.6.1.2.1.31.1.1.1.6.101 counter64 184502910440 varbind 1.3.6.1.2.1.31.1.1.1.1.101 string \"TenGigabitEthernet1/0/1\" wait 5ms\n    // 2. Acknowledged SNMPv2c InformRequest for linkDown (1.3.6.1.6.3.1.1.5.3) on UDP 162\n    dist_sw -> nms_poller snmp2 inform community \"infra-trap\" reqid 9001 sysuptime 43200500 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.2.2.1.1.101 int 101 varbind 1.3.6.1.2.1.2.2.1.8.101 int 2 wait 1ms\n    dist_sw <- nms_poller snmp2 response community \"infra-trap\" reqid 9001 varbind 1.3.6.1.2.1.1.3.0 timeticks 43200500 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3\n}\n```\n\n## 10.16 · SNMPv3 USM (authPriv) (`snmp3`): Full RFC 3414 Engine Discovery (`report`) + SHA-256/AES-128 `authPriv` Poll & Trap (`snmp3_usm_discovery_and_authpriv.frasm`)\n\nWalks through RFC 3414 USM engine discovery (`usmStatsUnknownEngineIDs.0`),\nauthenticated/encrypted `get` + `response` on UDP 161, and an `authPriv` encrypted\n`snmp3 trap` on UDP 162.\n\n- **Protocols:** `snmp3` (5 Ethernet frames)\n- **Wire Behavior:** Derives `msgFlags` automatically from provided credentials:\n  `noAuthNoPriv` (neither set), `authNoPriv` (`auth` only), or `authPriv` (`auth`\n  + `priv`, setting `0x03`, plus `0x04` Reportable on requests/informs). Runs RFC\n  3414 / RFC 7860 password-to-key (`Ku`, 1 MiB expansion) and engine-localized\n  (`Kul`) derivation for `md5`, `sha` (SHA-1), `sha256`, `sha384`, and `sha512`.\n- **Wireshark Filter:** `snmp`\n- **CLI Build:** `frameassembly show snmp3_usm_discovery_and_authpriv.frasm`\n\n```frameassembly\nhost zabbix_srv { ip 172.18.10.50 }\nhost core_rtr   { ip 172.18.10.1 }\n\ncompile {\n    // 1. Unauthenticated USM EngineID discovery probe -> Agent replies with Report PDU\n    zabbix_srv -> core_rtr snmp3 get user \"\" reqid 100 wait 1ms\n    zabbix_srv <- core_rtr snmp3 report user \"\" engineid \"80001f8880aabbccdd\" engineboots 5 enginetime 8420 reqid 100 varbind 1.3.6.1.6.3.15.1.1.4.0 counter32 1 wait 3ms\n    // 2. Encrypted authPriv (HMAC-SHA-256 + AES-128-CFB) GET & RESPONSE on UDP 161\n    zabbix_srv -> core_rtr snmp3 get user \"nms-v3-prod\" engineid \"80001f8880aabbccdd\" engineboots 5 enginetime 8420 auth sha256 \"StrongAuthKey2026!\" priv aes \"StrongPrivKey2026!\" reqid 101 oid 1.3.6.1.2.1.1.5.0 wait 2ms\n    zabbix_srv <- core_rtr snmp3 response user \"nms-v3-prod\" engineid \"80001f8880aabbccdd\" engineboots 5 enginetime 8420 auth sha256 \"StrongAuthKey2026!\" priv aes \"StrongPrivKey2026!\" reqid 101 varbind 1.3.6.1.2.1.1.5.0 string \"core-rtr-fra1.internal\" wait 5ms\n    // 3. Encrypted authPriv SNMPv3 Trap on UDP 162 (authoritative sender = core_rtr)\n    core_rtr -> zabbix_srv snmp3 trap user \"nms-v3-prod\" engineid \"80001f8880aabbccdd\" engineboots 5 enginetime 8425 auth sha256 \"StrongAuthKey2026!\" priv aes \"StrongPrivKey2026!\" sysuptime 842500 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.4 varbind 1.3.6.1.2.1.2.2.1.2.1 string \"HundredGigE0/0/0/1\"\n}\n```\n\n## 10.17 · Syslog (`syslog`): Multi-Severity Security Audit over UDP 514 & Reliable TCP 514 (`syslog_siem_pipeline.frasm`)\n\nSends a firewall drop alert and OSPF adjacency warning over UDP 514, then opens a\nTCP 514 session to deliver a high-priority authentication alert.\n\n- **Protocols:** `syslog`, `tcp` (6 Ethernet frames)\n- **Wire Behavior:** Computes `<PRI> = facility * 8 + severity` automatically\n  (default `facility 16` `local0`, `severity 6` `info` -> `<134>`). Formats a\n  complete RFC 5424 `<PRI>1 TIMESTAMP HOSTNAME APP PROCID MSGID - MSG` wire\n  payload that Wireshark and syslog-ng/rsyslog parse out of the box.\n- **Wireshark Filter:** `syslog`\n- **CLI Build:** `frameassembly show syslog_siem_pipeline.frasm`\n\n```frameassembly\nhost branch_fw { ip 172.16.1.1 }\nhost log_relay { ip 172.16.100.10 }\n\ncompile {\n    // 1. Stateless UDP 514 security & routing logs\n    branch_fw -> log_relay syslog facility 4 severity 4 hostname \"branch-fw-01\" app \"filterlog\" msgid \"DROP\" msg \"Blocked TCP SYN 203.0.113.99:44112 -> 172.16.1.10:3389\" wait 2ms\n    branch_fw -> log_relay syslog facility 16 severity 3 hostname \"branch-fw-01\" app \"ospfd\" msgid \"ADJCHG\" msg \"Neighbor 172.16.0.2 Down: Dead timer expired\" wait 4ms\n    // 2. Reliable TCP 514 syslog stream (transport tcp)\n    branch_fw -> log_relay tcp syn srcport 52514 dstport 514 win 65535 mss 1460 wait 1ms\n    branch_fw <- log_relay tcp syn ack win 65535 mss 1460 wait 1ms\n    branch_fw -> log_relay tcp ack wait 1ms\n    branch_fw -> log_relay syslog facility 10 severity 2 hostname \"branch-fw-01\" app \"sudo\" procid \"4812\" msg \"Critical privilege escalation alert\" transport tcp\n}\n```\n\n## 10.18 · NetFlow v5 (`netflow`): Multi-Flow Export: HTTPS Upload Spike, DNS Lookup & ICMP Probe (`netflow_collector_test.frasm`)\n\nExports three sequential NetFlow v5 records from a border router representing a\nlarge HTTPS transfer, a UDP DNS query, and an ICMP ping flow.\n\n- **Protocols:** `netflow` (3 Ethernet frames)\n- **Wire Behavior:** Defaults UDP destination port to `2055` and builds the exact\n  24-byte NetFlow v5 header + 48-byte flow record (`72` UDP payload bytes).\n  Populates protocol defaults (`proto 6` TCP, `packets 10`, `octets 1500`)\n  whenever counters are omitted.\n- **Wireshark Filter:** `cflow`\n- **CLI Build:** `frameassembly show netflow_collector_test.frasm`\n\n```frameassembly\nhost border_rtr     { ip 172.16.0.1 }\nhost flow_collector { ip 172.16.100.55 }\n\ncompile {\n    // 1. Large outbound HTTPS transfer (proto 6 = TCP)\n    border_rtr -> flow_collector netflow srcip 10.20.5.14 dstip 203.0.113.80 srcport 54120 dstport 443 proto 6 packets 8500 octets 12240000 wait 2ms\n    // 2. Internal-to-DMZ DNS flow (proto 17 = UDP)\n    border_rtr -> flow_collector netflow srcip 10.20.5.14 dstip 172.16.10.53 srcport 59102 dstport 53 proto 17 packets 2 octets 148 wait 2ms\n    // 3. ICMP reachability flow (proto 1 = ICMP)\n    border_rtr -> flow_collector netflow srcip 10.20.5.14 dstip 8.8.8.8 srcport 0 dstport 0 proto 1 packets 4 octets 336\n}\n```\n\n## 10.19 · IPFIX (`ipfix`): Mixed IPv4 & IPv6 VRF Flow Telemetry to an IPFIX Collector (`ipfix_dualstack_flows.frasm`)\n\nExports an IPv4 enterprise HTTPS flow (`domainid 10`) followed by an IPv6\nservice-mesh gRPC flow (`domainid 20`) to UDP port 4739.\n\n- **Protocols:** `ipfix` (2 Ethernet frames)\n- **Wire Behavior:** Defaults to UDP destination port `4739` and builds the\n  16-byte IPFIX Version `0x000a` header with exact total message length and\n  Observation Domain ID. Bundles a self-describing Template Set (`Set ID 2`,\n  Template ID `256`) plus the Data Set (`Set ID 256`) in one UDP datagram.\n- **Wireshark Filter:** `cflow.version == 10`\n- **CLI Build:** `frameassembly show ipfix_dualstack_flows.frasm`\n\n```frameassembly\nhost spine_exporter { ip 172.20.0.1 }\nhost ipfix_ingest   { ip 172.20.50.10 }\n\ncompile {\n    // 1. VRF 10 IPv4 flow record\n    spine_exporter -> ipfix_ingest ipfix domainid 10 srcip 10.100.4.15 dstip 203.0.113.44 srcport 50112 dstport 443 proto 6 packets 420 octets 512000 wait 3ms\n    // 2. VRF 20 IPv6 flow record over the same exporter session\n    spine_exporter -> ipfix_ingest ipfix domainid 20 srcip 2001:db8:20::15 dstip 2001:db8:99::5051 srcport 54200 dstport 50051 proto 6 packets 95 octets 84000\n}\n```\n\n## 10.20 · sFlow v5 (`sflow`): Multi-Switch Leaf-Spine sFlow v5 Telemetry Stream (`sflow_leaf_spine.frasm`)\n\nSimulates two leaf switches exporting sequential sFlow v5 datagrams (including an\nIPv6 loopback agent IP) to a central collector.\n\n- **Protocols:** `sflow` (3 Ethernet frames)\n- **Wire Behavior:** Defaults UDP destination port to `6343` and aligns all fields\n  to 4-byte XDR boundaries per the sFlow v5 specification. Sets Agent Address Type\n  to `1` (4-byte IPv4) or `2` (16-byte IPv6) automatically from `agentip`.\n- **Wireshark Filter:** `sflow`\n- **CLI Build:** `frameassembly show sflow_leaf_spine.frasm`\n\n```frameassembly\nhost leaf_01   { ip 172.18.1.11 }\nhost leaf_02   { ip 172.18.1.12 }\nhost collector { ip 172.18.100.50 }\n\ncompile {\n    leaf_01 -> collector sflow agentip 172.18.1.11 subagentid 0 seq 101 uptime 450000 samples 1 wait 2ms\n    leaf_01 -> collector sflow agentip 172.18.1.11 subagentid 0 seq 102 uptime 451000 samples 1 wait 2ms\n    leaf_02 -> collector sflow agentip 2001:db8:18::12 subagentid 1 seq 55 uptime 820000 samples 1\n}\n```\n"}
{"id":"pretrain-anthology-industrial-ics-scada-ot","kind":"examples_anthology","title":"Industrial ICS/SCADA & IIoT Captures (Modbus, DNP3, S7comm, OPC UA) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/industrial-ics-scada-ot","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","modbus","dnp3","s7comm","opcua","coap","bacnet","ethernetip"],"text":"# Industrial ICS/SCADA & IIoT Captures (Modbus, DNP3, S7comm, OPC UA)\n\n> **FrameAssembly v3.3.0** · Anthology 11 (Layer 7 · 14 Recipes) · MIT License ·\n> Canonical URL:\n> https://frameassembly-lang.dev/docs/examples/industrial-ics-scada-ot\n\nPurdue-model OT firewall and passive ICS sensor validation across `modbus`, `dnp3`\n(reflected 0x3d65 CRC-16), Siemens `s7comm`, `opcua`, `bacnet`, `ethernetip` CIP,\nand constrained `coap`.\n\n## Key Wire & Syntax Takeaways\n\n- `modbus`, `dnp3`, and `ethernetip` are whitelisted dual-transport protocols\n  supporting both stateful TCP conduits and `transport udp` I/O polling.\n- `dnp3` computes IEEE 1815 reflected `0x3d65` CRC-16s over link headers and\n  16-byte data chunks automatically (or accepts `crc <u16>` negative tests).\n- `s7comm` wraps TPKT + ISO 8073 COTP + Siemens `0x32` PDUs on TCP 102, while\n  `opcua` frames binary `HEL`/`ACK`/`OPN`/`MSG`/`CLO` chunks on TCP 4840.\n\n## 11.01 · Modbus TCP Register Poll vs. Modbus-over-UDP Serial Gateway (transport udp) (`modbus_tcp_and_udp_conduit.frasm`)\n\nTests Purdue Level 2 industrial firewall rules for standard Modbus/TCP polling\nalongside a serial-to-Ethernet gateway configured for UDP 502.\n\n- **Protocols:** `tcp`, `modbus` (6 Ethernet frames)\n- **Wire Behavior:** Encodes the 7-byte MBAP header (txid, protoid 0, length,\n  unitid) across both TCP 502 and transport udp.\n- **Wireshark Filter:** `mbtcp || modbus`\n- **CLI Build:** `frameassembly modbus_tcp_and_udp_conduit.frasm`\n\n```frameassembly\nhost scada_poller { ip 10.110.10.10 }\nhost plc_rack_01  { ip 10.110.20.50 }\nhost rtu_gw_udp   { ip 10.110.20.60 }\n\ncompile {\n    scada_poller -> plc_rack_01 tcp syn srcport 50502 dstport 502 win 65535 mss 1460 wait 1ms\n    scada_poller <- plc_rack_01 tcp syn ack win 65535 mss 1460 wait 1ms\n    scada_poller -> plc_rack_01 tcp ack wait 1ms\n    scada_poller -> plc_rack_01 modbus readholdingregisters txid 101 unitid 1 addr 40001 count 4 wait 2ms\n    scada_poller <- plc_rack_01 modbus readholdingregisters isresponse txid 101 unitid 1 count 4 wait 5ms\n    scada_poller -> rtu_gw_udp modbus readinputregisters txid 201 unitid 2 addr 30001 count 2 transport udp\n}\n```\n\n## 11.02 · DNP3 Valid IEEE 1815 CRC-16 vs. Intentional Corrupted CRC Negative Test (`dnp3_crc_negative_validation.frasm`)\n\nSends a valid UDP 20000 DNP3 Analog Input read (auto CRC-16) followed by an\nexplicit corrupted crc 0xdead packet to verify OT IDS malformed-frame alerts.\n\n- **Protocols:** `dnp3` (3 Ethernet frames)\n- **Wire Behavior:** Omitting crc computes exact reflected 0x3d65 CRC-16s; setting\n  crc 0xdead overrides the link-header checksum intentionally.\n- **Wireshark Filter:** `dnp3`\n- **CLI Build:** `frameassembly dnp3_crc_negative_validation.frasm`\n\n```frameassembly\nhost sub_master { ip 172.25.0.10 }\nhost bay_rtu    { ip 172.25.0.25 }\n\ncompile {\n    sub_master -> bay_rtu dnp3 read src 1 dst 25 group 30 variation 1 transport udp wait 5ms\n    sub_master <- bay_rtu dnp3 response src 25 dst 1 group 30 variation 1 transport udp wait 10ms\n    sub_master -> bay_rtu dnp3 read src 1 dst 25 group 30 variation 1 crc 0xdead transport udp\n}\n```\n\n## 11.03 · Minimal Two-Block Modbus TCP (`modbus`) Quickstart (`modbus_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Modbus TCP / UDP\nIndustrial Application Protocol (TCP 502 (or UDP 502 via transport udp),\nDual-Stack IPv4/IPv6).\n\n- **Protocols:** `modbus` (5 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `502` (`psh ack`), Protocol\n  ID `0`, `unitid 1`, and computes the 16-bit MBAP `Length` (`unitid + PDU bytes`)\n  automatically.\n- **Wireshark Filter:** `mbtcp || modbus`\n- **CLI Build:** `frameassembly modbus_quickstart.frasm`\n\n```frameassembly\nhost scada_hmi { ip 192.168.100.10 }\nhost plc_pump1 { ip 192.168.100.50 }\n\ncompile {\n    scada_hmi -> plc_pump1 tcp syn srcport 50502 dstport 502 wait 1ms\n    scada_hmi <- plc_pump1 tcp syn ack wait 1ms\n    scada_hmi -> plc_pump1 tcp ack wait 1ms\n    scada_hmi -> plc_pump1 modbus readholdingregisters txid 1 unitid 1 addr 100 count 2 wait 3ms\n    scada_hmi <- plc_pump1 modbus readholdingregisters txid 1 unitid 1 count 2 value 1500 isresponse\n}\n```\n\n## 11.04 · Minimal Two-Block DNP3 (IEEE 1815) (`dnp3`) Quickstart (`dnp3_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Distributed Network\nProtocol 3 (Electric & Water Utilities) (TCP 20000 (or UDP 20000 via transport\nudp), Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `dnp3` (5 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `20000` (`transport udp`\n  switches to UDP `20000`) and builds the `0x0564` Data Link + Transport\n  (`FIN|FIR`) + Application headers.\n- **Wireshark Filter:** `dnp3`\n- **CLI Build:** `frameassembly dnp3_quickstart.frasm`\n\n```frameassembly\nhost scada_master { ip 10.100.1.10 }\nhost sub_rtu_10   { ip 10.100.2.10 }\n\ncompile {\n    scada_master -> sub_rtu_10 tcp syn srcport 52000 dstport 20000 wait 1ms\n    scada_master <- sub_rtu_10 tcp syn ack wait 1ms\n    scada_master -> sub_rtu_10 tcp ack wait 1ms\n    scada_master -> sub_rtu_10 dnp3 read src 1 dst 10 group 30 variation 1 wait 3ms\n    scada_master <- sub_rtu_10 dnp3 response src 10 dst 1 group 30 variation 1\n}\n```\n\n## 11.05 · Minimal Two-Block Siemens S7comm (`s7comm`) Quickstart (`s7comm_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Siemens S7 Communication\nProtocol over ISO-on-TCP (TCP 102 (ISO-on-TCP), Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `s7comm` (6 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `102` (`psh ack`) and\n  computes the outer 4-byte TPKT (`0x03 0x00 <len>`) + 3-byte COTP DT (`0x02 0xf0\n  0x80`) framing automatically.\n- **Wireshark Filter:** `s7comm`\n- **CLI Build:** `frameassembly s7comm_quickstart.frasm`\n\n```frameassembly\nhost wincc_hmi { ip 192.168.10.20 }\nhost s7_plc    { ip 192.168.10.100 }\n\ncompile {\n    wincc_hmi -> s7_plc tcp syn srcport 50102 dstport 102 wait 1ms\n    wincc_hmi <- s7_plc tcp syn ack wait 1ms\n    wincc_hmi -> s7_plc tcp ack wait 1ms\n    wincc_hmi -> s7_plc s7comm rosctr \"job\" setupcomm pduref 1 wait 2ms\n    wincc_hmi <- s7_plc s7comm rosctr \"ackdata\" setupcomm pduref 1 wait 2ms\n    wincc_hmi -> s7_plc s7comm rosctr \"job\" readvar pduref 2 area 0x84 dbnum 1 offset 0 count 4\n}\n```\n\n## 11.06 · Minimal Two-Block OPC UA (`opcua`) Quickstart (`opcua_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for OPC Unified Architecture\nBinary TCP Protocol (TCP 4840, Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `opcua` (5 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `4840` (`psh ack`), `msgtype\n  \"HEL\"`, `chunktype \"F\"`, and calculates the 4-byte little-endian `MessageSize`\n  across the entire OPC UA frame.\n- **Wireshark Filter:** `opcua`\n- **CLI Build:** `frameassembly opcua_quickstart.frasm`\n\n```frameassembly\nhost historian { ip 10.130.35.10 }\nhost ua_server { ip 10.130.20.48 }\n\ncompile {\n    historian -> ua_server tcp syn srcport 54840 dstport 4840 wait 1ms\n    historian <- ua_server tcp syn ack wait 1ms\n    historian -> ua_server tcp ack wait 1ms\n    historian -> ua_server opcua msgtype \"HEL\" chunktype \"F\" endpointurl \"opc.tcp://10.130.20.48:4840\" wait 2ms\n    historian <- ua_server opcua msgtype \"ACK\" chunktype \"F\"\n}\n```\n\n## 11.07 · Minimal Two-Block CoAP (IoT) (`coap`) Quickstart (`coap_quickstart.frasm`)\n\nSmallest zero-boilerplate `host` + `compile` capture for Constrained Application\nProtocol (UDP 5683 (or RFC 8323 transport tcp), Dual-Stack IPv4/IPv6).\n\n- **Protocols:** `coap` (2 Ethernet frames)\n- **Wire Behavior:** Defaults to UDP destination port `5683` and packs CoAP\n  Version `1`, 2-bit Type, Token Length (`TKL`), 1-byte `c.dd` Code (`(class << 5)\n  | detail`), and 16-bit `msgid`.\n- **Wireshark Filter:** `coap`\n- **CLI Build:** `frameassembly coap_quickstart.frasm`\n\n```frameassembly\nhost sensor_01 { ip 10.70.1.50 }\nhost iot_gw    { ip 10.70.1.1 }\n\ncompile {\n    sensor_01 -> iot_gw coap con post msgid 101 token 0x4a1b uripath \"telemetry/humidity\" contentformat 50 payload \"{\\\"rh\\\":48.2}\" wait 3ms\n    sensor_01 <- iot_gw coap ack changed msgid 101 token 0x4a1b\n}\n```\n\n## 11.08 · Modbus TCP (`modbus`): Normal Historian Read Polling (`FC 3`) + Unauthorized Coil/Register Write (`FC 5` / `FC 6`) (`modbus_ot_conduit_test.frasm`)\n\nModels an HMI polling Holding Registers on Unit 1 (`FC 3` request + `isresponse`\nreply), followed by a `writesinglecoil` (`FC 5`) and `writesingleregister` (`FC\n6`) command to test OT write-detection alarms.\n\n- **Protocols:** `modbus`, `tcp` (8 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `502` (`psh ack`), Protocol\n  ID `0`, `unitid 1`, and computes the 16-bit MBAP `Length` (`unitid + PDU bytes`)\n  automatically. Formats client Request PDUs (`addr` + `count` / `value`) by\n  default, and switches to PLC Response PDUs (`byte_count` + register/coil values)\n  when `isresponse` is set.\n- **Wireshark Filter:** `mbtcp || modbus`\n- **CLI Build:** `frameassembly show modbus_ot_conduit_test.frasm`\n\n```frameassembly\nhost hmi_01   { ip 10.100.10.15 }\nhost vfd_plc  { ip 10.100.20.50 }\n\ncompile {\n    hmi_01 -> vfd_plc tcp syn srcport 51502 dstport 502 win 65535 mss 1460 wait 1ms\n    hmi_01 <- vfd_plc tcp syn ack win 65535 mss 1460 wait 1ms\n    hmi_01 -> vfd_plc tcp ack wait 1ms\n    // 1. Authorized Read Holding Registers (FC 3) + PLC Response (isresponse)\n    hmi_01 -> vfd_plc modbus readholdingregisters txid 101 unitid 1 addr 0 count 4 wait 2ms\n    hmi_01 <- vfd_plc modbus readholdingregisters txid 101 unitid 1 count 4 value 3600 isresponse wait 5ms\n    // 2. Write Single Coil (FC 5) & Write Single Register (FC 6) -> triggers OT IDS write alert!\n    hmi_01 -> vfd_plc modbus writesinglecoil txid 102 unitid 1 addr 10 value 1 wait 2ms\n    hmi_01 <- vfd_plc modbus writesinglecoil txid 102 unitid 1 addr 10 value 1 isresponse wait 3ms\n    hmi_01 -> vfd_plc modbus writesingleregister txid 103 unitid 1 addr 200 value 1800\n}\n```\n\n## 11.09 · BACnet/IP (`bacnet`): Data-Center CRAC Discovery (`Who-Is`/`I-Am`), Temperature Read & Setpoint Write (`bacnet_dc_cooling_audit.frasm`)\n\nDiscovers CRAC device instance `2001`, reads Analog-Input 1 `Present-Value`\n(`propertyid 85`), and tests an unauthorized `writeproperty` setpoint change.\n\n- **Protocols:** `bacnet` (4 Ethernet frames)\n- **Wire Behavior:** Defaults to UDP source and destination port `47808`\n  (`0xbac0`) and sets BVLC Function to `0x0b` (`Original-Broadcast-NPDU`) on\n  `whois`/`iam` or `0x0a` (`Original-Unicast-NPDU`) on\n  `readproperty`/`writeproperty`. Bit-packs the 10-bit `objecttype` and 22-bit\n  `objectinstance` into the 32-bit ASHRAE 135 `BACnetObjectIdentifier` tag.\n- **Wireshark Filter:** `bacnet || bvlc || bacapp`\n- **CLI Build:** `frameassembly show bacnet_dc_cooling_audit.frasm`\n\n```frameassembly\nhost bms_workstation { ip 192.168.90.10 }\nhost crac_unit_04    { ip 192.168.90.40 }\n\ncompile {\n    // 1. Device discovery: Who-Is -> I-Am (Object Type 8 = Device, Instance 2001)\n    bms_workstation -> crac_unit_04 bacnet whois wait 2ms\n    bms_workstation <- crac_unit_04 bacnet iam objecttype 8 objectinstance 2001 wait 5ms\n    // 2. Read return-air temperature (Object Type 0 = Analog-Input, Property 85 = Present-Value)\n    bms_workstation -> crac_unit_04 bacnet readproperty invokeid 10 objecttype 0 objectinstance 1 propertyid 85 wait 4ms\n    // 3. Write chiller setpoint (Object Type 2 = Analog-Value, Property 85 = Present-Value)\n    bms_workstation -> crac_unit_04 bacnet writeproperty invokeid 11 objecttype 2 objectinstance 1 propertyid 85 value 24\n}\n```\n\n## 11.10 · DNP3 (IEEE 1815) (`dnp3`): Substation Analog Input Poll (`Group 30`) + Select-Before-Operate (`Group 12` CROB) (`dnp3_substation_sbo.frasm`)\n\nPolls Analog Inputs (`group 30 variation 1`), receives an RTU\n`unsolicitedresponse` event (`group 2` Binary Input Change), and executes a\ntwo-step `select` -> `operate` breaker sequence.\n\n- **Protocols:** `dnp3`, `tcp` (10 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `20000` (`transport udp`\n  switches to UDP `20000`) and builds the `0x0564` Data Link + Transport\n  (`FIN|FIR`) + Application headers. Computes the reflected IEEE 1815 `0x3d65`\n  CRC-16 across the 8-byte Data Link header and every 16-byte user-data chunk\n  automatically.\n- **Wireshark Filter:** `dnp3`\n- **CLI Build:** `frameassembly show dnp3_substation_sbo.frasm`\n\n```frameassembly\nhost ems_master { ip 172.25.1.5 }\nhost feeder_rtu { ip 172.25.10.20 }\n\ncompile {\n    ems_master -> feeder_rtu tcp syn srcport 53000 dstport 20000 win 65535 mss 1460 wait 1ms\n    ems_master <- feeder_rtu tcp syn ack win 65535 mss 1460 wait 1ms\n    ems_master -> feeder_rtu tcp ack wait 1ms\n    // 1. Class/Group 30 Analog Input Read + RTU Response\n    ems_master -> feeder_rtu dnp3 read src 1 dst 20 group 30 variation 1 wait 3ms\n    ems_master <- feeder_rtu dnp3 response src 20 dst 1 group 30 variation 1 wait 10ms\n    // 2. RTU Unsolicited Event (Group 2 Binary Input Event) + Master Confirm\n    ems_master <- feeder_rtu dnp3 unsolicitedresponse src 20 dst 1 group 2 variation 2 wait 2ms\n    ems_master -> feeder_rtu dnp3 confirm src 1 dst 20 wait 5ms\n    // 3. Select-Before-Operate (Group 12 Variation 1 CROB) -> triggers high-priority OT alert\n    ems_master -> feeder_rtu dnp3 select src 1 dst 20 group 12 variation 1 wait 2ms\n    ems_master <- feeder_rtu dnp3 response src 20 dst 1 group 12 variation 1 wait 2ms\n    ems_master -> feeder_rtu dnp3 operate src 1 dst 20 group 12 variation 1\n}\n```\n\n## 11.11 · Siemens S7comm (`s7comm`): S7 Communication Setup, DB1 Read Poll, DB1 Write & PLC CPU Control Alert (`s7comm_plc_security_lab.frasm`)\n\nNegotiates S7 PDU parameters (`setupcomm`), polls 4 bytes from `DB1.DBB0` (`area\n0x84 dbnum 1`), writes to `DB1`, and emits a `plccontrol` Job to test critical OT\nsecurity alerts.\n\n- **Protocols:** `s7comm`, `tcp` (10 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `102` (`psh ack`) and\n  computes the outer 4-byte TPKT (`0x03 0x00 <len>`) + 3-byte COTP DT (`0x02 0xf0\n  0x80`) framing automatically. Writes the `0x32` S7 Protocol ID, ROSCTR (`0x01`\n  Job, `0x02` Ack, `0x03` Ack_Data, `0x07` Userdata), 2-byte error class/code on\n  `ackdata`, and exact Parameter/Data lengths.\n- **Wireshark Filter:** `s7comm`\n- **CLI Build:** `frameassembly show s7comm_plc_security_lab.frasm`\n\n```frameassembly\nhost tia_ws  { ip 10.110.1.15 }\nhost plc_315 { ip 10.110.2.102 }\n\ncompile {\n    tia_ws -> plc_315 tcp syn srcport 51102 dstport 102 win 65535 mss 1460 wait 1ms\n    tia_ws <- plc_315 tcp syn ack win 65535 mss 1460 wait 1ms\n    tia_ws -> plc_315 tcp ack wait 1ms\n    // 1. S7 Setup Communication (Func 0xf0)\n    tia_ws -> plc_315 s7comm rosctr \"job\" setupcomm pduref 100 wait 2ms\n    tia_ws <- plc_315 s7comm rosctr \"ackdata\" setupcomm pduref 100 wait 2ms\n    // 2. Read 4 bytes from Data Block 1 (area 0x84 = DB, dbnum 1, offset 0)\n    tia_ws -> plc_315 s7comm rosctr \"job\" readvar pduref 101 area 0x84 dbnum 1 offset 0 count 4 wait 2ms\n    tia_ws <- plc_315 s7comm rosctr \"ackdata\" readvar pduref 101 count 4 wait 5ms\n    // 3. WriteVar (0x05) + PLCControl (0x28) -> critical OT IDS signatures\n    tia_ws -> plc_315 s7comm rosctr \"job\" writevar pduref 102 area 0x84 dbnum 1 offset 0 count 2 wait 3ms\n    tia_ws <- plc_315 s7comm rosctr \"ackdata\" writevar pduref 102 wait 3ms\n    tia_ws -> plc_315 s7comm rosctr \"job\" plccontrol pduref 103\n}\n```\n\n## 11.12 · EtherNet/IP (CIP) (`ethernetip`): PLC Discovery (`ListIdentity`), Session Registration, CIP Attribute Read & UDP 2222 I/O (`ethernetip_cip_cell.frasm`)\n\nPerforms a `listidentity` check, registers session `0x00010042` on TCP 44818,\nreads Assembly Instance `100` Attribute `3` (`Get_Attribute_Single` `0x0e`), and\nsends an implicit I/O packet on UDP 2222.\n\n- **Protocols:** `ethernetip`, `tcp` (9 Ethernet frames)\n- **Wire Behavior:** Selects TCP port `44818` for explicit encapsulation commands\n  (`registersession`, `listidentity`, `sendrrdata`) and automatically switches to\n  UDP port `2222` on `sendunitdata` or `transport udp`. Encodes the 24-byte\n  little-endian EtherNet/IP Encapsulation Header (`Command`, `Length`, `Session\n  Handle`, `Status`, 8-byte `Sender Context`, `Options`).\n- **Wireshark Filter:** `enip || cip`\n- **CLI Build:** `frameassembly show ethernetip_cip_cell.frasm`\n\n```frameassembly\nhost studio_ws { ip 10.120.10.15 }\nhost clx_plc   { ip 10.120.10.60 }\n\ncompile {\n    studio_ws -> clx_plc tcp syn srcport 51818 dstport 44818 win 65535 mss 1460 wait 1ms\n    studio_ws <- clx_plc tcp syn ack win 65535 mss 1460 wait 1ms\n    studio_ws -> clx_plc tcp ack wait 1ms\n    // 1. ListIdentity (0x0063) + RegisterSession (0x0065)\n    studio_ws -> clx_plc ethernetip listidentity wait 2ms\n    studio_ws -> clx_plc ethernetip registersession context 0x1122334455667788 wait 2ms\n    studio_ws <- clx_plc ethernetip registersession sessionhandle 0x00010042 context 0x1122334455667788 status 0 wait 3ms\n    // 2. SendRRData (0x006f): CIP Get_Attribute_Single (0x0e) on Assembly Object (0x04), Instance 100, Attr 3\n    studio_ws -> clx_plc ethernetip sendrrdata sessionhandle 0x00010042 cipservice 0x0e cipclass 0x04 cipinstance 100 cipattr 3 wait 4ms\n    // 3. Implicit CIP I/O over UDP 2222 + UnRegisterSession\n    studio_ws -> clx_plc ethernetip sendunitdata sessionhandle 0x00010042 cipservice 0x0e cipclass 0x04 cipinstance 150 cipattr 3 transport udp wait 3ms\n    studio_ws -> clx_plc ethernetip unregistersession sessionhandle 0x00010042\n}\n```\n\n## 11.13 · OPC UA (`opcua`): Complete OPC UA Connection (`HEL`/`ACK`), `OpenSecureChannel`, `NodeId` Read & `CLO` (`opcua_idmz_historian.frasm`)\n\nEstablishes an OPC UA Binary TCP 4840 session across an Industrial DMZ, opens\nSecure Channel `1`, reads `\"ns=2;s=Turbine1.RPM\"` via `\"MSG\"`, and closes cleanly\nwith `\"CLO\"`.\n\n- **Protocols:** `opcua`, `tcp` (9 Ethernet frames)\n- **Wire Behavior:** Defaults to TCP destination port `4840` (`psh ack`), `msgtype\n  \"HEL\"`, `chunktype \"F\"`, and calculates the 4-byte little-endian `MessageSize`\n  across the entire OPC UA frame. Encodes IEC 62541-6 receive/send buffer sizes\n  (`65535`) + length-prefixed UTF-8 `endpointurl` inside `\"HEL\"` and `\"ACK\"`\n  frames.\n- **Wireshark Filter:** `opcua`\n- **CLI Build:** `frameassembly show opcua_idmz_historian.frasm`\n\n```frameassembly\nhost idmz_hist { ip 172.18.35.20 }\nhost plant_ua  { ip 192.168.48.10 }\n\ncompile {\n    idmz_hist -> plant_ua tcp syn srcport 51840 dstport 4840 win 65535 mss 1460 wait 1ms\n    idmz_hist <- plant_ua tcp syn ack win 65535 mss 1460 wait 1ms\n    idmz_hist -> plant_ua tcp ack wait 1ms\n    // 1. Transport Hello / Acknowledge\n    idmz_hist -> plant_ua opcua msgtype \"HEL\" chunktype \"F\" endpointurl \"opc.tcp://192.168.48.10:4840/UA/PlantServer\" wait 2ms\n    idmz_hist <- plant_ua opcua msgtype \"ACK\" chunktype \"F\" wait 2ms\n    // 2. OpenSecureChannel (OPN)\n    idmz_hist -> plant_ua opcua msgtype \"OPN\" chunktype \"F\" securechannelid 0 seqnum 1 reqid 1 wait 2ms\n    idmz_hist <- plant_ua opcua msgtype \"OPN\" chunktype \"F\" securechannelid 1 tokenid 1 seqnum 1 reqid 1 wait 3ms\n    // 3. Service Read Request (MSG) for NodeId + CloseSecureChannel (CLO)\n    idmz_hist -> plant_ua opcua msgtype \"MSG\" chunktype \"F\" securechannelid 1 tokenid 1 seqnum 2 reqid 2 nodeid \"ns=2;s=Turbine1.RPM\" wait 4ms\n    idmz_hist -> plant_ua opcua msgtype \"CLO\" chunktype \"F\" securechannelid 1 tokenid 1 seqnum 3 reqid 3\n}\n```\n\n## 11.14 · CoAP (IoT) (`coap`): Confirmable CoAP Sensor GET (`2.05 Content`) & Missing Resource (`4.04`) (`coap_ipv6_sensors.frasm`)\n\nQueries `/sensors/temp` over IPv6 receiving a piggybacked `ack` with `code \"2.05\"`\nJSON payload, then queries an unknown path returning `notfound` (`4.04`).\n\n- **Protocols:** `coap` (4 Ethernet frames)\n- **Wire Behavior:** Defaults to UDP destination port `5683` and packs CoAP\n  Version `1`, 2-bit Type, Token Length (`TKL`), 1-byte `c.dd` Code (`(class << 5)\n  | detail`), and 16-bit `msgid`. Splits slash-separated `uripath` strings\n  (`\"telemetry/humidity\"`) into individual delta-encoded Option `11` (`Uri-Path`)\n  segments automatically.\n- **Wireshark Filter:** `coap`\n- **CLI Build:** `frameassembly show coap_ipv6_sensors.frasm`\n\n```frameassembly\nhost collector { ip 2001:db8:70::1 }\nhost mote_12   { ip 2001:db8:70::12 }\n\ncompile {\n    // 1. Confirmable GET -> Piggybacked ACK 2.05 Content (contentformat 50 = application/json)\n    collector -> mote_12 coap con get msgid 500 token 0x0102 uripath \"sensors/temp\" wait 4ms\n    collector <- mote_12 coap ack code \"2.05\" msgid 500 token 0x0102 contentformat 50 payload \"{\\\"c\\\":22.4}\" wait 5ms\n    // 2. Unknown URI -> 4.04 Not Found\n    collector -> mote_12 coap con get msgid 501 token 0x0103 uripath \"sensors/valve9\" wait 4ms\n    collector <- mote_12 coap ack notfound msgid 501 token 0x0103\n}\n```\n"}
{"id":"pretrain-anthology-scapy-wireshark-migrations","kind":"examples_anthology","title":"Scapy, Wireshark Filter, tcprewrite & PCAP Reverse Migrations — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/examples/scapy-wireshark-migrations","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","http","qinq","ospf","snmp3","tls","bgp","vxlan","modbus","dnp3","dns","vlan","udp","smb"],"text":"# Scapy, Wireshark Filter, tcprewrite & PCAP Reverse Migrations\n\n> **FrameAssembly v3.3.0** · Anthology 12 (L2–L7 Cross-Layer · 14 Recipes) · MIT\n> License · Canonical URL:\n> https://frameassembly-lang.dev/docs/examples/scapy-wireshark-migrations\n\nSide-by-side translations from imperative Python/Scapy scripts, `tcprewrite`,\n`text2pcap` hex dumps, and Wireshark display filters into `.frasm`, plus full\nL2–L7 PCAP redaction with `frameassembly reverse`.\n\n## Key Wire & Syntax Takeaways\n\n- Replace manual Scapy `seq`/`ack` length math and duplicated `IP()`/`IPv6()`\n  packet builders with stateful `->`/`<-` lines and `flow(c, s)`.\n- Unlike `tcprewrite` (which only rewrites L2/L3 headers), `frameassembly reverse`\n  decompiles L2–L7 fields so redacted DNS/SNI/HTTP strings recompile with valid\n  lengths and checksums.\n- Store plain-text `.frasm` fixtures in Git instead of opaque `.pcap` blobs and\n  compile fresh captures in CI for Suricata, Zeek, and `tshark`.\n\n## 12.01 · Scapy Manual TCP Sequence Math -> Stateful .frasm HTTP Exchange (`mig_scapy_stateful_http.frasm`)\n\nIn Scapy, crafting a bidirectional HTTP conversation requires manually counting\npayload byte lengths, flipping IP/MAC/TCP port tuples on every reply, and\nmaintaining seq/ack variables. FrameAssembly tracks the 4-tuple state and <- port\nswap automatically.\n\n- **Protocols:** `tcp`, `http` (5 Ethernet frames)\n- **Wire Behavior:** Specify srcport and dstport once on syn; HTTP frames emit psh\n  ack and advance seq by exact wire byte length.\n- **Wireshark Filter:** `http && tcp.port == 8080`\n- **CLI Build:** `frameassembly mig_scapy_stateful_http.frasm`\n\n### Equivalent Imperative Scapy Script\n\n```python\nfrom scapy.all import Ether, IP, TCP, Raw, wrpcap\nreq = b\"GET /health HTTP/1.1\\r\\nHost: api.internal\\r\\n\\r\\n\"\nresp = b\"HTTP/1.1 200 OK\\r\\nContent-Length: 11\\r\\n\\r\\n{\\\"ok\\\":true}\"\npkts = [\n    Ether()/IP(src=\"10.0.0.10\", dst=\"10.0.0.20\")/TCP(sport=51200, dport=8080, flags=\"S\", seq=1000),\n    Ether()/IP(src=\"10.0.0.20\", dst=\"10.0.0.10\")/TCP(sport=8080, dport=51200, flags=\"SA\", seq=2000, ack=1001),\n    Ether()/IP(src=\"10.0.0.10\", dst=\"10.0.0.20\")/TCP(sport=51200, dport=8080, flags=\"A\", seq=1001, ack=2001),\n    Ether()/IP(src=\"10.0.0.10\", dst=\"10.0.0.20\")/TCP(sport=51200, dport=8080, flags=\"PA\", seq=1001, ack=2001)/Raw(req),\n    Ether()/IP(src=\"10.0.0.20\", dst=\"10.0.0.10\")/TCP(sport=8080, dport=51200, flags=\"PA\", seq=2001, ack=1001+len(req))/Raw(resp),\n]\nwrpcap(\"mig_scapy_stateful_http.pcap\", pkts)\n```\n\n```frameassembly\nhost client { ip 10.0.0.10 }\nhost server { ip 10.0.0.20 }\n\ncompile {\n    client -> server tcp syn srcport 51200 dstport 8080 win 65535 mss 1460 wait 1ms\n    client <- server tcp syn ack win 65535 mss 1460 wait 1ms\n    client -> server tcp ack wait 1ms\n    client -> server http get uri \"/health\" hosthdr \"api.internal\" wait 2ms\n    client <- server http status 200 reason \"OK\" contenttype \"application/json\" body \"{\\\"ok\\\":true}\"\n}\n```\n\n## 12.02 · Scapy Dot1AD / Dot1Q Stacking -> Cross-Layer qinq + innervlan Modifier (`mig_scapy_qinq_stack.frasm`)\n\nReplaces nested Scapy Ether(type=0x88a8)/Dot1Q()/Dot1Q() layer constructors with a\ndeclarative qinq <svlan> innervlan <cvlan> modifier usable on any L3–L7 protocol.\n\n- **Protocols:** `qinq`, `ospf` (1 Ethernet frame)\n- **Wire Behavior:** Writes outer IEEE 802.1ad TPID 0x88a8 (S-VLAN 300, PCP 5)\n  followed by inner 802.1Q TPID 0x8100 (C-VLAN 40).\n- **Wireshark Filter:** `vlan.id == 300 && ospf`\n- **CLI Build:** `frameassembly mig_scapy_qinq_stack.frasm`\n\n### Scapy 802.1ad + 802.1Q Layer Stack\n\n```python\nfrom scapy.all import Ether, Dot1AD, Dot1Q, IP, wrpcap\nfrom scapy.contrib.ospf import OSPF_Hdr, OSPF_Hello\npkt = (Ether(src=\"00:1c:73:01:00:01\", dst=\"01:00:5e:00:00:05\")\n       / Dot1AD(vlan=300, prio=5) / Dot1Q(vlan=40)\n       / IP(src=\"10.30.40.1\", dst=\"224.0.0.5\", ttl=1)\n       / OSPF_Hdr(src=\"10.30.40.1\", area=\"0.0.0.0\") / OSPF_Hello())\nwrpcap(\"mig_scapy_qinq_stack.pcap\", [pkt])\n```\n\n```frameassembly\nhost ce_rtr     { ip 10.30.40.1 mac 00:1c:73:01:00:01 }\nhost ospf_mcast { ip 224.0.0.5 }\n\ncompile {\n    ce_rtr -> ospf_mcast qinq 300 innervlan 40 pcp 5 ospf hello routerid 10.30.40.1 areaid 0.0.0.0 hellointerval 10 deadinterval 40 ttl 1\n}\n```\n\n## 12.03 · PySNMP / Scapy USM Boilerplate -> Single-Line Encrypted SNMPv3 Trap (`mig_snmpv3_usm_authpriv.frasm`)\n\nGenerating an encrypted RFC 3414/3826/7860 SNMPv3 authPriv trap in Python normally\nrequires PySNMP key localization, ASN.1 BER encoders, and MIB compilation.\nFrameAssembly performs SHA-256 key localization and AES-128-CFB encryption\nnatively.\n\n- **Protocols:** `snmp3` (1 Ethernet frame)\n- **Wire Behavior:** Computes localized Ku -> Kul keys from engineid hex, encrypts\n  the scopedPDU with AES-128, and signs the packet with HMAC-SHA-256.\n- **Wireshark Filter:** `snmp && udp.port == 162`\n- **CLI Build:** `frameassembly mig_snmpv3_usm_authpriv.frasm`\n\n### net-snmp CLI Equivalent (Requires Live Socket & Daemon)\n\n```bash\nsnmptrap -v 3 -e 0x80001f888001020304 -u secops \\\n  -a SHA-256 -A \"AuthSecret2026!\" -x AES -X \"PrivSecret2026!\" \\\n  -l authPriv 10.40.1.100:162 240000 1.3.6.1.6.3.1.1.5.3 \\\n  1.3.6.1.2.1.2.2.1.2.1 s \"TenGigE0/0/1\"\n```\n\n```frameassembly\nhost core_rtr { ip 10.40.1.1 }\nhost nms_srv  { ip 10.40.1.100 }\n\ncompile {\n    core_rtr -> nms_srv snmp3 trap user \"secops\" engineid \"80001f888001020304\" engineboots 3 enginetime 1200 auth sha256 \"AuthSecret2026!\" priv aes \"PrivSecret2026!\" sysuptime 240000 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.2.2.1.2.1 string \"TenGigE0/0/1\"\n}\n```\n\n## 12.04 · Scapy IP() vs IPv6() Script Duplication -> Reusable Dual-Stack flow(c, s) (`mig_dual_stack_tls_flow.frasm`)\n\nInstead of maintaining separate Scapy IP() and IPv6() builders for dual-stack\nregression suites, write one parameterized flow(c, s) and invoke it for IPv4 and\nIPv6 host pairs.\n\n- **Protocols:** `tcp`, `tls` (5 Ethernet frames)\n- **Wire Behavior:** Emits EtherType 0x0800 on the first call and EtherType 0x86dd\n  (with IPv6 pseudo-header TCP checksums) on the second call.\n- **Wireshark Filter:** `tls.handshake.extensions_server_name ==\n  \"api.example.com\"`\n- **CLI Build:** `frameassembly mig_dual_stack_tls_flow.frasm`\n\n### Duplicated IPv4 / IPv6 Scapy Construction\n\n```python\n# In Scapy, IP() and IPv6() require separate packet lists & L3 headers:\nv4_syn = Ether()/IP(src=\"10.1.1.10\", dst=\"10.1.1.20\")/TCP(sport=52443, dport=443, flags=\"S\")\nv6_syn = Ether()/IPv6(src=\"2001:db8::10\", dst=\"2001:db8::20\")/TCP(sport=52443, dport=443, flags=\"S\")\n```\n\n```frameassembly\nhost app_v4 { ip 10.1.1.10 }\nhost gw_v4  { ip 10.1.1.20 }\nhost app_v6 { ip 2001:db8::10 }\nhost gw_v6  { ip 2001:db8::20 }\n\nflow tls_sni_probe(c, s) {\n    c -> s tcp syn srcport 52443 dstport 443 win 65535 mss 1440 wait 1ms\n    c <- s tcp syn ack win 65535 mss 1440 wait 1ms\n    c -> s tcp ack wait 1ms\n    c -> s tls clienthello sni \"api.example.com\" alpn \"h2\" wait 2ms\n    c <- s tls serverhello ciphersuite 0x1301\n}\n\ncompile {\n    tls_sni_probe(app_v4, gw_v4)\n    tls_sni_probe(app_v6, gw_v6)\n}\n```\n\n## 12.05 · Scapy scapy.contrib.bgp Byte Packing -> Native bgp open / update (`mig_scapy_bgp_nlri.frasm`)\n\nTranslates verbose scapy.contrib.bgp path-attribute constructors into readable bgp\nopen, keepalive, update, and notification lines.\n\n- **Protocols:** `tcp`, `bgp` (6 Ethernet frames)\n- **Wire Behavior:** Automatically prepends the 16-byte all-ones BGP marker\n  (ff..ff) and 16-bit message length.\n- **Wireshark Filter:** `bgp`\n- **CLI Build:** `frameassembly mig_scapy_bgp_nlri.frasm`\n\n### Scapy BGP Contrib Imports & Path Attributes\n\n```python\nfrom scapy.contrib.bgp import BGPHeader, BGPOpen, BGPUpdate, BGPPAOrigin, BGPPANextHop, BGPNLRI_IPv4\nupd = BGPHeader(type=2) / BGPUpdate(\n    path_attr=[BGPPAOrigin(origin=\"IGP\"), BGPPANextHop(next_hop=\"192.0.2.1\")],\n    nlri=[BGPNLRI_IPv4(prefix=\"198.51.100.0/24\")]\n)\n```\n\n```frameassembly\nhost peer_a { ip 192.0.2.1 }\nhost peer_b { ip 192.0.2.2 }\n\ncompile {\n    peer_a -> peer_b tcp syn srcport 50179 dstport 179 ttl 1 wait 1ms\n    peer_a <- peer_b tcp syn ack ttl 1 wait 1ms\n    peer_a -> peer_b tcp ack ttl 1 wait 1ms\n    peer_a -> peer_b bgp open asn 64512 holdtime 180 bgpid 192.0.2.1 ttl 1 wait 2ms\n    peer_a <- peer_b bgp open asn 64513 holdtime 180 bgpid 192.0.2.2 ttl 1 wait 2ms\n    peer_a -> peer_b bgp update prefix \"198.51.100.0/24\" nexthop 192.0.2.1 asn 64512 ttl 1\n}\n```\n\n## 12.06 · Scapy VXLAN UDP/4789 Header Flags -> Declarative vxlan vni (`mig_scapy_vxlan_vni.frasm`)\n\nReplaces manual VXLAN(flags=0x08, vni=10500) bitmask setup on UDP 4789 with the\nnative vxlan protocol builder.\n\n- **Protocols:** `vxlan` (1 Ethernet frame)\n- **Wire Behavior:** Sets the VXLAN I-flag (0x08), 24-bit VNI 10500, and UDP\n  destination port 4789 automatically.\n- **Wireshark Filter:** `vxlan.vni == 10500`\n- **CLI Build:** `frameassembly mig_scapy_vxlan_vni.frasm`\n\n### Scapy VXLAN Framing\n\n```python\nfrom scapy.all import Ether, IP, UDP, VXLAN, wrpcap\npkt = Ether()/IP(src=\"10.250.0.1\", dst=\"10.250.0.2\", flags=\"DF\")/UDP(sport=51000, dport=4789)/VXLAN(flags=0x08, vni=10500)\nwrpcap(\"mig_scapy_vxlan_vni.pcap\", [pkt])\n```\n\n```frameassembly\nhost leaf_vtep1 { ip 10.250.0.1 }\nhost leaf_vtep2 { ip 10.250.0.2 }\n\ncompile {\n    leaf_vtep1 -> leaf_vtep2 vxlan vni 10500 srcport 51000 df payload \"inner-tenant-frame\"\n}\n```\n\n## 12.07 · Python struct.pack() Raw Modbus MBAP Bytes -> Native modbus Builder (`mig_scapy_modbus_mbap.frasm`)\n\nOT engineers frequently pack 12-byte Modbus MBAP + PDU structs by hand in Python.\nFrameAssembly builds request and isresponse MBAP frames natively.\n\n- **Protocols:** `tcp`, `modbus` (5 Ethernet frames)\n- **Wire Behavior:** Computes the 16-bit MBAP length field and function code 0x03\n  / 0x05 payloads on TCP 502.\n- **Wireshark Filter:** `mbtcp`\n- **CLI Build:** `frameassembly mig_scapy_modbus_mbap.frasm`\n\n### Manual Python struct.pack(\">HHHBBHH\", ...) MBAP Payload\n\n```python\nimport struct\nfrom scapy.all import Ether, IP, TCP, Raw\nmbap_pdu = struct.pack(\">HHHBBHH\", 0x0042, 0x0000, 6, 1, 0x03, 100, 2)\npkt = Ether()/IP(src=\"192.168.1.10\", dst=\"192.168.1.50\")/TCP(sport=50200, dport=502, flags=\"PA\")/Raw(mbap_pdu)\n```\n\n```frameassembly\nhost hmi_01 { ip 192.168.1.10 }\nhost plc_01 { ip 192.168.1.50 }\n\ncompile {\n    hmi_01 -> plc_01 tcp syn srcport 50200 dstport 502 wait 1ms\n    hmi_01 <- plc_01 tcp syn ack wait 1ms\n    hmi_01 -> plc_01 tcp ack wait 1ms\n    hmi_01 -> plc_01 modbus readholdingregisters txid 0x0042 unitid 1 addr 100 count 2 wait 2ms\n    hmi_01 <- plc_01 modbus readholdingregisters isresponse txid 0x0042 unitid 1 count 2\n}\n```\n\n## 12.08 · Custom DNP3 CRC-16 Python Loops -> Native dnp3 Select-Before-Operate (`mig_dnp3_auto_crc16.frasm`)\n\nScapy has no built-in DNP3 layer in core, forcing scripts to implement IEEE 1815\nreflected 0x3d65 CRC-16 loops over every 16-byte chunk. FrameAssembly emits valid\nDNP3 CROB frames directly.\n\n- **Protocols:** `tcp`, `dnp3` (6 Ethernet frames)\n- **Wire Behavior:** Calculates link-header and per-16-byte user-data CRC-16\n  octets automatically on port 20000.\n- **Wireshark Filter:** `dnp3`\n- **CLI Build:** `frameassembly mig_dnp3_auto_crc16.frasm`\n\n### Manual DNP3 Header + Reflected 0x3d65 CRC-16 Requirement\n\n```python\n# Without FrameAssembly, every 8B header + 16B chunk needs custom CRC-16:\nlink_hdr = bytes([0x05, 0x64, 0x0c, 0xc4, 0x0a, 0x00, 0x01, 0x00])\nhdr_crc = dnp3_crc16_le(link_hdr)  # custom ~crc16_0x3d65 implementation\n```\n\n```frameassembly\nhost scada_srv { ip 10.100.1.5 }\nhost rtu_10    { ip 10.100.2.10 }\n\ncompile {\n    scada_srv -> rtu_10 tcp syn srcport 52010 dstport 20000 wait 1ms\n    scada_srv <- rtu_10 tcp syn ack wait 1ms\n    scada_srv -> rtu_10 tcp ack wait 1ms\n    scada_srv -> rtu_10 dnp3 select src 1 dst 10 group 12 variation 1 wait 2ms\n    scada_srv <- rtu_10 dnp3 response src 10 dst 1 group 12 variation 1 wait 2ms\n    scada_srv -> rtu_10 dnp3 operate src 1 dst 10 group 12 variation 1\n}\n```\n\n## 12.09 · Wireshark Filter (dns.flags.rcode == 3 && ipv6) -> Deterministic .frasm Fixture (`mig_wireshark_ipv6_nxdomain.frasm`)\n\nTurns a Wireshark display filter used in DNS threat-hunting detections (IPv6 AAAA\nNXDOMAIN responses) into a deterministic 2-packet CI test capture.\n\n- **Protocols:** `dns` (2 Ethernet frames)\n- **Wire Behavior:** rcode 3 sets DNS Response Code NXDOMAIN (Name Error) inside\n  the 16-bit DNS flags word.\n- **Wireshark Filter:** `dns.flags.rcode == 3 && ipv6`\n- **CLI Build:** `frameassembly mig_wireshark_ipv6_nxdomain.frasm`\n\n### Target Wireshark / tshark Detection Filter\n\n```text\ndns.flags.response == 1 && dns.flags.rcode == 3 && ipv6.src == 2001:db8:53::53\n```\n\n```frameassembly\nhost endpoint_v6 { ip 2001:db8:10::44 }\nhost resolver_v6 { ip 2001:db8:53::53 }\n\ncompile {\n    endpoint_v6 -> resolver_v6 dns query txid 0x7a01 qname \"dga-8891a.example.invalid\" qtype \"AAAA\" wait 3ms\n    endpoint_v6 <- resolver_v6 dns response txid 0x7a01 qname \"dga-8891a.example.invalid\" qtype \"AAAA\" rcode 3\n}\n```\n\n## 12.10 · Wireshark Filter (tcp.analysis.retransmission) -> Exact RTO Replay Capture (`mig_wireshark_tcp_retrans.frasm`)\n\nGenerates a reproducible 250ms TCP retransmission fixture matching Wireshark\ntcp.analysis.retransmission without needing tc/netem packet loss.\n\n- **Protocols:** `tcp`, `http` (6 Ethernet frames)\n- **Wire Behavior:** Repeating seq 1001 after wait 250ms triggers Wireshark TCP\n  Retransmission expert analysis.\n- **Wireshark Filter:** `tcp.analysis.retransmission`\n- **CLI Build:** `frameassembly mig_wireshark_tcp_retrans.frasm`\n\n### Target Wireshark Expert Filter\n\n```text\ntcp.analysis.retransmission && tcp.port == 80\n```\n\n```frameassembly\nhost web_client { ip 10.15.1.20 }\nhost origin_srv { ip 10.15.2.80 }\n\ncompile {\n    web_client -> origin_srv tcp syn srcport 51900 dstport 80 win 65535 mss 1460 wait 1ms\n    web_client <- origin_srv tcp syn ack win 65535 mss 1460 wait 1ms\n    web_client -> origin_srv tcp ack wait 1ms\n    web_client -> origin_srv http get uri \"/report.csv\" hosthdr \"data.internal\" wait 250ms\n    web_client -> origin_srv seq 1001 http get uri \"/report.csv\" hosthdr \"data.internal\" wait 2ms\n    web_client <- origin_srv http status 200 reason \"OK\" body \"id,status\\n1,ok\\n\"\n}\n```\n\n## 12.11 · tcprewrite L3-Only Rewrite vs. frameassembly reverse Full L2–L7 Redaction (`mig_reverse_l7_redaction.frasm`)\n\ntcprewrite only rewrites Ethernet MACs and IPv4/IPv6 headers—leaving internal DNS\nqnames, TLS SNI hostnames, and HTTP Host headers exposed inside the payload.\nframeassembly reverse decompiles L2–L7 into editable .frasm text and recalculates\nlengths and checksums on recompile.\n\n- **Protocols:** `dns`, `tcp`, `tls`, `http` (6 Ethernet frames)\n- **Wire Behavior:** Changing qname, sni, and hosthdr from long internal names to\n  short RFC 2606 .example names automatically updates IP Total Length, TCP\n  seq/acknum, and checksums.\n- **Wireshark Filter:** `dns || tls || http`\n- **CLI Build:** `frameassembly reverse prod_incident.pcap scrubbed.frasm &&\n  frameassembly scrubbed.frasm safe_tac.pcap`\n\n### tcprewrite Limitation (Leaves DNS / SNI / HTTP Host Leaking in Payload)\n\n```bash\n# Rewrites outer IPs only; L7 DNS/SNI/HTTP strings remain unredacted!\ntcprewrite --pnat=10.0.0.0/8:198.51.100.0/24 -i prod_incident.pcap -o partial.pcap\n```\n\n```frameassembly\nhost host1 { ip 198.51.100.15 mac 02:00:00:00:00:01 }\nhost host2 { ip 198.51.100.53 mac 02:00:00:00:00:02 }\nhost host3 { ip 203.0.113.80  mac 02:00:00:00:00:03 }\n\ncompile {\n    host1 -> host2 dns query txid 0x3100 qname \"portal.example.com\" qtype \"A\" wait 2ms\n    host1 <- host2 dns response txid 0x3100 qname \"portal.example.com\" qtype \"A\" rdata \"203.0.113.80\" ansttl 300 wait 2ms\n    host1 -> host3 tcp syn srcport 52100 dstport 443 win 65535 mss 1460 wait 1ms\n    host1 <- host3 tcp syn ack win 65535 mss 1460 wait 1ms\n    host1 -> host3 tcp ack wait 1ms\n    host1 -> host3 tls clienthello sni \"portal.example.com\" alpn \"http/1.1\"\n}\n```\n\n## 12.12 · text2pcap Static Hex Offsets -> Readable .frasm + hexpayload Trailer (`mig_text2pcap_hexpayload.frasm`)\n\nReplaces brittle 0000 00 1c 73 ... text2pcap hex dumps with typed L2/L3/L4 headers\nand a concise hexpayload trailer for custom proprietary bytes.\n\n- **Protocols:** `vlan`, `udp` (2 Ethernet frames)\n- **Wire Behavior:** hexpayload accepts continuous, space-separated, or\n  colon-separated hex octets and computes UDP/IP lengths and checksums\n  automatically.\n- **Wireshark Filter:** `vlan.id == 120 && udp.port == 31000`\n- **CLI Build:** `frameassembly mig_text2pcap_hexpayload.frasm\n  mig_text2pcap_hexpayload.pcapng`\n\n### Legacy text2pcap Offset Dump (Breaks Checksums on Any Byte Edit)\n\n```bash\n# 0000  00 1c 73 00 00 02 00 1c 73 00 00 01 81 00 00 78 ...\ntext2pcap -u 50000,31000 raw_hex_dump.txt legacy.pcap\n```\n\n```frameassembly\nhost sensor_node { ip 10.120.1.10 mac 00:1c:73:00:00:01 }\nhost ingest_srv  { ip 10.120.1.20 mac 00:1c:73:00:00:02 }\n\ncompile {\n    sensor_node -> ingest_srv vlan 120 udp srcport 50000 dstport 31000 hexpayload \"ca:fe:ba:be:00:01:02:03\" wait 500ns\n    sensor_node <- ingest_srv vlan 120 udp hexpayload \"ca:fe:ba:be:80:01:00:00\"\n}\n```\n\n## 12.13 · Binary .pcap Git Blobs -> Plain-Text .frasm Suricata & tshark CI Fixture (`mig_ci_suricata_smb_tls.frasm`)\n\nChecking binary .pcap files into Git makes pull-request diffs unreadable. Storing\nplain-text .frasm fixtures lets CI compile fresh .pcap files on the fly for\nSuricata and tshark assertions.\n\n- **Protocols:** `tcp`, `tls`, `smb` (12 Ethernet frames)\n- **Wire Behavior:** frameassembly show prints the relative-timestamp packet\n  ladder in CI logs without writing temporary files.\n- **Wireshark Filter:** `tls || smb2`\n- **CLI Build:** `frameassembly show mig_ci_suricata_smb_tls.frasm &&\n  frameassembly mig_ci_suricata_smb_tls.frasm ci_out.pcap`\n\n### GitHub Actions / GitLab CI Verification Pipeline\n\n```bash\nframeassembly mig_ci_suricata_smb_tls.frasm ci_out.pcap\ntshark -r ci_out.pcap -Y \"tls.handshake.extensions_server_name || smb2.tree\"\n```\n\n```frameassembly\nhost wkstn_ci { ip 10.88.1.15 }\nhost edge_ci  { ip 198.51.100.44 }\nhost fs_ci    { ip 10.88.2.45 }\n\ncompile {\n    wkstn_ci -> edge_ci tcp syn srcport 51443 dstport 443 win 65535 mss 1460 wait 1ms\n    wkstn_ci <- edge_ci tcp syn ack win 65535 mss 1460 wait 1ms\n    wkstn_ci -> edge_ci tcp ack wait 1ms\n    wkstn_ci -> edge_ci tls clienthello sni \"updates.example.net\" alpn \"h2\" wait 4ms\n    wkstn_ci -> fs_ci tcp syn srcport 51445 dstport 445 win 65535 mss 1460 wait 1ms\n    wkstn_ci <- fs_ci tcp syn ack win 65535 mss 1460 wait 1ms\n    wkstn_ci -> fs_ci tcp ack wait 1ms\n    wkstn_ci -> fs_ci smb negotiate msgid 0 wait 1ms\n    wkstn_ci <- fs_ci smb negotiate msgid 0 status 0 wait 1ms\n    wkstn_ci -> fs_ci smb sessionsetup msgid 1 sessionid 0x1001 wait 1ms\n    wkstn_ci <- fs_ci smb sessionsetup msgid 1 sessionid 0x1001 status 0 wait 1ms\n    wkstn_ci -> fs_ci smb treeconnect msgid 2 sessionid 0x1001 share \"\\\\\\\\fs_ci\\\\IPC$\"\n}\n```\n\n## 12.14 · Sanitized Vendor TAC Capture (RFC 5737 Safe Subnets) (`tac_sanitized_support.frasm`)\n\nClean, share-ready template showing a reversed DNS + HTTPS trace scrubbed to RFC\n5737 documentation IPs (198.51.100.x) and neutral example hostnames.\n\n- **Protocols:** `dns`, `tcp`, `tls` (6 Ethernet frames)\n- **Wire Behavior:** Run frameassembly reverse incident.pcap clean.frasm, swap\n  your 10.x.x.x IPs and internal hostnames once, and rebuild a valid .pcap safe to\n  attach to external tickets.\n- **Wireshark Filter:** `dns || tls`\n- **CLI Build:** `frameassembly tac_sanitized_support.frasm`\n\n```frameassembly\n// Reversed capture scrubbed to RFC 5737 documentation IPs before sending to vendor TAC\nhost host1 { ip 198.51.100.21 mac 02:00:00:00:00:01 }\nhost host2 { ip 198.51.100.53 mac 02:00:00:00:00:02 }\nhost host3 { ip 203.0.113.44  mac 02:00:00:00:00:03 }\n\ncompile {\n    // 1. Redacted DNS lookup (replaced internal domain with sso.example.test)\n    host1 -> host2 dns query txid 0x5120 qname \"sso.example.test\" qtype \"A\" wait 3ms\n    host1 <- host2 dns response txid 0x5120 qname \"sso.example.test\" qtype \"A\" rdata \"203.0.113.44\" ansttl 120 wait 2ms\n\n    // 2. Stateful TCP 443 handshake + TLS ClientHello with recalculated lengths & checksums\n    host1 -> host3 tcp syn srcport 53400 dstport 443 win 65535 mss 1460 wait 1ms\n    host1 <- host3 tcp syn ack win 65535 mss 1460 wait 1ms\n    host1 -> host3 tcp ack wait 1ms\n    host1 -> host3 tls clienthello sni \"sso.example.test\" alpn \"h2\"\n}\n```\n"}
{"id":"pretrain-guide-getting-started","kind":"workflow_guide","title":"Create a .pcap File in 60 Seconds (host + compile) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/getting-started","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["dns","icmp","arp","tcp","http","tls","ssh"],"text":"# Create a `.pcap` File in 60 Seconds (`host` + `compile`)\n\n> **FrameAssembly v3.3.0** · Workflow Guide 01 · Canonical URL:\n> https://frameassembly-lang.dev/docs/getting-started\n\nName two boxes, draw `->` and `<-` arrows, and build a Wireshark-ready `.pcap` or\n`.pcapng` file with zero Scapy imports and zero `sudo`.\n\n## Key Takeaways\n\n- Every `.frasm` script needs only two blocks: `host` (who lives on the wire) and\n  `compile` (what they send).\n- `1 packet line = 1 Ethernet frame` with MACs, IP/TCP/UDP lengths, and RFC\n  checksums calculated for you.\n- Zero `sudo`, zero Npcap drivers, and zero virtualenvs — runs locally in your\n  browser tab or via one static CLI binary.\n\n## 1. `host` + `compile`: Name Boxes, Draw Arrows\n\nIf you can read a firewall rule or a `tcpdump` line, you already know `.frasm`.\nEvery capture needs just two pieces: one or more `host` blocks declaring\nendpoints, and one `compile` block listing the frames flying between them.\n\nPut plain IPv4 or IPv6 addresses inside each `host` block (no `/24` masks). Skip\n`mac` whenever you don’t care about specific vendor OUIs, and FrameAssembly hands\nout sequential MACs in order (`00:00:00:00:00:01`, `00:00:00:00:00:02`, ...) so\nyour Wireshark conversations stay tidy.\n\n### `first_dns_check.frasm`\n\n```frameassembly\n// 1. Name the boxes on your network (zero /24 subnet math)\nhost laptop-of-hope { ip 192.168.10.25 }\nhost corp-resolver  { ip 192.168.10.53 }\n\n// 2. Draw -> and <- top-to-bottom (1 line = 1 Ethernet frame)\ncompile {\n    laptop-of-hope -> corp-resolver dns query txid 0x1a2b qname \"intranet.corp.local\" qtype \"A\" wait 3ms\n    laptop-of-hope <- corp-resolver dns response txid 0x1a2b qname \"intranet.corp.local\" qtype \"A\" rdata \"10.20.30.40\"\n}\n```\n\n```bash\n# Compile straight to first_dns_check.pcap\nframeassembly first_dns_check.frasm\n\n# Or eyeball the relative timestamps and byte lengths in your terminal first\nframeassembly show first_dns_check.frasm\n```\n\n## 2. Keep Columns Straight (`->`, `<-`, and `wait`)\n\nSpot the `<-` on line 2 above? Keeping `laptop-of-hope` pinned on the left and\n`corp-resolver` pinned on the right makes a 20-packet exchange read like an RFC\nwhiteboard sketch: `laptop-of-hope -> corp-resolver` fires left-to-right, while\n`laptop-of-hope <- corp-resolver` fires the reply right-to-left and swaps MACs,\nIPs, and ports automatically.\n\nPacket #1 always lands at `0.000000000 s`. Tacking `wait <number><ns|us|ms|s|m>`\nonto the end of a line sets the clock gap *before* the next packet arrives\n(default `10ms` when omitted).\n\n- Time units: `ns`, `us`, `ms`, `s`, and `m` (always lowercase, glued onto the\n  number).\n- Use `wait 0ns` when you want back-to-back microbursts at the exact same\n  nanosecond.\n- `wait` always rides on the end of a packet line — never alone on a blank line.\n- Export `.pcapng` for full nanosecond Wireshark precision, or classic `.pcap` for\n  microsecond tools like `tcpdump`, `tcpreplay`, Suricata, and Zeek.\n\n| Downstream Tool | Classic .pcap (0xa1b2c3d4, 1 us) | Nanosecond .pcapng (IfTsResol=9, 1 ns) | Practitioner Recommendation |\n| --- | --- | --- | --- |\n| Wireshark & `tshark` (3.x / 4.x) | Full support (`1 us` display) | Native `0.000000001 s` display | Prefer `.pcapng` when inspecting `ns` bursts or IEEE 1588v2 `ptp` sync loops. |\n| `tcpdump` (libpcap 1.10+) | Native default across all OSes | Supported on modern `libpcap`; older BSD builds prefer `.pcap` | Prefer `.pcap` for portable SSH and container CLI pipelines. |\n| `tcpreplay` & `tcpprep` (4.4+) | Primary supported input format | Limited / build-dependent (`tcpprep` expects classic libpcap) | Always compile `.pcap` before two-NIC `tcpprep` + `tcpreplay` hardware replay. |\n| Suricata (7.x+), Zeek (6.x+) & Snort 3 | Universal offline `-r` support | Supported in Suricata 7+ / Zeek via modern `libpcap` | Prefer `.pcap` for maximum CI container compatibility unless testing `ns` timers. |\n\n## 3. Let the Compiler Babysit TCP `seq` & `acknum`\n\nHand-crafting TCP in Scapy usually ends with Wireshark painting your screen\nblack-and-red over bad sequence numbers or broken pseudo-header checksums.\nFrameAssembly tracks every 4-tuple session (`client:port <-> server:port`) across\nraw `tcp` and all TCP-based Layer 7 protocols (`http`, `tls`, `ssh`, `smb`,\n`postgres`, `bgp`, `modbus`, ...).\n\nSet `srcport` and `dstport` once on the opening `syn`, and every `<-` reply and L7\npayload inherits the port pair, swaps direction when needed, and advances `seq` /\n`acknum` by exact payload byte count.\n\n### `http_healthcheck.frasm`\n\n```frameassembly\nhost probe   { ip 10.20.1.50 }\nhost web_srv { ip 10.20.1.80 }\n\ncompile {\n    // 3-way TCP handshake on port 80\n    probe -> web_srv tcp syn srcport 51820 dstport 80 win 65535 mss 1460 wait 1ms\n    probe <- web_srv tcp syn ack win 65535 mss 1460 wait 1ms\n    probe -> web_srv tcp ack wait 1ms\n\n    // HTTP GET <-> 200 OK reuse 51820 <-> 80 and advance TCP seq automatically\n    probe -> web_srv http get uri \"/healthz\" hosthdr \"web.corp.local\" wait 2ms\n    probe <- web_srv http status 200 reason \"OK\" contenttype \"application/json\" body \"{\\\"healthy\\\":true}\"\n}\n```\n\n> **Why HTTP uses `hosthdr` instead of `host`:** Top-level `host` already declares\n> network boxes, so HTTP and SSDP use `hosthdr \"web.corp.local\"` to set the\n> `Host:` header without name clashes.\n\n## 4. Four Rules That Save You Every Time\n\nAll 81 protocols obey the exact same lexical rules, with zero guessing whether\nsome random option wants `snake_case`, `camelCase`, or hyphens:\n\n| Rule | Write This | Not This |\n| --- | --- | --- |\n| File extension | `.frasm` (`text/vnd.frameassembly`) | `.asm` (x86 CPU assembly) or `.txt` |\n| Built-in keywords | Lowercase `[a-z0-9]+` only: `echorequest`, `innervlan`, `sackperm`, `clienthello` | Underscores or caps: `echo_request`, `inner_vlan`, `SYN` |\n| Host IP literals | Plain host IP: `host fw { ip 10.0.0.1 }` | CIDR masks or `=`: `ip = \"10.0.0.1/24\"` |\n| Comments & quotes | `//` comments and double quotes `\"...\"` | `#` / `;` comments or single quotes `'...'` |\n"}
{"id":"pretrain-guide-edit-and-anonymize-pcap","kind":"workflow_guide","title":"Edit & Anonymize a .pcap File (IPs, VLANs & Payloads) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/edit-and-anonymize-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["dns","tls","tcp","vlan","esp"],"text":"# Edit & Anonymize a `.pcap` File (IPs, VLANs & Payloads)\n\n> **FrameAssembly v3.3.0** · Workflow Guide 02 · Canonical URL:\n> https://frameassembly-lang.dev/docs/edit-and-anonymize-pcap\n\nReverse captures into plain `.frasm` text, edit or redact customer IPs and\ninternal hostnames with find-and-replace, and rebuild clean checksums.\n\n## Key Takeaways\n\n- `frameassembly reverse` converts `.pcap` and `.pcapng` captures into editable\n  `.frasm` text across all 81 protocols.\n- Swap an IP once inside `host1`, and every packet in that flow updates its IP\n  header and L4 pseudo-header checksum.\n- Unlike hex editors or `tcprewrite`, changing Layer 7 text (`qname`, `sni`,\n  `hosthdr`) recalculates outer lengths and TCP `seq` numbers automatically.\n\n## 1. Why Hex Editors & `tcprewrite` Betray You\n\nVendor TAC wants a packet capture of your broken auth flow — except your raw\n`.pcap` is stuffed with internal `10.x` subnets, MAC OUIs, SNMP community strings,\nand `\"payroll.corp.internal\"` inside DNS and TLS SNI.\n\n`tcprewrite` can swap outer Layer 3 IPs, right up until you notice your internal\nhostnames are still sitting in plaintext inside Layer 7 payloads. Hex-edit those\nstrings and you immediately wreck IP total lengths, TCP sequence offsets, and\ntransport checksums. Going `.pcap -> .frasm -> .pcap` fixes the whole stack at\nonce.\n\n## 2. The 3-Step Loop: `reverse` -> Edit Text -> Rebuild\n\nPoint `frameassembly reverse` at any `.pcap` or `.pcapng` (or drop the file onto\nthe browser Playground — zero bytes ever leave your tab). FrameAssembly dissects\nevery frame, groups endpoints into `host1`, `host2`, ..., preserves inter-packet\n`wait` gaps, and writes clean `.frasm` text.\n\nRun find-and-replace in your favorite editor, then build a fresh, checksum-clean\n`.pcap`.\n\n### `sanitized_case.frasm`\n\n```frameassembly\n// Reversed capture after scrubbing production IPs and internal hostnames\nhost host1 { ip 10.254.1.10 mac 02:00:00:00:00:01 }\nhost host2 { ip 10.254.1.53 mac 02:00:00:00:00:02 }\nhost host3 { ip 10.254.2.80 mac 02:00:00:00:00:03 }\n\ncompile {\n    host1 -> host2 dns query txid 0x8821 qname \"app.sanitized-example.test\" qtype \"A\" vlan 100 wait 2ms\n    host1 <- host2 dns response txid 0x8821 qname \"app.sanitized-example.test\" qtype \"A\" rdata \"10.254.2.80\" ansttl 300 vlan 100 wait 4ms\n    host1 -> host3 tcp syn srcport 54320 dstport 443 win 65535 mss 1460 vlan 100 wait 1ms\n    host1 <- host3 tcp syn ack win 65535 mss 1460 vlan 100 wait 1ms\n    host1 -> host3 tcp ack vlan 100 wait 1ms\n    host1 -> host3 tls clienthello sni \"app.sanitized-example.test\" alpn \"h2\" vlan 100\n}\n```\n\n```bash\n# 1. Reverse customer_incident.pcap -> sanitized_case.frasm\nframeassembly reverse customer_incident.pcap sanitized_case.frasm\n\n# 2. Scrub IPs, VLANs, or hostnames in any editor, then preview the packet table\nframeassembly show sanitized_case.frasm\n\n# 3. Rebuild -> clean .pcap with recalculated lengths and checksums\nframeassembly sanitized_case.frasm sanitized_case.pcap\n```\n\n### What Changed Between customer_incident.pcap and sanitized_case.pcap\n\nChanging a 21-byte internal hostname (\"payroll.corp.internal\") to a 26-byte\nredacted hostname (\"app.sanitized-example.test\") grows every DNS & TLS frame by +5\nbytes — and recompiling fixes every outer length and checksum automatically:\n\n```diff\n--- reversed_raw.frasm (from customer_incident.pcap)\n+++ sanitized_case.frasm (ready for vendor TAC)\n- host host1 { ip 10.24.8.19  mac 00:50:56:9a:41:0c }\n+ host host1 { ip 10.254.1.10 mac 02:00:00:00:00:01 }\n  compile {\n-     host1 -> host2 dns query txid 0x8821 qname \"payroll.corp.internal\" qtype \"A\" wait 2ms\n+     host1 -> host2 dns query txid 0x8821 qname \"app.sanitized-example.test\" qtype \"A\" vlan 100 wait 2ms\n-     host1 -> host3 tls clienthello sni \"payroll.corp.internal\" alpn \"h2\"\n+     host1 -> host3 tls clienthello sni \"app.sanitized-example.test\" alpn \"h2\" vlan 100\n  }\n```\n\n- Ethernet II vendor OUI MACs replaced with locally administered 02:00:00:00:00:0x\n  + 802.1Q VLAN 100 inserted (+4 B)\n- DNS QNAME labels + UDP length + IPv4 Total Length + IPv4/UDP checksums\n  recalculated for +5 B hostname delta\n- TLS Record length, Handshake length, Server Name extension length, and TCP\n  pseudo-header checksum updated cleanly\n\n## 3. Edits That Used to Take 80 Lines of Python\n\nOnce a binary trace is `.frasm` text, surgery is just text editing:\n\n| What You Want | What You Edit in `.frasm` | What the Compiler Fixes for You |\n| --- | --- | --- |\n| Scrub customer subnets | Swap `ip` and `mac` inside `host1`, `host2`, ... | Ethernet MACs, IPv4/IPv6 headers, and TCP/UDP/ICMPv6 pseudo-header checksums |\n| Insert or strip VLAN / QinQ tags | Add, tweak, or delete `vlan 200` or `qinq 500 innervlan 20` | Outer EtherTypes (`0x8100` / `0x88a8`) and wire frame byte lengths |\n| Wipe hostnames or secrets | Edit `qname`, `sni`, `hosthdr`, `uri`, `community`, or `user` | L7 TLV/header lengths, IP total length, and downstream TCP `seq` / `acknum` |\n| Stretch or compress timing | Change `wait 500us` to `wait 50ms` | Cumulative `.pcap` / `.pcapng` timestamps on every subsequent frame |\n| Preserve unknown payloads | Leave or edit `hexpayload \"...\"` | Keeps custom or proprietary wire bytes byte-for-byte intact |\n\n> **IPsec ESP Reverse Note (`esp` <-> `ipsec`):** When reversing IP protocol 50\n> traffic, `reverse` emits `esp` preserving `spi`, `seq`, and encrypted payload\n> bytes cleanly.\n\n## 4. `frameassembly reverse` Fidelity & Boundary Matrix\n\nUnderstanding what `frameassembly reverse` converts into editable fields and what\nstays as raw bytes keeps TAC redaction predictable:\n\n| Input Frame / Container Class | frameassembly reverse Output Behavior | Recompile Round-Trip Guarantee |\n| --- | --- | --- |\n| Container & Link-Layer Normalization | Reads classic/nanosecond `.pcap` and `.pcapng` (`SHB`/`IDB`/`EPB`/`SPB`); normalizes `ETHERNET`, `RAW`, `IPV4`, `IPV6`, `LINUX_SLL`, `LINUX_SLL2`, `NULL`, and `LOOP` into Ethernet II; strips trailing 60/64B zero-padding and 4B FCS. | Clean Ethernet II output (`LINKTYPE_ETHERNET`) with preserved nanosecond inter-packet `wait` deltas. |\n| Cleartext & Structured L2–L7 Protocols (80 builders) | Converts packets into `host1`, `host2`, ... + lowercase `.frasm` protocol fields (`dns qname`, `tls clienthello sni`, `http`, `bgp`, `modbus`, `dnp3`, `snmp1`/`snmp2`, `snmp3` `noAuthNoPriv`), verified byte-for-byte on round-trip. | Editing variable-length strings or adding `vlan`/`qinq` recalculates L7 TLV lengths, IPv4/UDP lengths, downstream TCP `seq`/`acknum`, and all checksums. |\n| IPsec ESP (IP Protocol 50) | Emits `esp` (`spi`, `seq`, `iv`, `icv` / encrypted payload) rather than the `ipsec` shorthand. | Preserves SPI, sequence number, and ciphertext while recalculating outer IP headers if `hostN` IPs are redacted. |\n| Encrypted `snmp3` (`authPriv` / keyed `authNoPriv`) & Unknown Payloads | Falls back cleanly to `udp` / `tcp` with lossless `hexpayload \"...\"` because USM decryption requires external keys. | Byte-exact payload preservation on recompile while still allowing outer MAC, VLAN, IP, and port redaction. |\n\n## 5. Choosing the Right PCAP Scrubber (`frameassembly reverse` vs. `tcprewrite` & TraceWrangler)\n\nDifferent capture-scrubbing jobs call for different tools. Use `tcprewrite`,\n`TraceWrangler`, or `editcap` when slicing or remapping multi-gigabyte captures in\nbulk; reach for `frameassembly reverse` when you need to edit Layer 7 strings,\nVLAN/QinQ tags, or trim an incident trace down to a clean TAC reproducer:\n\n| Tool | Best For | Layer 7 Hostname & String Edits | Trade-Offs |\n| --- | --- | --- | --- |\n| `frameassembly reverse` (`.frasm`) | Scrubbing 5–500 packet TAC reproducers, editing L2–L7 fields (`qname`, `sni`, `hosthdr`, `vlan`), and checking captures into Git. | Recalculates DNS/TLS/HTTP lengths, IPv4/UDP lengths, TCP `seq`/`acknum`, and checksums on recompile. | Converts the capture into plain text; for multi-GB captures, filter the relevant conversation with `tshark` or `editcap` first. |\n| `tcprewrite` (`tcpreplay` suite) | Fast bulk L2 MAC, VLAN, and L3 IP/CIDR remapping across large `.pcap` files from the Linux CLI. | Does not rewrite variable-length Layer 7 strings (`sni`, `qname`, `hosthdr`) or shift downstream TCP `seq` numbers. | Great for fast subnet NAT before `tcpreplay`; leaves internal hostnames exposed inside L7 payloads. |\n| TraceWrangler (Windows GUI) | Batch-anonymizing IPv4/IPv6 subnets, MAC OUIs, and DHCP/DNS options across large multi-file Windows captures. | Strong automated anonymization profiles, but does not turn packets into human-editable L2–L7 text lines. | Windows desktop workflow (or Wine); less suited for hand-crafting or diffing custom protocol edge cases in Git. |\n| `editcap` & `tshark` (Wireshark CLI) | Slicing time windows, deduplicating frames, stripping packet bytes (`-s`), or filtering a noisy capture down to one flow. | Filters or truncates payloads (`-s 96`) rather than replacing hostnames while keeping L7 sessions intact. | Ideal first step (`tshark -r big.pcap -Y \"ip.addr==...\" -w slim.pcap`) right before `frameassembly reverse`. |\n"}
{"id":"pretrain-guide-test-firewalls-and-ids","kind":"workflow_guide","title":"Poke Stateful Firewalls, Suricata, Zeek & OT Conduits — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/test-firewalls-and-ids","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tls","http","http2","quic","dns","tcp","udp","icmp","smb","kerberos","ldap","modbus","dnp3","s7comm","bacnet","ethernetip","opcua"],"text":"# Poke Stateful Firewalls, Suricata, Zeek & OT Conduits\n\n> **FrameAssembly v3.3.0** · Workflow Guide 03 · Canonical URL:\n> https://frameassembly-lang.dev/docs/test-firewalls-and-ids\n\nCraft sessions that actually survive stateful TCP tracking, or intentionally\ninject Xmas scans, fragments, and rogue SQL/Modbus writes to prove your sensors\nare awake.\n\n## Key Takeaways\n\n- Stateful firewalls and Suricata (`flow:established,to_server;`) silently drop\n  lone spoofed L7 packets — give them a 3-line `->` / `<-` handshake first.\n- Or go full gremlin: override `seq`, `acknum`, Xmas flags (`fin psh urg`), or\n  IPv4 fragments (`mf`, `fragoffset`) to verify your scrubbers actually block\n  garbage.\n- Test Purdue Level 1–3 OT rules (`modbus`, `dnp3` CRC-16, `s7comm`, `opcua`) in a\n  `.pcap` instead of gambling with a live plant PLC.\n\n## 1. Why Lone Spoofed Packets Get Ghosted by Suricata & NGFWs\n\nModern firewalls (Palo Alto, FortiGate, Check Point, Firepower) and IDS engines\n(Suricata, Zeek) track full TCP streams. Fire a naked TLS `ClientHello` or HTTP\n`POST` with no prior `SYN -> SYN-ACK -> ACK` and the sensor shrugs and drops it as\nmid-stream noise, leaving you wondering why your shiny new detection rule never\nfired.\n\nThree handshake lines in `.frasm` open the flow cleanly, and your L7 payload rides\nin on the exact expected `seq` and `acknum` so `flow:established` rules evaluate\nevery byte.\n\n### `suricata_tls_sni_check.frasm`\n\n```frameassembly\n// Test Suricata tls.sni Shadow-IT rule on TCP 443\n// Run: suricata -r suricata_tls_sni_check.pcap -l ./logs\nhost workstation { ip 10.10.20.45 }\nhost shadow_saas { ip 198.51.100.77 }\n\ncompile {\n    workstation -> shadow_saas tcp syn srcport 53110 dstport 443 win 65535 mss 1460 sackperm wait 1ms\n    workstation <- shadow_saas tcp syn ack win 65535 mss 1460 sackperm wait 1ms\n    workstation -> shadow_saas tcp ack wait 1ms\n    workstation -> shadow_saas tls clienthello handshakeversion 0x0303 sni \"unapproved-upload.example.net\" alpn \"h2\" wait 2ms\n    workstation <- shadow_saas tls alert\n}\n```\n\n```bash\n# Compile and feed straight into Suricata + Zeek offline mode (zero root!)\nframeassembly suricata_tls_sni_check.frasm\nsuricata -r suricata_tls_sni_check.pcap -l ./suricata-out\nzeek -C -r suricata_tls_sni_check.pcap\n```\n\n## 2. Intentional Chaos: Out-of-State ACKs, Xmas Scans & IPv4 Fragments\n\nHalf of security testing is proving bad packets get *dropped*. Whenever you\nexplicitly specify `fin psh urg`, custom `seq` / `acknum` overrides, or IPv4\nfragmentation flags (`ipid`, `mf`, `fragoffset`), FrameAssembly puts your exact\nbogus flags on the wire while keeping IP/TCP checksums valid so the NIC doesn’t\neat the frame before the firewall sees it.\n\n### `firewall_anomaly_probes.frasm`\n\n```frameassembly\nhost red_scanner { ip 203.0.113.99 }\nhost dmz_bastion { ip 192.0.2.25 }\n\ncompile {\n    // 1. Out-of-state ACK probe -> expect RST or silent drop\n    red_scanner -> dmz_bastion tcp ack srcport 44900 dstport 22 seq 9000 acknum 1 win 1024 wait 5ms\n    red_scanner <- dmz_bastion tcp rst seq 1 wait 10ms\n\n    // 2. Classic TCP Xmas tree packet (FIN + PSH + URG) -> HTTPS 443\n    red_scanner -> dmz_bastion tcp fin psh urg srcport 44901 dstport 443 seq 1000 urgent 0 wait 10ms\n\n    // 3. Two-piece IPv4 UDP fragment pair (mf -> fragoffset 1)\n    red_scanner -> dmz_bastion udp srcport 44902 dstport 161 ipid 0x3344 mf fragoffset 0 payload \"AAAAAAAA\" wait 1ms\n    red_scanner -> dmz_bastion udp srcport 44902 dstport 161 ipid 0x3344 fragoffset 1 payload \"BBBBBBBB\"\n}\n```\n\n## 3. OT / ICS Conduit Checks Without Brick-Risking a Live PLC\n\nPoking a live turbine or water-plant PLC just to verify Claroty, Dragos, Nozomi,\nor an industrial firewall blocks Function Code 6 writes is a career-limiting move.\nBuild authentic `modbus`, `dnp3` (with real IEEE 1815 per-chunk CRC-16), `s7comm`,\n`bacnet`, `ethernetip`, and `opcua` traces in user space instead:\n\n### `ot_modbus_write_audit.frasm`\n\n```frameassembly\n// Prove OT firewall allows FC 03 (Read) <-> alerts on FC 06 (Write)\nhost eng_ws { ip 172.16.30.15 }\nhost plc_01 { ip 172.16.10.50 }\n\ncompile {\n    eng_ws -> plc_01 tcp syn srcport 50900 dstport 502 win 64240 mss 1460 vlan 30 wait 1ms\n    eng_ws <- plc_01 tcp syn ack win 64240 mss 1460 vlan 30 wait 1ms\n    eng_ws -> plc_01 tcp ack vlan 30 wait 1ms\n    // Allowed: Read Holding Registers (FC 03)\n    eng_ws -> plc_01 modbus txid 1 unitid 1 readholdingregisters addr 40001 count 2 vlan 30 wait 3ms\n    eng_ws <- plc_01 modbus txid 1 unitid 1 readholdingregisters isresponse value 1500 vlan 30 wait 5ms\n    // Unauthorized: Write Single Register (FC 06) -> should fire conduit alert!\n    eng_ws -> plc_01 modbus txid 2 unitid 1 writesingleregister addr 40001 value 9999 vlan 30\n}\n```\n"}
{"id":"pretrain-guide-simulate-snmp-and-monitoring","kind":"workflow_guide","title":"Encrypted SNMPv3 Traps, Syslog & NetFlow From Your Desk — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/simulate-snmp-and-monitoring","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["snmp3","snmp2","snmp1","syslog","tacacs","radius","ntp","ptp","netflow","ipfix","sflow"],"text":"# Encrypted SNMPv3 Traps, Syslog & NetFlow From Your Desk\n\n> **FrameAssembly v3.3.0** · Workflow Guide 04 · Canonical URL:\n> https://frameassembly-lang.dev/docs/simulate-snmp-and-monitoring\n\nTest Zabbix, PRTG, LibreNMS, or Splunk alert rules on demand with MIB-free\nSNMPv1/v2c/v3 `authPriv` traps, Syslog events, and NetFlow/IPFIX/sFlow records.\n\n## Key Takeaways\n\n- Zero MIB files needed — type numeric OIDs directly and let FrameAssembly encode\n  the ASN.1 BER tree.\n- `snmp3` runs real RFC 3414 / 3826 / 7860 key localization, HMAC digests, and\n  AES-128-CFB encryption so Wireshark and `snmptrapd` decrypt every varbind.\n- Drop SNMP traps + Syslog + TACACS+ + NetFlow/IPFIX/sFlow into one `.frasm`\n  timeline to test SIEM correlation rules.\n\n## 1. SNMPv2c & Encrypted SNMPv3 (`authPriv`) Without Net-SNMP Pain\n\n\"Wait until a core PSU actually catches fire\" is a terrible way to find out your\nZabbix trap receiver had the wrong EngineID configured. And fighting `snmptrap`\nflags plus broken vendor MIB imports on your laptop isn’t much better.\n\nFrameAssembly emits `snmp1`, `snmp2`, and USM-encrypted `snmp3` datagrams straight\nfrom numeric OIDs using repeatable `varbind <oid> <type> <val>` clauses (`string`,\n`int`, `oidval`, `ipval`, `counter32`, `gauge32`, `timeticks`, `counter64`,\n`null`, `nullval`).\n\n### `snmpv3_linkdown_trap.frasm`\n\n```frameassembly\n// SNMPv2c + encrypted SNMPv3 authPriv linkDown traps -> UDP 162\nhost core_sw { ip 10.50.0.1 }\nhost nms_srv { ip 10.50.0.100 }\n\ncompile {\n    // 1. SNMPv2c linkDown (snmpTrapOID.0 -> 1.3.6.1.6.3.1.1.5.3)\n    core_sw -> nms_srv snmp2 trap community \"noc-ro\" sysuptime 452000 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.2.2.1.2.1 string \"TenGigE0/1/0\" wait 5ms\n\n    // 2. Encrypted SNMPv3 USM authPriv (HMAC-SHA256 + AES-128) trap\n    core_sw -> nms_srv snmp3 trap user \"nms-secops\" engineid \"80001f888011223344\" engineboots 7 enginetime 9410 auth sha256 \"AuthSecret2026!\" priv aes \"PrivSecret2026!\" sysuptime 452005 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.2.2.1.2.1 string \"TenGigE0/1/0\"\n}\n```\n\n> **Decrypting `snmp3` in Wireshark:** In Wireshark (`Preferences -> Protocols ->\n> SNMP -> Users Table`), plug in Engine ID `80001f888011223344`, user\n> `nms-secops`, SHA-256 (`AuthSecret2026!`), and AES (`PrivSecret2026!`) to\n> decrypt the ScopedPDU.\n\n## 2. Stitch Traps + Syslog + TACACS+ Into One Timeline\n\nWant to test a SIEM rule that correlates an admin `tacacs` login on TCP 49 with a\nBGP neighbor `syslog` drop 4 milliseconds later? Put both in the same `compile`\nblock:\n\n### `noc_siem_correlation.frasm`\n\n```frameassembly\nhost edge_rtr  { ip 10.60.1.1 }\nhost siem_col  { ip 10.60.10.50 }\nhost tacacs_sv { ip 10.60.10.49 }\n\ncompile {\n    // Admin TACACS+ login on TCP 49 -> Critical BGP Syslog alert 4ms later\n    edge_rtr -> tacacs_sv tcp syn srcport 51400 dstport 49 win 65535 mss 1460 wait 1ms\n    edge_rtr <- tacacs_sv tcp syn ack win 65535 mss 1460 wait 1ms\n    edge_rtr -> tacacs_sv tcp ack wait 1ms\n    edge_rtr -> tacacs_sv tacacs authen sessionid 0x9001ab user \"netadmin\" data \"tty0\" wait 4ms\n    edge_rtr -> siem_col syslog facility 16 severity 2 hostname \"edge-rtr-01\" app \"BGP\" msgid \"ADJCHANGE\" msg \"Neighbor 198.51.100.1 Down: Hold Timer Expired\"\n}\n```\n\n## 3. Synthetic Top-Talkers: NetFlow v5, IPFIX & sFlow\n\nFeed ElastiFlow, Akvorado, pmacct, or ntopng deterministic flow spikes using\n`netflow` (UDP 2055), `ipfix` (UDP 4739, auto-bundling Template Set + Data Set so\nWireshark decodes it immediately), and `sflow` (UDP 6343):\n\n### `flow_collector_test.frasm`\n\n```frameassembly\nhost core_exporter { ip 172.20.0.1 }\nhost flow_ingest   { ip 172.20.0.205 }\n\ncompile {\n    core_exporter -> flow_ingest netflow srcip 10.10.5.25 dstip 198.51.100.80 srcport 52400 dstport 443 proto 6 packets 1250 octets 1680000 wait 5ms\n    core_exporter -> flow_ingest ipfix domainid 100 srcip 2001:db8:5::25 dstip 2001:db8:99::80 srcport 52401 dstport 443 proto 6 packets 840 octets 1120000 wait 5ms\n    core_exporter -> flow_ingest sflow agentip 172.20.0.1 subagentid 1 seq 42 uptime 360000 samples 1\n}\n```\n"}
{"id":"pretrain-guide-vlans-tunnels-and-ipv6","kind":"workflow_guide","title":"VLANs, QinQ, MPLS, Tunnel Soup & Dual-Stack IPv6 — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/vlans-tunnels-and-ipv6","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","qinq","mpls","lldp","stp","lacp","eapol","vxlan","geneve","gre","ikev2","esp","ah","wireguard","icmp","ndp","bgp","ospf","vrrp","dhcp"],"text":"# VLANs, QinQ, MPLS, Tunnel Soup & Dual-Stack IPv6\n\n> **FrameAssembly v3.3.0** · Workflow Guide 05 · Canonical URL:\n> https://frameassembly-lang.dev/docs/vlans-tunnels-and-ipv6\n\nStamp 802.1Q / 802.1ad QinQ tags that OS NIC drivers usually eat, stack\nMPLS/VXLAN/WireGuard/IPsec headers, and reuse one `flow(a, b)` across IPv4 & IPv6.\n\n## Key Takeaways\n\n- Laptop NIC drivers love eating outer 802.1Q and QinQ tags on live captures —\n  FrameAssembly writes `0x8100`, `0x88a8`, and `0x8847` straight into the file.\n- Slap `vlan`, `qinq`, `mpls`, `ttl`, `dscp`, `ecn`, or IPv6 `flowlabel` onto\n  almost any Layer 3–7 statement.\n- Write `flow peer_check(a, b) { ... }` once and run it on both IPv4 router pairs\n  and IPv6 router pairs.\n\n## 1. 802.1Q, Carrier QinQ & MPLS Without Driver Tag-Eating\n\nEver capture on a laptop USB dongle for twenty minutes only to realize Windows or\nLinux hardware offload silently stripped every 802.1Q tag? FrameAssembly writes\nexact IEEE 802.1Q (`0x8100`), 802.1ad QinQ (`0x88a8` S-Tag + `0x8100` C-Tag), and\n32-bit MPLS (`0x8847`) shims straight to `.pcap`.\n\nUse `vlan`, `qinq`, and `mpls` either as pure Layer 2 frames (even between\nMAC-only switch hosts) or as cross-layer modifiers on any IP/TCP/UDP/L7 frame:\n\n### `trunk_qinq_mpls.frasm`\n\n```frameassembly\nhost pe_west { ip 172.16.100.1 mac 00:1c:73:aa:00:01 }\nhost pe_east { ip 172.16.100.2 mac 00:1c:73:aa:00:02 }\n\ncompile {\n    // 1. Voice VLAN 200 + 802.1p priority 5 (pcp 5) + DiffServ EF (dscp 46)\n    pe_west -> pe_east rtp pt 0 seq 100 timestamp 160 ssrc 0x12345678 vlan 200 pcp 5 dscp 46 wait 2ms\n\n    // 2. Metro-E QinQ: outer S-VLAN 1000 -> inner C-VLAN 40 carrying OSPF Hello\n    pe_west -> pe_east ospf hello routerid 10.0.0.1 areaid 0 qinq 1000 innervlan 40 pcp 6 wait 2ms\n\n    // 3. MPLS label 24010 (EXP 6, BoS 1) carrying BGP Keepalive\n    pe_west -> pe_east bgp keepalive mpls 24010 exp 6 bos 1 mplsttl 64\n}\n```\n\n## 2. Tunnel Soup: VXLAN, GENEVE, GRE, IKEv2, ESP & WireGuard\n\nNeed a clean reference `.pcap` to debug underlay UDP ports, `df` MTU drops, or VPN\nfirewall ACLs? One `compile` block covers `gre`, `vxlan` (UDP 4789), `geneve` (UDP\n6081), `ikev2` (UDP 500), `esp` / `ipsec` / `ah`, and `wireguard` (UDP 51820):\n\n### `vpn_and_overlays.frasm`\n\n```frameassembly\nhost vtep_a { ip 10.0.250.11 }\nhost vtep_b { ip 10.0.250.12 }\n\ncompile {\n    vtep_a -> vtep_b vxlan vni 10500 dscp 16 df wait 2ms\n    vtep_a -> vtep_b geneve vni 20500 optclass 0x0102 opttype 1 wait 2ms\n    vtep_a -> vtep_b ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0 msgid 0 wait 3ms\n    vtep_a <- vtep_b ikev2 sainit initiatorspi 0xa1b2c3d4e5f60708 responderspi 0x1122334455667788 msgid 0 wait 3ms\n    vtep_a -> vtep_b wireguard initiation sender 0x01020304\n}\n```\n\n## 3. Dual-Stack Magic: One `flow(a, b)` for Both IPv4 & IPv6\n\n70 of the 73 Layer 3–7 protocols work identically over IPv4 and IPv6, while\n`icmp`, `ospf`, `rip`, `vrrp`, `hsrp`, and `dhcp` morph between their v4 and v6\nwire encodings automatically based on your host IPs (`igmp` stays IPv4-only; `ndp`\nand `mld` stay IPv6-only).\n\nWrap your sequence in `flow peer_check(a, b) { ... }` once, then call it on both\nv4 and v6 router pairs:\n\n### `dual_stack_ping_and_bgp.frasm`\n\n```frameassembly\nhost rtr_a_v4 { ip 192.0.2.1 }\nhost rtr_b_v4 { ip 192.0.2.2 }\nhost rtr_a_v6 { ip 2001:db8:1::1 }\nhost rtr_b_v6 { ip 2001:db8:1::2 }\n\nflow peer_check(a, b) {\n    a -> b icmp echorequest id 50 seq 1 wait 1ms\n    a <- b icmp echoreply id 50 seq 1 wait 2ms\n    a -> b tcp syn srcport 50179 dstport 179 win 65535 mss 1440 wait 1ms\n    a <- b tcp syn ack win 65535 mss 1440 wait 1ms\n    a -> b tcp ack wait 1ms\n    a -> b bgp open asn 4200000001 holdtime 90 bgpid 192.0.2.1\n}\n\ncompile {\n    peer_check(rtr_a_v4, rtr_b_v4)\n    peer_check(rtr_a_v6, rtr_b_v6)\n}\n```\n\n> **4-Byte BGP ASNs (`asn > 65535`) Just Work:** Pass `asn 4200000001` and\n> FrameAssembly automatically puts `AS_TRANS` (`23456`) in the legacy 16-bit slot\n> + appends RFC 6793 Capability 65 with your 32-bit ASN.\n"}
{"id":"pretrain-guide-cli-and-file-format","kind":"workflow_guide","title":"CLI Cheat Sheet, Address Formats & Common Gotchas — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/cli-and-file-format","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":[],"text":"# CLI Cheat Sheet, Address Formats & Common Gotchas\n\n> **FrameAssembly v3.3.0** · Workflow Guide 06 · Canonical URL:\n> https://frameassembly-lang.dev/docs/cli-and-file-format\n\nEvery `frameassembly` v3.2.2 terminal command, accepted IP/MAC/OID format, typo\nfix, and why `.frasm` has nothing to do with x86 CPU assemblers.\n\n## Key Takeaways\n\n- Positional paths all the way: `frameassembly in.frasm [out.pcap|.pcapng]`,\n  `show`, `reverse`, `update`, `help`, `version` — zero `-o` flags, zero `compile`\n  subcommand, zero flags on `update`.\n- Paste MACs straight out of Cisco IOS (`001a.2b3c.4d5e`), Windows\n  (`00-1A-2B-3C-4D-5E`), or Linux (`00:1a:2b:3c:4d:5e`).\n- `.frasm` = FrameAssembly packet captures (`text/vnd.frameassembly`), completely\n  distinct from `.asm` CPU assembly files.\n\n## 1. Every CLI Command on One Card (`v3.2.2`)\n\nThe `frameassembly` binary is a single static Rust executable on Windows, macOS,\nand Linux — zero Python, zero libc drama, zero network permissions:\n\n```bash\n# Compile -> inspect in tshark -> round-trip reverse back to .frasm\nframeassembly lab.frasm lab.pcapng\ntshark -r lab.pcapng\nframeassembly reverse lab.pcapng lab_copy.frasm\n```\n\n| Command | What Happens |\n| --- | --- |\n| `frameassembly demo.frasm` | Compiles `demo.frasm -> demo.pcap` in the same directory. |\n| `frameassembly demo.frasm out.pcap` | Compiles `demo.frasm -> out.pcap` (microsecond libpcap `0xa1b2c3d4` for `tcpdump`, `tcpreplay`, Suricata, and Zeek). |\n| `frameassembly demo.frasm out.pcapng` | Compiles `demo.frasm -> out.pcapng` (nanosecond `IfTsResol=9` for Wireshark and `tshark`). |\n| `frameassembly show demo.frasm` | Validates and prints the relative-timestamp packet ladder to stdout without writing files. |\n| `frameassembly reverse capture.pcap [out.frasm]` | Reverses `.pcap` or `.pcapng -> .frasm` (`host1`, `host2`, ...). |\n| `frameassembly update` | Strictly zero-flag self-updater: tries Cargo/`rustup` first (`rustc >= 1.89` & linker preflight), then falls back to SHA-256-verified GitHub Release binaries. |\n| `frameassembly help [subcommand]` / `frameassembly version` | Prints CLI usage or `frameassembly 3.2.2`. |\n\n## 2. IP, MAC, Hex & OID Formats You Can Paste Directly\n\nCopy-paste addresses straight from `show mac address-table`, `ipconfig /all`, or\n`ip addr` without reformatting:\n\n| Literal Type | Valid Examples | Notes |\n| --- | --- | --- |\n| User names (`host`, `flow`) | `client`, `Core_SW_1`, `fw-dmz-01` | Letters, digits, underscores, and internal hyphens. |\n| IPv4 & IPv6 literals | `10.0.0.1`, `2001:db8::1`, `fe80::1` | Plain host addresses — no `/24` or `/64` prefix lengths. |\n| Ethernet MAC literals | `00:1a:2b:3c:4d:5e`, `00-1A-2B-3C-4D-5E`, `001a.2b3c.4d5e` | Auto-derived when omitted (`00:00:00:00:00:01`, RFC multicast MACs, or IEEE L2 group MACs). |\n| Integers & hex numbers | `443`, `0x0806`, `0x1a2b` | Decimal or `0x` hex; signed negatives allowed on `ntp precision`, `ldap msgid`, `kerberos etype`, and SNMP `int`. |\n| Hex byte strings | `hexpayload \"deadbeef\"`, `hexpayload \"de:ad:be:ef\"` | Even-length hex octets (spaces or colons fine); mutually exclusive with `payload \"...\"`. |\n| SNMP OIDs | `1.3.6.1.2.1.1.1.0` or `.1.3.6.1.2.1.1.1.0` | Unquoted numeric trees (>= 2 arcs) or double-quoted strings. |\n\n## 3. Six Muscle-Memory Typos & Their Instant Fixes\n\nMistype a keyword and the compiler’s edit-distance suggester usually tells you the\nexact fix (`Did you mean echorequest?`). Here are the top six classics:\n\n| Muscle-Memory Typo | Valid v3.2.2 `.frasm` / CLI | Why |\n| --- | --- | --- |\n| `a -> b icmp echo_request` | `a -> b icmp echorequest` | Built-in keywords are strictly `[a-z0-9]+` with zero underscores. |\n| Standalone `wait 10ms` line | `a -> b icmp echorequest wait 10ms` | `wait` is a post-packet suffix on the frame that precedes the gap. |\n| `a -> b tcp ack 1001` | `a -> b tcp ack acknum 1001` | Bare `ack` = ACK flag bit; `acknum` = 32-bit acknowledgment number. |\n| `a -> b http get host \"x.test\"` | `a -> b http get hosthdr \"x.test\"` | `host` declares top-level boxes; `hosthdr` sets HTTP / SSDP `Host:`. |\n| `flow ping { ... }` or `loop 5 { ... }` | `flow ping(a, b) { ... }` called inside `compile { ... }` | `flow` always takes parameters in parentheses; repeat calls in `compile` instead of `loop`. |\n| `frameassembly update --check` / `--force` | `frameassembly update` | `update` takes strictly zero flags — run it bare to self-update via Cargo or a SHA-256-verified release binary. |\n\n## 4. Name Check: `.frasm` (Packets) vs. `.asm` (x86 Assembly)\n\nFrameAssembly uses `.frasm` (`text/vnd.frameassembly`) to create and reverse\nnetwork packet captures (`.pcap <-> .pcapng`). It has zero connection to\nx86/x86-64 CPU assemblers (`.asm`, `;` comments) or FPGA hardware bitstream tile\nfiles.\n\n## 5. `.pcap` vs. `.pcapng` (`IfTsResol=9`) Downstream Tool Compatibility\n\nPick your output extension based on the tool reading the file next (`frameassembly\nin.frasm out.pcap` vs. `out.pcapng`):\n\n| Downstream Tool | Classic `.pcap` (`0xa1b2c3d4`, `1 µs`) | Nanosecond `.pcapng` (`IfTsResol=9`, `1 ns`) | Practitioner Recommendation |\n| --- | --- | --- | --- |\n| Wireshark & `tshark` (`3.x` / `4.x`) | Full support (`1 µs` display) | Native `0.000000001 s` display | Prefer `.pcapng` when inspecting `ns` bursts or IEEE 1588v2 `ptp` sync loops. |\n| `tcpdump` (`libpcap 1.10+`) | Native default across all OSes | Supported on modern `libpcap`; older BSD builds prefer `.pcap` | Prefer `.pcap` for portable SSH/container CLI pipelines. |\n| `tcpreplay` & `tcpprep` (`4.4+`) | Primary supported input format | Limited / build-dependent (`tcpprep` expects classic libpcap) | Always compile `.pcap` before two-NIC `tcpprep` + `tcpreplay` hardware replay. |\n| Suricata (`7.x+`), Zeek (`6.x+`) & Snort 3 | Universal offline `-r` support | Supported in Suricata 7+ / Zeek via modern `libpcap` | Prefer `.pcap` for maximum CI container compatibility unless testing `ns` timers. |\n\n## Frequently Asked Questions\n\n### How do I stop ChatGPT / Claude / Gemini from inventing fake underscored keywords?\n\nGrab `llms-full.txt` from the top navbar\n(`https://frameassembly-lang.dev/llms-full.txt`) and drop it into your prompt. It\nhands the LLM the exact v3.2.2 grammar and all 81 protocol modifiers so it stops\nhallucinating `echo_request` or `-o` flags.\n"}
{"id":"pretrain-guide-physical-hardware-labs","kind":"workflow_guide","title":"Physical Hardware Labs: Blasting .pcap Captures onto Copper & Fiber — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/physical-hardware-labs","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tls","quic","vlan","modbus","dnp3","arp","tcp","http","icmp","bgp","ospf","lldp","eapol","qinq","stp","lacp","ptp","snmp3"],"text":"# Physical Hardware Labs: Blasting `.pcap` Captures onto Copper & Fiber\n\n> **FrameAssembly v3.3.0** · Workflow Guide 07 · Canonical URL:\n> https://frameassembly-lang.dev/docs/physical-hardware-labs\n\nWire `.frasm -> .pcap` captures into SPAN ports, optical TAPs, two-NIC firewall\nhairpins (`tcpprep` + `tcpreplay`), and managed switch trunks without NIC drivers\neating your VLAN tags.\n\n## Key Takeaways\n\n- FrameAssembly never touches raw sockets: it writes `.pcap` files in user space,\n  and `tcpreplay` / Bittwist / Ostinato blasts those bytes onto real copper or\n  SFP+ fiber.\n- Two-NIC hairpins (`eth1 -> Trust`, `eth2 <- Untrust`) let one Linux box\n  impersonate both client and server across a hardware firewall via `tcpprep` +\n  `tcpreplay`.\n- Turn off Linux NIC VLAN-stripping offloads (`ethtool -K eth1 rxvlan off txvlan\n  off`) before replaying 802.1Q, QinQ, or deliberately weird anomaly packets.\n\n## 1. SPAN Ports, Optical TAPs & Passive NDR / OT Sensors\n\nStanding up a hardware IDS/NDR box (Suricata, Zeek, Corelight, ExtraHop) or an\nindustrial OT sensor (Claroty, Dragos, Nozomi) hanging off a SPAN port or passive\nfiber TAP? Plug one spare lab NIC straight into the monitor port and feed it a\nclassic `.pcap`.\n\nBecause passive sensors never talk back, your `.frasm` script has to carry *both*\nsides (`->` and `<-`) of the TCP handshake so the stream reassembler marks the\nflow established before inspecting TLS SNI, HTTP, SMB, or Modbus.\n\n### `span_sensor_audit.frasm`\n\n```frameassembly\n// Bidirectional VLAN 120 trace -> physical SPAN / optical TAP sensor port\nhost branch_ws   { ip 10.20.15.42 mac 00:50:56:aa:15:42 }\nhost shadow_edge { ip 198.51.100.84 mac 00:1c:73:00:00:01 }\n\ncompile {\n    // Full 3-way handshake -> stream reassembler marks flow established\n    branch_ws -> shadow_edge tcp syn srcport 54210 dstport 443 win 65535 mss 1460 vlan 120 wait 1ms\n    branch_ws <- shadow_edge tcp syn ack win 65535 mss 1460 vlan 120 wait 1ms\n    branch_ws -> shadow_edge tcp ack vlan 120 wait 1ms\n\n    // TLS 1.3 ClientHello SNI + HTTP/3 QUIC Initial probe\n    branch_ws -> shadow_edge tls clienthello sni \"unmanaged-transfer.example.net\" alpn \"h2\" vlan 120 wait 2ms\n    branch_ws -> shadow_edge quic initial version 1 dcid 0x1122334455667788 scid 0xaabbccddeeff0011 pktnum 1 vlan 120\n}\n```\n\n```bash\n# 1. Compile classic microsecond .pcap (what tcpreplay expects)\nframeassembly span_sensor_audit.frasm span_sensor_audit.pcap\n\n# 2. Bring up your spare lab NIC and fire away\nsudo ip link set dev eth1 up\nsudo tcpreplay --intf1=eth1 --pps=500 span_sensor_audit.pcap\n```\n\n## 2. Two-NIC Hardware Firewall Hairpin (`eth1` -> NGFW <- `eth2`)\n\nBlast a two-way `.pcap` out of *one* NIC into a stateful Layer 3 hardware firewall\n(Palo Alto, FortiGate, SRX, Firepower) and watch every server reply die horribly\non the Trust port thanks to Reverse Path Forwarding (RPF) and zone checks.\n\nThe bench trick: cable two NICs on your Linux tester (`eth1` -> Firewall Trust,\n`eth2` -> Firewall Untrust/DMZ). Toss two gratuitous `arp` frames at the top so\nthe firewall doesn’t stall ARPing for fake hosts, set `dstmac` to each ingress\ninterface MAC, and let `tcpprep` + `tcpreplay` split client <-> server across both\ncables:\n\n### `inline_ngfw_hairpin.frasm`\n\n```frameassembly\n// Two-NIC inline L3 firewall bench:\n// eth1 -> Firewall Trust:   10.10.1.1   mac 00:1b:17:00:01:01\n// eth2 -> Firewall Untrust: 172.16.2.1  mac 00:1b:17:00:02:01\nhost trust_client { ip 10.10.1.50  mac 02:00:00:10:01:50 }\nhost dmz_server   { ip 172.16.2.80 mac 02:00:00:16:02:80 }\nhost fw_trust     { ip 10.10.1.1   mac 00:1b:17:00:01:01 }\nhost fw_untrust   { ip 172.16.2.1  mac 00:1b:17:00:02:01 }\n\ncompile {\n    // 1. Seed firewall ARP tables on Trust (eth1) and Untrust (eth2)\n    trust_client -> fw_trust arp gratuitous wait 5ms\n    dmz_server -> fw_untrust arp gratuitous wait 5ms\n\n    // 2. Stateful TCP + HTTP flow addressed to each firewall ingress MAC\n    trust_client -> dmz_server tcp syn srcport 52100 dstport 8080 win 65535 mss 1460 dstmac 00:1b:17:00:01:01 wait 1ms\n    dmz_server -> trust_client tcp syn ack srcport 8080 dstport 52100 seq 5000 acknum 1001 win 65535 mss 1460 dstmac 00:1b:17:00:02:01 wait 1ms\n    trust_client -> dmz_server tcp ack srcport 52100 dstport 8080 seq 1001 acknum 5001 dstmac 00:1b:17:00:01:01 wait 1ms\n    trust_client -> dmz_server http get uri \"/api/v1/health\" hosthdr \"dmz-api.lab.local\" srcport 52100 dstport 8080 seq 1001 acknum 5001 dstmac 00:1b:17:00:01:01 wait 2ms\n    dmz_server -> trust_client http status 200 reason \"OK\" body \"{\\\"zone\\\":\\\"dmz\\\"}\" srcport 8080 dstport 52100 seq 5001 acknum 1072 dstmac 00:1b:17:00:02:01\n}\n```\n\n```bash\n# 1. Compile classic .pcap\nframeassembly inline_ngfw_hairpin.frasm inline_ngfw_hairpin.pcap\n\n# 2. Split client (10.10.1.0/24 -> eth1) vs server (everything else -> eth2)\ntcpprep --cidr=10.10.1.0/24 --pcap=inline_ngfw_hairpin.pcap --cachefile=hairpin.cache\n\n# 3. Replay synchronously across Trust (eth1) <-> Untrust (eth2)\nsudo tcpreplay --cachefile=hairpin.cache --intf1=eth1 --intf2=eth2 inline_ngfw_hairpin.pcap\n```\n\n> **Virtual-Wire (`vwire`) Mode Is Even Lazier:** Put your lab firewall in Layer 2\n> Virtual-Wire / transparent bridge mode between `eth1` and `eth2` and you can\n> skip all the `dstmac` overrides — plain `->` and `<-` arrows work out of the\n> box.\n\n## 3. Managed Switch Ports: LLDP, 802.1X EAPOL & QinQ Trunks\n\nCabling a lab NIC straight into a Cisco Catalyst/Nexus, Arista, Juniper, or\nMikroTik port lets you test `show lldp neighbors`, 802.1X `eapol` port auth,\nDynamic ARP Inspection (DAI), and carrier 802.1ad QinQ trunks.\n\nBecause all 8 pure Layer 2 protocols (`arp`, `vlan`, `qinq`, `lldp`, `stp`,\n`lacp`, `eapol`, `mpls`) accept MAC-only `host` blocks, you don’t even need dummy\nIPs for L2 bring-up:\n\n### `switch_port_bringup.frasm`\n\n```frameassembly\n// Direct switch-port poke: LLDP + 802.1X EAPOL + QinQ double-tag\nhost lab_nic   { mac 00:1b:21:aa:bb:01 }\nhost tor_sw_01 { mac 00:1c:73:00:09:99 }\nhost cpe_edge  { ip 172.20.40.10 mac 00:1b:21:aa:bb:02 }\nhost pe_core   { ip 172.20.40.1  mac 00:1c:73:00:09:98 }\n\ncompile {\n    // 1. Light up 'show lldp neighbors'\n    lab_nic -> tor_sw_01 lldp chassisid \"lab-tester-01\" portid \"eth1\" ttl 120 sysname \"packet-bench.lab\" wait 5ms\n\n    // 2. Wake up 802.1X authenticator on the switch port\n    lab_nic -> tor_sw_01 eapol start version 2 wait 5ms\n    lab_nic -> tor_sw_01 eapol eappacket version 2 eapcode 2 eapid 1 eapmethod 1 identity \"host/bench01.corp.local\" wait 5ms\n\n    // 3. Test 802.1ad QinQ S-VLAN 2100 -> C-VLAN 40 handoff\n    cpe_edge -> pe_core icmp echorequest id 77 seq 1 qinq 2100 innervlan 40 pcp 5\n}\n```\n\n## 4. Five Ways a Physical NIC or Switch Will Quietly Sabotage You\n\nBefore blaming your `.frasm` script when packets vanish on copper, check these\nfive hardware traps:\n\n```bash\n# Turn off Linux NIC VLAN-tag eating & segmentation offloads on your replay port\nsudo ethtool -K eth1 rxvlan off txvlan off tx off rx off tso off gso off gro off\n\n# Bump MTU so QinQ (+8B) or VXLAN (+50B) doesn't hit errno=90 (Message too long)\nsudo ip link set dev eth1 mtu 1558\n```\n\n| Hardware Trap | What Goes Sideways | Fix |\n| --- | --- | --- |\n| NIC VLAN offload (`txvlan on`) | Outer `vlan` or `qinq` tags vanish or mutate on the wire | `sudo ethtool -K eth1 txvlan off rxvlan off` before `tcpreplay`. |\n| `1500` byte NIC MTU | `tcpreplay` complains `Message too long (errno=90)` on QinQ / VXLAN frames | Raise replay NIC + switch port MTU (`1508` QinQ, `1558+` VXLAN, or `9000` jumbo). |\n| Switch `bpduguard` | Sending one `stp` BPDU instantly slams your switch port into `err-disabled` | Only fire `stp` frames into isolated lab ports where BPDU Guard is what you are testing! |\n| Burst rate vs `wait` timers | Hardware policer drops zero-gap bursts | Default `tcpreplay` honors `.frasm` `wait` deltas; add `--pps=100` for gentle pacing. |\n| Windows laptops | No native `AF_PACKET` socket for `tcpreplay` | Use `Npcap` (with raw 802.1Q enabled) + Ostinato/Bittwist, or pass a USB NIC into Linux. |\n\n## 5. Classic `.pcap` vs. Nanosecond `.pcapng` (`IfTsResol=9`) for Lab Gear\n\nAlways compile classic `.pcap` before feeding `tcpprep` + `tcpreplay`, and reserve\n`.pcapng` (`IfTsResol=9`) for nanosecond Wireshark / `tshark` / PTPv2 clock\nanalysis:\n\n| Downstream Tool | Classic `.pcap` (`0xa1b2c3d4`, `1 µs`) | Nanosecond `.pcapng` (`IfTsResol=9`, `1 ns`) | Practitioner Recommendation |\n| --- | --- | --- | --- |\n| Wireshark & `tshark` (`3.x` / `4.x`) | Full support (`1 µs` display) | Native `0.000000001 s` display | Prefer `.pcapng` when inspecting `ns` bursts or IEEE 1588v2 `ptp` sync loops. |\n| `tcpdump` (`libpcap 1.10+`) | Native default across all OSes | Supported on modern `libpcap`; older BSD builds prefer `.pcap` | Prefer `.pcap` for portable SSH/container CLI pipelines. |\n| `tcpreplay` & `tcpprep` (`4.4+`) | Primary supported input format | Limited / build-dependent (`tcpprep` expects classic libpcap) | Always compile `.pcap` before two-NIC `tcpprep` + `tcpreplay` hardware replay. |\n| Suricata (`7.x+`), Zeek (`6.x+`) & Snort 3 | Universal offline `-r` support | Supported in Suricata 7+ / Zeek via modern `libpcap` | Prefer `.pcap` for maximum CI container compatibility unless testing `ns` timers. |\n"}
{"id":"pretrain-guide-cursed-packets-cookbook","kind":"workflow_guide","title":"Cursed Packets Cookbook: Weird Frames, Middlebox Lies & Reproducers — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/cursed-packets-cookbook","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","tls","http","quic","qinq","vlan","lldp","eapol","stp","http2","smb","modbus","dnp3","s7comm","opcua","bacnet","ethernetip"],"text":"# Cursed Packets Cookbook: Weird Frames, Middlebox Lies & Reproducers\n\n> **FrameAssembly v3.3.0** · Workflow Guide 08 · Canonical URL:\n> https://frameassembly-lang.dev/docs/cursed-packets-cookbook\n\nFour copy-paste packet war stories for catching forged middlebox TCP resets,\n802.1ad QinQ native-VLAN leaks, IDS stream-reassembler edge cases, and offline OT\ncoil writes.\n\n## Key Takeaways\n\n- Isolate forged inline middlebox TCP resets by comparing the origin server\n  SYN-ACK TTL (`52`) against the sudden RST TTL (`251`) and IPID (`0x0000`).\n- Standard OS network stacks will not emit double-tagged QinQ frames, overlapping\n  TCP sequence offsets, or custom hop-limit jumps — `.frasm` writes exact wire\n  bytes directly to `.pcap`.\n- Every recipe compiles to `.pcap` or `.pcapng` with valid Ethernet/IP/TCP/CRC\n  checksums for Wireshark, Suricata, Zeek, and `tcpreplay`.\n\n## 1. Inline Middlebox TCP Reset Detection (TTL & IPID Discrepancy)\n\nWhen a TLS connection terminates 400 microseconds after `ClientHello` — faster\nthan round-trip propagation to the origin server — an adjacent inline DPI firewall\nor proxy is typically injecting a forged `RST+ACK`.\n\nIn Wireshark, compare the origin server (`upstream_api`) `SYN-ACK` at `ttl 52`\n(twelve router hops away) against the sudden `RST+ACK` arriving with `ttl 251`,\n`ipid 0x0000`, and `win 0`. This 5-frame `.frasm` reproducer builds a\ndeterministic regression capture:\n\n### `middlebox_rst_autopsy.frasm`\n\n```frameassembly\n// Reproduce TTL jump (52 -> 251) when an inline DPI middlebox resets TLS SNI\nhost client_host  { ip 10.42.10.99   mac 00:1b:21:aa:bb:01 }\nhost upstream_api { ip 198.51.100.42 mac 00:1c:73:00:00:01 }\n\ncompile {\n    // Origin server sits 12 router hops away (64 - 12 = TTL 52)\n    client_host -> upstream_api tcp syn srcport 54321 dstport 443 ttl 64 win 65535 mss 1460 wscale 7 sackperm wait 14ms\n    client_host <- upstream_api tcp syn ack ttl 52 ipid 0x4a21 win 65535 mss 1460 wscale 7 sackperm wait 1ms\n    client_host -> upstream_api tcp ack ttl 64 wait 1ms\n\n    // TLS ClientHello triggers an inline middlebox reset 400us later\n    client_host -> upstream_api tls clienthello sni \"git.corp-internal.example\" ciphersuite 0x1301 alpn \"h2\" ttl 64 wait 400us\n    client_host <- upstream_api tcp rst ack ttl 251 ipid 0x0000 win 0\n}\n```\n\n```bash\n# Compile and inspect the sudden TTL jump (52 -> 251) in tshark\nframeassembly middlebox_rst_autopsy.frasm\ntshark -r middlebox_rst_autopsy.pcap -T fields -e frame.number -e frame.time_relative -e ip.ttl -e ip.id -e tcp.flags.str\n```\n\n> **Wireshark Filter for Suspect Resets:** Filter on `tcp.flags.reset == 1 &&\n> ip.id == 0` (or check whether `ip.ttl` jumps by 60+ mid-stream compared to the\n> initial `SYN-ACK`).\n\n## 2. Unsolicited LLDP Discovery & Native-VLAN 802.1ad QinQ Tag Popping\n\nUnmanaged endpoints often broadcast firmware and management details over `lldp`\nwhile sharing access ports. If a switch trunk leaves VLAN 1 untagged as its native\nVLAN, an outer `0x88a8` tag (`qinq 1 innervlan 20`) can be stripped on the first\ntrunk hop and forward the inner tag into VLAN 20.\n\nBecause client OS NIC drivers strip VLAN headers before user space, validating\nswitch port-security and double-tag drop policies normally requires dedicated\nhardware. Here is the 3-frame `.frasm` audit:\n\n### `qinq_printer_hop.frasm`\n\n```frameassembly\n// Step 1: Unsolicited LLDP advertisement · Step 2: Outer VLAN 1 -> Inner VLAN 20 probe\nhost access_endpoint { ip 10.1.1.250 mac 00:11:0a:99:88:77 }\nhost core_trunk_sw   { mac 00:1c:73:aa:00:01 }\nhost finance_db      { ip 10.1.20.54 mac 00:50:56:bb:20:54 }\n\ncompile {\n    // Unsolicited LLDP multicast to 01:80:c2:00:00:0e\n    access_endpoint -> core_trunk_sw lldp chassisid \"access-port-3f\" portid \"eth0\" ttl 120 sysname \"prn-3f-east.local\" sysdesc \"Embedded JetDirect; management enabled\" wait 2ms\n\n    // Double-tagged 802.1ad S-VLAN 1 + 802.1Q C-VLAN 20 SYN probe toward Postgres\n    access_endpoint -> finance_db qinq 1 innervlan 20 tcp syn srcport 60123 dstport 5432 win 64240 mss 1460 wait 2ms\n    access_endpoint -> finance_db vlan 20 icmp echorequest id 0x1020 seq 1 payload \"native-vlan1-audit\"\n}\n```\n\n## 3. Overlapping TCP `seq` Retransmits (First-Seen vs. Last-Seen)\n\nFrameAssembly tracks 4-tuple `seq` and `acknum` automatically across every TCP\nframe. When testing IDS stream reassemblers, passing an explicit `seq` value\noverrides the sequence counter on that frame and re-anchors subsequent segments.\n\nSend two `PSH+ACK` segments at the exact same `seq 1001` (`wait 500us` apart) with\ndifferent HTTP URIs and TTLs to verify whether Suricata, Zeek, or an inline proxy\ninspects the first-seen or last-seen segment:\n\n### `seq_retransmit_puzzle.frasm`\n\n```frameassembly\n// Stream-reassembler validation: two HTTP segments at TCP seq 1001\nhost test_client { ip 172.16.50.15 }\nhost inline_ids  { ip 172.16.50.80 }\n\ncompile {\n    test_client -> inline_ids tcp syn srcport 51999 dstport 80 win 65535 mss 1460 wait 1ms\n    test_client <- inline_ids tcp syn ack win 65535 mss 1460 wait 1ms\n    test_client -> inline_ids tcp ack wait 1ms\n\n    // Segment A at seq 1001 with short TTL 3\n    test_client -> inline_ids http get uri \"/index.html\" hosthdr \"app.lab.local\" seq 1001 ttl 3 wait 500us\n\n    // Segment B 500us later at the same seq 1001 with full TTL 64\n    test_client -> inline_ids http get uri \"/admin/debug-vars\" hosthdr \"app.lab.local\" seq 1001 ttl 64\n}\n```\n\n```bash\n# Inspect reassembly behavior offline in Suricata and Zeek\nframeassembly seq_retransmit_puzzle.frasm\nsuricata -r seq_retransmit_puzzle.pcap -k none -l ./suricata-retransmit\nzeek -C -r seq_retransmit_puzzle.pcap\n```\n\n## 4. Offline OT Firewall & NDR Audit: Modbus Coil Writes & DNP3 Direct Operate\n\nValidating OT firewall policies and industrial NDR detections for unauthorized\nModbus coil writes (`0x05`) or DNP3 Direct Operate commands should never require\nsending write frames toward live substation RTUs or plant PLCs.\n\nCompile a deterministic 6-frame `.pcap` with valid TCP port 502 sequence tracking\nand computed IEEE 1815 DNP3 per-chunk CRC-16 checksums, then replay or ingest it\nagainst your sensor offline:\n\n### `ot_midnight_coil.frasm`\n\n```frameassembly\n// Offline OT conduit test: permitted FC 03 read -> blocked FC 05 write -> DNP3 CROB\nhost eng_workstation { ip 192.168.120.99 }\nhost substation_plc  { ip 192.168.120.10 }\n\ncompile {\n    eng_workstation -> substation_plc tcp syn srcport 50502 dstport 502 win 64240 mss 1460 vlan 120 wait 1ms\n    eng_workstation <- substation_plc tcp syn ack win 64240 mss 1460 vlan 120 wait 1ms\n    eng_workstation -> substation_plc tcp ack vlan 120 wait 1ms\n\n    // 1. Permitted SCADA poll (FC 03 Read Holding Registers)\n    eng_workstation -> substation_plc modbus readholdingregisters txid 10 unitid 1 addr 40001 count 2 vlan 120 wait 2ms\n\n    // 2. Unauthorized FC 05 Write Single Coil (expected to trigger OT policy block/alert)\n    eng_workstation -> substation_plc modbus writesinglecoil txid 11 unitid 1 addr 1 value 0xff00 vlan 120 wait 3ms\n\n    // 3. DNP3 Direct Operate over UDP 20000 (computes IEEE 1815 CRC-16 chunks automatically)\n    eng_workstation -> substation_plc transport udp dnp3 directoperate src 3 dst 10 group 12 variation 1 vlan 120\n}\n```\n\n| Anomaly / Pattern | Wireshark Display Filter | `.frasm` Modifier |\n| --- | --- | --- |\n| Forged middlebox TCP reset | `tcp.flags.reset == 1 && ip.ttl > 200` | `tcp rst ack ttl 251 ipid 0x0000 win 0` |\n| 802.1ad QinQ double-VLAN hop | `vlan.etype == 0x88a8` | `qinq 1 innervlan 20` |\n| Duplicate / overlapping TCP `seq` | `tcp.analysis.retransmission` | Explicit `seq 1001` on two consecutive frames (`ttl 3` vs `ttl 64`) |\n| Unauthorized OT coil / breaker write | `modbus.func_code == 5 \\|\\| dnp3.al.func == 5` | `modbus writesinglecoil value 0xff00` / `dnp3 directoperate` |\n"}
{"id":"pretrain-guide-ci-cd-pcap-testing","kind":"workflow_guide","title":"Zero-Binary .pcap Fixtures in Git & CI/CD (Suricata, Zeek & pytest) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/ci-cd-pcap-testing","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","http","tls","dns","snmp3","modbus","bgp"],"text":"# Zero-Binary `.pcap` Fixtures in Git & CI/CD (Suricata, Zeek & pytest)\n\n> **FrameAssembly v3.3.0** · Workflow Guide 09 · Canonical URL:\n> https://frameassembly-lang.dev/docs/ci-cd-pcap-testing\n\nStop committing mystery `test_case_final_v3.pcap` blobs to Git. Check in diffable\n`.frasm` text and build identical `.pcap` or `.pcapng` fixtures on the fly in CI.\n\n## Key Takeaways\n\n- Binary `.pcap` files in Git show `Binary files differ` in pull requests and\n  frequently hide unredacted customer IPs or stale checksums.\n- Checking `.frasm` files into `tests/fixtures/` makes every IP, TCP flag, VLAN\n  tag, and Layer 7 payload line-by-line reviewable in `git diff`.\n- `frameassembly` compiles a typical test fixture in under 2 milliseconds with\n  zero `sudo`, zero Npcap, and zero Python dependency resolution.\n\n## 1. Why Binary `.pcap` Fixtures Rot in Repositories\n\nEvery detection engineering, firewall automation, or protocol parser repository\neventually grows a `tests/pcaps/` folder full of opaque binary blobs nobody dares\ntouch. When a pull request updates `cve_2026_probe.pcap`, reviewers cannot see\nwhether the author changed one HTTP header or accidentally leaked a production\nsubnet.\n\nStoring `.frasm` source files in Git instead turns packet captures into ordinary\ncode reviews. Reviewers read exact `->` and `<-` lines in GitHub or GitLab diffs,\nand CI compiles byte-identical `.pcap` files during the test job.\n\n### `tests_http_sqli_fixture.frasm`\n\n```frameassembly\n// Reviewable Git fixture for WAF / Suricata rule SID:2099001\nhost scanner { ip 198.51.100.44 }\nhost app_waf { ip 10.30.0.80 }\n\ncompile {\n    scanner -> app_waf tcp syn srcport 54120 dstport 80 win 65535 mss 1460 wait 1ms\n    scanner <- app_waf tcp syn ack win 65535 mss 1460 wait 1ms\n    scanner -> app_waf tcp ack wait 1ms\n    scanner -> app_waf http get uri \"/search?q=%27%20OR%201%3D1--\" hosthdr \"shop.example.test\" useragent \"ci-regression/1.0\" wait 2ms\n    scanner <- app_waf http status 403 reason \"Forbidden\" contenttype \"application/json\" body \"{\\\"blocked\\\":true}\"\n}\n```\n\n## 2. GitHub Actions Pipeline: `.frasm` -> Suricata, Zeek & `tshark`\n\nBecause `frameassembly` is a single static binary that needs zero root\ncapabilities (`CAP_NET_RAW`), it runs cleanly inside unprivileged Docker\ncontainers and standard GitHub Actions runners:\n\n```bash\n# Quick local pre-commit check: validate every .frasm file without writing disk artifacts\nfor f in tests/fixtures/*.frasm; do frameassembly show \"$f\" > /dev/null; done\n```\n\n### .github/workflows/packet-regression.yml\n\n```yaml\nname: Detection & Dissector Regression\non: [push, pull_request]\n\njobs:\n  suricata-and-tshark:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n\n      - name: Install FrameAssembly + tshark + Suricata\n        run: |\n          curl -fsSL https://raw.githubusercontent.com/SteveWinschel/FrameAssembly/main/install.sh | sh\n          echo \"$HOME/.local/bin\" >> \"$GITHUB_PATH\"\n          sudo apt-get update && sudo apt-get install -y tshark suricata jq\n\n      - name: Compile .frasm fixtures and verify alerts\n        run: |\n          for f in tests/fixtures/*.frasm; do\n            frameassembly \"$f\" \"${f%.frasm}.pcap\"\n          done\n          suricata -r tests/fixtures/tests_http_sqli_fixture.pcap -S rules/local.rules -l ./suricata-logs\n          jq -e 'select(.event_type == \"alert\" and .alert.signature_id == 2099001)' ./suricata-logs/eve.json\n```\n\n## 3. Ephemeral `.pcap` Fixtures in `pytest` (Python) & `cargo test` (Rust)\n\nTesting a Python dissector, Go collector, or Rust DPI library? Compile `.frasm`\nstrings into `tmp_path` during `pytest` (or directly in RAM via `cargo add --dev\nframeassembly`) so tests stay fast and self-contained:\n\n### tests/test_dns_parser.py (pytest + subprocess)\n\n```python\nimport subprocess\nfrom pathlib import Path\n\ndef compile_frasm(tmp_path: Path, name: str, frasm_src: str) -> Path:\n    frasm_file = tmp_path / f\"{name}.frasm\"\n    pcap_file = tmp_path / f\"{name}.pcapng\"\n    frasm_file.write_text(frasm_src, encoding=\"utf-8\")\n    subprocess.run([\"frameassembly\", str(frasm_file), str(pcap_file)], check=True)\n    return pcap_file\n\ndef test_dns_nxdomain_wire_parse(tmp_path: Path) -> None:\n    pcap = compile_frasm(\n        tmp_path,\n        \"nxdomain\",\n        \"\"\"\n        host c { ip 10.0.0.10 }\n        host s { ip 10.0.0.53 }\n        compile {\n            c -> s dns query txid 0x3100 qname \"missing.corp.test\" qtype \"A\" wait 2ms\n            c <- s dns response txid 0x3100 rcode 3 qname \"missing.corp.test\" qtype \"A\"\n        }\n        \"\"\",\n    )\n    out = subprocess.check_output(\n        [\"tshark\", \"-r\", str(pcap), \"-Y\", \"dns.flags.rcode == 3\", \"-T\", \"fields\", \"-e\", \"dns.qry.name\"],\n        text=True,\n    ).strip()\n    assert out == \"missing.corp.test\"\n```\n\n> **Migrating Existing Binary `.pcap` Tests in One Loop:** Run `for p in\n> tests/pcaps/*.pcap; do frameassembly reverse \"$p\" \"${p%.pcap}.frasm\"; done` to\n> convert legacy binary captures into human-readable `.frasm` fixtures.\n"}
{"id":"pretrain-guide-migrating-from-scapy-and-tcprewrite","kind":"workflow_guide","title":"Coming from Scapy, tcprewrite & Packetdrill (Patterns & Tradeoffs) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/migrating-from-scapy-and-tcprewrite","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","http","vlan","tls","dns","snmp3","modbus","qinq"],"text":"# Coming from Scapy, `tcprewrite` & Packetdrill (Patterns & Tradeoffs)\n\n> **FrameAssembly v3.3.0** · Workflow Guide 10 · Canonical URL:\n> https://frameassembly-lang.dev/docs/migrating-from-scapy-and-tcprewrite\n\nHow common Scapy scripts, `tcprewrite` flags, and Packetdrill tests translate into\n`.frasm` — plus an honest guide to when you should still reach for Scapy or\n`tcpreplay`.\n\n## Key Takeaways\n\n- Scapy shines when you need live interactive Python socket loops; FrameAssembly\n  shines when you want clean, zero-dependency `.pcap` / `.pcapng` files without\n  tracking TCP `seq` offsets by hand.\n- `tcprewrite` and TraceWrangler rewrite outer L2–L4 headers quickly, while\n  `frameassembly reverse` lets you edit inner Layer 7 hostnames, OIDs, and VLAN\n  stacks on Linux, macOS, Windows, or in the browser and rebuild valid lengths +\n  checksums.\n- They compose cleanly: author or scrub in `.frasm`, inspect in\n  Wireshark/`tshark`, and transmit onto lab copper with `tcpreplay`.\n\n## 1. Side-by-Side: Building a Valid VLAN-Tagged TCP + HTTP Flow\n\nIn Scapy, `wrpcap()` writes raw frames faithfully—meaning *you* are responsible\nfor tracking client `seq`, server `seq`, `len(payload)` increments, bidirectional\nport swaps, and relative `pkt.time` timestamps across every segment:\n\n### `healthcheck_equivalent.frasm`\n\n```frameassembly\n// The FrameAssembly Way: zero seq math, zero port repetition, zero Python venv\nhost client { ip 10.10.1.50 }\nhost server { ip 10.10.1.80 }\n\ncompile {\n    client -> server tcp syn srcport 51200 dstport 80 vlan 120 wait 2ms\n    client <- server tcp syn ack vlan 120 wait 2ms\n    client -> server tcp ack vlan 120 wait 2ms\n    client -> server http get uri \"/healthz\" hosthdr \"api.corp.test\" vlan 120 wait 2ms\n    client <- server http status 200 reason \"OK\" body \"OK\" vlan 120\n}\n```\n\n### The Scapy Way (24 lines + manual seq/ack/timestamp bookkeeping)\n\n```python\nfrom scapy.all import Ether, Dot1Q, IP, TCP, Raw, wrpcap\n\nc_mac, s_mac = \"00:00:00:00:00:01\", \"00:00:00:00:00:02\"\nc_ip, s_ip = \"10.10.1.50\", \"10.10.1.80\"\nreq = b\"GET /healthz HTTP/1.1\\r\\nHost: api.corp.test\\r\\n\\r\\n\"\nresp = b\"HTTP/1.1 200 OK\\r\\nContent-Length: 2\\r\\n\\r\\nOK\"\n\npkts = [\n    Ether(src=c_mac, dst=s_mac)/Dot1Q(vlan=120)/IP(src=c_ip, dst=s_ip)/TCP(sport=51200, dport=80, flags=\"S\", seq=1000),\n    Ether(src=s_mac, dst=c_mac)/Dot1Q(vlan=120)/IP(src=s_ip, dst=c_ip)/TCP(sport=80, dport=51200, flags=\"SA\", seq=5000, ack=1001),\n    Ether(src=c_mac, dst=s_mac)/Dot1Q(vlan=120)/IP(src=c_ip, dst=s_ip)/TCP(sport=51200, dport=80, flags=\"A\", seq=1001, ack=5001),\n    Ether(src=c_mac, dst=s_mac)/Dot1Q(vlan=120)/IP(src=c_ip, dst=s_ip)/TCP(sport=51200, dport=80, flags=\"PA\", seq=1001, ack=5001)/Raw(req),\n    Ether(src=s_mac, dst=c_mac)/Dot1Q(vlan=120)/IP(src=s_ip, dst=c_ip)/TCP(sport=80, dport=51200, flags=\"PA\", seq=5001, ack=1001+len(req))/Raw(resp),\n]\nfor i, p in enumerate(pkts):\n    p.time = i * 0.002\nwrpcap(\"healthcheck.pcap\", pkts)\n```\n\n## 2. `tcprewrite` vs. `frameassembly reverse` for `.pcap` Surgery\n\n`tcprewrite` operates on binary packets in-place: it is great for rewriting `/24`\nsubnets across a 2 GB capture, right up until you need to replace\n`\"corp-dc01.internal\"` with `\"lab.example.test\"` inside DNS, TLS SNI, HTTP\n`Host:`, or SNMP varbinds. Changing payload length in-place breaks IP `tot_len`,\nUDP length, and every downstream TCP `seq` / `acknum` in the stream.\n\nDecompiling with `frameassembly reverse` turns the capture into `.frasm`\nstatements so changing a 12-byte hostname to a 28-byte hostname cleanly recomputes\nevery outer header and sequence number upon recompilation.\n\n```bash\n# Decompile -> replace subnet + internal domain across L3 and L7 -> recompile\nframeassembly reverse raw_incident.pcap incident.frasm\nsed -i 's/10\\.24\\.8\\./10.254.1./g; s/corp-dc01\\.internal/lab.example.test/g' incident.frasm\nframeassembly incident.frasm sanitized_incident.pcap\n```\n\n## 3. Honest Tool Selection Matrix: Right Tool for the Job\n\nFrameAssembly is purposefully an offline `.frasm <-> .pcap / .pcapng` compiler and\ndecompiler—not a live network scanner or kernel TCP stack tester. Use this matrix\nto pick the sharpest tool:\n\n| Task | Best Tool | Why |\n| --- | --- | --- |\n| Craft L2–L7 `.pcap` / `.pcapng` test fixtures for Wireshark, Suricata, Zeek, or Git CI | FrameAssembly (`.frasm`) | Readable `->` / `<-` flows, automatic 4-tuple TCP `seq`/`acknum`, 81 built-in protocols, zero root or Python setup. |\n| Redact IPs, VLANs, and Layer 7 hostnames/secrets inside a `.pcap` (<50k frames) | `frameassembly reverse` -> edit -> `frameassembly` | Recalculates L7 lengths, IP lengths, and downstream TCP sequence numbers automatically. |\n| Interactive live probing (`sr1()`), fuzzing loops, or custom 1-off bit-field research | Scapy (Python) | Full Python scripting with live raw socket send/receive reactivity. |\n| Bulk subnet NAT rewrite across a 10 GB full-take capture (or Windows-only subnet scrubbing) | `tcprewrite` / `editcap` / TraceWrangler | Streaming header rewriting across huge captures without converting millions of frames to text. |\n| Testing Linux/BSD kernel TCP congestion control (`cubic`, `bbr`) live on a `tun` device | Packetdrill | Asserts exact kernel socket syscall timing and live kernel network stack responses. |\n| Transmitting `.frasm`-built `.pcap` files onto physical copper or SFP+ fiber | FrameAssembly + `tcpreplay` | Build clean frames without root using `frameassembly`, then transmit at line rate with `tcpreplay`. |\n"}
{"id":"pretrain-guide-cheat-sheet","kind":"workflow_guide","title":"Wireshark / tcpdump / Scapy -> .frasm Rosetta Stone — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/cheat-sheet","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","vlan","qinq","mpls","http","tls","snmp3","arp","igmp","ndp","mld","dns","modbus","dnp3"],"text":"# Wireshark / tcpdump / Scapy -> `.frasm` Rosetta Stone\n\n> **FrameAssembly v3.3.0** · Reference Guide R1 · Canonical URL:\n> https://frameassembly-lang.dev/docs/cheat-sheet\n\nOne-page translation map from Wireshark display filters, `tcpdump`, Scapy, and\n`tcprewrite` to exact FrameAssembly v3.2.2 keywords.\n\n## Key Takeaways\n\n- Every built-in `.frasm` v3.2.2 keyword, protocol, flag, and time unit is\n  strictly `[a-z0-9]+` — zero underscores, zero hyphens.\n- Frame #1 = `0ns`; inline `wait <n><ns|us|ms|s|m>` sets the gap *before* the next\n  frame (default `+10ms` when omitted).\n- 8 L2 protocols allow MAC-only hosts · 9 dual-L4 protocols accept `transport\n  tcp|udp` · 70 L3–L7 protocols run over both IPv4 & IPv6.\n\n## 1. Wireshark Display Filter -> `.frasm` Modifier Map\n\nKnow the Wireshark filter? Here is the exact `.frasm` token to type:\n\n### `rosetta_all_in_one.frasm`\n\n```frameassembly\nhost client { ip 10.10.20.15 mac 001a.2b3c.4d15 }\nhost edge   { ip 10.10.20.1  mac 001a.2b3c.4d01 }\n\ncompile {\n    client -> edge tcp syn srcport 51443 dstport 443 win 65535 mss 1460 sackperm vlan 100 pcp 5 dscp 46 wait 1ms\n    client <- edge tcp syn ack win 65535 mss 1460 sackperm vlan 100 pcp 5 dscp 46 wait 1ms\n    client -> edge tcp ack vlan 100 pcp 5 dscp 46 wait 1ms\n    client -> edge tls clienthello sni \"portal.corp.local\" alpn \"h2\" vlan 100 pcp 5 dscp 46\n}\n```\n\n| Intent | Wireshark Filter | FrameAssembly v3.2.2 (`.frasm`) |\n| --- | --- | --- |\n| 802.1Q VLAN + 802.1p Priority | `vlan.id == 100 && vlan.priority == 5` | `vlan 100 pcp 5 dei 0` |\n| 802.1ad QinQ S-Tag + C-Tag | `vlan.etype == 0x88a8` | `qinq 2000 innervlan 150` |\n| MPLS Shim Label | `mpls.label == 24010 && mpls.bottom == 1` | `mpls 24010 exp 5 bos 1 mplsttl 64` |\n| IPv4/IPv6 Hop Limit & DiffServ | `ip.ttl == 64 && ip.dsfield.dscp == 46` | `ttl 64 dscp 46 ecn 0` |\n| IPv4 DF / Fragmentation | `ip.flags.df == 1` / `ip.frag_offset > 0` | `df` or `ipid 0x1234 mf fragoffset 0` |\n| TCP Ports, Flags & Options | `tcp.dstport == 443 && tcp.flags.syn == 1` | `tcp syn srcport 51234 dstport 443 win 65535 mss 1460 wscale 7 sackperm` |\n| Explicit TCP SEQ & ACK Numbers | `tcp.seq == 1000 && tcp.ack == 5001` | `tcp ack seq 1000 acknum 5001` (bare `ack` = flag bit!) |\n| HTTP Request + Host Header | `http.host == \"api.internal\" && http.request.method == \"POST\"` | `http post uri \"/v1/login\" hosthdr \"api.internal\"` |\n| TLS ClientHello SNI & ALPN | `tls.handshake.extensions_server_name == \"app.corp.local\"` | `tls clienthello sni \"app.corp.local\" alpn \"h2\"` |\n| SNMPv2c / v3 Trap OID + String | `snmp.name == 1.3.6.1.6.3.1.1.4.1.0` | `varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.1.5.0 string \"sw1\"` |\n\n## 2. Scapy, `tcprewrite`, TraceWrangler, `text2pcap` & Packetdrill -> FrameAssembly\n\nHow common packet-crafting and capture-editing tools map to `.frasm` — and when\nyou should still reach for one of the others:\n\n| Job / Tool | Traditional Workflow | FrameAssembly (`v3.2.2`) |\n| --- | --- | --- |\n| Stateful TCP + L7 stream (`Scapy`) | 25+ lines of Python tracking `seq`, `ack`, `len(payload)`, and virtualenvs | 3 handshake lines (`->` / `<-`) + 1 L7 line inside `compile { ... }` |\n| Scrub IPs, VLANs & L7 hostnames (`tcprewrite`) | `tcprewrite --srcipmap=... --fixcsum` (fast L2–L4 bulk NAT, but breaks if L7 string length changes) | `frameassembly reverse in.pcap edit.frasm` -> edit IPs, `sni`, `qname`, `hosthdr` -> recompile |\n| Redact customer captures (`TraceWrangler`) | Windows GUI batch anonymizer for bulk IP/MAC/DHCP profiles across multi-file captures | Cross-platform CLI or zero-upload browser Playground that turns captures into diffable `.frasm` text |\n| Build a `.pcap` from hex / ASCII (`text2pcap`) | `od -Ax -tx1` hex-offset dumps + dummy `-e` / `-i` / `-u` header flags | Named L2–L7 protocol fields (`dns`, `tls`, `bgp`, `modbus`) + `hexpayload \"...\"` only where needed |\n| Test TCP timing & anomalies (`Packetdrill`) | Live kernel-socket script testing a host OS TCP stack (`+0.010 < S ...`) | Offline `.pcap` / `.pcapng` file generation across 81 L2–L7 protocols for Suricata, Zeek, Wireshark & `tcpreplay` |\n| Encrypted SNMPv3 `authPriv` trap (`snmptrap`) | `snmptrap -v 3 -e 0x...` + missing vendor MIB errors + live UDP socket | `snmp3 trap user \"...\" engineid \"...\" auth sha256 \"...\" priv aes \"...\"` straight to `.pcap` |\n\n> **When to Pick Scapy, Packetdrill, or `tcprewrite` Instead:** Use Scapy or\n> Packetdrill when conversing live with a remote kernel TCP stack over raw sockets\n> or running 100,000-packet fuzzing loops, and use `tcprewrite` or `editcap` when\n> rewriting multi-gigabyte captures in bulk without changing Layer 7 string\n> lengths.\n\n## 3. Timing & Protocol Whitelist Cheat Matrix\n\nFour compiler rules worth keeping in your back pocket:\n\n| Rule | Exact Set / Behavior | Notes |\n| --- | --- | --- |\n| Post-packet `wait` clock | Frame #1 = `0ns`. `wait <n><ns\\|us\\|ms\\|s\\|m>` advances clock before the *next* frame. | Omitted `wait` = `+10ms` · `wait 0ns` = zero-gap burst · never standalone. |\n| 8 MAC-only L2 protocols | `arp`, `vlan`, `qinq`, `lldp`, `stp`, `lacp`, `eapol`, `mpls` | `host sw1 { mac 00:1c:73:00:00:01 }` works here; all 73 L3-L7 protocols require matching IPs. |\n| IPv4 vs IPv6 rules | IPv4-only: `igmp` · IPv6-only: `ndp`, `mld` · Dual-stack: all other 70 L3-L7 protocols | `icmp`, `ospf`, `rip`, `vrrp`, `hsrp`, and `dhcp` morph v4 <-> v6 automatically (`ospf routerid` stays dotted-quad). |\n| 9 `transport tcp\\|udp` protocols | Default UDP: `dns`, `sip`, `syslog`, `kerberos`, `memcached` · Default TCP: `dnp3`, `modbus`, `nfs`, `ethernetip` | Rejected on single-transport protocols (`http`, `bgp`, `quic`, `ntp`, ...). |\n\n## 4. Six Deliberate Keyword Disambiguations\n\nSix modifier names avoid colliding with top-level blocks or flag bits:\n\n- `hosthdr \"api.internal\"` — HTTP / SSDP `Host:` header (`host` declares network\n  boxes).\n- `transporthdr \"RTP/AVP;unicast;client_port=5004-5005\"` — RTSP `Transport:`\n  header (`transport tcp|udp` picks L4).\n- `acknum 1001` — 32-bit TCP acknowledgment number (bare `ack` = ACK flag bit).\n- `srcport` / `dstport` — L4 ports (`sport` / `dport` are rejected).\n- `varbind <oid> string \"<txt>\"` & `varbind 1.3.6.1.6.3.1.1.4.1.0 oidval <oid>` —\n  SNMP varbinds (`str` and `trapoid` do not exist).\n- CoAP shorthands (`get`, `post`, `put`, `delete`, `created`, `changed`,\n  `notfound`) and `code \"0.01\"` are mutually exclusive on the same frame.\n"}
{"id":"pretrain-guide-specification","kind":"workflow_guide","title":".frasm Language Spec, Validation Rules & v3.2 Upgrade Map — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/specification","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["bfd","ospf","bgp","snmp3"],"text":"# `.frasm` Language Spec, Validation Rules & v3.2 Upgrade Map\n\n> **FrameAssembly v3.3.0** · Reference Guide R2 · Canonical URL:\n> https://frameassembly-lang.dev/docs/specification\n\nFormal lexical rules, `text/vnd.frameassembly` MIME registration, cross-layer\nsemantic checks, and upgrading old v1/v2 `.frasm` snippets to `v3.2.2`.\n\n## Key Takeaways\n\n- Extension is strictly `.frasm` (`text/vnd.frameassembly`, UTF-8) — distinct from\n  `.asm` CPU assembly and FPGA bitstreams.\n- Program layout: `>= 1 host` + optional parameterized `flow(p1, ...)` + `1\n  compile`.\n- `validate_semantics` rejects mixed IPv4/IPv6 pairs, illegal `transport`\n  overrides, and out-of-range fields before a single byte is written.\n\n## 1. `.frasm` Packet Captures vs. CPU Assembly & Hardware Bitstreams\n\nFrameAssembly uses the dedicated `.frasm` (`text/vnd.frameassembly`) extension so\nnetwork packet captures never collide with x86 CPU assemblers or FPGA bitstream\nfiles:\n\n| Property | FrameAssembly (This Project) | CPU Assemblers / FPGA Bitstreams |\n| --- | --- | --- |\n| What it builds | Layer 2-7 network packet captures (`.frasm` <-> `.pcap` / `.pcapng`) | x86 / x86-64 CPU machine code (or FPGA hardware bitstreams) |\n| Extension & MIME | `.frasm` (`text/vnd.frameassembly`, UTF-8) | `.asm`, `.s`, `.inc`, `.bit` |\n| Line comments | `//` double-slash only | `;` semicolon (x86 `.asm`) or `#` hash (hardware tiles) |\n| Top-level blocks | `host <id> { ... }` -> `flow <name>(...) { ... }` -> `compile { ... }` | CPU mnemonics (`mov`, `syscall`, `section`) |\n\n## 2. Lexical & Structural Invariants\n\nNo significant whitespace, no semicolons, and zero underscore roulette:\n\n- Built-in tokens (81 protocol names, modifiers, flags, and\n  `ns`/`us`/`ms`/`s`/`m`) match `^[a-z0-9]+$` — lowercase letters + digits only.\n- User identifiers (`host`, `flow`, formal parameters) match\n  `[a-zA-Z_][a-zA-Z0-9_]*(-[a-zA-Z0-9_]+)*` (e.g. `fw-dmz-01`, `Core_SW_1`),\n  stopping cleanly before `->` or `<-`.\n- Strings use double quotes `\"...\"` (`\\r`, `\\n`, `\\t`, `\\\\`, `\\\"`, `\\xHH`,\n  `\\uXXXX`). Hex strings (`hexpayload`, `iv`, `icv`, `engineid`) accept\n  even-length octets with optional spaces or colons.\n- Every `host <id> { ... }` requires at least `ip <v4|v6>` or `mac\n  <colon|hyphen|cisco_dot>`.\n- Every `flow <name>(<p1>[, ...]) { ... }` requires parentheses with `>= 1`\n  parameter and may only reference its formal parameters inside its body.\n- One `compile { ... }` block executes frame statements and `flow(...)` calls\n  top-to-bottom (`1 frame statement = 1 Ethernet frame`).\n\n### `spec_canonical_program.frasm`\n\n```frameassembly\n// Canonical FrameAssembly v3.2.2: host -> flow(a, b) -> compile\nhost leaf-sw-01 { ip 10.100.0.1  mac 001c.7300.0001 }\nhost spine-sw-1 { ip 10.100.0.2  mac 001c.7300.0002 }\n\nflow bfd_up(a, b) {\n    a -> b bfd state 3 diag 0 mult 3 mydisc 0x1001 yourdisc 0x2002 mintx 50000 minrx 50000 dscp 48 wait 500us\n    a <- b bfd state 3 diag 0 mult 3 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 dscp 48\n}\n\ncompile {\n    bfd_up(leaf-sw-01, spine-sw-1)\n}\n```\n\n## 3. Cross-Layer Semantic Validation (`validate_semantics`)\n\nBefore emitting a single `.pcap` byte, the compiler enforces cross-layer sanity:\n\n| Check | Compiler Rule |\n| --- | --- |\n| MAC-only vs IP hosts | MAC-only hosts are valid *only* on the 8 L2 protocols (`arp`, `vlan`, `qinq`, `lldp`, `stp`, `lacp`, `eapol`, `mpls`). All 73 L3-L7 protocols require matching-family IPs. |\n| IP-family protocol locks | `igmp` requires IPv4 hosts; `ndp` and `mld` require IPv6 hosts. |\n| Transport & TCP-only guards | `transport tcp\\|udp` works *only* on the 9 dual-L4 protocols; TCP flags/options (`syn`, `acknum`, `mss`, `wscale`, `sackperm`, `tsval`, `tsecr`) fail validation on non-TCP frames. |\n| Field & RFC bounds | `dns`/`mdns` label `<= 63`B & total `<= 253`B · `snmp3 engineid` even-length hex · `hsrp hellotime`/`holdtime` `0..255` · max one `mpls` shim per frame · `payload` vs `hexpayload` mutually exclusive. |\n\n## 4. Old v1 / v2 Snippets -> `v3.2.2` Upgrade Map\n\nIf an older blog post or unprimed LLM hands you v1/v2 syntax, swap these straight\nacross:\n\n| Old v1 / v2 Artifact | Valid `v3.2.2` Replacement |\n| --- | --- |\n| `frameassembly compile demo.frasm -o out.pcap` | `frameassembly demo.frasm out.pcap` |\n| `echo_request`, `echo_reply`, `dest_unreach`, `time_exceeded` | `echorequest`, `echoreply`, `destunreach`, `timeexceeded` |\n| `inner_vlan`, `sack_perm`, `ans_ttl`, `client_hello` | `innervlan`, `sackperm`, `ansttl`, `clienthello` |\n| `host \"api.local\"` (on HTTP) / `host_hdr` | `hosthdr \"api.local\"` |\n| `sport 50000 dport 443` / `ack 1001` | `srcport 50000 dstport 443` / `ack acknum 1001` |\n| `loop 3 { ... }` or parameterless `flow demo { ... }` | `flow demo(a, b) { ... }` called inside `compile { ... }` |\n| `host_1` (old reverse output) | `host1`, `host2`, ... |\n"}
{"id":"pretrain-guide-compiler-and-rust-api","kind":"workflow_guide","title":"Under the Hood: 6-Stage Rust Engine, Cargo Crate & EBNF Grammars — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/compiler-and-rust-api","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ndp","icmp","dns","bgp"],"text":"# Under the Hood: 6-Stage Rust Engine, Cargo Crate & EBNF Grammars\n\n> **FrameAssembly v3.3.0** · Reference Guide R3 · Canonical URL:\n> https://frameassembly-lang.dev/docs/compiler-and-rust-api\n\nHow the 6-stage Rust packet engine and `.pcap` reverse reader work in memory, plus\nembedding `frameassembly` in Rust tests and grammar schemas.\n\n## Key Takeaways\n\n- Pure safe Rust (`1.89+`, Edition `2024`) in memory: zero shelling out, zero\n  `libpcap` C FFI, and zero raw sockets (`CAP_NET_RAW`).\n- Embed directly into Rust integration or DPI regression tests via `cargo add\n  frameassembly` (`parse_program`, `compile_program`, `serialize_classic_pcap`,\n  `serialize_pcapng`, `reverse_pcap_bytes`).\n- Ships root `grammar.ebnf`, `frameassembly.gbnf`, and `frameassembly.lark`\n  schemas + `/llms-full.txt` tested against 2,600+ packet scenarios.\n\n## 1. Six Stages: `.frasm` <-> Wire Bytes\n\nEverything runs in safe Rust in memory — zero shelling out, zero libpcap C\nbindings, zero raw sockets:\n\n| Stage | What It Actually Does |\n| --- | --- |\n| 1. Lexer (`lexer::lex`) | Tokenizes UTF-8 `.frasm`, `->` / `<-` arrows, time units, IPv4/IPv6, colon/hyphen/Cisco MACs, hex strings, and OIDs with source line/column spans. |\n| 2. Parser (`parser::parse_program`) | Builds the AST (`host`, `flow`, `compile`), runs Levenshtein typo suggestions (`Did you mean ...?`), and invokes `validation::validate_semantics`. |\n| 3. Semantic Validator (`parser::validation::validate_semantics`) | Enforces L2 MAC-only vs L3–L7 IP rules, `igmp`/`ndp`/`mld` families, the 9-protocol `transport` whitelist, and field bounds. |\n| 4. Stateful Expander (`backend::compile_program`) | Inlines `flow(...)` calls, advances the nanosecond `wait` clock (`0ns` start, `+10ms` default), and tracks 4-tuple TCP `seq`/`acknum` + port memory. |\n| 5. Wire Encoder | Serializes L7 payloads (including SNMPv3 USM key localization + AES-128-CFB and DNP3 CRC-16 chunks), wraps L4/L3/MPLS/QinQ/802.1Q/Ethernet II, and computes RFC checksums. |\n| 6. `.pcap` / `.pcapng` <-> `reverse` | Emits classic `.pcap` (`pcap::serialize_classic_pcap`) or nanosecond `.pcapng` (`pcap::serialize_pcapng`), and reverses captures via `reverse::reverse_pcap_bytes`. |\n\n## 2. Embedding in Rust Tests & Tools (`cargo add frameassembly`)\n\nWriting automated network parser, firewall, or DPI regression tests in Rust? Call\nthe verified `frameassembly 3.2.2` library entrypoints directly in RAM without\ntouching disk:\n\n```bash\n# Add the FrameAssembly Rust crate from crates.io (MSRV Rust 1.89+, Edition 2024)\ncargo add frameassembly\n```\n\n### In-Memory Rust Test (src/main.rs)\n\n```rust\nuse frameassembly::backend::compile_program;\nuse frameassembly::parser::parse_program;\nuse frameassembly::pcap::{serialize_classic_pcap, serialize_pcapng};\nuse frameassembly::reverse::reverse_pcap_bytes;\n\nfn main() -> Result<(), Box<dyn std::error::Error>> {\n    let src = r#\"\n        host sensor { ip 10.0.0.10 }\n        host target { ip 10.0.0.20 }\n        compile {\n            sensor -> target icmp echorequest id 1 seq 1 wait 2ms\n            sensor <- target icmp echoreply   id 1 seq 1\n        }\n    \"#;\n\n    let program = parse_program(src)?;\n    let frames = compile_program(&program)?;\n    let pcap_bytes = serialize_classic_pcap(&frames)?;\n    let pcapng_bytes = serialize_pcapng(&frames)?;\n    let rev = reverse_pcap_bytes(&pcapng_bytes)?;\n    assert!(pcap_bytes.len() > 24 && rev.packet_count == 2 && rev.host_count == 2 && rev.warnings.is_empty());\n    Ok(())\n}\n```\n\n| Rust Crate Entrypoint (`frameassembly 3.2.2`) | Signature & Behavior |\n| --- | --- |\n| `frameassembly::parser::parse_program(src)` | `Result<Program, CompilerError>` — executes `lexer::lex`, `winnow` AST parse, and `validation::validate_semantics`. |\n| `frameassembly::backend::compile_program(&program)` | Returns `(frame_bytes, timestamp_ns)` Ethernet II byte buffers paired with relative `u64` nanosecond timestamps (`Result<..., String>`). |\n| `frameassembly::pcap::serialize_classic_pcap(&frames)` | Returns classic libpcap `.pcap` file bytes (`0xa1b2c3d4`, `1 µs` timestamps, `Result<..., String>`). |\n| `frameassembly::pcap::serialize_pcapng(&frames)` | Returns nanosecond `.pcapng` file bytes (`IfTsResol=9`, `LINKTYPE_ETHERNET`, `Result<..., String>`). |\n| `frameassembly::backend::generate_pcap(&program, output_path)` | `Result<(), String>` — compiles and writes `.pcap` or `.pcapng` directly by file extension. |\n| `frameassembly::reverse::{reverse_pcap_bytes, reverse_pcap_file, reverse_pcap_reader}` | `Result<ReverseOutput, CompilerError>` — auto-detects `.pcap` / `.pcapng`, normalizes link types, and returns reversed `.frasm` text + `packet_count`, `host_count`, and `warnings`. |\n\n## 3. JavaScript / TypeScript WebAssembly SDK (`npm install frameassembly-wasm`)\n\nBuilding browser-local packet tools, Web Worker inspectors, or Node.js `.pcap`\nregression harnesses? The official `frameassembly-wasm` (`v3.2.2`, MIT,\n`https://www.npmjs.com/package/frameassembly-wasm`) package ships the exact\n`wasm-pack` bindings running inside `/playground`:\n\n```bash\n# Install the official WebAssembly SDK for browsers, Web Workers, or Node.js\nnpm install frameassembly-wasm\n```\n\n### Browser / Web Worker / Node.js Usage (wasm-demo.ts)\n\n```typescript\nimport initWasm, {\n  validate_frasm,\n  inspect_frasm,\n  compile_frasm_to_pcap,\n  compile_frasm_to_pcapng,\n  reversePcap,\n} from 'frameassembly-wasm';\n\nawait initWasm();\n\nconst src = `host client { ip 10.0.0.10 }\nhost server { ip 10.0.0.20 }\ncompile {\n    client -> server dns query txid 0x1a2b qname \"api.internal\" qtype \"A\"\n}`;\n\nconst diagnostics = validate_frasm(src);\nconst frames = inspect_frasm(src);\nconst pcapBytes = compile_frasm_to_pcap(src);\nconst pcapngBytes = compile_frasm_to_pcapng(src);\nconst reversed = reversePcap(pcapBytes);\n```\n\n| `frameassembly-wasm` (`3.2.2`) Export | TypeScript Signature & Behavior |\n| --- | --- |\n| `default` (`initWasm`) / `initSync` | Initializes `frameassembly_wasm_bg.wasm` asynchronously (`fetch` / `Response` / `BufferSource`) or synchronously (`initSync({ module })` in Node.js / Workers). |\n| `validate_frasm(source: string)` | Returns structured `WasmDiagnostic[]` (`line`, `column`, `end_column`, `severity`, `message`, `suggestion`, `replacement`) with zero disk I/O. |\n| `inspect_frasm(source: string)` | Compiles in memory and returns `InspectedFrame[]` (`index`, `timestamp_ms`, `length`, space-delimited `hex`). |\n| `compile_frasm_to_pcap(source: string)` | Returns `Uint8Array` classic libpcap (`.pcap`, `0xa1b2c3d4`, `1 µs` resolution). |\n| `compile_frasm_to_pcapng(source: string)` | Returns `Uint8Array` nanosecond PCAPNG (`.pcapng`, `IfTsResol=9`, `LINKTYPE_ETHERNET`). |\n| `reversePcap(bytes: Uint8Array)` / `reverse_pcap` | Auto-detects `.pcap` or `.pcapng` bytes and returns `{ success, frasm, packetCount, hostCount, warnings, error }`. |\n\n## 4. Constrained Decoding Schemas (`grammar.ebnf`, `frameassembly.gbnf`, `frameassembly.lark`)\n\nRunning local `llama.cpp` / `XGrammar` constrained decoding, `Outlines` / `vLLM`,\nor feeding an LLM? Fetch the root-level grammar schemas straight from\n`SteveWinschel/FrameAssembly` (or `/llms-full.txt` from this site):\n\n- ISO/IEC 14977 EBNF (`grammar.ebnf`):\n  `https://raw.githubusercontent.com/SteveWinschel/FrameAssembly/main/grammar.ebnf`\n- llama.cpp / XGrammar GBNF (`frameassembly.gbnf`):\n  `https://raw.githubusercontent.com/SteveWinschel/FrameAssembly/main/frameassembly.gbnf`\n- Outlines / vLLM Lark (`frameassembly.lark`):\n  `https://raw.githubusercontent.com/SteveWinschel/FrameAssembly/main/frameassembly.lark`\n\n### `grammar_verified_sample.frasm`\n\n```frameassembly\nhost verifier_a { ip 2001:db8:10::1  mac 00:1b:21:aa:00:01 }\nhost verifier_b { ip 2001:db8:10::2  mac 00:1c:73:bb:00:02 }\n\ncompile {\n    verifier_a -> verifier_b ndp neighborsolicit target 2001:db8:10::2 slla 00:1b:21:aa:00:01 wait 1ms\n    verifier_a <- verifier_b ndp neighboradvert target 2001:db8:10::2 tlla 00:1c:73:bb:00:02\n}\n```\n\n### Excerpt from grammar.ebnf (v3.2.2)\n\n```ebnf\nprogram       = { host_block | flow_block } , compile_block , { host_block | flow_block } ;\nhost_block    = \"host\" , identifier , \"{\" , host_attr , { host_attr } , \"}\" ;\nhost_attr     = ( \"ip\" , ip_literal ) | ( \"mac\" , mac_literal ) ;\nflow_block    = \"flow\" , identifier , \"(\" , param_list , \")\" , \"{\" , { frame_stmt } , \"}\" ;\ncompile_block = \"compile\" , \"{\" , { frame_stmt | flow_call } , \"}\" ;\nframe_stmt    = identifier , ( \"->\" | \"<-\" ) , identifier , protocol_kw , { modifier } ;\n```\n\n## 5. `frameassembly reverse` Fidelity & Boundary Matrix\n\nThe 5-stage reverse engine verifies every dissected frame against an internal\nself-check oracle so round-trip edits stay deterministic:\n\n| Input Frame / Container Class | `frameassembly reverse` Output Behavior | Recompile Round-Trip Guarantee |\n| --- | --- | --- |\n| Container & Link-Layer Normalization | Reads classic/nanosecond `.pcap` and `.pcapng` (`SHB`/`IDB`/`EPB`/`SPB`); normalizes `ETHERNET`, `RAW`, `IPV4`, `IPV6`, `LINUX_SLL`, `LINUX_SLL2`, `NULL`, and `LOOP` into Ethernet II; strips trailing 60/64B zero-padding and 4B FCS. | Clean Ethernet II output (`LINKTYPE_ETHERNET`) with preserved nanosecond inter-packet `wait` deltas. |\n| Cleartext & Structured L2–L7 Protocols (`80` builders) | Dissects into symbolic `host1`, `host2`, ... + lowercase `.frasm` protocol modifiers (`dns qname`, `tls clienthello sni`, `http`, `bgp`, `modbus`, `dnp3`, `snmp1`/`snmp2`, `snmp3` `noAuthNoPriv`), verified per-packet by the internal self-check oracle. | Editing variable-length strings or adding `vlan`/`qinq` recalculates L7 TLV lengths, IPv4/UDP lengths, downstream TCP `seq`/`acknum`, and all checksums. |\n| IPsec ESP (`IP Protocol 50`) | Emits canonical `esp` (`spi`, `seq`, `iv`, `icv` / encrypted payload) rather than the `ipsec` authoring alias. | Preserves SPI, sequence number, and ciphertext while recalculating outer IP headers if `hostN` IPs are redacted. |\n| Encrypted `snmp3` (`authPriv` / keyed `authNoPriv`) & Unknown Payloads | Steps down deterministically to `udp` / `tcp` with lossless `hexpayload \"...\"` because USM decryption requires out-of-band secrets. | Byte-exact payload preservation on recompile while still allowing outer MAC, VLAN, IP, and port redaction. |\n"}
{"id":"pretrain-guide-diagnostics","kind":"workflow_guide","title":"Troubleshooting & Error Reference (E01–E14) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/diagnostics","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":[],"text":"# Troubleshooting & Error Reference (`E01`–`E14`)\n\n> **FrameAssembly v3.3.0** · Reference Guide R4 · Canonical URL:\n> https://frameassembly-lang.dev/docs/diagnostics\n\nEvery syntax, block/modifier, and IP/port/protocol validation rule in\nFrameAssembly v3.3.0 — paste your error message or filter by category to see the\nexact broken vs. valid `.frasm` fix.\n\n## Key Takeaways\n\n- FrameAssembly catches syntax typos, mismatched IPv4/IPv6 host pairs, unsupported\n  `transport` overrides, and out-of-range header values *before* writing a single\n  `.pcap` byte.\n- All built-in keywords match `^[a-z0-9]+$` (zero underscores, zero hyphens),\n  while your own `host` and `flow` names freely allow capitals, `_`, and internal\n  `-`.\n- Use the interactive filter below (or press `⌘K` anywhere on the site) to paste\n  any error fragment and jump straight to a working fix.\n\n## 1. Three Checks Before Any Byte Hits `.pcap`\n\nUnlike raw hex builders that happily write broken headers and leave you staring at\nred Wireshark warnings, FrameAssembly checks your file in three plain groups\nbefore generating packets: **Syntax & Typos** (comment markers, quotes, and\nlowercase keyword suggestions), **Blocks & Modifiers** (`host`/`flow`/`compile`\nlayout, `->`/`<-` lines, and close-match typo hints), and **IP, Port & Protocol\nRules** (matching IPv4/IPv6 endpoints, allowed `transport` overrides, and field\nbit-width ranges).\n\nFilter all 14 error rules below by category or keyword, and click **Preview Valid\nFix** on any card to inspect the resulting packets directly in your browser.\n\n## Diagnostic Rules (`E01`–`E14`)\n\n### E01 (Syntax & Typos): Uppercase, Underscore, or Hyphenated Built-In Keyword\n\n- **Compiler Message:** `replace 'echo_request' with 'echorequest'`\n- **Why It Happens:** Every built-in protocol name, modifier, TCP flag, and time\n  unit in FrameAssembly is strictly lowercase alphanumeric ([a-z0-9]+) with zero\n  underscores and zero hyphens. User-defined host and flow names may still use\n  capitals, underscores, or internal hyphens.\n\n```frameassembly\nhost Laptop_01 { ip 10.0.0.10 }\nhost Core-GW   { ip 10.0.0.1 }\n\ncompile {\n    Laptop_01 -> Core-GW icmp echorequest wait 5ms\n}\n```\n\n### E02 (Blocks & Modifiers): CIDR Subnet Mask (/24), Equals Sign, or Quotes Inside host Block\n\n- **Compiler Message:** `expected plain IPv4 or IPv6 address literal inside host\n  block`\n- **Why It Happens:** Ethernet frames carry 32-bit IPv4 or 128-bit IPv6 host\n  addresses on the wire—never subnet masks. Declare plain IP literals without /24\n  suffixes, quotes, commas, or = signs.\n\n```frameassembly\nhost firewall { ip 10.10.1.1 }\nhost server   { ip 10.10.1.20 }\n\ncompile {\n    firewall -> server icmp echorequest\n}\n```\n\n### E03 (Syntax & Typos): Hash (#) Comments or Single-Quoted Strings\n\n- **Compiler Message:** `unexpected character: use // for comments and \"...\" for\n  text literals`\n- **Why It Happens:** FrameAssembly uses // line comments and double-quoted UTF-8\n  strings (\"...\") exclusively so shell-style # comments and single quotes never\n  create escaping ambiguity.\n\n```frameassembly\n// DNS lookup test\nhost client   { ip 192.168.1.10 }\nhost resolver { ip 192.168.1.53 }\n\ncompile {\n    client -> resolver dns query qname \"portal.internal\" qtype \"A\"\n}\n```\n\n### E04 (Blocks & Modifiers): Using sport / dport Instead of srcport / dstport, or ack 1001 Instead of acknum 1001\n\n- **Compiler Message:** `unknown modifier 'sport'; did you mean 'srcport'?`\n- **Why It Happens:** Bare ack sets the 1-bit TCP ACK control flag, whereas acknum\n  sets the 32-bit acknowledgment header value. Transport ports always use explicit\n  srcport and dstport.\n\n```frameassembly\nhost c { ip 10.0.0.1 }\nhost s { ip 10.0.0.2 }\n\ncompile {\n    c -> s tcp syn srcport 51000 dstport 443 seq 1000 wait 1ms\n    c <- s tcp syn ack seq 5000 acknum 1001\n}\n```\n\n### E05 (Blocks & Modifiers): Writing host on HTTP/SSDP Instead of hosthdr, or transport on RTSP Instead of transporthdr\n\n- **Compiler Message:** `unexpected keyword 'host' inside frame statement; use\n  'hosthdr' for HTTP Host header`\n- **Why It Happens:** Top-level host opens an endpoint declaration and transport\n  selects L4 encapsulation (35 TCP/UDP protocols plus universal Layer 7 transport\n  sctp). HTTP/SSDP use hosthdr and RTSP uses transporthdr to set their Layer 7\n  text headers unambiguously.\n\n```frameassembly\nhost cam_client { ip 10.10.2.15 }\nhost nvr_srv    { ip 10.10.2.80 }\n\ncompile {\n    cam_client -> nvr_srv tcp syn srcport 53100 dstport 80 wait 1ms\n    cam_client <- nvr_srv tcp syn ack wait 1ms\n    cam_client -> nvr_srv tcp ack wait 1ms\n    cam_client -> nvr_srv http get uri \"/status\" hosthdr \"nvr.lab.local\"\n}\n```\n\n### E06 (Blocks & Modifiers): Using Removed v1 loop Instead of repeat, Leading wait Before Frame 1, or Parameterless flow\n\n- **Compiler Message:** `unexpected identifier 'loop' inside compile block; use\n  'repeat <count> { ... }'`\n- **Why It Happens:** FrameAssembly v3.3.0 uses repeat <count> { ... } (up to\n  100,000 total emitted frames; never v1 loop), requires every flow template to\n  declare at least one formal parameter flow name(a, b), and only accepts wait as\n  a trailing modifier after a frame statement.\n\n```frameassembly\nhost a { ip 10.0.0.1 }\nhost b { ip 10.0.0.2 }\n\nflow ping_pair(src, dst) {\n    src -> dst icmp echorequest id 1 wait 5ms\n    src <- dst icmp echoreply id 1 wait 5ms\n}\n\ncompile {\n    repeat 2 {\n        ping_pair(a, b)\n    }\n}\n```\n\n### E07 (IP, Port & Protocol Rules): MAC-Only Host Used on a Layer 3, Layer 4, or Layer 7 Protocol\n\n- **Compiler Message:** `protocol requires an IPv4 or IPv6 address on both source\n  and destination hosts`\n- **Why It Happens:** MAC-only host declarations are valid across all 18 Layer 2\n  protocols (arp, vlan, qinq, lldp, stp, lacp, eapol, mpls, cdp, isis, macsec,\n  pfc, pppoe, nsh, profinet, goose, sv, ethercat; profinet and ethercat require ip\n  when using transport udp). All 128 Layer 3–7 protocols build an IPv4 or IPv6\n  header and require ip on both endpoints.\n\n```frameassembly\nhost sw1 { ip 10.255.0.1 mac 00:1c:73:00:00:01 }\nhost sw2 { ip 10.255.0.2 mac 00:1c:73:00:00:02 }\n\ncompile {\n    sw1 -> sw2 ospf hello areaid 0.0.0.0\n}\n```\n\n### E08 (IP, Port & Protocol Rules): Mixing an IPv4 Source Host with an IPv6 Destination Host\n\n- **Compiler Message:** `source and destination hosts must share the same IP\n  address family (both IPv4 or both IPv6)`\n- **Why It Happens:** A single IP packet header is either IPv4 (EtherType 0x0800)\n  or IPv6 (EtherType 0x86dd). To run the same exchange across both families,\n  define a parameterized flow(c, s) and call it once with IPv4 hosts and once with\n  IPv6 hosts.\n\n```frameassembly\nhost v4_client { ip 10.10.1.10 }\nhost v4_server { ip 10.10.1.20 }\nhost v6_client { ip 2001:db8::10 }\nhost v6_server { ip 2001:db8::20 }\n\nflow tls_open(c, s) {\n    c -> s tcp syn srcport 50100 dstport 443 wait 1ms\n    c <- s tcp syn ack\n}\n\ncompile {\n    tls_open(v4_client, v4_server)\n    tls_open(v6_client, v6_server)\n}\n```\n\n### E09 (IP, Port & Protocol Rules): Running igmp Over IPv6 Hosts or ndp / mld / srv6 Over IPv4 Hosts\n\n- **Compiler Message:** `igmp requires IPv4 endpoints (use mld for IPv6 multicast\n  listener discovery)`\n- **Why It Happens:** While 124 of the 128 IP protocols automatically adapt\n  between IPv4 and IPv6, IGMP (IP protocol 2) exists only in IPv4, and NDP, MLD,\n  and SRv6 (Segment Routing over IPv6 Routing Header Type 4) exist only in IPv6.\n\n```frameassembly\nhost listener_v6 { ip fe80::10 }\nhost querier_v6  { ip fe80::1 }\n\ncompile {\n    listener_v6 -> querier_v6 mld report multicastaddr ff02::1:ff00:10\n}\n```\n\n### E10 (IP, Port & Protocol Rules): Using an Unsupported transport tcp|udp|sctp Override for a Fixed-Encapsulation Protocol\n\n- **Compiler Message:** `protocol 'vxlan' does not support 'transport tcp'`\n- **Why It Happens:** FrameAssembly v3.3.0 supports transport tcp|udp across 35\n  dual-transport protocols (including dns, llmnr, sip, syslog, kerberos, nfs,\n  memcached, modbus, dnp3, ethernetip, ldap, snmp1..3, radius, coap, mqtt, rtsp,\n  ntp, twamp, ldp, mssql, kafka, turn, h323, mgcp, someip, doip, hartip, fins,\n  melsec, synchrophasor, rocplus, bsap, c1222), transport udp on\n  profinet/ethercat/l2tp, and universal transport sctp across all 94 Layer 7\n  protocols. Fixed-L3/tunnel protocols such as vxlan, wireguard, or ospf reject\n  incompatible transport overrides.\n\n```frameassembly\nhost client   { ip 10.0.0.10 }\nhost resolver { ip 10.0.0.53 }\n\ncompile {\n    client -> resolver tcp syn srcport 53120 dstport 53 wait 1ms\n    client <- resolver tcp syn ack wait 1ms\n    client -> resolver tcp ack wait 1ms\n    client -> resolver dns query txid 0x4410 qname \"zone.corp.local\" qtype \"AXFR\" transport tcp\n}\n```\n\n### E11 (IP, Port & Protocol Rules): Applying TCP Flags/Options to Non-TCP Frames or nochecksum to Non-UDP Frames\n\n- **Compiler Message:** `TCP header flags and options are only valid on tcp and\n  TCP-based Layer 7 protocols`\n- **Why It Happens:** UDP, ICMP, and pure L2/L3 headers have no sequence numbers,\n  window fields, or TCP control flags, and nochecksum is valid only on UDP or\n  UDP-encapsulated protocols. Restrict syn, ack, fin, rst, psh, seq, acknum, win,\n  mss, wscale, sackperm, sackblock, tcpmd5, and tfo to tcp and TCP-carried L7\n  protocols.\n\n```frameassembly\nhost a { ip 10.0.0.1 }\nhost b { ip 10.0.0.2 }\n\ncompile {\n    a -> b udp srcport 12000 dstport 9000 nochecksum payload \"probe\"\n}\n```\n\n### E12 (IP, Port & Protocol Rules): Out-of-Range VLAN ID (>4095), DSCP (>63), NSH TTL (>63), or Duplicate TCP Flag\n\n- **Compiler Message:** `vlan ID 5000 exceeds 12-bit IEEE 802.1Q maximum\n  (0..=4095)`\n- **Why It Happens:** FrameAssembly checks every header field width before writing\n  bytes: VLAN/QinQ VIDs are 12 bits (0..4095), PCP is 3 bits (0..7), DSCP is 6\n  bits (0..63), ECN is 2 bits (0..3), NSH TTL is 6 bits (0..63), and MPLS labels\n  are 20 bits (0..1048575; mpls is repeatable in v3.3.0 to build multi-label\n  stacks).\n\n```frameassembly\nhost pe1 { ip 10.1.1.1 }\nhost pe2 { ip 10.1.1.2 }\n\ncompile {\n    pe1 -> pe2 icmp echorequest mpls 16000 exp 6 mpls 24000 dscp 46\n}\n```\n\n### E13 (IP, Port & Protocol Rules): Odd-Length SNMPv3 engineid Hex or Invalid varbind Value Type\n\n- **Compiler Message:** `snmp3 engineid must contain an even number of hexadecimal\n  digits`\n- **Why It Happens:** SNMPv3 USM key localization hashes raw engine ID octets, so\n  engineid requires even-length hex (such as \"80001f888001020304\"). Also use\n  varbind <oid> string \"...\" or oidval <oid> (never str or trapoid).\n\n```frameassembly\nhost rtr { ip 10.40.1.1 }\nhost nms { ip 10.40.1.100 }\n\ncompile {\n    rtr -> nms snmp3 trap user \"ops\" engineid \"80001f888001020304\" auth sha256 \"AuthPass123!\" priv aes \"PrivPass123!\" varbind 1.3.6.1.2.1.1.5.0 string \"core1\"\n}\n```\n\n### E14 (IP, Port & Protocol Rules): DNS / mDNS / LLMNR Label Longer Than 63 Bytes or Payload + HexPayload Collision\n\n- **Compiler Message:** `DNS label exceeds RFC 1035 maximum of 63 octets per label\n  (253 total)`\n- **Why It Happens:** DNS wire compression uses the top 2 bits of each label\n  length byte as pointer flags, capping single labels at 63 octets and full domain\n  names at 253 characters. Separately, payload and hexpayload are mutually\n  exclusive on the same frame.\n\n```frameassembly\nhost ws { ip 10.0.0.10 }\nhost ns { ip 10.0.0.53 }\n\ncompile {\n    ws -> ns dns query txid 0x2201 qname \"sub-01.telemetry-ingest.internal\" qtype \"AAAA\"\n}\n```\n"}
{"id":"pretrain-guide-keyword-reference","kind":"workflow_guide","title":"Complete .frasm Keyword & Feature Reference (All 653 Tokens) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/docs/keyword-reference","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":[],"text":"# Complete `.frasm` Keyword & Feature Reference (All 653 Tokens)\n\n> **FrameAssembly v3.3.0** · Reference Guide R5 · Canonical URL:\n> https://frameassembly-lang.dev/docs/keyword-reference\n\nEvery built-in keyword, operator, time unit, cross-layer header modifier, protocol\nsubkeyword, alias, compiler rule, CLI subcommand, and reverse-decompiler\ncapability in FrameAssembly v3.3.0.\n\n## Key Takeaways\n\n- Covers all 653 lexer tokens in FrameAssembly v3.3.0: 7 operators/delimiters\n  (`{`, `}`, `(`, `)`, `,`, `->`, `<-`), 5 `wait` time units (`ns`, `us`, `ms`,\n  `s`, `m`), and 641 strict-lowercase `[a-z0-9]+` keywords across 81 Layer 2–7\n  protocols.\n- Documents every compiler & runtime feature: parameterized `flow(a, b)`\n  templates, deterministic unicast/multicast/IEEE MAC synthesis, stateful 4-tuple\n  TCP `seq`/`acknum` progression, dynamic L7 port pairing, live SNMPv3 USM `Ku ->\n  Kul` crypto, and 9-protocol `transport` whitelisting.\n- Details all CLI & library capabilities: classic `.pcap` vs nanosecond `.pcapng`\n  (`IfTsResol=9`), `show`, 5-stage `reverse` decompilation with self-check\n  compiler oracle across 8 `LINKTYPE_*` formats, zero-flag `update`, Rust crate\n  entrypoints, and EBNF/GBNF/Lark grammars.\n\n## 1. How FrameAssembly v3.3.0 Organizes Its 653 Tokens & Compiler Pipeline\n\nEvery built-in word in `.frasm` follows one memorizable lexical invariant:\n**strictly lowercase alphanumeric (`^[a-z0-9]+$`) with zero underscores and zero\nhyphens** (`echorequest`, `innervlan`, `sackperm`, `hosthdr`, `transporthdr`,\n`readholdingregisters`, `nullval`). User-defined `host`, `flow`, and parameter\nidentifiers freely allow capitals, underscores, and internal hyphens (`fw-dmz-01`,\n`Core_SW_1`).\n\nUse the interactive explorer below to search any token, Wireshark field alias,\nprotocol scope, or compiler feature — or switch between the **653-Token Lexicon**\nand the **Language & Compiler Feature Matrix**.\n\n## Complete Language, Compiler & CLI Feature Matrix\n\n### Program Structure (`host` + `compile`), `repeat` Loops & Nested `flow` Composition (Blocks & Lexical Rules)\n\nEvery `.frasm` specification needs `1+` `host` declarations and `1` `compile`\nblock, with optional parameterized `flow(p1, p2)` templates and bounded `repeat\n<count> { ... }` loops.\n\n- `1 statement = 1 Ethernet frame`: statements inside `compile` and `flow` execute\n  deterministically top-to-bottom.\n- `flow <name>(<p1>[, <p2>, ...]) { ... }` requires `>= 1` parameter in\n  parentheses; inside a `flow`, statements may reference formal parameters, global\n  `host` declarations, nested `flow(...)` calls (checked for cycles, max depth\n  `64`), and `repeat` blocks.\n- `repeat <count> { ... }` repeats nested frame statements, nested `repeat`\n  blocks, or `flow(...)` calls up to `100,000` total emitted frames across the\n  program (never use the removed v1 `loop` keyword).\n- `compile` freely mixes inline `a -> b ...` / `a <- b ...` frame lines, `repeat`\n  blocks, and `flow(...)` calls.\n\n```frameassembly\nhost app_v4 { ip 10.10.1.10 }\nhost db_v4  { ip 10.10.1.20 }\nhost audit  { ip 10.10.1.99 }\n\nflow tcp_open(c, s) {\n    c -> s tcp syn srcport 52100 dstport 5432 win 65535 mss 1460 wait 1ms\n    c <- s tcp syn ack win 65535 mss 1460 wait 1ms\n    c -> s tcp ack wait 1ms\n}\n\nflow pg_session(c, s) {\n    tcp_open(c, s)\n    repeat 2 {\n        c -> s postgres query sql \"SELECT 1;\" wait 2ms\n    }\n    s -> audit syslog severity 6 msg \"pg healthcheck ok\"\n}\n\ncompile {\n    pg_session(app_v4, db_v4)\n}\n```\n\n### Strict-Lowercase Built-In Keywords (`[a-z0-9]+`) vs. Flexible User Identifiers (Blocks & Lexical Rules)\n\nAll 1,126 built-in keywords and time units use lowercase letters and digits with\nzero underscores or hyphens, while user-defined `host` and `flow` names allow\ncapitals, `_`, and internal `-`.\n\n- Built-in keywords match `^[a-z0-9]+$` (`echorequest`, `innervlan`, `sackperm`,\n  `badipchecksum`, `routeralert`, `hosthdr`, `transporthdr`); uppercase or `_`\n  typos trigger self-healing suggestions.\n- User identifiers match `[a-zA-Z_][a-zA-Z0-9_]*(-[a-zA-Z0-9_]+)*` (e.g.\n  `fw-dmz-01`, `Core_SW_1`), stopping cleanly before `->`.\n- Line comments begin with `//` (leading UTF-8 BOM is stripped automatically; `#`\n  and `;` are rejected with an explicit diagnostic).\n- Strings are double-quoted UTF-8 supporting `\\r`, `\\n`, `\\t`, `\\\\`, `\\\"`, and\n  `\\xNN` raw octets (single-quoted strings are rejected).\n- Integers accept decimal (`443`) or hex (`0x0800`); signed integers accept\n  negative decimal (`-20`); IEEE-754 floats (`21.5`) are accepted for `real` on\n  `bacnet` and `iec104`.\n- ASN.1 OIDs (`oid`, `enterprise`, `varbind`, `oidval`, `callingap`, `calledap`)\n  accept unquoted dotted trees with `>= 4` numeric arcs (`1.3.6.1.2.1.1.1.0`) or\n  quoted strings.\n\n### Deterministic Unicast MACs, RFC 1112/2464 Multicast MACs & 18 MAC-Only L2 Protocols (Host & MAC Resolution)\n\nFrameAssembly synthesizes deterministic Ethernet framing automatically whenever\n`mac`, `srcmac`, or `dstmac` is omitted.\n\n- Unicast `host` blocks without `mac` receive sequential deterministic MACs in\n  1-based declaration order: `00:00:00:00:00:01`, `00:00:00:00:00:02`,\n  `00:00:00:00:00:03`, and so on.\n- Explicit `mac`, `srcmac`, and `dstmac` values accept colon\n  (`00:1a:2b:3c:4d:5e`), hyphen (`00-1A-2B-3C-4D-5E`), or Cisco dot-quad\n  (`001a.2b3c.4d5e`) notation.\n- IPv4 multicast destinations (`224.0.0.0/4`) derive RFC 1112 MACs\n  (`01:00:5e:xx:xx:xx`); IPv6 multicast destinations (`ff00::/8`) derive RFC 2464\n  MACs (`33:33:xx:xx:xx:xx`).\n- Pure Layer 2 control protocols derive IEEE/vendor group destination MACs\n  automatically unless `dstmac` is set: `stp` (`01:80:c2:00:00:00`), `pfc`\n  (`01:80:c2:00:00:01`), `lacp` (`01:80:c2:00:00:02`), `eapol`\n  (`01:80:c2:00:00:03`), `lldp` (`01:80:c2:00:00:0e`), and `cdp`\n  (`01:00:0c:cc:cc:cc`).\n- MAC-only hosts (`host sw1 { mac 00:11:22:33:44:55 }`) are valid across all 18\n  Layer 2 protocols (`arp`, `vlan`, `qinq`, `lldp`, `stp`, `lacp`, `eapol`,\n  `mpls`, `cdp`, `isis`, `macsec`, `pfc`, `pppoe`, `nsh`, `profinet`, `goose`,\n  `sv`, `ethercat`).\n\n### Post-Packet Nanosecond `wait` Capture Clock (`ns`, `us`, `ms`, `s`, `m`) (Clock & L4 State)\n\nEvery capture starts at `0ns` on Frame 1 and advances deterministically after each\nemitted packet with zero system-clock jitter.\n\n- Frame 1 is always emitted at relative timestamp `0.000000000 s` (`0ns`).\n- `wait <u32><ns|us|ms|s|m>` is an inline post-packet modifier: Frame `k`\n  transmits at the current clock value, then advances the clock before Frame `k +\n  1`.\n- Omitting `wait` advances the clock by the default inter-packet gap of `10ms`\n  (`10,000,000 ns`).\n- `wait 0ns` emits back-to-back microbursts with zero timestamp delta; `.pcapng`\n  stores full `1ns` precision (`IfTsResol = 9`).\n\n### Shared 4-Tuple TCP State, SCTP Associations & `<-` Bidirectional Port Memory (Clock & L4 State)\n\nRaw `tcp`/`sctp` frames and Layer 7 protocols share canonical endpoint-pair port\ninheritance and transport sequence tracking.\n\n- Setting `srcport 51234 dstport 443` on `a -> b` (or relying on ephemeral `49152+\n  -> default_port`) automatically swaps ports to `443 -> 51234` on `a <- b`\n  replies across TCP, UDP, and SCTP.\n- Initial TCP `seq` defaults to `1000` per direction; `syn` and `fin` each advance\n  next `seq` by `+1`, and TCP payloads/L7 frames advance next `seq` by\n  `+payload_len` with `psh ack`.\n- SCTP associations automatically track verification tags (`vtag`) and\n  per-direction Transmission Sequence Numbers (`tsn`), including native `ngap`\n  (`38412`, PPID `60`), `s1ap` (`36412`, PPID `18`), `diameter` (`3868`, PPID\n  `46`), and any L7 protocol using `transport sctp`.\n- Explicit `seq <u32>`, `acknum <u32>`, `vtag <u32>`, or `tsn <u32>` overrides\n  emit exact wire values and re-anchor downstream state.\n\n### Dynamic Layer 7 Port Pairing & Automatic Multicast Overrides (Clock & L4 State)\n\nProtocols with asymmetric request/reply or control/data port pairs select\nRFC-accurate ports and multicast groups automatically.\n\n- `dhcp`: IPv4 `discover`/`request`/`release` use UDP `68 -> 67` and `offer`/`ack`\n  use `67 -> 68`; over IPv6 hosts, `solicit`/`request` use UDP `546 -> 547` and\n  `advertise`/`reply` use `547 -> 546`.\n- `mdns`, `llmnr`, `wsdiscovery`, and `glbp`: Automatically target their protocol\n  multicast addresses (`224.0.0.251`/`ff02::fb`, `224.0.0.252`/`ff02::1:3`,\n  `239.255.255.250`/`ff02::c`, `224.0.0.102`) unless overridden.\n- `ptp`: Event messages (`sync`, `delayreq`) use UDP `319`; general messages\n  (`followup`, `delayresp`, `announce`) use UDP `320`.\n- `lisp` & `h323`: `lisp data` uses UDP `4341` while control messages use `4342`;\n  `h323` Q.931 signaling uses TCP `1720` while Gatekeeper RAS\n  (`grq`/`gcf`/`rrq`/`rcf`) uses UDP `1719`.\n- `snmp1` / `snmp2` / `snmp3`: `trap`, `inform`, and `report` default to port\n  `162`; `get`, `getnext`, `getbulk`, `set`, and `response` default to port `161`.\n\n### VLAN, QinQ, Repeatable MPLS Stacks, SRv6, RouterAlert & Fault Injection (Tagging & Wire Crypto)\n\nAny L2–L7 statement supports single-line VLAN/QinQ/MPLS/QoS wrapping plus\ndeterministic negative-testing checksum and FCS overrides.\n\n- `vlan <0..4095> [pcp <0..7>] [dei <0|1>]` wraps frames in IEEE 802.1Q\n  (`0x8100`); `qinq <0..4095> [innervlan <0..4095>]` emits outer S-Tag (`0x88a8`)\n  + inner C-Tag (`0x8100`).\n- `mpls <0..1048575> [exp|tc <0..7>] [bos <0|1>] [mplsttl <0..255>]` is\n  **repeatable** (`mpls 16000 mpls 24000`) to build multi-label MPLS VPN/TE stacks\n  with automatic `bos` bit placement.\n- `fcs` appends a valid IEEE 802.3 CRC-32 trailer; `badfcs`, `badipchecksum`,\n  `badchecksum`, and `nochecksum` inject exact L2/L3/L4 checksum faults;\n  `routeralert` injects IPv4 Router Alert (`0x94040000`); `comment \"<str>\"` writes\n  PCAPNG EPB comments.\n- TCP options include `mss`, `wscale`, `sackperm`, repeatable `sackblock <left>\n  <right>`, `tsval`/`tsecr`, BGP `tcpmd5 \"<16B_hex>\"`, and `tfo \"<cookie_hex>\"`.\n\n### Live Wire Checksums, SNMPv3 USM Crypto (`Ku -> Kul`), BGP 4-Byte ASN & OT CRCs (Tagging & Wire Crypto)\n\nFrameAssembly computes real cryptographic digests and wire-exact CRCs offline so\nWireshark, Suricata, and NMS receivers validate every byte.\n\n- `snmp3`: Performs full RFC 3414 / RFC 7860 1 MiB password-to-key (`Ku`) and\n  `engineid`-localized (`Kul`) derivation, live HMAC (`md5`, `sha`, `sha256`,\n  `sha384`, `sha512`), and `ScopedPDU` encryption via AES-128-CFB (`priv aes`) or\n  CBC-DES (`priv des`).\n- `bgp`: Supports full 32-bit `asn <u32>`; when `asn > 65535` on `bgp open`,\n  writes `AS_TRANS` (`23456`) in the 16-bit header slot and appends Capability\n  `65` (RFC 6793 4-octet ASN).\n- `sctp`, `ngap`, `s1ap`, & `rocev2`: Computes Castagnoli **CRC-32c** on SCTP\n  frames (including `shutdowncomplete` and universal `transport sctp`) and\n  Invariant CRC-32 on RoCEv2 BTH frames.\n- `dnp3`, `synchrophasor`, & `rocplus`: Computes per-block DNP3 CRC-16 (`0x3d65`),\n  IEEE C37.118 CRC-CCITT, and Emerson ROC Plus reflected CRC-16 automatically\n  unless overridden.\n\n### Compile-Time `validate_semantics` Bounds, 35 TCP/UDP Protocols & Universal `transport sctp` (Validation & Guardrails)\n\nInvalid IP family pairings, out-of-range bit-widths, cyclic `flow` calls, and\nillegal L4 overrides fail cleanly at compile time.\n\n- Endpoint family match: both hosts on a frame must be IPv4, both IPv6, or (on the\n  18 L2 protocols) MAC-only. `igmp` requires IPv4 hosts; `ndp`, `mld`, and `srv6`\n  require IPv6 hosts.\n- `transport tcp|udp` is supported across 35 TCP/UDP protocols (`ldp` plus 34 L7\n  protocols including `dns`, `llmnr`, `sip`, `syslog`, `kerberos`, `nfs`,\n  `memcached`, `modbus`, `dnp3`, `ethernetip`, `ldap`, `snmp1..3`, `radius`,\n  `coap`, `mqtt`, `rtsp`, `ntp`, `twamp`, `someip`, `doip`, `mssql`, `kafka`,\n  etc.); `transport sctp` is valid on all 94 L7 protocols; `profinet`, `ethercat`,\n  and `l2tp` v3 accept `transport udp`.\n- TCP flags, `seq`/`acknum`/`win`/`urgent`, and TCP options are rejected on\n  non-TCP frames; `nochecksum` is accepted exclusively on UDP frames; `nsh ttl`\n  validates `0..=63`.\n- Nested `flow` calls are checked for recursion cycles (max depth `64`), and\n  `repeat` expansion enforces the `100,000` maximum emitted packet ceiling.\n\n### Context-Sensitive Shared Keyword Disambiguation (`ack`, `rst`, `seq`, `whois`, `hosthdr`) (Validation & Guardrails)\n\nThe parser resolves shared protocol/transport tokens deterministically by position\nand avoids top-level keyword collisions.\n\n- `ack` and `rst` placed immediately after `dhcp`, `tftp`, `sip`, or `coap` parse\n  as that protocol’s message type rather than TCP control flags.\n- On `tacacs`, writing `seq <u32>` *before* the `tacacs` keyword sets the 32-bit\n  TCP sequence number, while writing `seq <u8>` *after* `tacacs` sets the 8-bit\n  RFC 8907 TACACS+ `seq_no`.\n- `whois` works both as standalone TCP/43 WHOIS (`a -> b whois query domain\n  \"example.com\"`) and as a BACnet unconfirmed service (`a -> b bacnet whois`).\n- HTTP/DoH/NTLM/SSDP `Host:` headers use `hosthdr \"<str>\"` (never `host`), and\n  RTSP `Transport:` headers use `transporthdr \"<str>\"` (never `transport`).\n\n### Rootless CLI Commands, Stdin/Stdout (`-`) Streaming & `show` on Captures (CLI & Streaming)\n\nSingle static binary with default root compilation plus 5 subcommands (`show`,\n`reverse`, `update`, `version`, `help`), Unix pipeline `-` streaming, and zero\nroot socket privileges.\n\n- `frameassembly <in.frasm|-> [out.pcap | out.pcapng | -]` compiles `.frasm` to\n  classic libpcap `.pcap` by default, nanosecond `.pcapng` (`IfTsResol = 9`), or\n  streams `stdin -> stdout` PCAPNG when `-` is passed.\n- `frameassembly show <in.frasm | capture.pcap | capture.pcapng | ->` prints the\n  relative-timestamp packet ladder directly from either `.frasm` code or an\n  existing binary capture without writing disk files.\n- `frameassembly reverse <in.pcap|.pcapng|-> [out.frasm|-]` decompiles captures\n  back into canonical `.frasm` code across files or Unix pipes.\n- `frameassembly update` runs a zero-flag self-updater via Cargo/rustup or SHA-256\n  verified GitHub Release archives.\n\n```bash\n# Compile .frasm -> classic .pcap, nanosecond .pcapng, or stream to tshark via '-'\nframeassembly capture.frasm capture.pcap\nframeassembly capture.frasm capture.pcapng\nframeassembly - < capture.frasm | tshark -r -\n\n# Inspect .frasm code or binary .pcap/.pcapng ladder in stdout\nframeassembly show capture.frasm\nframeassembly show capture.pcap\n\n# Decompile .pcap or .pcapng -> editable .frasm code\nframeassembly reverse incident.pcapng incident.frasm\n```\n\n### 5-Stage `reverse` Decompiler Across 146 Protocols, Oracle & Formal Grammars (Reverse & Rust API)\n\n`frameassembly reverse` normalizes 8 link-layer types, reconstructs high-level\n`.frasm` statements across all 146 protocols, and verifies every frame through an\nin-memory compiler oracle.\n\n- Container parser supports classic libpcap (microsecond & nanosecond, LE & BE)\n  and PCAPNG (`SHB`, `IDB`, `EPB` with `opt_comment`, `SPB`, `IfTsResol`,\n  `IfTsOffset`, and truncated block salvage).\n- Link-layer normalization converts 8 `LINKTYPE_*` formats (`ETHERNET`, `RAW`,\n  `IPV4`, `IPV6`, `LINUX_SLL`, `LINUX_SLL2`, `NULL`, `LOOP`) into canonical\n  Ethernet II frames while preserving explicit `fcs`/`badfcs` and checksum states.\n- Self-check compiler oracle & shadow TCP/SCTP state tracker: every candidate\n  `.frasm` statement is compiled in memory and compared byte-for-byte against the\n  original wire frame, stepping down cleanly to `hexpayload` whenever proprietary\n  or encrypted bytes require lossless preservation.\n- Rust crate (`frameassembly` on Crates.io, Edition 2024, `rustc >= 1.89`) exposes\n  `lexer::lex`, `parser::parse_program`, `parser::validation::validate_semantics`,\n  `backend::{compile_program, generate_pcap, generate_pcapng}`, and\n  `reverse::{reverse_pcap_bytes, reverse_pcap_file, reverse_pcap_reader}`.\n- Constrained LLM decoding grammars ship alongside the compiler: ISO/IEC 14977\n  `grammar.ebnf`, `frameassembly.gbnf` (`llama.cpp` / `XGrammar`), and\n  `frameassembly.lark` (`Outlines` / `vLLM`), plus `/llms.txt` and\n  `/llms-full.txt`.\n\n```rust\nuse frameassembly::{backend, lexer, parser, reverse};\n\nlet tokens = lexer::lex(src)?;\nlet ast = parser::parse_program(&tokens, src)?;\nparser::validation::validate_semantics(&ast, src)?;\nlet frames = backend::compile_program(&ast)?;\nlet pcap_bytes = backend::generate_pcap(&frames);\nlet roundtrip_frasm = reverse::reverse_pcap_bytes(&pcap_bytes)?;\n```\n\n## Exhaustive 653-Token `.frasm` Lexicon\n\n### Program Blocks, Loops & Host Fields (6 tokens)\n\nTop-level declarations (`host`, `flow`, `compile`), bounded `repeat` loop blocks,\nand endpoint address attributes (`ip`, `mac`).\n\n- **Token**: `compile`\n  - **Scopes**: top-level\n  - **Syntax**: `compile { <inline_frames_flow_calls_or_repeat> }`\n  - **Value / Range**: Required execution block (1 per file)\n  - **Default**: 1 frame statement = 1 Ethernet frame\n  - **Summary**: Executes inline frame statements, repeat <count> { ... } blocks,\n  and flow(...) invocations top-to-bottom in deterministic capture order.\n- **Token**: `flow`\n  - **Scopes**: top-level\n  - **Syntax**: `flow <name>(<p1>[, <p2>, ...]) { <statements> }`\n  - **Value / Range**: Parameterized template block (>= 1 param)\n  - **Default**: Optional reusable sequence (supports nested flow calls & repeat)\n  - **Summary**: Defines a reusable parameterized packet sequence supporting\n  nested flow(...) calls (max depth 64), repeat blocks, and global host\n  references.\n- **Token**: `host`\n  - **Scopes**: top-level\n  - **Syntax**: `host <id> { [ip <ipv4|ipv6>] [mac <mac>] }`\n  - **Value / Range**: Endpoint declaration block\n  - **Default**: Auto MAC 00:00:00:00:00:01, :02, ... when mac omitted\n  - **Summary**: Declares a named network endpoint with an IPv4/IPv6 literal, a\n  MAC address, or both (MAC-only hosts are valid across all 18 Layer 2 protocols).\n- **Token**: `ip`\n  - **Scopes**: host block, dns (qtype/rdata context)\n  - **Syntax**: `ip <ipv4_or_ipv6_literal>`\n  - **Value / Range**: Plain IPv4 (10.0.0.1) or IPv6 (2001:db8::1) literal\n  - **Default**: Required for all 128 L3/L4/L7 protocols\n  - **Summary**: Assigns the host IPv4 or IPv6 endpoint address (never write /24\n  CIDR suffixes, =, :, or commas inside host blocks).\n- **Token**: `mac`\n  - **Scopes**: host block\n  - **Syntax**: `mac <00:1a:2b:3c:4d:5e | 00-1A-2B-3C-4D-5E | 001a.2b3c.4d5e>`\n  - **Value / Range**: 48-bit Ethernet MAC (colon, hyphen, or Cisco dot-quad)\n  - **Default**: 00:00:00:00:00:0N in 1-based host declaration order\n  - **Summary**: Assigns an explicit hardware MAC address to a host in colon,\n  hyphen, or Cisco four-hex-group notation.\n- **Token**: `repeat`\n  - **Scopes**: compile, flow\n  - **Syntax**: `repeat <0..100000> { <statements> }`\n  - **Value / Range**: Bounded loop block (max 100,000 total emitted frames)\n  - **Default**: Executes nested statements or flow calls <count> times\n  - **Summary**: Repeats nested frame statements, nested repeat blocks, or\n  flow(...) calls inside flow or compile blocks while advancing stateful TCP/SCTP\n  counters and capture timestamps.\n\n### Operators & Delimiters (7 tokens)\n\nDirectional frame arrows (`->`, `<-`), block braces (`{`, `}`), and `flow`\nparameter delimiters (`(`, `)`, `,`).\n\n- **Token**: `(`\n  - **Scopes**: flow, compile\n  - **Syntax**: `flow ping(a, b) { ... } · ping(h1, h2)`\n  - **Value / Range**: Opening parameter parenthesis\n  - **Default**: Required on flow definitions and flow calls\n  - **Summary**: Opens the formal parameter list on a flow declaration or the host\n  argument list on a flow call.\n- **Token**: `)`\n  - **Scopes**: flow, compile\n  - **Syntax**: `flow ping(a, b) { ... } · ping(h1, h2)`\n  - **Value / Range**: Closing parameter parenthesis\n  - **Default**: Required on flow definitions and flow calls\n  - **Summary**: Closes the formal parameter list on a flow declaration or the\n  host argument list on a flow call.\n- **Token**: `,`\n  - **Scopes**: flow, compile\n  - **Syntax**: `flow relay(client, proxy, backend)`\n  - **Value / Range**: Parameter separator\n  - **Default**: Used only inside flow(...) parameter/argument lists\n  - **Summary**: Separates parameters in flow declarations and invocations (never\n  used inside host blocks or between frame modifiers).\n- **Token**: `->`\n  - **Scopes**: compile, flow\n  - **Syntax**: `<a> -> <b> <protocol> [modifiers...]`\n  - **Value / Range**: Forward frame operator\n  - **Default**: Source = a, Destination = b\n  - **Summary**: Transmits one Ethernet frame from left endpoint a to right\n  endpoint b and records the 4-tuple port pair.\n- **Token**: `<-`\n  - **Scopes**: compile, flow\n  - **Syntax**: `<a> <- <b> <protocol> [modifiers...]`\n  - **Value / Range**: Reverse frame operator\n  - **Default**: Source = b, Destination = a (auto-swaps remembered ports)\n  - **Summary**: Transmits one Ethernet frame from right endpoint b back to left\n  endpoint a while keeping initiator/responder columns visually aligned.\n- **Token**: `{`\n  - **Scopes**: host, flow, compile, repeat\n  - **Syntax**: `host a { ... } · flow f(x, y) { ... } · repeat 3 { ... } ·\n  compile { ... }`\n  - **Value / Range**: Opening block brace\n  - **Default**: Required block opener\n  - **Summary**: Opens a host attribute block, parameterized flow body, repeat\n  loop block, or top-level compile block.\n- **Token**: `}`\n  - **Scopes**: host, flow, compile, repeat\n  - **Syntax**: `host a { ... } · flow f(x, y) { ... } · repeat 3 { ... } ·\n  compile { ... }`\n  - **Value / Range**: Closing block brace\n  - **Default**: Required block closer\n  - **Summary**: Closes a host attribute block, parameterized flow body, repeat\n  loop block, or top-level compile block.\n\n### Timing, Metadata & Universal Payload (4 tokens)\n\nPost-packet nanosecond capture clock gaps (`wait` + `ns`, `us`, `ms`, `s`, `m`),\nPCAPNG `comment`, and raw `payload` / `hexpayload` overrides.\n\n- **Token**: `comment`\n  - **Scopes**: all frames\n  - **Syntax**: `comment \"<str>\"`\n  - **Value / Range**: PCAPNG Enhanced Packet Block opt_comment string\n  - **Default**: Omitted unless specified\n  - **Summary**: Attaches a per-packet Wireshark annotation (EPB option code 1\n  opt_comment) when compiling to .pcapng containers.\n- **Token**: `hexpayload`\n  - **Scopes**: all frames\n  - **Syntax**: `hexpayload \"<even_hex_octets>\"`\n  - **Value / Range**: Hex string (\"deadbeef\", \"de:ad:be:ef\", or \"de ad be ef\")\n  - **Default**: Omitted (mutually exclusive with payload)\n  - **Summary**: Attaches or overrides exact binary payload octets (also emitted\n  by frameassembly reverse when preserving opaque or encrypted bytes lossless).\n- **Token**: `payload`\n  - **Scopes**: all frames\n  - **Syntax**: `payload \"<utf8_str>\"`\n  - **Value / Range**: Double-quoted UTF-8 string (escapes \\r, \\n, \\t, \\xNN)\n  - **Default**: Omitted (mutually exclusive with hexpayload)\n  - **Summary**: Attaches or overrides raw UTF-8 payload bytes and automatically\n  recomputes IP/UDP/TCP/SCTP lengths, checksums, and sequence progression.\n- **Token**: `wait`\n  - **Scopes**: all frames\n  - **Syntax**: `wait <u32><ns|us|ms|s|m>`\n  - **Value / Range**: Inline post-packet delay\n  - **Default**: wait 10ms (10,000,000 ns) when omitted; Frame 1 = 0ns\n  - **Summary**: Emits the current frame at the active capture clock timestamp,\n  then advances the clock before the next frame (`wait 0ns` emits zero-gap\n  bursts).\n\n### Cross-Layer L2 (MAC, VLAN, QinQ, MPLS, FCS) (13 tokens)\n\nEthernet II MAC/EtherType overrides, IEEE 802.1Q VLAN tags, 802.1ad QinQ double\ntags, repeatable MPLS label stacks, and `fcs` / `badfcs` trailers.\n\n- **Token**: `badfcs`\n  - **Scopes**: all frames\n  - **Syntax**: `badfcs`\n  - **Value / Range**: Corrupted 4-byte IEEE 802.3 CRC-32 trailer\n  - **Default**: Omitted unless specified\n  - **Summary**: Appends an intentionally XOR-corrupted 4-byte Ethernet CRC-32 FCS\n  trailer for negative NIC/tap/dissector testing.\n- **Token**: `bos`\n  - **Scopes**: all frames (with mpls), mpls\n  - **Syntax**: `mpls <label> bos <0|1>`\n  - **Value / Range**: 1-bit Bottom-of-Stack flag (0..1)\n  - **Default**: Auto 0 on outer labels, 1 on innermost label\n  - **Summary**: Sets or overrides the Bottom-of-Stack bit (`S`) inside a 32-bit\n  MPLS shim header.\n- **Token**: `dei`\n  - **Scopes**: all frames (with vlan/qinq), vlan, qinq\n  - **Syntax**: `vlan <vid> dei <0|1>`\n  - **Value / Range**: 1-bit Drop Eligible Indicator (0..1)\n  - **Default**: 0\n  - **Summary**: Sets the 1-bit Drop Eligible Indicator bit inside an 802.1Q VLAN\n  or 802.1ad QinQ TCI header.\n- **Token**: `dstmac`\n  - **Scopes**: all frames\n  - **Syntax**: `dstmac <mac>`\n  - **Value / Range**: 48-bit MAC (colon, hyphen, or Cisco dot)\n  - **Default**: Peer MAC, RFC 1112/2464 multicast MAC, or IEEE L2 group MAC\n  - **Summary**: Overrides the 14-byte Ethernet II destination MAC address for a\n  single frame.\n- **Token**: `ethertype`\n  - **Scopes**: all frames, vlan, qinq\n  - **Syntax**: `ethertype <0..65535>`\n  - **Value / Range**: 16-bit unsigned int (decimal or hex e.g. 0x0800, 0x86dd,\n  0x88cc)\n  - **Default**: Auto-selected by protocol / IP family\n  - **Summary**: Overrides the outer or inner Ethernet II EtherType field\n  (`0..=65535`).\n- **Token**: `exp`\n  - **Scopes**: all frames (with mpls), mpls\n  - **Syntax**: `mpls <label> exp <0..7>`\n  - **Value / Range**: 3-bit MPLS Traffic Class / Experimental bits (0..7)\n  - **Default**: 0 (alias: tc)\n  - **Summary**: Sets the 3-bit Traffic Class (`EXP` / `TC`) field in the 32-bit\n  MPLS shim header (`tc` is an exact alias).\n- **Token**: `fcs`\n  - **Scopes**: all frames\n  - **Syntax**: `fcs`\n  - **Value / Range**: IEEE 802.3 4-byte CRC-32 Frame Check Sequence trailer\n  - **Default**: Omitted unless specified\n  - **Summary**: Computes and appends a valid 4-byte IEEE 802.3 Ethernet CRC-32\n  FCS trailer at the end of the frame.\n- **Token**: `innervlan`\n  - **Scopes**: all frames (with qinq), qinq\n  - **Syntax**: `qinq <outer_svid 0..4095> innervlan <inner_cvid 0..4095>`\n  - **Value / Range**: 12-bit inner C-Tag VLAN ID (0..4095)\n  - **Default**: 1 (when qinq is present)\n  - **Summary**: Sets the inner IEEE 802.1Q C-VLAN (`0x8100`) carried inside an\n  outer IEEE 802.1ad S-VLAN (`0x88a8`).\n- **Token**: `label`\n  - **Scopes**: mpls, rsvp, ldp\n  - **Syntax**: `mpls label <0..1048575> · mpls <0..1048575>`\n  - **Value / Range**: 20-bit MPLS label value (0..1048575)\n  - **Default**: 16\n  - **Summary**: Explicit keyword form for setting the 20-bit MPLS shim label\n  (also sets signaled labels on `rsvp` and `ldp`).\n- **Token**: `mplsttl`\n  - **Scopes**: all frames (with mpls), mpls\n  - **Syntax**: `mpls <label> mplsttl <0..255>`\n  - **Value / Range**: 8-bit MPLS Time-To-Live (0..255)\n  - **Default**: 64\n  - **Summary**: Sets the 8-bit MPLS shim TTL independently of the inner IPv4/IPv6\n  `ttl` modifier.\n- **Token**: `pcp`\n  - **Scopes**: all frames (with vlan/qinq), vlan, qinq\n  - **Syntax**: `vlan <vid> pcp <0..7>`\n  - **Value / Range**: 3-bit IEEE 802.1p Priority Code Point (0..7)\n  - **Default**: 0 (Best Effort)\n  - **Summary**: Sets the 3-bit IEEE 802.1p Class of Service priority inside an\n  802.1Q VLAN or 802.1ad QinQ tag.\n- **Token**: `srcmac`\n  - **Scopes**: all frames\n  - **Syntax**: `srcmac <mac>`\n  - **Value / Range**: 48-bit MAC (colon, hyphen, or Cisco dot)\n  - **Default**: Source host MAC (or 00:00:00:00:00:0N)\n  - **Summary**: Overrides the 14-byte Ethernet II source MAC address for a single\n  frame (e.g. MAC spoofing or VRRP/GLBP virtual MACs).\n- **Token**: `tc`\n  - **Scopes**: all frames (with mpls), mpls\n  - **Syntax**: `mpls <label> tc <0..7>`\n  - **Value / Range**: 3-bit MPLS Traffic Class bits (0..7)\n  - **Default**: 0 (alias: exp)\n  - **Summary**: RFC 5462 alias for `exp <0..7>` on standalone or repeatable\n  cross-layer `mpls` shim headers.\n\n### Cross-Layer L3 (IPv4, IPv6, QoS, Frag, Faults) (10 tokens)\n\nUnified TTL/Hop Limit, DiffServ DSCP & ECN markings, IPv6 flow labels, IPv4\nfragmentation, `routeralert`, and `badipchecksum` fault injection.\n\n- **Token**: `badipchecksum`\n  - **Scopes**: IPv4 L3/L4/L7 frames\n  - **Syntax**: `badipchecksum`\n  - **Value / Range**: Corrupted 16-bit IPv4 header checksum flag\n  - **Default**: Valid RFC 791 checksum\n  - **Summary**: XOR-corrupts the 16-bit IPv4 header checksum after assembly to\n  verify firewall, NIC offload, and router drop counters.\n- **Token**: `df`\n  - **Scopes**: IPv4 L3/L4/L7 frames\n  - **Syntax**: `df`\n  - **Value / Range**: Boolean IPv4 Don't Fragment flag\n  - **Default**: Unset\n  - **Summary**: Sets the IPv4 Don't Fragment (`DF`) flag bit for Path MTU\n  Discovery probes.\n- **Token**: `dscp`\n  - **Scopes**: all L3/L4/L7 frames\n  - **Syntax**: `dscp <0..63>`\n  - **Value / Range**: 6-bit DiffServ Code Point (0..63, e.g. 46 = EF)\n  - **Default**: 0 (CS0)\n  - **Summary**: Sets the upper 6 bits of the IPv4 TOS byte or IPv6 Traffic Class\n  field for QoS policy testing.\n- **Token**: `ecn`\n  - **Scopes**: all L3/L4/L7 frames\n  - **Syntax**: `ecn <0..3>`\n  - **Value / Range**: 2-bit Explicit Congestion Notification (0..3)\n  - **Default**: 0 (Non-ECT)\n  - **Summary**: Sets the lower 2 ECN bits (`0`=Not-ECT, `1`=ECT(1), `2`=ECT(0),\n  `3`=CE) in IPv4 TOS or IPv6 Traffic Class.\n- **Token**: `flowlabel`\n  - **Scopes**: IPv6 L3/L4/L7 frames\n  - **Syntax**: `flowlabel <0..1048575>`\n  - **Value / Range**: 20-bit IPv6 Flow Label (0..1048575 / 0x0..0xfffff)\n  - **Default**: 0 (IPv6 hosts only; rejected on IPv4)\n  - **Summary**: Sets the 20-bit IPv6 Flow Label (`0..=0xfffff`) for ECMP hashing\n  tests on IPv6 frames.\n- **Token**: `fragoffset`\n  - **Scopes**: IPv4 L3/L4/L7 frames\n  - **Syntax**: `fragoffset <0..8191>`\n  - **Value / Range**: 13-bit IPv4 fragment offset in 8-byte blocks (0..8191)\n  - **Default**: 0\n  - **Summary**: Sets the 13-bit IPv4 fragment offset (in 8-octet units) for\n  fragmentation and IDS reassembly tests.\n- **Token**: `ipid`\n  - **Scopes**: IPv4 L3/L4/L7 frames\n  - **Syntax**: `ipid <0..65535>`\n  - **Value / Range**: 16-bit IPv4 Identification (0..65535)\n  - **Default**: 0 (IPv4 hosts only; rejected on IPv6)\n  - **Summary**: Overrides the 16-bit IPv4 Identification field for fragment\n  reassembly and OS fingerprint testing.\n- **Token**: `mf`\n  - **Scopes**: IPv4 L3/L4/L7 frames\n  - **Syntax**: `mf`\n  - **Value / Range**: Boolean IPv4 More Fragments flag\n  - **Default**: Unset\n  - **Summary**: Sets the IPv4 More Fragments (`MF`) flag bit on non-terminal IPv4\n  fragments.\n- **Token**: `routeralert`\n  - **Scopes**: IPv4 L3/L4/L7 frames\n  - **Syntax**: `routeralert`\n  - **Value / Range**: RFC 2113 IPv4 Router Alert option (0x94 0x04 0x00 0x00)\n  - **Default**: Auto on IGMPv2/v3 & RSVP; omitted otherwise\n  - **Summary**: Injects the 4-byte RFC 2113 IPv4 Router Alert option into the\n  outer IPv4 header (IHL = 6) and recomputes the IPv4 checksum.\n- **Token**: `ttl`\n  - **Scopes**: all L3/L4/L7 frames, lldp (0..65535), cdp (0..255), nsh (0..63)\n  - **Syntax**: `ttl <0..255> (L3/cdp) · lldp ttl <0..65535> · nsh ttl <0..63>`\n  - **Value / Range**: u8 IPv4 TTL / IPv6 Hop Limit (0..255); u16 on lldp; 6-bit\n  on nsh\n  - **Default**: 64 (255 on ndp/vrrp/bfd; 1 on ospf/igmp/mld/glbp/llmnr; 120 on\n  lldp)\n  - **Summary**: Unified hop-count modifier setting IPv4 TTL or IPv6 Hop Limit on\n  L3+ frames (and protocol TTL fields on `lldp`, `cdp`, and `nsh`).\n\n### Cross-Layer L4 (Ports, Transport, TCP, Checksums) (26 tokens)\n\nPort overrides (`srcport`, `dstport`), `transport tcp|udp|sctp`, stateful TCP\n`seq`/`acknum`, flags, SACK/MD5/TFO options, and `badchecksum` / `nochecksum`.\n\n- **Token**: `ack`\n  - **Scopes**: tcp, TCP L7, dhcp, tftp, sip, coap\n  - **Syntax**: `tcp syn ack · dhcp ack · tftp ack · sip ack · coap ack`\n  - **Value / Range**: TCP ACK bit (0x10) or L7 message kind\n  - **Default**: Auto psh ack on TCP L7 frames\n  - **Summary**: Sets the TCP ACK control flag on TCP frames, or selects the\n  protocol acknowledgment message when placed immediately after `dhcp`, `tftp`,\n  `sip`, or `coap`.\n- **Token**: `acknum`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `acknum <0..4294967295>`\n  - **Value / Range**: 32-bit unsigned TCP acknowledgment number\n  - **Default**: Peer expected next seq (0 on initial SYN)\n  - **Summary**: Overrides the 32-bit TCP acknowledgment header number (`ack`\n  alone sets the 1-bit ACK flag).\n- **Token**: `badchecksum`\n  - **Scopes**: tcp, udp, sctp, icmp, all L7 frames\n  - **Syntax**: `badchecksum`\n  - **Value / Range**: Corrupted L4 checksum flag (TCP/UDP/ICMP/ICMPv6/SCTP)\n  - **Default**: Valid RFC checksum / Castagnoli CRC-32c\n  - **Summary**: XOR-corrupts the TCP, UDP, ICMP/ICMPv6, or SCTP CRC-32c transport\n  checksum for negative firewall/IDS verification.\n- **Token**: `cwr`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `cwr`\n  - **Value / Range**: TCP Congestion Window Reduced bit (0x80, RFC 3168)\n  - **Default**: Unset\n  - **Summary**: Sets the TCP Congestion Window Reduced (`CWR`) flag bit.\n- **Token**: `dstport`\n  - **Scopes**: tcp, udp, sctp, all L7 TCP/UDP/SCTP protocols\n  - **Syntax**: `dstport <0..65535>`\n  - **Value / Range**: 16-bit transport destination port (0..65535)\n  - **Default**: Protocol standard port (remembered & swapped onto srcport on <-\n  replies)\n  - **Summary**: Overrides the TCP, UDP, or SCTP destination port (e.g. running\n  HTTP over 8080 or Diameter over custom ports).\n- **Token**: `ece`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `ece`\n  - **Value / Range**: TCP ECN-Echo control bit (0x40, RFC 3168)\n  - **Default**: Unset\n  - **Summary**: Sets the TCP ECN-Echo (`ECE`) flag bit for RFC 3168 Explicit\n  Congestion Notification negotiation and signaling.\n- **Token**: `fin`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `fin`\n  - **Value / Range**: TCP Finish control bit (0x01)\n  - **Default**: Advances sender next seq by +1\n  - **Summary**: Sets the TCP FIN connection-close flag bit (use `finbit` for the\n  WebSocket frame FIN bit).\n- **Token**: `mss`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `mss <0..65535>`\n  - **Value / Range**: TCP Option Kind 2 Maximum Segment Size (u16)\n  - **Default**: Omitted unless specified (e.g. mss 1460 or mss 1360)\n  - **Summary**: Appends the 4-byte TCP Maximum Segment Size option (`Kind=2,\n  Len=4`) and pads the TCP header to a 32-bit boundary.\n- **Token**: `nochecksum`\n  - **Scopes**: udp, UDP-encapsulated protocols\n  - **Syntax**: `nochecksum`\n  - **Value / Range**: Zero UDP checksum flag (0x0000)\n  - **Default**: Computed RFC 768 checksum\n  - **Summary**: Writes 0x0000 into the 16-bit UDP checksum field (valid on UDP\n  and UDP-encapsulated tunnel/L7 frames; rejected on non-UDP transports).\n- **Token**: `psh`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `psh`\n  - **Value / Range**: TCP Push control bit (0x08)\n  - **Default**: Emitted automatically (`psh ack`) on TCP payload & L7 frames\n  - **Summary**: Sets the TCP PSH flag bit.\n- **Token**: `rst`\n  - **Scopes**: tcp, TCP L7, coap\n  - **Syntax**: `tcp rst ack · coap rst`\n  - **Value / Range**: TCP Reset bit (0x04) or CoAP Reset type (3)\n  - **Default**: Unset\n  - **Summary**: Sets the TCP RST connection-abort flag bit on TCP frames, or\n  selects a CoAP Reset (`T=3`) message after `coap`.\n- **Token**: `sackblock`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `sackblock <left_u32> <right_u32>`\n  - **Value / Range**: Repeatable TCP Option Kind 5 SACK edge pair (RFC 2018)\n  - **Default**: Omitted unless specified\n  - **Summary**: Appends one or more 8-byte RFC 2018 Selective Acknowledgment\n  left/right 32-bit sequence edge blocks inside TCP Option Kind 5.\n- **Token**: `sackperm`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `sackperm`\n  - **Value / Range**: TCP Option Kind 4 SACK Permitted (RFC 2018)\n  - **Default**: Omitted unless specified\n  - **Summary**: Appends the 2-byte RFC 2018 TCP Selective Acknowledgment\n  Permitted option (`Kind=4, Len=2`).\n- **Token**: `seq`\n  - **Scopes**: tcp, TCP L7, icmp, esp, ipsec, ah (+3 more)\n  - **Syntax**: `seq <u32> (TCP/ESP/AH/sFlow) · icmp/rtp seq <u16> · tacacs seq\n  <u8>`\n  - **Value / Range**: u32 TCP sequence override (or protocol seq field)\n  - **Default**: 1000 initial TCP seq, auto +1 on syn/fin & +len on payload\n  - **Summary**: Overrides the 32-bit TCP sequence number and re-anchors the\n  4-tuple state machine (or sets protocol sequence fields on `icmp`,\n  `esp`/`ipsec`, `ah`, `rtp`, `tacacs`, and `sflow`).\n- **Token**: `srcport`\n  - **Scopes**: tcp, udp, sctp, all L7 TCP/UDP/SCTP protocols\n  - **Syntax**: `srcport <0..65535>`\n  - **Value / Range**: 16-bit transport source port (0..65535)\n  - **Default**: 49152 (remembered & swapped onto dstport on <- replies)\n  - **Summary**: Overrides the TCP, UDP, or SCTP source port and anchors\n  bidirectional port memory for the host pair.\n- **Token**: `syn`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `syn`\n  - **Value / Range**: TCP Synchronize control bit (0x02)\n  - **Default**: Advances sender next seq by +1\n  - **Summary**: Sets the TCP SYN flag bit (rejected on UDP/SCTP/L2/L3 non-TCP\n  frames and if repeated twice on one line).\n- **Token**: `tcpmd5`\n  - **Scopes**: tcp, bgp, ldp, all TCP L7 protocols\n  - **Syntax**: `tcpmd5 \"<16_byte_hex>\"`\n  - **Value / Range**: TCP Option Kind 19 MD5 Signature (16-byte hex digest, RFC\n  2385)\n  - **Default**: Omitted unless specified\n  - **Summary**: Appends the 18-byte RFC 2385 TCP-MD5 Signature option carrying a\n  16-byte hex digest for authenticated BGP/LDP peering captures.\n- **Token**: `tfo`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `tfo \"<even_hex_cookie>\"`\n  - **Value / Range**: TCP Option Kind 34 Fast Open Cookie (RFC 7413)\n  - **Default**: Omitted unless specified\n  - **Summary**: Appends the RFC 7413 TCP Fast Open option (empty string requests\n  a TFO cookie; 4..16 byte hex sends an active cookie).\n- **Token**: `transport`\n  - **Scopes**: ldp, dns, llmnr, sip, syslog, kerberos (+31 more)\n  - **Syntax**: `transport <tcp|udp|sctp>`\n  - **Value / Range**: L4 selector (`tcp`, `udp`, or `sctp`)\n  - **Default**: Protocol RFC default transport (auto-tracks TCP 4-tuple or SCTP\n  vtag/tsn)\n  - **Summary**: Switches L4 encapsulation across 35 TCP/UDP protocols, enables\n  universal `transport sctp` across all 94 Layer 7 protocols, and enables UDP mode\n  on `profinet`, `ethercat`, and `l2tp` v3.\n- **Token**: `tsecr`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `tsval <u32> tsecr <u32>`\n  - **Value / Range**: TCP Option Kind 8 Timestamp Echo Reply (u32, RFC 7323)\n  - **Default**: 0 when tsval is set alone\n  - **Summary**: Sets the `TSecr` echoed peer timestamp inside the 10-byte RFC\n  7323 TCP Timestamps option.\n- **Token**: `tsval`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `tsval <u32> [tsecr <u32>]`\n  - **Value / Range**: TCP Option Kind 8 Timestamp Value (u32, RFC 7323)\n  - **Default**: Omitted unless tsval or tsecr is set\n  - **Summary**: Appends the 10-byte RFC 7323 TCP Timestamps option (`Kind=8,\n  Len=10`) with the sender `TSval` clock value.\n- **Token**: `urg`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `urg urgent 1`\n  - **Value / Range**: TCP Urgent control bit (0x20)\n  - **Default**: Unset\n  - **Summary**: Sets the TCP URG control bit indicating the 16-bit `urgent`\n  pointer field is significant.\n- **Token**: `urgent`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `urgent <0..65535>`\n  - **Value / Range**: 16-bit TCP urgent pointer offset (0..65535)\n  - **Default**: 0\n  - **Summary**: Sets the 16-bit TCP Urgent Pointer field (pair with bare `urg`\n  flag for out-of-band/IDS evasion tests).\n- **Token**: `win`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `win <0..65535>`\n  - **Value / Range**: 16-bit TCP receive window (0..65535)\n  - **Default**: 65535 (alias: window)\n  - **Summary**: Sets the 16-bit TCP receive window size (`win 0` simulates a TCP\n  ZeroWindow stall; `window` is an exact alias).\n- **Token**: `window`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `window <0..65535>`\n  - **Value / Range**: 16-bit TCP receive window (0..65535)\n  - **Default**: 65535 (alias: win)\n  - **Summary**: Full-word alias for `win <0..65535>` on `tcp` and all TCP-based\n  Layer 7 frames.\n- **Token**: `wscale`\n  - **Scopes**: tcp, all TCP L7 protocols\n  - **Syntax**: `wscale <0..255>`\n  - **Value / Range**: TCP Option Kind 3 Window Scale shift count (u8, RFC 7323)\n  - **Default**: Omitted unless specified (e.g. wscale 7)\n  - **Summary**: Appends the 3-byte RFC 7323 TCP Window Scale option (`Kind=3,\n  Len=3`).\n\n### 146 Native Protocol Keywords (146 tokens)\n\nEvery Layer 2 through Layer 7 protocol builder keyword compiled natively by\nFrameAssembly v3.3.0 (18 L2 / 31 L3 / 3 L4 / 94 L7).\n\n- **Token**: `ah`\n  - **Scopes**: Layer 3 (IP Proto 51)\n  - **Syntax**: `ah [spi <number>] [seq <number>] [icv \"<hex>\"] [nextheader\n  <0..255>]`\n  - **Value / Range**: IPsec AH (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 51\n  - **Summary**: IPsec Authentication Header (RFC 4302)\n- **Token**: `amqp`\n  - **Scopes**: Layer 7 (TCP 5672)\n  - **Syntax**: `amqp [protocolheader | connectionstart | channelopen |\n  basicpublish | basicdeliver | heartbeat] [channel <0..65535>] [exchange\n  \"<text>\"] [routingkey \"<text>\"]`\n  - **Value / Range**: AMQP 0-9-1 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 5672\n  - **Summary**: Advanced Message Queuing Protocol (RabbitMQ) (AMQP 0-9-1)\n- **Token**: `arp`\n  - **Scopes**: Layer 2 (EtherType 0x0806), MAC-only or IP hosts\n  - **Syntax**: `arp [request | reply | gratuitous | garp] [sendermac|sha <mac>]\n  [senderip|spa <ipv4>] [targetmac|tha <mac>] [targetip|tpa <ipv4>]`\n  - **Value / Range**: ARP / GARP (MAC-Only or IP)\n  - **Default**: EtherType 0x0806\n  - **Summary**: Address Resolution Protocol & Gratuitous ARP (RFC 826, RFC 5227)\n- **Token**: `bacnet`\n  - **Scopes**: Layer 7 (UDP 47808 (0xbac0))\n  - **Syntax**: `bacnet [whois | iam | readproperty | writeproperty] [invokeid\n  <0..255>] [objecttype <0..1023>] [objectinstance <number>] [propertyid <number>]\n  [value <number>]`\n  - **Value / Range**: BACnet/IP (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 47808 (0xbac0)\n  - **Summary**: BACnet/IP Building Automation & Control Networks (ASHRAE 135, ISO\n  16484-5)\n- **Token**: `bfd`\n  - **Scopes**: Layer 3 (UDP 3784 (Multihop 4784, TTL 255))\n  - **Syntax**: `bfd [state <0..3>] [diag <0..31>] [mydisc <number>] [yourdisc\n  <number>] [mintx <number>] [minrx <number>] [mult <0..255>]`\n  - **Value / Range**: BFD (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 3784 (Multihop 4784, TTL 255)\n  - **Summary**: Bidirectional Forwarding Detection Control Packet (RFC 5880, RFC\n  5881, RFC 5883)\n- **Token**: `bgp`\n  - **Scopes**: Layer 3 (TCP 179)\n  - **Syntax**: `bgp [open | update | notification | keepalive] [asn <number>]\n  [holdtime <0..65535>] [bgpid <ipv4>] [prefix|nlri <str|ip>] [nexthop <ip>]`\n  - **Value / Range**: BGP-4 / 4-Byte ASN (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 179\n  - **Summary**: Border Gateway Protocol 4 & 4-Byte ASN Capability (RFC 4271, RFC\n  6793)\n- **Token**: `bmp`\n  - **Scopes**: Layer 3 (TCP 1790)\n  - **Syntax**: `bmp [routemon | statsreport | peerdown | peerup | initiation |\n  termination] [version <0..255>] [peertype <0..255>] [flags <0..255>] [peerip\n  <ip>] [asn <number>] [bgpid <ipv4>] [sysname \"<text>\"] [sysdesc \"<text>\"]\n  [reason <0..65535>]`\n  - **Value / Range**: BMP v3 (RFC 7854) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 1790\n  - **Summary**: BGP Monitoring Protocol v3 (RFC 7854, RFC 8671, RFC 9069)\n- **Token**: `bsap`\n  - **Scopes**: Layer 7 (UDP 1234 (or TCP 1234 via transport tcp))\n  - **Syntax**: `bsap [read | write | poll | func \"<text_or_num>\"] [dst\n  <0..65535>] [src <0..65535>] [seqnum <0..255>] [addr <0..65535>] [count\n  <0..65535>] [value <number>] [isresponse] [transport <udp|tcp>]`\n  - **Value / Range**: Bristol Babcock BSAP (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 1234 (or TCP 1234 via transport tcp)\n  - **Summary**: Emerson / Bristol Babcock Synchronous Asynchronous Protocol\n  (BSAP/IP) (Emerson OpenBSI / Bristol Babcock ControlWave BSAP IP Specification)\n- **Token**: `c1222`\n  - **Scopes**: Layer 7 (UDP 1153 (or TCP 1153 via transport tcp))\n  - **Syntax**: `c1222 [read | write | identify | logon | logoff | terminate |\n  response | ok | service \"<text_or_num>\"] [callingap <oid>] [calledap <oid>]\n  [callingid <number>] [calledid <number>] [epsemctrl <0..255>] [edclass <number>]\n  [tableid <0..65535>] [value <0..65535>] [errcode <0..255>] [transport\n  <udp|tcp>]`\n  - **Value / Range**: ANSI C12.22 (AMI Smart Grid) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 1153 (or TCP 1153 via transport tcp)\n  - **Summary**: ANSI C12.22 / IEEE 1703 Smart-Meter Utility AMI Application\n  Protocol (ANSI C12.22-2012, IEEE 1703, ANSI C12.19 (Tables))\n- **Token**: `cdp`\n  - **Scopes**: Layer 2 (802.3 SNAP 0x2000), MAC-only or IP hosts\n  - **Syntax**: `cdp [version <0..255>] [ttl <0..255>] [deviceid \"<text>\"] [addr\n  <ip>] [portid \"<text>\"] [capabilities <number>] [swversion \"<text>\"] [platform\n  \"<text>\"] [nativevlan <0..65535>]`\n  - **Value / Range**: Cisco CDP v2 (MAC-Only or IP)\n  - **Default**: 802.3 SNAP 0x2000\n  - **Summary**: Cisco Discovery Protocol v2 (IEEE 802.3 LLC/SNAP) (Cisco CDP v2,\n  IEEE 802.2 LLC/SNAP)\n- **Token**: `coap`\n  - **Scopes**: Layer 7 (UDP 5683 (or RFC 8323 transport tcp))\n  - **Syntax**: `coap [con | non | ack | rst | msgtype \"<text>\"] [get | post | put\n  | delete | created | changed | notfound | code \"<c.dd>\"] [msgid <0..65535>]\n  [token <hex_or_num>] [uripath \"<text>\"] [contentformat <0..65535>]`\n  - **Value / Range**: CoAP (IoT) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 5683 (or RFC 8323 transport tcp)\n  - **Summary**: Constrained Application Protocol (RFC 7252)\n- **Token**: `dcerpc`\n  - **Scopes**: L7 (TCP (135))\n  - **Syntax**: `<a> -> <b> dcerpc [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (135)\n  - **Summary**: Distributed Computing Environment / Remote Procedure Calls\n  (MS-RPCE) — Connection-oriented DCE/RPC v5 endpoint mapper and Windows RPC\n  framing on TCP 135 (Bind, Bind_ack, Request, Response, Fault) with Interface\n  UUID and Opnum.\n- **Token**: `dhcp`\n  - **Scopes**: Layer 7 (UDP 68/67 (DHCPv4) · UDP 546/547 (DHCPv6))\n  - **Syntax**: `dhcp [discover | offer | request | ack | release | solicit |\n  advertise | reply] [xid <number>] [ciaddr <ipv4>] [yiaddr <ipv4>] [siaddr\n  <ipv4>] [chaddr <mac>] [subnetmask <ipv4>] [router <ipv4>] [dnsserver <ip>]\n  [leasetime <number>] [hostname \"<text>\"]`\n  - **Value / Range**: DHCPv4 / DHCPv6 (Dual-Stack Morphing (v4/v6))\n  - **Default**: UDP 68/67 (DHCPv4) · UDP 546/547 (DHCPv6)\n  - **Summary**: Dynamic Host Configuration Protocol — DHCPv4 & DHCPv6 (RFC 2131,\n  RFC 2132, RFC 8415)\n- **Token**: `diameter`\n  - **Scopes**: Layer 7 (TCP 3868 (or SCTP 3868 / PPID 46 via transport sctp))\n  - **Syntax**: `diameter [cer | cea | dwr | dwa | ccr | cca] [request | response]\n  [cmd|command \"<text_or_num>\"] [flags <0..255>] [appid <number>] [hopid <number>]\n  [endid <number>] [originhost \"<text>\"] [realm \"<text>\"] [dsthost \"<text>\"]\n  [dstrealm \"<text>\"] [sessionid \"<text>\"] [resultcode <number>] [user \"<text>\"]\n  [transport sctp]`\n  - **Value / Range**: Diameter (RFC 6733) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 3868 (or SCTP 3868 / PPID 46 via transport sctp)\n  - **Summary**: Diameter Base, Credit-Control & 3GPP S6a/Gx/Gy AAA Signaling (RFC\n  6733, RFC 8506, 3GPP TS 29.272)\n- **Token**: `dnp3`\n  - **Scopes**: Layer 7 (TCP 20000 (or UDP 20000 via transport udp))\n  - **Syntax**: `dnp3 [read | write | select | operate | directoperate | confirm |\n  response | unsolicitedresponse | func \"<text>\"] [src <0..65535>] [dst\n  <0..65535>] [group <0..255>] [variation <0..255>] [crc <hex_or_num>] [transport\n  <tcp|udp>]`\n  - **Value / Range**: DNP3 (IEEE 1815) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 20000 (or UDP 20000 via transport udp)\n  - **Summary**: Distributed Network Protocol 3 (Electric & Water Utilities) (IEEE\n  1815-2012)\n- **Token**: `dns`\n  - **Scopes**: Layer 7 (UDP 53 (or TCP 53 via transport tcp))\n  - **Syntax**: `dns [query | response] [txid <0..65535>] [qname \"<text>\"] [qtype\n  \"<text>\"] [rdata \"<text>\"] [rcode <0..15>] [ansttl <number>] [transport\n  <udp|tcp>]`\n  - **Value / Range**: DNS (UDP/TCP) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 53 (or TCP 53 via transport tcp)\n  - **Summary**: Domain Name System over UDP or TCP (RFC 1035, RFC 3596, RFC 2782)\n- **Token**: `doh`\n  - **Scopes**: L7 (TCP (80))\n  - **Syntax**: `<a> -> <b> doh [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (80)\n  - **Summary**: DNS over HTTPS — DoH Wireformat Framing (RFC 8484) — RFC 8484\n  application/dns-message HTTP GET/POST queries and responses embedding wire-valid\n  DNS payloads with EDNS0 and DNSSEC DO bit support.\n- **Token**: `doip`\n  - **Scopes**: Layer 7 (TCP 13400 (or UDP 13400 via transport udp))\n  - **Syntax**: `doip [routingreq | routingresp | diagnostic | diagack | diagnack\n  | vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"] [version <0..255>] [invversion\n  <0..255>] [src <0..65535>] [dst <0..65535>] [code <0..255>] [vin \"<text>\"] [eid\n  <mac_or_hex>] [gid <mac_or_hex>] [transport <tcp|udp>]`\n  - **Value / Range**: DoIP (ISO 13400-2) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 13400 (or UDP 13400 via transport udp)\n  - **Summary**: Diagnostics over Internet Protocol (Automotive UDS Transport)\n  (ISO 13400-2:2019, ISO 14229-1 (UDS))\n- **Token**: `eapol`\n  - **Scopes**: Layer 2 (EtherType 0x888e -> 01:80:c2:00:00:03), MAC-only or IP\n  hosts\n  - **Syntax**: `eapol [version <0..255>] [type <eappacket|start|logoff|key> |\n  eappacket | start | logoff | key] [eapcode <0..255>] [eapid <0..255>] [eapmethod\n  <0..255>] [identity \"<text>\"]`\n  - **Value / Range**: 802.1X EAPOL (MAC-Only or IP)\n  - **Default**: EtherType 0x888e -> 01:80:c2:00:00:03\n  - **Summary**: IEEE 802.1X Port-Based Network Access Control (EAP over LAN)\n  (IEEE 802.1X, RFC 3748)\n- **Token**: `erspan`\n  - **Scopes**: Layer 3 (IP Proto 47 (GRE 0x88be v2 / 0x22eb v3))\n  - **Syntax**: `erspan [v2 | v3 | version <2|3>] [sessionid <0..1023>] [vid\n  <0..4095>] [cos <0..7>] [greseq <number>] [index <number>] [timestamp <number>]\n  [direction <0|1>]`\n  - **Value / Range**: ERSPAN II & III (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 47 (GRE 0x88be v2 / 0x22eb v3)\n  - **Summary**: Cisco Encapsulated Remote SPAN Port Mirroring (Type II & Type\n  III) (IETF draft-foschiano-erspan, RFC 2784)\n- **Token**: `esp`\n  - **Scopes**: Layer 3 (IP Proto 50)\n  - **Syntax**: `esp [spi <number>] [seq <number>] [iv \"<hex>\"] [icv \"<hex>\"]\n  [nextheader <0..255>]`\n  - **Value / Range**: IPsec ESP (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 50\n  - **Summary**: IPsec Encapsulating Security Payload (RFC 4303)\n- **Token**: `ethercat`\n  - **Scopes**: Layer 2 (EtherType 0x88a4 (or UDP 34980)), MAC-only or IP hosts\n  - **Syntax**: `ethercat [nop | read | write | cmd \"<text>\"] [idx <0..255>]\n  [adp|addr <0..65535>] [ado|offset <0..65535>] [irq <0..65535>] [wkc <0..65535>]\n  [transport udp]`\n  - **Value / Range**: EtherCAT (MAC-Only or IP)\n  - **Default**: EtherType 0x88a4 (or UDP 34980)\n  - **Summary**: IEC 61158 EtherCAT Industrial Ethernet Fieldbus (0x88a4 / UDP\n  34980) (IEC 61158 Type 12, ETG.1000.4)\n- **Token**: `ethernetip`\n  - **Scopes**: Layer 7 (TCP 44818 (Explicit) / UDP 2222 (Implicit I/O))\n  - **Syntax**: `ethernetip [nop | listservices | listidentity | listinterfaces |\n  registersession | unregistersession | sendrrdata | sendunitdata | cmd \"<text>\"]\n  [sessionhandle <hex_or_num>] [status <number>] [context <hex_or_str>]\n  [cipservice <hex_or_num>] [cipclass <hex_or_num>] [cipinstance <number>]\n  [cipattr <number>] [transport <tcp|udp>]`\n  - **Value / Range**: EtherNet/IP (CIP) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 44818 (Explicit) / UDP 2222 (Implicit I/O)\n  - **Summary**: ODVA EtherNet/IP & Common Industrial Protocol (Rockwell) (ODVA\n  EtherNet/IP, CIP Vol. 1 & Vol. 2)\n- **Token**: `fins`\n  - **Scopes**: Layer 7 (UDP 9600 (or TCP 9600 via transport tcp))\n  - **Syntax**: `fins [read | write | cmd \"<text_or_num>\"] [response | isresponse]\n  [icf <0..255>] [dna <0..255>] [da1 <0..255>] [da2 <0..255>] [sna <0..255>] [sa1\n  <0..255>] [sa2 <0..255>] [sid <0..255>] [area \"<text_or_num>\"] [addr <0..65535>]\n  [count <0..65535>] [value <0..65535>] [errcode <0..65535>] [transport\n  <udp|tcp>]`\n  - **Value / Range**: Omron FINS (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 9600 (or TCP 9600 via transport tcp)\n  - **Summary**: Omron Factory Interface Network Service (NJ/NX/CJ/CS PLC\n  Protocol) (Omron W342 / W227 FINS Reference Manual)\n- **Token**: `ftp`\n  - **Scopes**: Layer 7 (TCP 21)\n  - **Syntax**: `ftp [cmd \"<text>\"] [arg \"<text>\"] [code <100..599>] [reply\n  \"<text>\"]`\n  - **Value / Range**: FTP (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 21\n  - **Summary**: File Transfer Protocol Control Channel (RFC 959, RFC 2428)\n- **Token**: `geneve`\n  - **Scopes**: Layer 3 (UDP 6081 (Proto 0x6558))\n  - **Syntax**: `geneve [vni|vnid <0..16777215>] [optclass <0..65535>] [opttype\n  <0..255>] [protocoltype <0..65535>]`\n  - **Value / Range**: GENEVE (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 6081 (Proto 0x6558)\n  - **Summary**: Generic Network Virtualization Encapsulation (RFC 8926)\n- **Token**: `gesrtp`\n  - **Scopes**: Layer 7 (TCP 18245)\n  - **Syntax**: `gesrtp [init | initack | request | response | read | write | type\n  \"<text>\"] [seqnum <0..65535>] [func \"<text_or_num>\"] [area \"<text_or_num>\"]\n  [addr <0..65535>] [count <0..65535>] [value <number>] [status <0..65535>]`\n  - **Value / Range**: GE SRTP (Emerson PACSystems) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 18245\n  - **Summary**: General Electric / Emerson Service Request Transport Protocol (GE\n  Fanuc / Emerson PACSystems TCP/IP Ethernet Manual (GFK-1541))\n- **Token**: `glbp`\n  - **Scopes**: Layer 3 (UDP 3222 (Multicast 224.0.0.102, TTL 1))\n  - **Syntax**: `glbp [hello | request | response] [version <0..255>] [group\n  <0..1023>] [ownerid <mac>] [state <0..255>] [priority <0..255>] [weight\n  <0..255>] [forwarder <0..255>] [hellotime <number>] [holdtime <number>]\n  [redirect <0..65535>] [timeout <0..65535>] [vip <ip>] [vmac <mac>] [auth\n  \"<text>\"]`\n  - **Value / Range**: Cisco GLBP (3222) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 3222 (Multicast 224.0.0.102, TTL 1)\n  - **Summary**: Cisco Gateway Load Balancing Protocol (Cisco GLBP Specification)\n- **Token**: `goose`\n  - **Scopes**: Layer 2 (EtherType 0x88b8), MAC-only or IP hosts\n  - **Syntax**: `goose [appid <0..65535>] [gocbref \"<text>\"] [timetolive <number>]\n  [datset \"<text>\"] [goid \"<text>\"] [stnum <number>] [sqnum <number>] [simulation]\n  [confrev <number>] [ndscom] [numdatsetentries <number>]`\n  - **Value / Range**: IEC 61850 GOOSE (MAC-Only or IP)\n  - **Default**: EtherType 0x88b8\n  - **Summary**: IEC 61850-8-1 Generic Object Oriented Substation Events (IEC\n  61850-8-1, IEEE 802.1Q)\n- **Token**: `gre`\n  - **Scopes**: Layer 3 (IP Proto 47)\n  - **Syntax**: `gre [grekey|key <number>] [greseq <number>] [greproto <0..65535>]\n  [checksum]`\n  - **Value / Range**: GRE / NVGRE (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 47\n  - **Summary**: Generic Routing Encapsulation (GRE, GRETAP & NVGRE) (RFC 2784,\n  RFC 2890, RFC 7637)\n- **Token**: `grpc`\n  - **Scopes**: Layer 7 (TCP 50051)\n  - **Syntax**: `grpc [service \"<text>\"] [method \"<text>\"] [grpcstatus <number>]`\n  - **Value / Range**: gRPC (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 50051\n  - **Summary**: gRPC Remote Procedure Calls over HTTP/2 (gRPC over HTTP/2, RFC\n  9113)\n- **Token**: `gtpc`\n  - **Scopes**: Layer 7 (UDP 2123)\n  - **Syntax**: `gtpc [echorequest | echoreply | echoresponse |\n  createsessionrequest | createsessionresponse | modifybearerrequest |\n  modifybearerresponse | deletesessionrequest | deletesessionresponse | msgtype\n  \"<text>\"] [teid <number>] [seqnum <0..16777215>] [cause <0..255>] [imsi\n  \"<text>\"] [apn \"<text>\"] [rat <0..255>] [recovery <0..255>] [addr <ip>]`\n  - **Value / Range**: GTPv2-C (3GPP TS 29.274) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 2123\n  - **Summary**: GPRS Tunneling Protocol v2 Control Plane (4G S11 / S5-C) (3GPP TS\n  29.274, RFC 768)\n- **Token**: `gtpu`\n  - **Scopes**: Layer 3 (UDP 2152)\n  - **Syntax**: `gtpu [gpdu | echorequest | echoreply | errorindication |\n  endmarker] [teid <number>] [flags <0..255>] [seqnum <0..65535>] [npdu <0..255>]\n  [qfi <0..63>]`\n  - **Value / Range**: GTPv1-U (UDP 2152) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 2152\n  - **Summary**: GPRS Tunneling Protocol User Plane (4G S1-U & 5G N3/N9) (3GPP TS\n  29.281, 3GPP TS 38.415)\n- **Token**: `h323`\n  - **Scopes**: L7 (TCP 1720 / UDP 1719 (1720 / 1719))\n  - **Syntax**: `<a> -> <b> h323 [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: ITU-T H.323 Multimedia Call Signaling (H.225.0 Q.931 & RAS) —\n  Enterprise voice/video H.225.0 Q.931 call setup over TPKT TCP 1720 (Setup,\n  Alerting, Connect, ReleaseComplete) and Gatekeeper RAS over UDP 1719 (GRQ/GCF,\n  RRQ/RCF).\n- **Token**: `hartip`\n  - **Scopes**: Layer 7 (UDP 5094 (or TCP 5094 via transport tcp))\n  - **Syntax**: `hartip [init | close | keepalive | msgid \"<text_or_num>\"]\n  [version <0..255>] [msgtype \"<text_or_num>\"] [isresponse | response] [status\n  <0..255>] [txid <0..65535>] [mode <0..255>] [holdtime <number>] [addr <0..255>]\n  [cmd <0..255>] [transport <udp|tcp>]`\n  - **Value / Range**: HART-IP (IEC 62591) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 5094 (or TCP 5094 via transport tcp)\n  - **Summary**: Highway Addressable Remote Transducer Over IP (Process Field\n  Instruments) (FieldComm Group HCF_SPEC-085, IEC 62591 (WirelessHART))\n- **Token**: `hsrp`\n  - **Scopes**: Layer 3 (UDP 1985 (v1) / UDP 2029 (v2))\n  - **Syntax**: `hsrp [group <0..255>] [priority <0..255>] [state <0..255>]\n  [hellotime <0..255>] [holdtime <0..255>] [auth \"<text>\"] [vip <ip>]`\n  - **Value / Range**: HSRPv1 / HSRPv2 (Dual-Stack Morphing (v4/v6))\n  - **Default**: UDP 1985 (v1) / UDP 2029 (v2)\n  - **Summary**: Cisco Hot Standby Router Protocol v1 & v2 (RFC 2281)\n- **Token**: `http`\n  - **Scopes**: Layer 7 (TCP 80)\n  - **Syntax**: `http [get | post | put | delete | head | options | patch | method\n  \"<text>\"] [uri \"<text>\"] [version \"<text>\"] [hosthdr \"<text>\"] [useragent\n  \"<text>\"] [contenttype \"<text>\"] [status <100..599>] [reason \"<text>\"] [header\n  \"<name>\" \"<value>\" ...] [body \"<text>\"]`\n  - **Value / Range**: HTTP/1.1 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 80\n  - **Summary**: Hypertext Transfer Protocol HTTP/1.1 (RFC 9110, RFC 9112)\n- **Token**: `http2`\n  - **Scopes**: Layer 7 (TCP 443)\n  - **Syntax**: `http2 [preface | settings | headers | data | windowupdate | ping\n  | goaway] [streamid <number>]`\n  - **Value / Range**: HTTP/2 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 443\n  - **Summary**: Hypertext Transfer Protocol Version 2 Binary Framing (RFC 9113)\n- **Token**: `icmp`\n  - **Scopes**: Layer 3 (IP Proto 1 (v4) / NextHdr 58 (v6))\n  - **Syntax**: `icmp [echorequest | echoreply | destunreach | timeexceeded |\n  redirect] [type <0..255>] [code <0..255>] [id <0..65535>] [seq <0..65535>]\n  [gateway <ipv4>]`\n  - **Value / Range**: ICMP / ICMPv6 (Dual-Stack Morphing (v4/v6))\n  - **Default**: IP Proto 1 (v4) / NextHdr 58 (v6)\n  - **Summary**: Internet Control Message Protocol v4 & Dual-Stack ICMPv6 (RFC\n  792, RFC 4443)\n- **Token**: `iec104`\n  - **Scopes**: Layer 7 (TCP 2404)\n  - **Syntax**: `iec104 [startdt | stopdt | testfr | sframe | msgtype \"<text>\"]\n  [confirm] [txseq <0..32767>] [rxseq <0..32767>] [typeid <0..255>] [cot\n  \"<text_or_num>\"] [ca <0..65535>] [ioa <0..16777215>] [value <number>] [real\n  <decimal>]`\n  - **Value / Range**: IEC 60870-5-104 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 2404\n  - **Summary**: IEC 60870-5-104 Substation Telecontrol Over TCP/IP (IEC\n  60870-5-104, IEC 60870-5-101)\n- **Token**: `igmp`\n  - **Scopes**: Layer 3 (IPv4 Proto 2 (TTL 1))\n  - **Syntax**: `igmp [query | report | leave] [v1 | v2 | v3 | version <1|2|3>]\n  [group <ipv4>] [maxresp <0..255>]`\n  - **Value / Range**: IGMPv1/v2/v3 (IPv4-Only)\n  - **Default**: IPv4 Proto 2 (TTL 1)\n  - **Summary**: Internet Group Management Protocol v1, v2 & v3 (RFC 1112, RFC\n  2236, RFC 3376)\n- **Token**: `ikev2`\n  - **Scopes**: Layer 3 (UDP 500 -> 500 (NAT-T 4500))\n  - **Syntax**: `ikev2 [exchange <sainit|auth|createchildsa|informational> |\n  sainit | auth | createchildsa | informational] [initiatorspi <u64|\"hex\">]\n  [responderspi <u64|\"hex\">] [msgid <number>] [flags <0..255>]\n  [nextpayload|nextheader <0..255>]`\n  - **Value / Range**: IKEv2 (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 500 -> 500 (NAT-T 4500)\n  - **Summary**: Internet Key Exchange Protocol Version 2 (RFC 7296, RFC 3948)\n- **Token**: `imap`\n  - **Scopes**: Layer 7 (TCP 143)\n  - **Syntax**: `imap [tag \"<text>\"] [cmd \"<text>\"] [arg \"<text>\"] [status\n  \"<text>\"] [response \"<text>\"]`\n  - **Value / Range**: IMAP4 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 143\n  - **Summary**: Internet Message Access Protocol IMAP4rev1 (RFC 3501, RFC 9051)\n- **Token**: `ipfix`\n  - **Scopes**: Layer 7 (UDP 4739)\n  - **Syntax**: `ipfix [domainid <number>] [srcip <ip>] [dstip <ip>] [srcport\n  <0..65535>] [dstport <0..65535>] [proto <0..255>] [packets <number>] [octets\n  <number>]`\n  - **Value / Range**: IPFIX (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 4739\n  - **Summary**: IP Flow Information Export (NetFlow v10) (RFC 7011, RFC 7012)\n- **Token**: `ipip`\n  - **Scopes**: Layer 3 (IP Proto 4 (IPv4) / 41 (IPv6))\n  - **Syntax**: `ipip [v4 | v6 | version <4|6>] [srcip <ip>] [dstip <ip>]\n  [innerttl <0..255>] [innerdscp <0..63>] [proto <0..255>]`\n  - **Value / Range**: IP-in-IP (RFC 2003 / 4213) (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 4 (IPv4) / 41 (IPv6)\n  - **Summary**: IP-in-IP & IPv6-in-IPv4 Tunneling (RFC 2003, RFC 4213, RFC 2473)\n- **Token**: `ipmi`\n  - **Scopes**: L7 (UDP (623))\n  - **Syntax**: `<a> -> <b> ipmi [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: UDP (623)\n  - **Summary**: Intelligent Platform Management Interface — RMCP / IPMI v2.0 —\n  Out-of-band BMC server management over RMCP UDP 623 supporting ASF Ping/Pong and\n  IPMI v1.5/v2.0 session commands (NetFn, Cmd, LUN, Session ID).\n- **Token**: `ipsec`\n  - **Scopes**: Layer 3 (IP Proto 50 (ESP))\n  - **Syntax**: `ipsec [spi <number>] [seq <number>] [iv \"<hex>\"] [icv \"<hex>\"]\n  [nextheader <0..255>]`\n  - **Value / Range**: IPsec (ESP Alias) (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 50 (ESP)\n  - **Summary**: IPsec Encapsulating Security Payload (Protocol Alias) (RFC 4303,\n  RFC 4301)\n- **Token**: `irc`\n  - **Scopes**: L7 (TCP (6667))\n  - **Syntax**: `<a> -> <b> irc [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (6667)\n  - **Summary**: Internet Relay Chat Text Protocol (RFC 1459 / RFC 2812) —\n  Line-oriented chat and command-and-control protocol on TCP 6667 supporting\n  prefix tags, NICK, JOIN, PRIVMSG, PING/PONG, and QUIT messages.\n- **Token**: `iscsi`\n  - **Scopes**: Layer 7 (TCP 3260)\n  - **Syntax**: `iscsi [login | logout | read | write | nop | response | data |\n  text | cmd \"<text>\"] [opcode <0..63>] [initiator \"<text>\"] [target \"<text>\"]\n  [lun <0..65535>] [itt <number>] [cmdsn <number>] [statsn <number>] [status\n  <0..255>] [flags <0..255>] [offset <number>]`\n  - **Value / Range**: iSCSI (RFC 7143) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 3260\n  - **Summary**: Internet Small Computer Systems Interface Block SAN (RFC 7143,\n  RFC 3720, SAM-5)\n- **Token**: `isis`\n  - **Scopes**: Layer 2 (802.3 LLC CLNS 0xfefe03), MAC-only or IP hosts\n  - **Syntax**: `isis [l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp |\n  l1psnp | l2psnp] [sysid \"<text>\"] [area \"<text>\"] [holdtime <0..65535>]\n  [priority <0..255>] [lanid \"<text>\"] [circuittype <0..255>] [lifetime\n  <0..65535>] [seqnum <number>] [hostname \"<text>\"]`\n  - **Value / Range**: IS-IS (MAC-Only or IP)\n  - **Default**: 802.3 LLC CLNS 0xfefe03\n  - **Summary**: Intermediate System to Intermediate System (ISO/IEC 10589)\n  (ISO/IEC 10589, RFC 1195, RFC 5301, RFC 5308)\n- **Token**: `kafka`\n  - **Scopes**: L7 (TCP / UDP (9092))\n  - **Syntax**: `<a> -> <b> kafka [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP / UDP (9092)\n  - **Summary**: Apache Kafka Binary Wire Protocol — Distributed event-streaming\n  broker protocol on port 9092 supporting ApiVersions, Metadata, Produce, Fetch,\n  and Heartbeat requests and correlated responses.\n- **Token**: `kerberos`\n  - **Scopes**: Layer 7 (UDP 88 (or TCP 88 via transport tcp))\n  - **Syntax**: `kerberos [asreq | asrep | tgsreq | tgsrep | krberror] [realm\n  \"<text>\"] [cname \"<text>\"] [sname \"<text>\"] [etype <number>] [transport\n  <udp|tcp>]`\n  - **Value / Range**: Kerberos v5 (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 88 (or TCP 88 via transport tcp)\n  - **Summary**: Kerberos Network Authentication Service v5 (Active Directory)\n  (RFC 4120, RFC 3962, RFC 4757)\n- **Token**: `knxnetip`\n  - **Scopes**: Layer 7 (UDP 3671)\n  - **Syntax**: `knxnetip [connect | connack | disconnect | service\n  \"<text_or_num>\"] [channel <0..255>] [seqnum <0..255>] [status <0..255>] [src\n  <0..65535>] [dst <0..65535>] [read | write] [value <number>]`\n  - **Value / Range**: KNXnet/IP (ISO/IEC 14543-3) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 3671\n  - **Summary**: KNXnet/IP Building Automation Tunneling & Group Telegrams\n  (ISO/IEC 14543-3-10, EN 50090, KNX Spec v2.1 (03/08/02/04))\n- **Token**: `l2tp`\n  - **Scopes**: Layer 3 (UDP 1701 (v2) / IP Proto 115 or transport udp (v3))\n  - **Syntax**: `l2tp [v2 | v3 | version <2|3>] [hello | sccrq | sccrp | scccn |\n  stopccn | data | msgtype \"<text>\" | msgtype <0..65535>] [tunnelid <number>]\n  [sessionid <number>] [ns <0..65535>] [nr <0..65535>] [flags <0..65535>]\n  [transport udp]`\n  - **Value / Range**: L2TPv2 & L2TPv3 (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 1701 (v2) / IP Proto 115 or transport udp (v3)\n  - **Summary**: Layer Two Tunneling Protocol v2 & v3 (RFC 2661, RFC 3931)\n- **Token**: `lacp`\n  - **Scopes**: Layer 2 (EtherType 0x8809 (Slow Subtype 0x01)), MAC-only or IP\n  hosts\n  - **Syntax**: `lacp [actorsys <mac>] [actorkey <0..65535>] [actorport\n  <0..65535>] [actorstate <0..255>] [partnersys <mac>] [partnerkey <0..65535>]\n  [partnerport <0..65535>] [partnerstate <0..255>]`\n  - **Value / Range**: LACP (MAC-Only or IP)\n  - **Default**: EtherType 0x8809 (Slow Subtype 0x01)\n  - **Summary**: IEEE 802.3ad / 802.1AX Link Aggregation Control Protocol (IEEE\n  802.1AX, IEEE 802.3ad)\n- **Token**: `ldap`\n  - **Scopes**: Layer 7 (TCP 389 (or CLDAP transport udp))\n  - **Syntax**: `ldap [msgid <number>] [bindreq | bindres | searchreq |\n  searchentry | searchdone | unbindreq] [basedn \"<text>\"] [filter \"<text>\"]\n  [resultcode <number>]`\n  - **Value / Range**: LDAPv3 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 389 (or CLDAP transport udp)\n  - **Summary**: Lightweight Directory Access Protocol v3 (ASN.1 BER) (RFC 4511)\n- **Token**: `ldp`\n  - **Scopes**: Layer 3 (TCP 646 (Session) / UDP 646 (transport udp Hello))\n  - **Syntax**: `ldp [hello | init | keepalive | notification | labelmapping |\n  labelrequest | labelwithdraw | labelrelease] [lsrid <ipv4>] [labelspace\n  <0..65535>] [msgid <number>] [holdtime <0..65535>] [label <number>] [prefix\n  \"<cidr>\"] [status <number>] [transport <tcp|udp>]`\n  - **Value / Range**: MPLS LDP (Port 646) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 646 (Session) / UDP 646 (transport udp Hello)\n  - **Summary**: Label Distribution Protocol (RFC 5036, RFC 7552)\n- **Token**: `lisp`\n  - **Scopes**: Layer 3 (UDP 4341 (Data) / UDP 4342 (Control))\n  - **Syntax**: `lisp [data | maprequest | mapreply | mapregister | mapnotify |\n  ecm] [flags <0..255>] [iid <0..16777215>] [nonce <number>] [eid \"<cidr>\"] [rloc\n  <ip>] [priority <0..255>] [weight <0..255>]`\n  - **Value / Range**: LISP (RFC 9300 / 9301) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 4341 (Data) / UDP 4342 (Control)\n  - **Summary**: Locator/ID Separation Protocol (Data & Control Plane) (RFC 9300,\n  RFC 9301, RFC 8060)\n- **Token**: `lldp`\n  - **Scopes**: Layer 2 (EtherType 0x88cc), MAC-only or IP hosts\n  - **Syntax**: `lldp [chassisid \"<text>\"] [portid \"<text>\"] [ttl <0..65535>]\n  [sysname \"<text>\"] [sysdesc \"<text>\"]`\n  - **Value / Range**: LLDP (MAC-Only or IP)\n  - **Default**: EtherType 0x88cc\n  - **Summary**: IEEE 802.1AB Link Layer Discovery Protocol (IEEE 802.1AB)\n- **Token**: `llmnr`\n  - **Scopes**: L7 (UDP / TCP (5355))\n  - **Syntax**: `<a> -> <b> llmnr [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: UDP / TCP (5355)\n  - **Summary**: Link-Local Multicast Name Resolution (RFC 4795) — Windows/Linux\n  link-local hostname resolution on multicast 224.0.0.252 / ff02::1:3 (port 5355,\n  TTL 1) with TXID, QNAME, QTYPE, and RDATA.\n- **Token**: `macsec`\n  - **Scopes**: Layer 2 (EtherType 0x88e5), MAC-only or IP hosts\n  - **Syntax**: `macsec [tci <0..255>] [an <0..3>] [sl <0..63>] [pn <number>] [sci\n  <number>] [icv \"<hex>\"]`\n  - **Value / Range**: MACsec (802.1AE) (MAC-Only or IP)\n  - **Default**: EtherType 0x88e5\n  - **Summary**: IEEE 802.1AE Media Access Control Security (MACsec) (IEEE\n  802.1AE, IEEE 802.1AEbw)\n- **Token**: `mdns`\n  - **Scopes**: Layer 7 (UDP 5353 -> 5353 (224.0.0.251 / ff02::fb))\n  - **Syntax**: `mdns [query | response] [txid <0..65535>] [qname \"<text>\"] [qtype\n  \"<text>\"] [rdata \"<text>\"] [rcode <0..15>] [ansttl <number>]`\n  - **Value / Range**: mDNS (Zero-Conf) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 5353 -> 5353 (224.0.0.251 / ff02::fb)\n  - **Summary**: Multicast DNS Zero-Configuration Discovery (RFC 6762, RFC 6763)\n- **Token**: `melsec`\n  - **Scopes**: Layer 7 (TCP 5000 (or UDP 5000 via transport udp))\n  - **Syntax**: `melsec [read | write | cmd \"<text_or_num>\"] [response |\n  isresponse] [subcmd <0..65535>] [network <0..255>] [pc <0..255>] [io <0..65535>]\n  [station <0..255>] [timer <0..65535>] [device \"<text_or_num>\"] [addr\n  <0..16777215>] [count <0..65535>] [value <0..65535>] [endcode|errcode\n  <0..65535>] [transport <tcp|udp>]`\n  - **Value / Range**: Mitsubishi MELSEC MC (3E) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 5000 (or UDP 5000 via transport udp)\n  - **Summary**: Mitsubishi Electric MELSEC Communication Protocol (QnA / iQ-R 3E\n  Frame) (Mitsubishi MELSEC Communication Protocol Reference (SH-080008))\n- **Token**: `memcached`\n  - **Scopes**: Layer 7 (UDP 11211 (or TCP 11211 via transport tcp))\n  - **Syntax**: `memcached [get | set | cmd \"<text>\"] [key \"<text>\"] [value\n  \"<text>\"] [flags <number>] [exptime <number>] [opcode <hex_or_num>] [opaque\n  <hex_or_num>] [cas <hex_or_num>] [transport <udp|tcp>]`\n  - **Value / Range**: Memcached (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 11211 (or TCP 11211 via transport tcp)\n  - **Summary**: Memcached ASCII & Binary Cache Protocol (Memcached Protocol\n  Specification)\n- **Token**: `mgcp`\n  - **Scopes**: L7 (UDP / TCP (2427))\n  - **Syntax**: `<a> -> <b> mgcp [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Media Gateway Control Protocol (RFC 3435) — Carrier voice gateway\n  call-agent control protocol on port 2427 supporting CRCX, MDCX, DLCX, RQNT,\n  NTFY, AUEP, and RSIP verbs with SDP media descriptions.\n- **Token**: `mld`\n  - **Scopes**: Layer 3 (ICMPv6 NextHdr 58 (Hop Limit 1))\n  - **Syntax**: `mld [query | report | done] [multicastaddr <ipv6>] [maxrespdelay\n  <0..65535>]`\n  - **Value / Range**: IPv6 MLD (IPv6-Only)\n  - **Default**: ICMPv6 NextHdr 58 (Hop Limit 1)\n  - **Summary**: Multicast Listener Discovery v1 & v2 (IPv6) (RFC 2710, RFC 3810)\n- **Token**: `mms`\n  - **Scopes**: Layer 7 (TCP 102 (TPKT + COTP + OSI Session/Pres/ACSE))\n  - **Syntax**: `mms [init | initack | getnamelist | read | write | report |\n  conclude | service \"<text>\"] [isresponse | response] [invokeid <number>] [domain\n  \"<text>\"] [item \"<text>\"] [value <number>]`\n  - **Value / Range**: ISO 9506 MMS (IEC 61850-8-1) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 102 (TPKT + COTP + OSI Session/Pres/ACSE)\n  - **Summary**: Manufacturing Message Specification (IEC 61850 Station Bus) (ISO\n  9506-1 / 9506-2, IEC 61850-8-1, RFC 1006)\n- **Token**: `modbus`\n  - **Scopes**: Layer 7 (TCP 502 (or UDP 502 via transport udp))\n  - **Syntax**: `modbus [readcoils | readdiscreteinputs | readholdingregisters |\n  readinputregisters | writesinglecoil | writesingleregister |\n  writemultipleregisters | func \"<name_or_fc>\"] [txid <0..65535>] [protoid\n  <0..65535>] [unitid <0..255>] [addr <0..65535>] [count <0..65535>] [value\n  <0..65535>] [isresponse] [transport <tcp|udp>]`\n  - **Value / Range**: Modbus TCP (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 502 (or UDP 502 via transport udp)\n  - **Summary**: Modbus TCP / UDP Industrial Application Protocol (Modbus\n  Application Protocol v1.1b3)\n- **Token**: `mongodb`\n  - **Scopes**: L7 (TCP (27017))\n  - **Syntax**: `<a> -> <b> mongodb [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (27017)\n  - **Summary**: MongoDB Wire Protocol — OP_MSG & OP_QUERY — Binary BSON document\n  database wire protocol on TCP 27017 encoding MsgHeader + OP_MSG (opcode 2013)\n  sections for ping, find, insert, and command replies.\n- **Token**: `mpls`\n  - **Scopes**: Layer 2 (EtherType 0x8847 (Label 16)), cross-layer L2 wrapper,\n  MAC-only or IP hosts\n  - **Syntax**: `mpls [<0..1048575> | label <0..1048575>] [exp|tc <0..7>] [bos\n  <0|1>] [mplsttl <0..255>] (repeatable)`\n  - **Value / Range**: MPLS (MAC-Only or IP)\n  - **Default**: EtherType 0x8847 (Label 16)\n  - **Summary**: Multiprotocol Label Switching Unicast Shim (RFC 3032, RFC 5462)\n- **Token**: `mqtt`\n  - **Scopes**: Layer 7 (TCP 1883 (or transport udp))\n  - **Syntax**: `mqtt [connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect | pkttype \"<text>\"] [clientid \"<text>\"] [topic\n  \"<text>\"] [qos <0..2>] [retain] [pktid <0..65535>] [keepalive <0..65535>]\n  [returncode <0..255>]`\n  - **Value / Range**: MQTT (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 1883 (or transport udp)\n  - **Summary**: Message Queuing Telemetry Transport (IoT & IIoT) (OASIS MQTT\n  v3.1.1, OASIS MQTT v5.0)\n- **Token**: `mssql`\n  - **Scopes**: L7 (TCP / UDP (1433))\n  - **Syntax**: `<a> -> <b> mssql [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP / UDP (1433)\n  - **Summary**: Microsoft SQL Server Tabular Data Stream — TDS (MS-TDS) — SQL\n  Server 8-byte TDS packet framing on port 1433 supporting Pre-Login, TDS7 Login,\n  UTF-16LE SQL Batch queries, Tabular Result OK/ERR tokens, and Attention signals.\n- **Token**: `mysql`\n  - **Scopes**: Layer 7 (TCP 3306)\n  - **Syntax**: `mysql [greeting | login | query | ok | err | eof] [serverversion\n  \"<text>\"] [user \"<text>\"] [db \"<text>\"] [sql \"<text>\"] [errcode <0..65535>]`\n  - **Value / Range**: MySQL / MariaDB (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 3306\n  - **Summary**: MySQL & MariaDB Wire Protocol v10 (MySQL Client/Server Protocol\n  v10)\n- **Token**: `nbns`\n  - **Scopes**: L7 (UDP (137))\n  - **Syntax**: `<a> -> <b> nbns [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: UDP (137)\n  - **Summary**: NetBIOS Name Service — NBNS (RFC 1001 / RFC 1002) —\n  NetBIOS-over-TCP/IP name registration, query, refresh, and release datagrams on\n  UDP 137 with 16-byte NetBIOS suffix byte (nbtype) and group flag.\n- **Token**: `ndp`\n  - **Scopes**: Layer 3 (ICMPv6 NextHdr 58 (Hop Limit 255))\n  - **Syntax**: `ndp [routersolicit | routeradvert | neighborsolicit |\n  neighboradvert | redirect] [target <ipv6>] [slla <mac>] [tlla <mac>]\n  [routerlifetime <0..65535>]`\n  - **Value / Range**: IPv6 NDP (IPv6-Only)\n  - **Default**: ICMPv6 NextHdr 58 (Hop Limit 255)\n  - **Summary**: IPv6 Neighbor Discovery Protocol (RFC 4861)\n- **Token**: `netconf`\n  - **Scopes**: L7 (TCP (830))\n  - **Syntax**: `<a> -> <b> netconf [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (830)\n  - **Summary**: Network Configuration Protocol over SSH/TCP (RFC 6241 / RFC 6242)\n  — XML/YANG router configuration management framing on TCP 830 supporting Hello\n  capabilities, RPC, RPC-Reply, Notifications, and RFC 6242 chunked framing.\n- **Token**: `netflow`\n  - **Scopes**: Layer 7 (UDP 2055)\n  - **Syntax**: `netflow [srcip <ipv4>] [dstip <ipv4>] [srcport <0..65535>]\n  [dstport <0..65535>] [proto <0..255>] [packets <number>] [octets <number>]`\n  - **Value / Range**: NetFlow v5 (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 2055\n  - **Summary**: Cisco NetFlow Version 5 Flow Export (Cisco NetFlow v5)\n- **Token**: `nfs`\n  - **Scopes**: Layer 7 (TCP 2049 (or UDP 2049 via transport udp))\n  - **Syntax**: `nfs [vers <3|4>] [compound | proc \"<text>\"] [tag \"<text>\"] [path\n  \"<text>\"] [xid <hex_or_num>] [transport <tcp|udp>]`\n  - **Value / Range**: NFSv3 / v4 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 2049 (or UDP 2049 via transport udp)\n  - **Summary**: Network File System over ONC RPC (RFC 7530, RFC 8881, RFC 1813)\n- **Token**: `ngap`\n  - **Scopes**: Layer 7 (SCTP 38412 (PPID 60))\n  - **Syntax**: `ngap [ngsetuprequest | ngsetupresponse | ngsetupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication] [msgtype\n  \"<text>\"] [proccode <0..255>] [criticality \"<text>\"] [amfueid <number>] [ranueid\n  <number>] [plmn \"<text>\"] [gnbid <number>] [tac <0..16777215>] [ranname\n  \"<text>\"] [naspdu \"<hex>\"]`\n  - **Value / Range**: 5G NGAP (3GPP TS 38.413) (Dual-Stack IPv4/IPv6)\n  - **Default**: SCTP 38412 (PPID 60)\n  - **Summary**: 5G Next Generation Application Protocol (N2 gNB <-> AMF over\n  SCTP) (3GPP TS 38.413, 3GPP TS 24.501, RFC 9260)\n- **Token**: `nsh`\n  - **Scopes**: Layer 2 (EtherType 0x894f), MAC-only or IP hosts\n  - **Syntax**: `nsh [version <0..3>] [oam] [ttl <0..63>] [mdtype <1|2>]\n  [nextproto <0..255 | \"ipv4\" | \"ipv6\" | \"ethernet\" | \"nsh\" | \"mpls\">] [spi\n  <0..16777215>] [si <0..255>] [context \"<hex>\"]`\n  - **Value / Range**: NSH (RFC 8300) (MAC-Only or IP)\n  - **Default**: EtherType 0x894f\n  - **Summary**: Network Service Header (Service Function Chaining) (RFC 8300, RFC\n  7665)\n- **Token**: `ntlm`\n  - **Scopes**: L7 (TCP (80))\n  - **Syntax**: `<a> -> <b> ntlm [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (80)\n  - **Summary**: Microsoft NT LAN Manager Authentication over HTTP (MS-NLMP) —\n  Three-leg NTLMSSP challenge-response authentication (Negotiate Type 1, Challenge\n  Type 2, Authenticate Type 3) embedded in HTTP Authorization / WWW-Authenticate\n  headers.\n- **Token**: `ntp`\n  - **Scopes**: Layer 7 (UDP 123 (or transport tcp))\n  - **Syntax**: `ntp [li <0..3>] [vn <1..4>] [mode <0..7>] [stratum <0..16>] [poll\n  <0..255>] [precision <-128..127>] [refid \"<text>\"] [txtimestamp <number>]`\n  - **Value / Range**: NTPv4 (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 123 (or transport tcp)\n  - **Summary**: Network Time Protocol v1–v4 (RFC 5905)\n- **Token**: `nvmetcp`\n  - **Scopes**: Layer 7 (TCP 4420)\n  - **Syntax**: `nvmetcp [icreq | icresp | read | write | response | h2cdata |\n  c2hdata | r2t | msgtype \"<text>\" | cmd \"<text>\"] [opcode <0..255>] [nsid\n  <number>] [qid <0..65535>] [reqid <0..65535>] [flags <0..255>] [status\n  <0..65535>] [offset <number>] [count <number>]`\n  - **Value / Range**: NVMe/TCP (NVMe-oF) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 4420\n  - **Summary**: NVM Express over Fabrics TCP Transport (TP 8000) (NVM Express TCP\n  Transport 1.0c, NVMe Base Spec 2.0)\n- **Token**: `opcua`\n  - **Scopes**: Layer 7 (TCP 4840)\n  - **Syntax**: `opcua [msgtype \"<HEL|ACK|OPN|MSG|CLO|ERR>\"] [chunktype \"<F|C|A>\"]\n  [securechannelid <number>] [tokenid <number>] [seqnum <number>] [reqid <number>]\n  [endpointurl \"<text>\"] [nodeid \"<text>\"]`\n  - **Value / Range**: OPC UA (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 4840\n  - **Summary**: OPC Unified Architecture Binary TCP Protocol (IEC 62541-6)\n- **Token**: `openflow`\n  - **Scopes**: Layer 3 (TCP 6653)\n  - **Syntax**: `openflow [hello | echoreq | echorequest | echoreply | featuresreq\n  | featuresreply | packetin | packetout | flowmod | type <0..255>] [version\n  <0..255>] [xid <number>] [dpid <number>] [tableid <0..255>] [priority\n  <0..65535>]`\n  - **Value / Range**: OpenFlow SDN (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 6653\n  - **Summary**: OpenFlow SDN Control Channel (OpenFlow 1.3 / 1.4) (ONF OpenFlow\n  1.3 (TS-023), OpenFlow 1.4)\n- **Token**: `ospf`\n  - **Scopes**: Layer 3 (IP Proto 89 (TTL 1))\n  - **Syntax**: `ospf [hello | dbd | lsr | lsu | lsack] [routerid <ipv4>] [areaid\n  <u32|ipv4>] [hellointerval <0..65535>] [deadinterval <number>] [priority\n  <0..255>]`\n  - **Value / Range**: OSPFv2 / OSPFv3 (Dual-Stack Morphing (v4/v6))\n  - **Default**: IP Proto 89 (TTL 1)\n  - **Summary**: Open Shortest Path First — OSPFv2 & Dual-Stack OSPFv3 (RFC 2328,\n  RFC 5340)\n- **Token**: `pfc`\n  - **Scopes**: Layer 2 (EtherType 0x8808 (Opcode 0x0101)), MAC-only or IP hosts\n  - **Syntax**: `pfc [enable <0..65535>] [quanta <0..65535>] [q0 <0..65535>] [q1\n  <0..65535>] [q2 <0..65535>] [q3 <0..65535>] [q4 <0..65535>] [q5 <0..65535>] [q6\n  <0..65535>] [q7 <0..65535>]`\n  - **Value / Range**: PFC (802.1Qbb) (MAC-Only or IP)\n  - **Default**: EtherType 0x8808 (Opcode 0x0101)\n  - **Summary**: IEEE 802.1Qbb Priority-based Flow Control (Lossless Ethernet)\n  (IEEE 802.1Qbb, IEEE 802.3x MAC Control)\n- **Token**: `pfcp`\n  - **Scopes**: Layer 7 (UDP 8805)\n  - **Syntax**: `pfcp [heartbeatrequest | heartbeatresponse |\n  associationsetuprequest | associationsetupresponse | sessionestablishmentrequest\n  | sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"] [seid <number>] [seqnum <0..16777215>] [cause <0..255>]\n  [nodeid <ip_or_text>] [recovery <number>]`\n  - **Value / Range**: PFCP (3GPP TS 29.244) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 8805\n  - **Summary**: Packet Forwarding Control Protocol (5G N4 / 4G Sxa-Sxb CUPS)\n  (3GPP TS 29.244, RFC 768)\n- **Token**: `pim`\n  - **Scopes**: Layer 3 (IP Proto 103)\n  - **Syntax**: `pim [hello | joinprune | register] [holdtime <0..65535>]\n  [drpriority <number>] [group <ip>] [source <ip>] [rp <ip>]`\n  - **Value / Range**: PIM-SM (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 103\n  - **Summary**: Protocol Independent Multicast — Sparse Mode (RFC 7761)\n- **Token**: `pop3`\n  - **Scopes**: Layer 7 (TCP 110)\n  - **Syntax**: `pop3 [cmd \"<text>\"] [arg \"<text>\"] [ok | err] [response\n  \"<text>\"]`\n  - **Value / Range**: POP3 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 110\n  - **Summary**: Post Office Protocol Version 3 (RFC 1939)\n- **Token**: `postgres`\n  - **Scopes**: Layer 7 (TCP 5432)\n  - **Syntax**: `postgres [startup | authok | query | commandcomplete |\n  readyforquery | errorresponse] [user \"<text>\"] [db \"<text>\"] [sql \"<text>\"]`\n  - **Value / Range**: PostgreSQL (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 5432\n  - **Summary**: PostgreSQL Frontend/Backend Wire Protocol v3.0 (PostgreSQL\n  Protocol v3.0)\n- **Token**: `pppoe`\n  - **Scopes**: Layer 2 (EtherType 0x8863 / 0x8864), MAC-only or IP hosts\n  - **Syntax**: `pppoe [padi | pado | padr | pads | padt | session] [sessionid\n  <0..65535>] [servicename \"<text>\"] [acname \"<text>\"] [hostuniq \"<hex>\"]\n  [accookie \"<hex>\"] [pppproto <0..65535>]`\n  - **Value / Range**: PPPoE (MAC-Only or IP)\n  - **Default**: EtherType 0x8863 / 0x8864\n  - **Summary**: Point-to-Point Protocol over Ethernet (Discovery & Session) (RFC\n  2516, RFC 4638)\n- **Token**: `profinet`\n  - **Scopes**: Layer 2 (EtherType 0x8892 (or UDP 34964)), MAC-only or IP hosts\n  - **Syntax**: `profinet [frameid <0..65535>] [cycle <0..65535>] [datastatus\n  <0..255>] [transferstatus <0..255>] [service \"<text>\"] [xid <number>] [request |\n  response | read | write | get | set | connect | release] [transport udp]`\n  - **Value / Range**: PROFINET RT (MAC-Only or IP)\n  - **Default**: EtherType 0x8892 (or UDP 34964)\n  - **Summary**: IEC 61158 PROFINET Real-Time & DCP (Ethernet 0x8892 / UDP 34964)\n  (IEC 61158, IEC 61784-2, PROFINET IO)\n- **Token**: `ptp`\n  - **Scopes**: Layer 7 (UDP 319 (Event) / UDP 320 (General))\n  - **Syntax**: `ptp [sync | delayreq | followup | delayresp | announce | msgtype\n  \"<text>\"] [domain <0..255>] [seqid <0..65535>] [clockid \"<text>\"]`\n  - **Value / Range**: PTPv2 (IEEE 1588) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 319 (Event) / UDP 320 (General)\n  - **Summary**: IEEE 1588 Precision Time Protocol v2 (IEEE 1588-2008, SMPTE ST\n  2059-2, ITU-T G.8275.2)\n- **Token**: `qinq`\n  - **Scopes**: Layer 2 (Outer 0x88a8 + Inner 0x8100), cross-layer L2 wrapper,\n  MAC-only or IP hosts\n  - **Syntax**: `qinq [<outer_svlan 0..4095>] [innervlan <inner_cvlan 0..4095>]\n  [pcp <0..7>] [dei <0|1>]`\n  - **Value / Range**: 802.1ad QinQ (MAC-Only or IP)\n  - **Default**: Outer 0x88a8 + Inner 0x8100\n  - **Summary**: IEEE 802.1ad Provider Bridge Double VLAN Tagging (S-Tag + C-Tag)\n  (IEEE 802.1ad, IEEE 802.1Q)\n- **Token**: `quic`\n  - **Scopes**: Layer 7 (UDP 443)\n  - **Syntax**: `quic [initial | zerortt | handshake | retry | short] [version\n  <number>] [dcid <hex_or_num>] [scid <hex_or_num>] [token \"<text>\"] [pktnum\n  <number>]`\n  - **Value / Range**: QUIC (HTTP/3) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 443\n  - **Summary**: QUIC v1 & v2 Encrypted UDP Transport (RFC 9000, RFC 9369)\n- **Token**: `radius`\n  - **Scopes**: Layer 7 (UDP/TCP 1812 (Auth) / 1813 (Accounting))\n  - **Syntax**: `radius [accessrequest | accessaccept | accessreject |\n  accesschallenge | accountingrequest | accountingresponse | code \"<text>\"] [id\n  <0..255>] [user \"<text>\"] [nasip <ipv4>] [servicetype <number>] [framedip\n  <ipv4>]`\n  - **Value / Range**: RADIUS (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP/TCP 1812 (Auth) / 1813 (Accounting)\n  - **Summary**: Remote Authentication Dial-In User Service (Auth & Accounting)\n  (RFC 2865, RFC 2866)\n- **Token**: `rdp`\n  - **Scopes**: L7 (TCP (3389))\n  - **Syntax**: `<a> -> <b> rdp [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (3389)\n  - **Summary**: Microsoft Remote Desktop Protocol — TPKT / X.224 / MCS\n  (MS-RDPBCGR) — Remote Desktop connection sequence over TPKT TCP 3389 (X.224\n  Connection Request/Confirm and MCS Connect Initial) with mstshash cookie,\n  security protocol flags, and desktop geometry.\n- **Token**: `redis`\n  - **Scopes**: Layer 7 (TCP 6379)\n  - **Syntax**: `redis [get | set | cmd \"<text>\"] [key \"<text>\"] [args \"<text>\"]\n  [value \"<text>\"] [replytype \"<ok|err|integer|bulk>\"]`\n  - **Value / Range**: Redis (RESP) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 6379\n  - **Summary**: Redis Serialization Protocol Cache & Broker (Redis RESP2 / RESP3)\n- **Token**: `rip`\n  - **Scopes**: Layer 3 (UDP 520 (RIPv2) / UDP 521 (RIPng))\n  - **Syntax**: `rip [request | response | reply] [prefix <ip>] [metric <1..16>]\n  [nexthop <ip>] [tag <0..65535>]`\n  - **Value / Range**: RIPv2 / RIPng (Dual-Stack Morphing (v4/v6))\n  - **Default**: UDP 520 (RIPv2) / UDP 521 (RIPng)\n  - **Summary**: Routing Information Protocol — RIPv2 & Dual-Stack RIPng (RFC\n  2453, RFC 2080)\n- **Token**: `rocev2`\n  - **Scopes**: Layer 7 (UDP 4791)\n  - **Syntax**: `rocev2 [read | write | opcode \"<text_or_num>\"] [pkey <0..65535>]\n  [destqp <0..16777215>] [ackreq] [seqnum <0..16777215>] [addr <number>] [key\n  <number>] [count <number>] [status <0..255>] [msgid <0..16777215>] [crc\n  <number>]`\n  - **Value / Range**: RoCEv2 (InfiniBand BTH) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 4791\n  - **Summary**: RDMA over Converged Ethernet v2 (InfiniBand Annex A17) (IBTA\n  RoCEv2 Annex A17, InfiniBand Arch Vol 1)\n- **Token**: `rocplus`\n  - **Scopes**: Layer 7 (TCP 4000 (or UDP 4000 via transport udp))\n  - **Syntax**: `rocplus [read | write | error | opcode \"<text_or_num>\" | func\n  \"<text_or_num>\"] [dst <0..255>] [group <0..255>] [src <0..255>] [type <0..255>]\n  [addr <0..255>] [param <0..255>] [value <number>] [isresponse] [crc <0..65535>]\n  [transport <tcp|udp>]`\n  - **Value / Range**: Emerson ROC Plus (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 4000 (or UDP 4000 via transport udp)\n  - **Summary**: Emerson Fisher ROC Plus Oil & Gas Pipeline RTU Protocol (Emerson\n  Fisher ROC Plus Protocol Specifications Manual (D301151X012))\n- **Token**: `rpkirtr`\n  - **Scopes**: Layer 3 (TCP 323)\n  - **Syntax**: `rpkirtr [serialnotify | serialquery | resetquery | cacheresponse\n  | ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport] [version\n  <0|1>] [sessionid <0..65535>] [serial <number>] [announce | withdraw | flags\n  <0..255>] [prefix \"<cidr>\"] [maxlen <0..255>] [asn <number>] [refresh <number>]\n  [retry <number>] [expire <number>] [errcode <0..65535>] [errmsg \"<text>\"]`\n  - **Value / Range**: RPKI-RTR (TCP 323) (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 323\n  - **Summary**: RPKI-Router Origin Validation Protocol (RFC 6810, RFC 8210)\n- **Token**: `rsvp`\n  - **Scopes**: Layer 3 (IP Proto 46 (Router Alert Optional))\n  - **Syntax**: `rsvp [path | resv | patherr | resverr | pathtear | resvtear |\n  resvconf | hello] [tunnelid <0..65535>] [lspid <0..65535>] [label <number>]\n  [refresh <number>] [srcip <ip>] [dstip <ip>] [errcode <0..255>]`\n  - **Value / Range**: RSVP-TE (RFC 3209) (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 46 (Router Alert Optional)\n  - **Summary**: Resource Reservation Protocol — Traffic Engineering (RFC 2205,\n  RFC 3209, RFC 4090)\n- **Token**: `rtcp`\n  - **Scopes**: L7 (UDP (5005))\n  - **Syntax**: `<a> -> <b> rtcp [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: UDP (5005)\n  - **Summary**: RTP Control Protocol (RFC 3550) — Companion VoIP/WebRTC media\n  quality feedback on UDP 5005 (Sender Report, Receiver Report, SDES CNAME, BYE,\n  APP) reporting jitter, packet loss, and SSRC counters.\n- **Token**: `rtp`\n  - **Scopes**: Layer 7 (UDP 5004)\n  - **Syntax**: `rtp [pt <0..127>] [seq <0..65535>] [timestamp <number>] [ssrc\n  <hex_or_num>] [marker <0|1>]`\n  - **Value / Range**: RTP (Media) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 5004\n  - **Summary**: Real-time Transport Protocol Audio & Video Streams (RFC 3550, RFC\n  3551, RFC 4733)\n- **Token**: `rtsp`\n  - **Scopes**: Layer 7 (TCP 554 (or transport udp))\n  - **Syntax**: `rtsp [options | describe | setup | play | teardown | method\n  \"<text>\"] [uri \"<text>\"] [status <100..599>] [cseq <number>] [transporthdr\n  \"<text>\"] [session \"<text>\"]`\n  - **Value / Range**: RTSP (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 554 (or transport udp)\n  - **Summary**: Real Time Streaming Protocol IP Camera & Media Control (RFC 2326,\n  RFC 7826)\n- **Token**: `s1ap`\n  - **Scopes**: Layer 7 (SCTP 36412 (PPID 18))\n  - **Syntax**: `s1ap [s1setuprequest | s1setupresponse | s1setupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication] [msgtype\n  \"<text>\"] [proccode <0..255>] [criticality \"<text>\"] [mmeueid <number>] [enbueid\n  <0..16777215>] [plmn \"<text>\"] [enbid <number>] [tac <0..65535>] [enbname\n  \"<text>\"] [naspdu \"<hex>\"]`\n  - **Value / Range**: 4G S1AP (3GPP TS 36.413) (Dual-Stack IPv4/IPv6)\n  - **Default**: SCTP 36412 (PPID 18)\n  - **Summary**: 4G LTE S1 Application Protocol (S1-MME eNB <-> MME over SCTP)\n  (3GPP TS 36.413, 3GPP TS 24.301, RFC 9260)\n- **Token**: `s7comm`\n  - **Scopes**: Layer 7 (TCP 102 (ISO-on-TCP))\n  - **Syntax**: `s7comm [setupcomm | readvar | writevar | plccontrol | func\n  \"<text>\"] [rosctr \"<job|ack|ackdata|userdata>\"] [pduref <0..65535>] [area\n  <hex_or_str>] [dbnum <0..65535>] [offset <number>] [count <0..65535>]`\n  - **Value / Range**: Siemens S7comm (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 102 (ISO-on-TCP)\n  - **Summary**: Siemens S7 Communication Protocol over ISO-on-TCP (RFC 1006\n  (TPKT), ISO 8073 (COTP), Siemens S7comm)\n- **Token**: `s7commplus`\n  - **Scopes**: Layer 7 (TCP 102 (TPKT + COTP + 0x72))\n  - **Syntax**: `s7commplus [version <1..3>] [opcode \"<text_or_num>\"] [isresponse\n  | response] [func \"<text_or_num>\"] [seqnum <0..65535>] [sessionid <number>] [id\n  <number>] [flags <0..255>]`\n  - **Value / Range**: Siemens S7commPlus (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 102 (TPKT + COTP + 0x72)\n  - **Summary**: Siemens SIMATIC S7-1200 / S7-1500 S7commPlus OMS Protocol (RFC\n  1006 (ISO-on-TCP), ISO 8073 COTP, Siemens OMS+ / S7commPlus)\n- **Token**: `sccp`\n  - **Scopes**: L7 (TCP (2000))\n  - **Syntax**: `<a> -> <b> sccp [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (2000)\n  - **Summary**: Cisco Skinny Client Control Protocol (SCCP) — Cisco Unified\n  Communications Manager IP phone control protocol on TCP 2000 supporting\n  Register, KeepAlive, OffHook/OnHook, CallState, KeypadButton, and\n  OpenReceiveChannel.\n- **Token**: `sctp`\n  - **Scopes**: Layer 4 (IP Proto 132 (38412 NGAP / 36412 S1AP))\n  - **Syntax**: `sctp [chunk <type> | data | init | initack | sack | heartbeat |\n  heartbeatack | abort | shutdown | shutdownack | shutdowncomplete | cookieecho |\n  cookieack] [vtag <number>] [tsn <number>] [stream <0..65535>] [ssn <0..65535>]\n  [ppid <number>]`\n  - **Value / Range**: SCTP (CRC-32c) (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 132 (38412 NGAP / 36412 S1AP)\n  - **Summary**: Stream Control Transmission Protocol (RFC 9260, RFC 4960, 3GPP TS\n  38.412)\n- **Token**: `sflow`\n  - **Scopes**: Layer 7 (UDP 6343)\n  - **Syntax**: `sflow [agentip <ip>] [subagentid <number>] [seq <number>] [uptime\n  <number>] [samples <number>]`\n  - **Value / Range**: sFlow v5 (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 6343\n  - **Summary**: sFlow Version 5 Switched & Routed Packet Sampling (sFlow v5\n  Specification)\n- **Token**: `sip`\n  - **Scopes**: Layer 7 (UDP 5060 (or TCP 5060 via transport tcp))\n  - **Syntax**: `sip [invite | ack | bye | cancel | register | options | method\n  \"<text>\"] [uri \"<text>\"] [status <100..699>] [reason \"<text>\"] [from \"<text>\"]\n  [to \"<text>\"] [callid \"<text>\"] [cseq <number>] [via \"<text>\"] [contact\n  \"<text>\"] [contenttype \"<text>\"] [body \"<text>\"] [transport <udp|tcp>]`\n  - **Value / Range**: SIP (VoIP) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 5060 (or TCP 5060 via transport tcp)\n  - **Summary**: Session Initiation Protocol VoIP Signaling (RFC 3261)\n- **Token**: `smb`\n  - **Scopes**: Layer 7 (TCP 445)\n  - **Syntax**: `smb [negotiate | sessionsetup | treeconnect | treedisconnect |\n  create | close | read | write | logoff | command \"<text>\"] [status <hex_or_num>]\n  [treeid <number>] [sessionid <hex_or_num>] [msgid <number>] [share \"<unc_path>\"]\n  [filename \"<text>\"]`\n  - **Value / Range**: SMB2 / SMB3 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 445\n  - **Summary**: Server Message Block SMB2 & SMB3 File Sharing (MS-SMB2)\n- **Token**: `smtp`\n  - **Scopes**: Layer 7 (TCP 25 (or dstport 587 Submission))\n  - **Syntax**: `smtp [ehlo [\"<domain>\"] | helo [\"<domain>\"] | mailfrom \"<addr>\" |\n  rcptto \"<addr>\" | data | quit | cmd \"<verb>\" [param \"<text>\"]] [code <200..599>]\n  [reply \"<text>\"] [body \"<text>\"]`\n  - **Value / Range**: SMTP (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 25 (or dstport 587 Submission)\n  - **Summary**: Simple Mail Transfer Protocol (RFC 5321)\n- **Token**: `snmp1`\n  - **Scopes**: Layer 7 (UDP/TCP 162 (trap) / 161 (get/set))\n  - **Syntax**: `snmp1 [trap | get | getnext | set | response] [community\n  \"<text>\"] [enterprise <oid>] [agentip <ipv4>] [gentrap <0..6>] [spectrap\n  <number>] [sysuptime <number>] [reqid <number>] [oid <oid>] [varbind <oid>\n  <type_val> ...]`\n  - **Value / Range**: SNMPv1 (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP/TCP 162 (trap) / 161 (get/set)\n  - **Summary**: Simple Network Management Protocol v1 (RFC 1157, RFC 1155, RFC\n  3584)\n- **Token**: `snmp2`\n  - **Scopes**: Layer 7 (UDP/TCP 162 (trap/inform) / 161 (get/getbulk))\n  - **Syntax**: `snmp2 [trap | inform | report | get | getnext | getbulk | set |\n  response] [community \"<text>\"] [reqid <number>] [nonrepeaters <number>]\n  [maxrepetitions <number>] [sysuptime <number>] [oid <oid>] [varbind <oid>\n  <type_val> ...]`\n  - **Value / Range**: SNMPv2c (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP/TCP 162 (trap/inform) / 161 (get/getbulk)\n  - **Summary**: Simple Network Management Protocol v2c (RFC 3416, RFC 3418, RFC\n  2863)\n- **Token**: `snmp3`\n  - **Scopes**: Layer 7 (UDP/TCP 162 (trap/inform/report) / 161 (get/getbulk))\n  - **Syntax**: `snmp3 [trap | inform | report | get | getnext | getbulk | set |\n  response] [user \"<text>\"] [engineid \"<even_hex>\"] [engineboots <number>]\n  [enginetime <number>] [contextname \"<text>\"] [auth\n  <md5|sha|sha256|sha384|sha512> \"<password>\"] [priv <des|aes> \"<password>\"]\n  [reqid <number>] [nonrepeaters <number>] [maxrepetitions <number>] [sysuptime\n  <number>] [oid <oid>] [varbind <oid> <type_val> ...]`\n  - **Value / Range**: SNMPv3 USM (authPriv) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP/TCP 162 (trap/inform/report) / 161 (get/getbulk)\n  - **Summary**: Simple Network Management Protocol v3 with USM Auth & Privacy\n  (RFC 3414, RFC 3826, RFC 7860)\n- **Token**: `socks`\n  - **Scopes**: L7 (TCP (1080))\n  - **Syntax**: `<a> -> <b> socks [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (1080)\n  - **Summary**: SOCKS5 / SOCKS4 Proxy Protocol (RFC 1928 / RFC 1929) — TCP/UDP\n  proxy negotiation on TCP 1080 supporting SOCKS5 method greeting,\n  username/password auth, and CONNECT/BIND/UDP_ASSOCIATE target requests.\n- **Token**: `someip`\n  - **Scopes**: Layer 7 (UDP 30490 (or TCP 30490 via transport tcp))\n  - **Syntax**: `someip [findservice | offerservice | subscribe | subscribeack |\n  request | requestnoreply | notification | response | error | msgtype\n  \"<text_or_num>\"] [serviceid <0..65535>] [methodid <0..65535>] [clientid\n  <0..65535>] [sessionid <0..65535>] [protover <0..255>] [ifacever <0..255>]\n  [returncode <0..255>] [flags <0..255>] [sdservice <0..65535>] [instanceid\n  <0..65535>] [majorver <0..255>] [sdttl <0..16777215>] [minorver <number>]\n  [endpointip <ip>] [endpointport <0..65535>] [transport <udp|tcp>]`\n  - **Value / Range**: SOME/IP & SD (AUTOSAR) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 30490 (or TCP 30490 via transport tcp)\n  - **Summary**: Scalable service-Oriented MiddlewarE over IP & Service Discovery\n  (AUTOSAR FO R22-11 SOME/IP Protocol, AUTOSAR SOME/IP-SD)\n- **Token**: `srv6`\n  - **Scopes**: Layer 3 (IPv6 NextHdr 43 (Routing Type 4))\n  - **Syntax**: `srv6 [nextheader <0..255>] [segleft <0..255>] [flags <0..255>]\n  [tag <0..65535>] [sid <ipv6>]...`\n  - **Value / Range**: SRv6 SRH (RFC 8754) (IPv6-Only)\n  - **Default**: IPv6 NextHdr 43 (Routing Type 4)\n  - **Summary**: Segment Routing over IPv6 — Segment Routing Header (RFC 8754, RFC\n  8986, RFC 9252)\n- **Token**: `ssdp`\n  - **Scopes**: Layer 7 (UDP 1900 (239.255.255.250 / ff02::c))\n  - **Syntax**: `ssdp [msearch | notify] [hosthdr \"<text>\"] [man \"<text>\"] [mx\n  <0..255>] [st \"<text>\"] [nt \"<text>\"] [nts \"<text>\"] [usn \"<text>\"] [location\n  \"<text>\"]`\n  - **Value / Range**: SSDP (UPnP) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 1900 (239.255.255.250 / ff02::c)\n  - **Summary**: Simple Service Discovery Protocol & UPnP Multicast (UPnP Device\n  Architecture 2.0)\n- **Token**: `ssh`\n  - **Scopes**: Layer 7 (TCP 22)\n  - **Syntax**: `ssh [banner \"<text>\"] [kexinit] [newkeys] [msgcode <0..255>]\n  [cookie \"<text>\"]`\n  - **Value / Range**: SSH-2 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 22\n  - **Summary**: Secure Shell Transport Layer Protocol (RFC 4253)\n- **Token**: `stp`\n  - **Scopes**: Layer 2 (802.3 LLC 0x4242 -> 01:80:c2:00:00:00), MAC-only or IP\n  hosts\n  - **Syntax**: `stp [rstp] [rootid \"<text>\"] [bridgeid \"<text>\"] [portid\n  <0..65535>] [cost <number>] [maxage <0..65535>] [hellotime <0..65535>]\n  [forwarddelay <0..65535>] [flags <0..255>]`\n  - **Value / Range**: STP / RSTP (MAC-Only or IP)\n  - **Default**: 802.3 LLC 0x4242 -> 01:80:c2:00:00:00\n  - **Summary**: IEEE 802.1D Spanning Tree & IEEE 802.1w Rapid Spanning Tree (IEEE\n  802.1D, IEEE 802.1w)\n- **Token**: `stun`\n  - **Scopes**: Layer 7 (UDP 3478)\n  - **Syntax**: `stun [bindingrequest | bindingresponse | bindingerror] [txid\n  <hex_or_num>] [xormappedaddr <ip>] [software \"<text>\"]`\n  - **Value / Range**: STUN (NAT) (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 3478\n  - **Summary**: Session Traversal Utilities for NAT (RFC 5389)\n- **Token**: `sv`\n  - **Scopes**: Layer 2 (EtherType 0x88ba), MAC-only or IP hosts\n  - **Syntax**: `sv [appid <0..65535>] [svid \"<text>\"] [datset \"<text>\"] [smpcnt\n  <0..65535>] [confrev <number>] [smpsynch <0|1|2>] [smprate <0..65535>]\n  [simulation]`\n  - **Value / Range**: IEC 61850 SV (MAC-Only or IP)\n  - **Default**: EtherType 0x88ba\n  - **Summary**: IEC 61850-9-2 Substation Sampled Values (Process Bus) (IEC\n  61850-9-2, IEC 61869-9 (9-2LE))\n- **Token**: `synchrophasor`\n  - **Scopes**: Layer 7 (TCP 4712 (or UDP 4712/4713 via transport udp))\n  - **Syntax**: `synchrophasor [msgtype \"<text>\"] [version <1..2>] [id <0..65535>]\n  [timestamp <number>] [fracsec <number>] [cmd \"<text_or_num>\"] [status\n  <0..65535>] [station \"<text>\"] [crc <0..65535>] [transport <tcp|udp>]`\n  - **Value / Range**: IEEE C37.118 Synchrophasor (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 4712 (or UDP 4712/4713 via transport udp)\n  - **Summary**: IEEE C37.118.2 PMU / PDC Wide-Area Grid Synchrophasor Telemetry\n  (IEEE C37.118.2-2011, IEC/IEEE 60255-118-1)\n- **Token**: `syslog`\n  - **Scopes**: Layer 7 (UDP 514 (or TCP 514 via transport tcp))\n  - **Syntax**: `syslog [facility <0..23>] [severity <0..7>] [pri <0..191>]\n  [hostname \"<text>\"] [app \"<text>\"] [procid \"<text>\"] [msgid \"<text>\"] [msg\n  \"<text>\"] [transport <udp|tcp>]`\n  - **Value / Range**: Syslog (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 514 (or TCP 514 via transport tcp)\n  - **Summary**: Syslog Event Logging over UDP or TCP (RFC 5424, RFC 3164, RFC\n  6587)\n- **Token**: `tacacs`\n  - **Scopes**: Layer 7 (TCP 49)\n  - **Syntax**: `tacacs [authen | author | acct | type <authen|author|acct>] [seq\n  <0..255>] [flags <0..255>] [sessionid <number>] [user \"<text>\"] [data \"<text>\"]`\n  - **Value / Range**: TACACS+ (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 49\n  - **Summary**: Terminal Access Controller Access-Control System Plus (RFC 8907)\n- **Token**: `tcp`\n  - **Scopes**: Layer 4 (IP Proto 6 (Default dstport 80))\n  - **Syntax**: `tcp [syn] [ack] [fin] [rst] [psh] [urg] [ece] [cwr] [srcport\n  <0..65535>] [dstport <0..65535>] [seq <number>] [acknum <number>] [win|window\n  <0..65535>] [urgent <0..65535>] [mss <0..65535>] [wscale <0..255>] [sackperm]\n  [sackblock <number> <number>] [tsval <number>] [tsecr <number>] [tcpmd5 \"<hex>\"]\n  [tfo \"<hex>\"]`\n  - **Value / Range**: TCP & RFC 7323 (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 6 (Default dstport 80)\n  - **Summary**: Transmission Control Protocol & RFC 7323 Options (RFC 9293, RFC\n  7323, RFC 2018, RFC 2385, RFC 7413)\n- **Token**: `telnet`\n  - **Scopes**: Layer 7 (TCP 23)\n  - **Syntax**: `telnet [do <0..255>] [dont <0..255>] [will <0..255>] [wont\n  <0..255>] [option <0..255>] [data \"<text>\"]`\n  - **Value / Range**: Telnet (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 23\n  - **Summary**: Telnet Cleartext Terminal & IAC Negotiation (RFC 854, RFC 855)\n- **Token**: `tftp`\n  - **Scopes**: Layer 7 (UDP 69)\n  - **Syntax**: `tftp [rrq | wrq | data | ack | error | err] [filename \"<text>\"]\n  [mode \"<text>\"] [block <0..65535>] [errcode <0..65535>] [errmsg \"<text>\"]`\n  - **Value / Range**: TFTP (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 69\n  - **Summary**: Trivial File Transfer Protocol (RFC 1350)\n- **Token**: `tls`\n  - **Scopes**: Layer 7 (TCP 443)\n  - **Syntax**: `tls [clienthello | serverhello | certificate | finished | appdata\n  | alert] [recordversion <hex>] [handshakeversion <hex>] [sni \"<text>\"]\n  [ciphersuite <hex>] [alpn \"<text>\"]`\n  - **Value / Range**: TLS 1.2 / 1.3 (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 443\n  - **Summary**: Transport Layer Security Record & Handshake Layer (RFC 8446, RFC\n  5246, RFC 6066)\n- **Token**: `tns`\n  - **Scopes**: L7 (TCP (1521))\n  - **Syntax**: `<a> -> <b> tns [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (1521)\n  - **Summary**: Oracle Transparent Network Substrate — Net8 / TNS — Oracle\n  Database listener session protocol on TCP 1521 supporting Connect (with\n  SERVICE_NAME / SID descriptor), Accept, Refuse, Redirect, Data SQL Piggyback,\n  and Marker packets.\n- **Token**: `turn`\n  - **Scopes**: L7 (UDP / TCP (3478))\n  - **Syntax**: `<a> -> <b> turn [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Traversal Using Relays around NAT (RFC 8656) — WebRTC media relay\n  allocation and forwarding protocol on port 3478 supporting Allocate, Refresh,\n  CreatePermission, ChannelBind, ChannelData, and Send/Data Indications.\n- **Token**: `twamp`\n  - **Scopes**: L7 (UDP / TCP (862))\n  - **Syntax**: `<a> -> <b> twamp [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Two-Way Active Measurement Protocol (RFC 5357) — SLA synthetic\n  latency/jitter/loss active probe protocol on port 862 supporting TWAMP-Test\n  sender/reflector packets and TWAMP-Control session negotiation.\n- **Token**: `udp`\n  - **Scopes**: Layer 4 (IP Proto 17 (Default dstport 80))\n  - **Syntax**: `udp [srcport <0..65535>] [dstport <0..65535>] [nochecksum]\n  [payload \"<text>\" | hexpayload \"<hex>\"]`\n  - **Value / Range**: UDP (Dual-Stack IPv4/IPv6)\n  - **Default**: IP Proto 17 (Default dstport 80)\n  - **Summary**: User Datagram Protocol (RFC 768, RFC 8200)\n- **Token**: `vlan`\n  - **Scopes**: Layer 2 (TPID 0x8100 (VID 1)), cross-layer L2 wrapper, MAC-only or\n  IP hosts\n  - **Syntax**: `vlan [<vid 0..4095>] [pcp <0..7>] [dei <0|1>]`\n  - **Value / Range**: 802.1Q VLAN (MAC-Only or IP)\n  - **Default**: TPID 0x8100 (VID 1)\n  - **Summary**: IEEE 802.1Q Virtual LAN Tagging & 802.1p QoS (IEEE 802.1Q, IEEE\n  802.1p)\n- **Token**: `vnc`\n  - **Scopes**: L7 (TCP (5900))\n  - **Syntax**: `<a> -> <b> vnc [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: TCP (5900)\n  - **Summary**: Virtual Network Computing — RFB Protocol (RFC 6143) — Remote\n  Framebuffer (RFB 003.008) desktop sharing protocol on TCP 5900 supporting\n  version handshake, security negotiation, ServerInit geometry, KeyEvent, and\n  PointerEvent.\n- **Token**: `vrrp`\n  - **Scopes**: Layer 3 (IP Proto 112 (TTL 255))\n  - **Syntax**: `vrrp [vrid <1..255>] [priority <0..255>] [advint <0..65535>] [vip\n  <ip>] [version <2|3>]`\n  - **Value / Range**: VRRPv2 / VRRPv3 (Dual-Stack Morphing (v4/v6))\n  - **Default**: IP Proto 112 (TTL 255)\n  - **Summary**: Virtual Router Redundancy Protocol v2 & v3 (RFC 3768, RFC 5798)\n- **Token**: `vxlan`\n  - **Scopes**: Layer 3 (UDP 4789 (VNI 1))\n  - **Syntax**: `vxlan [vni|vnid <0..16777215>]`\n  - **Value / Range**: VXLAN (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 4789 (VNI 1)\n  - **Summary**: Virtual eXtensible Local Area Network Overlay (RFC 7348)\n- **Token**: `websocket`\n  - **Scopes**: Layer 7 (TCP 80)\n  - **Syntax**: `websocket [text | binary | close | ping | pong | opcode \"<text>\"]\n  [finbit <0|1>] [maskkey <number>] [payload \"<text>\"]`\n  - **Value / Range**: WebSocket (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 80\n  - **Summary**: WebSocket Framed Bidirectional Messaging (RFC 6455)\n- **Token**: `whois`\n  - **Scopes**: Layer 7 (TCP 43), bacnet service\n  - **Syntax**: `whois [query | response] [domain \"<text>\"] [registrar \"<text>\"]`\n  - **Value / Range**: WHOIS (Dual-Stack IPv4/IPv6)\n  - **Default**: TCP 43\n  - **Summary**: WHOIS Domain & IP Directory Query Protocol (RFC 3912) (also\n  accepted after `bacnet` to emit a BACnet unconfirmed Who-Is APDU).\n- **Token**: `wireguard`\n  - **Scopes**: Layer 3 (UDP 51820)\n  - **Syntax**: `wireguard [type <initiation|response|cookie|data> | initiation |\n  response | cookie | data] [sender <number>] [receiver <number>] [counter\n  <number>]`\n  - **Value / Range**: WireGuard (Dual-Stack IPv4/IPv6)\n  - **Default**: UDP 51820\n  - **Summary**: WireGuard Noise_IK Secure Network Tunnel (WireGuard Whitepaper\n  (NDSS 2017))\n- **Token**: `wsdiscovery`\n  - **Scopes**: L7 (UDP (3702))\n  - **Syntax**: `<a> -> <b> wsdiscovery [modifiers...]`\n  - **Value / Range**: L7 protocol builder\n  - **Default**: UDP (3702)\n  - **Summary**: OASIS Web Services Dynamic Discovery (WS-Discovery / ONVIF) —\n  SOAP-over-UDP multicast device discovery on 239.255.255.250 / ff02::c (UDP 3702)\n  for ONVIF IP cameras, printers, and enterprise appliances.\n\n### Protocol-Specific Subkeywords & Fields (921 tokens)\n\nAll PDU types, message opcodes, header fields, USM crypto selectors, SMIv2 varbind\nvalue types, and aliases across the 146 protocols.\n\n- **Token**: `abort`\n  - **Scopes**: sctp\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Selects the RFC 9260 SCTP chunk type (`0`=DATA, `1`=INIT,\n  `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT, `5`=HEARTBEAT_ACK, `6`=ABORT,\n  `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO, `11`=COOKIE_ACK,\n  `14`=SHUTDOWN_COMPLETE).\n- **Token**: `accept`\n  - **Scopes**: tns\n  - **Syntax**: `tns ... accept`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (1521)\n  - **Summary**: Configures the `accept` PDU selector or header field on `tns`\n  frames.\n- **Token**: `acceptsession`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... acceptsession`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `acceptsession` PDU selector or header field on\n  `twamp` frames.\n- **Token**: `accessaccept`\n  - **Scopes**: radius\n  - **Syntax**: `accessrequest | accessaccept | accessreject | accesschallenge |\n  accountingrequest | accountingresponse`\n  - **Value / Range**: RADIUS packet code keyword (or `code \"<text>\"`)\n  - **Default**: accessrequest (Code 1, UDP 1812)\n  - **Summary**: Sets the 1-byte RADIUS Code (`1` Access-Request, `2`\n  Access-Accept, `3` Access-Reject, `4` Accounting-Request, `5`\n  Accounting-Response, `11` Access-Challenge) and selects UDP `1812` or `1813`.\n- **Token**: `accesschallenge`\n  - **Scopes**: radius\n  - **Syntax**: `accessrequest | accessaccept | accessreject | accesschallenge |\n  accountingrequest | accountingresponse`\n  - **Value / Range**: RADIUS packet code keyword (or `code \"<text>\"`)\n  - **Default**: accessrequest (Code 1, UDP 1812)\n  - **Summary**: Sets the 1-byte RADIUS Code (`1` Access-Request, `2`\n  Access-Accept, `3` Access-Reject, `4` Accounting-Request, `5`\n  Accounting-Response, `11` Access-Challenge) and selects UDP `1812` or `1813`.\n- **Token**: `accessreject`\n  - **Scopes**: radius\n  - **Syntax**: `accessrequest | accessaccept | accessreject | accesschallenge |\n  accountingrequest | accountingresponse`\n  - **Value / Range**: RADIUS packet code keyword (or `code \"<text>\"`)\n  - **Default**: accessrequest (Code 1, UDP 1812)\n  - **Summary**: Sets the 1-byte RADIUS Code (`1` Access-Request, `2`\n  Access-Accept, `3` Access-Reject, `4` Accounting-Request, `5`\n  Accounting-Response, `11` Access-Challenge) and selects UDP `1812` or `1813`.\n- **Token**: `accessrequest`\n  - **Scopes**: radius\n  - **Syntax**: `accessrequest | accessaccept | accessreject | accesschallenge |\n  accountingrequest | accountingresponse`\n  - **Value / Range**: RADIUS packet code keyword (or `code \"<text>\"`)\n  - **Default**: accessrequest (Code 1, UDP 1812)\n  - **Summary**: Sets the 1-byte RADIUS Code (`1` Access-Request, `2`\n  Access-Accept, `3` Access-Reject, `4` Accounting-Request, `5`\n  Accounting-Response, `11` Access-Challenge) and selects UDP `1812` or `1813`.\n- **Token**: `accookie`\n  - **Scopes**: pppoe\n  - **Syntax**: `accookie \"<hex>\"`\n  - **Value / Range**: Quoted hex byte string\n  - **Default**: Omitted unless set\n  - **Summary**: Encodes Discovery Tag `0x0104` (`AC-Cookie` SYN-cookie-style\n  anti-spoofing token).\n- **Token**: `accountingrequest`\n  - **Scopes**: radius\n  - **Syntax**: `accessrequest | accessaccept | accessreject | accesschallenge |\n  accountingrequest | accountingresponse`\n  - **Value / Range**: RADIUS packet code keyword (or `code \"<text>\"`)\n  - **Default**: accessrequest (Code 1, UDP 1812)\n  - **Summary**: Sets the 1-byte RADIUS Code (`1` Access-Request, `2`\n  Access-Accept, `3` Access-Reject, `4` Accounting-Request, `5`\n  Accounting-Response, `11` Access-Challenge) and selects UDP `1812` or `1813`.\n- **Token**: `accountingresponse`\n  - **Scopes**: radius\n  - **Syntax**: `accessrequest | accessaccept | accessreject | accesschallenge |\n  accountingrequest | accountingresponse`\n  - **Value / Range**: RADIUS packet code keyword (or `code \"<text>\"`)\n  - **Default**: accessrequest (Code 1, UDP 1812)\n  - **Summary**: Sets the 1-byte RADIUS Code (`1` Access-Request, `2`\n  Access-Accept, `3` Access-Reject, `4` Accounting-Request, `5`\n  Accounting-Response, `11` Access-Challenge) and selects UDP `1812` or `1813`.\n- **Token**: `acct`\n  - **Scopes**: tacacs\n  - **Syntax**: `authen | author | acct | type <authen|author|acct>`\n  - **Value / Range**: TACACS+ AAA packet type\n  - **Default**: authen (0x01)\n  - **Summary**: Selects TACACS+ Type `0x01` Authentication (`authen`), `0x02`\n  Authorization (`author`), or `0x03` Accounting (`acct`).\n- **Token**: `ackreq`\n  - **Scopes**: rocev2\n  - **Syntax**: `ackreq | seqnum <0..16777215>`\n  - **Value / Range**: Acknowledge Request bit (`0x80`) & 24-bit Packet Sequence\n  Number (`PSN`)\n  - **Default**: ackreq off, seqnum 1\n  - **Summary**: Populates BTH bytes 8..11 (`A`-bit in MSB of byte 8 + 24-bit\n  `PSN` in bytes 9..11).\n- **Token**: `acks`\n  - **Scopes**: kafka\n  - **Syntax**: `kafka ... acks <i16>`\n  - **Value / Range**: Parameter <i16>\n  - **Default**: TCP / UDP (9092)\n  - **Summary**: Configures the `acks` PDU selector or header field on `kafka`\n  frames.\n- **Token**: `acname`\n  - **Scopes**: pppoe\n  - **Syntax**: `acname \"<text>\"`\n  - **Value / Range**: Quoted Access Concentrator name\n  - **Default**: Omitted unless set (or \"AC\" on PADO)\n  - **Summary**: Encodes Discovery Tag `0x0102` (`AC-Name` advertised by the BNG\n  in `pado`).\n- **Token**: `actorkey`\n  - **Scopes**: lacp\n  - **Syntax**: `actorkey <0..65535> | actorport <0..65535>`\n  - **Value / Range**: 16-bit unsigned integers\n  - **Default**: actorkey 1, actorport 1\n  - **Summary**: Sets the Actor Operational Key (LAG ID) and Actor Port Number.\n- **Token**: `actorport`\n  - **Scopes**: lacp\n  - **Syntax**: `actorkey <0..65535> | actorport <0..65535>`\n  - **Value / Range**: 16-bit unsigned integers\n  - **Default**: actorkey 1, actorport 1\n  - **Summary**: Sets the Actor Operational Key (LAG ID) and Actor Port Number.\n- **Token**: `actorstate`\n  - **Scopes**: lacp\n  - **Syntax**: `actorstate <0..255>`\n  - **Value / Range**: 8-bit IEEE 802.1AX state bitmask\n  - **Default**: 0x3d\n  - **Summary**: Bitmask: `0x01` Activity, `0x02` Timeout (1=Short 1s), `0x04`\n  Aggregation, `0x08` Sync, `0x10` Collecting, `0x20` Distributing, `0x40`\n  Defaulted, `0x80` Expired.\n- **Token**: `actorsys`\n  - **Scopes**: lacp\n  - **Syntax**: `actorsys <mac>`\n  - **Value / Range**: 48-bit MAC address\n  - **Default**: Source host MAC\n  - **Summary**: Sets the 6-byte Actor System MAC identifier inside TLV `0x01`.\n- **Token**: `addr`\n  - **Scopes**: cdp, ethercat, gtpc, rocev2, modbus, hartip (+8 more)\n  - **Syntax**: `addr <ip>`\n  - **Value / Range**: IPv4 or IPv6 literal\n  - **Default**: Source host IP when present\n  - **Summary**: Used across `cdp`, `ethercat`, `gtpc`, `rocev2`, `modbus`,\n  `hartip`, `fins`, `melsec`, `gesrtp`, `rocplus`, `bsap`, `wsdiscovery`, `socks`,\n  `sccp`: Encodes TLV `0x0002` (Management Address list entry with NLPID protocol\n  header).\n- **Token**: `ado`\n  - **Scopes**: ethercat\n  - **Syntax**: `ado <0..65535> | offset <0..65535>`\n  - **Value / Range**: 16-bit ESC Register / High Word Offset (e.g. 0x0130)\n  - **Default**: 0\n  - **Summary**: Sets the little-endian 16-bit `ADO` physical memory/register\n  offset (`offset` is an exact alias).\n- **Token**: `adp`\n  - **Scopes**: ethercat\n  - **Syntax**: `adp <0..65535> | addr <0..65535>`\n  - **Value / Range**: 16-bit Slave Position / Configured / Logical Base Address\n  - **Default**: 0\n  - **Summary**: Sets the little-endian 16-bit `ADP` / low address word (`addr` is\n  validated `0..=65535` at compile time).\n- **Token**: `advertise`\n  - **Scopes**: dhcp\n  - **Syntax**: `discover | offer | request | ack | release | solicit | advertise\n  | reply`\n  - **Value / Range**: DHCPv4 / DHCPv6 message type keyword\n  - **Default**: discover (IPv4) / solicit (IPv6)\n  - **Summary**: Sets DHCPv4 Option `53` + BOOTP `op` (`1` request, `2` reply) or\n  DHCPv6 `msg-type` (`1` Solicit, `2` Advertise, `3` Request, `7` Reply, `8`\n  Release).\n- **Token**: `advint`\n  - **Scopes**: vrrp\n  - **Syntax**: `advint <0..65535>`\n  - **Value / Range**: u8 seconds (v2) or 12-bit centiseconds (v3)\n  - **Default**: 1 (v2) / 100 (v3)\n  - **Summary**: Sets Advertisement Interval (`1` second in VRRPv2; `100`\n  centiseconds = `1.00s` in VRRPv3).\n- **Token**: `aes`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `priv des | aes \"<password>\"`\n  - **Value / Range**: `des` (CBC-DES) or `aes` (AES-128-CFB) + passphrase\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Encrypts the `ScopedPDU`\n  (`authPriv`, requires `auth`) and populates the 8-byte `msgPrivacyParameters`\n  salt/IV.\n- **Token**: `agentip`\n  - **Scopes**: snmp1, sflow, snmp2, snmp3\n  - **Syntax**: `agentip <ipv4>`\n  - **Value / Range**: IPv4 dotted-quad literal\n  - **Default**: Source IPv4 (or 0.0.0.0 on IPv6)\n  - **Summary**: Used across `snmp1`, `sflow`, `snmp2`, `snmp3`: Sets the 4-byte\n  `NetworkAddress` (`agent-addr`) inside SNMPv1 `trap` PDUs.\n- **Token**: `alert`\n  - **Scopes**: tls\n  - **Syntax**: `clienthello | serverhello | certificate | finished | appdata |\n  alert`\n  - **Value / Range**: TLS record / handshake message type\n  - **Default**: clienthello\n  - **Summary**: Selects Handshake (`22`: `clienthello`, `serverhello`,\n  `certificate`, `finished`), Application Data (`23`: `appdata`), or Alert (`21`:\n  `alert`).\n- **Token**: `alerting`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... alerting`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `alerting` PDU selector or header field on `h323`\n  frames.\n- **Token**: `alivecheckreq`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `alivecheckresp`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `allocate`\n  - **Scopes**: turn\n  - **Syntax**: `turn ... allocate`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Configures the `allocate` PDU selector or header field on `turn`\n  frames.\n- **Token**: `alpn`\n  - **Scopes**: tls\n  - **Syntax**: `alpn \"<text>\"`\n  - **Value / Range**: Quoted protocol ID (`\"h2\"`, `\"http/1.1\"`, `\"mqtt\"`)\n  - **Default**: Omitted unless set\n  - **Summary**: Adds TLS Extension `0x0010` (Application-Layer Protocol\n  Negotiation) to `clienthello`.\n- **Token**: `altercontext`\n  - **Scopes**: dcerpc\n  - **Syntax**: `dcerpc ... altercontext`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (135)\n  - **Summary**: Configures the `altercontext` PDU selector or header field on\n  `dcerpc` frames.\n- **Token**: `amfueid`\n  - **Scopes**: ngap\n  - **Syntax**: `amfueid <number> | ranueid <number>`\n  - **Value / Range**: 40-bit AMF-UE-NGAP-ID (IE 10) & 32-bit RAN-UE-NGAP-ID (IE\n  85)\n  - **Default**: amfueid 1, ranueid 1 on UE messages\n  - **Summary**: Encodes APER integer IEs correlating a specific UE across N2\n  uplink and downlink NAS messages.\n- **Token**: `an`\n  - **Scopes**: macsec\n  - **Syntax**: `an <0..3>`\n  - **Value / Range**: 2-bit Association Number (0..3)\n  - **Default**: 0\n  - **Summary**: Sets the active SAK Association Number in the low 2 bits of the\n  TCI/AN byte.\n- **Token**: `announce`\n  - **Scopes**: rpkirtr, ptp\n  - **Syntax**: `announce | withdraw | flags <0..255>`\n  - **Value / Range**: ROA announcement flag (`1`) or withdrawal (`0`)\n  - **Default**: announce (flags 1)\n  - **Summary**: Used across `rpkirtr`, `ptp`: Sets the `Flags` byte in\n  `ipv4prefix` / `ipv6prefix` PDUs (`1` announce VRP, `0` withdraw VRP).\n- **Token**: `announcement`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `ansttl`\n  - **Scopes**: dns, mdns, llmnr, nbns, doh\n  - **Syntax**: `ansttl <number>`\n  - **Value / Range**: Whole number (seconds)\n  - **Default**: 300\n  - **Summary**: Used across `dns`, `mdns`, `llmnr`, `nbns`, `doh`: Sets the\n  32-bit caching TTL inside the Answer Resource Record (never `ans_ttl`).\n- **Token**: `apikey`\n  - **Scopes**: kafka\n  - **Syntax**: `kafka ... apikey <str|u16>`\n  - **Value / Range**: Parameter <str|u16>\n  - **Default**: TCP / UDP (9092)\n  - **Summary**: Configures the `apikey` PDU selector or header field on `kafka`\n  frames.\n- **Token**: `apiversions`\n  - **Scopes**: kafka\n  - **Syntax**: `kafka ... apiversions`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP / UDP (9092)\n  - **Summary**: Configures the `apiversions` PDU selector or header field on\n  `kafka` frames.\n- **Token**: `apn`\n  - **Scopes**: gtpc\n  - **Syntax**: `apn \"<text>\"`\n  - **Value / Range**: Access Point Name string (IE Type 71)\n  - **Default**: Omitted\n  - **Summary**: Appends IE Type `71` (`APN`, e.g. `\"internet\"` or\n  `\"ims.mnc001.mcc001.gprs\"`).\n- **Token**: `app`\n  - **Scopes**: syslog, rtcp\n  - **Syntax**: `hostname \"<text>\" | app \"<text>\" | procid \"<text>\" | msgid\n  \"<text>\"`\n  - **Value / Range**: Quoted text fields\n  - **Default**: Standard RFC 5424 defaults\n  - **Summary**: Used across `syslog`, `rtcp`: Populates the structured RFC 5424\n  header fields before the log message body.\n- **Token**: `appdata`\n  - **Scopes**: tls\n  - **Syntax**: `clienthello | serverhello | certificate | finished | appdata |\n  alert`\n  - **Value / Range**: TLS record / handshake message type\n  - **Default**: clienthello\n  - **Summary**: Selects Handshake (`22`: `clienthello`, `serverhello`,\n  `certificate`, `finished`), Application Data (`23`: `appdata`), or Alert (`21`:\n  `alert`).\n- **Token**: `appid`\n  - **Scopes**: goose, sv, diameter\n  - **Syntax**: `appid <0..65535>`\n  - **Value / Range**: 16-bit IEC 61850 APPID (typically 0x0000..0x3fff or\n  0x8000..0xbfff)\n  - **Default**: 0x1000\n  - **Summary**: Used across `goose`, `sv`, `diameter`: Sets bytes 0..1 of the\n  8-byte GOOSE header.\n- **Token**: `area`\n  - **Scopes**: isis, s7comm, fins, gesrtp\n  - **Syntax**: `area \"<text>\"`\n  - **Value / Range**: Hex ISO Area Address (e.g. \"49.0001\")\n  - **Default**: \"49.0001\"\n  - **Summary**: Used across `isis`, `s7comm`, `fins`, `gesrtp`: Encodes Area\n  Addresses TLV `1` inside Hello and LSP PDUs.\n- **Token**: `areaid`\n  - **Scopes**: ospf\n  - **Syntax**: `areaid <u32|ipv4>`\n  - **Value / Range**: u32 integer (0) or dotted-quad (0.0.0.0)\n  - **Default**: 0 (Backbone Area 0.0.0.0)\n  - **Summary**: Sets the 32-bit OSPF Area ID.\n- **Token**: `arg`\n  - **Scopes**: ftp, imap, pop3\n  - **Syntax**: `arg \"<text>\"`\n  - **Value / Range**: Quoted command argument (username, path, etc.)\n  - **Default**: Omitted unless set\n  - **Summary**: Used across `ftp`, `imap`, `pop3`: Appends a space and argument\n  after `cmd` before `\\r\\n`.\n- **Token**: `args`\n  - **Scopes**: redis\n  - **Syntax**: `key \"<text>\" | value \"<text>\" | args \"<text>\"`\n  - **Value / Range**: Quoted key, value, or extra arguments\n  - **Default**: key \"mykey\" on get/set\n  - **Summary**: Populates subsequent `$len\\r\\n...` elements in requests or\n  payload text in server replies.\n- **Token**: `asn`\n  - **Scopes**: bgp, bmp, rpkirtr\n  - **Syntax**: `asn <number>`\n  - **Value / Range**: 16-bit or 32-bit Autonomous System Number\n  - **Default**: 65001\n  - **Summary**: Used across `bgp`, `bmp`, `rpkirtr`: Sets the Autonomous System\n  in `open` (`<= 65535` direct; `> 65535` `AS_TRANS` `23456` + Capability `65`)\n  and `AS_PATH` in `update`.\n- **Token**: `asrep`\n  - **Scopes**: kerberos\n  - **Syntax**: `asreq | asrep | tgsreq | tgsrep | krberror`\n  - **Value / Range**: Kerberos v5 message type\n  - **Default**: asreq (msg-type 10)\n  - **Summary**: Selects Authentication Service Request/Reply (`10`/`11`),\n  Ticket-Granting Service Request/Reply (`12`/`13`), or Error (`30`).\n- **Token**: `asreq`\n  - **Scopes**: kerberos\n  - **Syntax**: `asreq | asrep | tgsreq | tgsrep | krberror`\n  - **Value / Range**: Kerberos v5 message type\n  - **Default**: asreq (msg-type 10)\n  - **Summary**: Selects Authentication Service Request/Reply (`10`/`11`),\n  Ticket-Granting Service Request/Reply (`12`/`13`), or Error (`30`).\n- **Token**: `associationsetuprequest`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `associationsetupresponse`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `attention`\n  - **Scopes**: mssql\n  - **Syntax**: `mssql ... attention`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP / UDP (1433)\n  - **Summary**: Configures the `attention` PDU selector or header field on\n  `mssql` frames.\n- **Token**: `aucx`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... aucx`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `aucx` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `auep`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... auep`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `auep` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `auth`\n  - **Scopes**: ikev2, hsrp, glbp, snmp3, snmp1, snmp2\n  - **Syntax**: `sainit | auth | createchildsa | informational | exchange <...>`\n  - **Value / Range**: RFC 7296 Exchange Type keyword or u8\n  - **Default**: sainit (34)\n  - **Summary**: Used across `ikev2`, `hsrp`, `glbp`, `snmp3`, `snmp1`, `snmp2`:\n  Sets Exchange Type: `sainit` (`34` IKE_SA_INIT), `auth` (`35` IKE_AUTH),\n  `createchildsa` (`36` CREATE_CHILD_SA), `informational` (`37` INFORMATIONAL).\n- **Token**: `authen`\n  - **Scopes**: tacacs\n  - **Syntax**: `authen | author | acct | type <authen|author|acct>`\n  - **Value / Range**: TACACS+ AAA packet type\n  - **Default**: authen (0x01)\n  - **Summary**: Selects TACACS+ Type `0x01` Authentication (`authen`), `0x02`\n  Authorization (`author`), or `0x03` Accounting (`acct`).\n- **Token**: `authenticate`\n  - **Scopes**: ntlm\n  - **Syntax**: `ntlm ... authenticate`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (80)\n  - **Summary**: Configures the `authenticate` PDU selector or header field on\n  `ntlm` frames.\n- **Token**: `authok`\n  - **Scopes**: postgres\n  - **Syntax**: `startup | authok | query | commandcomplete | readyforquery |\n  errorresponse`\n  - **Value / Range**: PostgreSQL v3.0 message type\n  - **Default**: query ('Q')\n  - **Summary**: Selects untagged `StartupMessage` (`startup`), `'R'` AuthOK\n  (`authok`), `'Q'` Simple Query (`query`), `'C'` CommandComplete, `'Z'`\n  ReadyForQuery, or `'E'` ErrorResponse.\n- **Token**: `author`\n  - **Scopes**: tacacs\n  - **Syntax**: `authen | author | acct | type <authen|author|acct>`\n  - **Value / Range**: TACACS+ AAA packet type\n  - **Default**: authen (0x01)\n  - **Summary**: Selects TACACS+ Type `0x01` Authentication (`authen`), `0x02`\n  Authorization (`author`), or `0x03` Accounting (`acct`).\n- **Token**: `banner`\n  - **Scopes**: ssh\n  - **Syntax**: `banner \"<text>\"`\n  - **Value / Range**: Quoted SSH identification string (e.g.\n  \"SSH-2.0-OpenSSH_9.7\")\n  - **Default**: \"SSH-2.0-OpenSSH_9.6\"\n  - **Summary**: Emits the cleartext `\\r\\n`-terminated SSH version banner.\n- **Token**: `basedn`\n  - **Scopes**: ldap\n  - **Syntax**: `basedn \"<text>\"`\n  - **Value / Range**: Quoted Distinguished Name (`\"dc=corp,dc=internal\"`)\n  - **Default**: \"dc=example,dc=com\"\n  - **Summary**: Sets the Bind DN on `bindreq`, Base Object on `searchreq`, or\n  Object Name on `searchentry`.\n- **Token**: `basicdeliver`\n  - **Scopes**: amqp\n  - **Syntax**: `protocolheader | connectionstart | channelopen | basicpublish |\n  basicdeliver | heartbeat`\n  - **Value / Range**: AMQP 0-9-1 frame/method selector\n  - **Default**: basicpublish (channel 1)\n  - **Summary**: Selects the 8-byte AMQP header, Method frame (`Type 1`), or\n  Heartbeat frame (`Type 8`).\n- **Token**: `basicpublish`\n  - **Scopes**: amqp\n  - **Syntax**: `protocolheader | connectionstart | channelopen | basicpublish |\n  basicdeliver | heartbeat`\n  - **Value / Range**: AMQP 0-9-1 frame/method selector\n  - **Default**: basicpublish (channel 1)\n  - **Summary**: Selects the 8-byte AMQP header, Method frame (`Type 1`), or\n  Heartbeat frame (`Type 8`).\n- **Token**: `bgpid`\n  - **Scopes**: bgp, bmp\n  - **Syntax**: `bgpid <ipv4>`\n  - **Value / Range**: 32-bit dotted-quad identifier\n  - **Default**: Source IPv4 (or 1.1.1.1 on IPv6)\n  - **Summary**: Used across `bgp`, `bmp`: Sets the 4-byte BGP Identifier in\n  `open` messages (always 32-bit dotted-quad on both v4 and v6).\n- **Token**: `binary`\n  - **Scopes**: websocket\n  - **Syntax**: `text | binary | close | ping | pong | opcode \"<text>\"`\n  - **Value / Range**: WebSocket frame opcode\n  - **Default**: text (0x1)\n  - **Summary**: Selects RFC 6455 opcode `0x1` (`text`), `0x2` (`binary`), `0x8`\n  (`close`), `0x9` (`ping`), `0xa` (`pong`), or `\"continuation\"` (`0x0`).\n- **Token**: `bind`\n  - **Scopes**: socks, dcerpc\n  - **Syntax**: `socks ... bind`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (1080)\n  - **Summary**: Used across `socks`, `dcerpc`: Configures the `bind` PDU selector\n  or header field across `socks`, `dcerpc` frames.\n- **Token**: `bindack`\n  - **Scopes**: dcerpc\n  - **Syntax**: `dcerpc ... bindack`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (135)\n  - **Summary**: Configures the `bindack` PDU selector or header field on `dcerpc`\n  frames.\n- **Token**: `bindingerror`\n  - **Scopes**: stun\n  - **Syntax**: `bindingrequest | bindingresponse | bindingerror`\n  - **Value / Range**: STUN message class/method\n  - **Default**: bindingrequest (0x0001)\n  - **Summary**: Selects STUN Binding Request (`0x0001`), Binding Success Response\n  (`0x0101`), or Binding Error Response (`0x0111`).\n- **Token**: `bindingrequest`\n  - **Scopes**: stun\n  - **Syntax**: `bindingrequest | bindingresponse | bindingerror`\n  - **Value / Range**: STUN message class/method\n  - **Default**: bindingrequest (0x0001)\n  - **Summary**: Selects STUN Binding Request (`0x0001`), Binding Success Response\n  (`0x0101`), or Binding Error Response (`0x0111`).\n- **Token**: `bindingresponse`\n  - **Scopes**: stun\n  - **Syntax**: `bindingrequest | bindingresponse | bindingerror`\n  - **Value / Range**: STUN message class/method\n  - **Default**: bindingrequest (0x0001)\n  - **Summary**: Selects STUN Binding Request (`0x0001`), Binding Success Response\n  (`0x0101`), or Binding Error Response (`0x0111`).\n- **Token**: `bindnak`\n  - **Scopes**: dcerpc\n  - **Syntax**: `dcerpc ... bindnak`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (135)\n  - **Summary**: Configures the `bindnak` PDU selector or header field on `dcerpc`\n  frames.\n- **Token**: `bindreq`\n  - **Scopes**: ldap\n  - **Syntax**: `bindreq | bindres | searchreq | searchentry | searchdone |\n  unbindreq`\n  - **Value / Range**: LDAPv3 protocol operation keyword\n  - **Default**: searchreq\n  - **Summary**: Selects the ASN.1 BER `protocolOp` tag inside `LDAPMessage`.\n- **Token**: `bindres`\n  - **Scopes**: ldap\n  - **Syntax**: `bindreq | bindres | searchreq | searchentry | searchdone |\n  unbindreq`\n  - **Value / Range**: LDAPv3 protocol operation keyword\n  - **Default**: searchreq\n  - **Summary**: Selects the ASN.1 BER `protocolOp` tag inside `LDAPMessage`.\n- **Token**: `block`\n  - **Scopes**: tftp\n  - **Syntax**: `block <0..65535>`\n  - **Value / Range**: 16-bit block number\n  - **Default**: 1\n  - **Summary**: Sets the 2-byte Block Number in `data` and `ack` packets (`0`\n  acknowledges a `wrq`).\n- **Token**: `body`\n  - **Scopes**: http, sip, smtp, netconf, mgcp\n  - **Syntax**: `body \"<text>\"`\n  - **Value / Range**: Quoted response or request payload\n  - **Default**: Empty\n  - **Summary**: Used across `http`, `sip`, `smtp`, `netconf`, `mgcp`: Appends the\n  HTTP body after `\\r\\n\\r\\n` and calculates `Content-Length` automatically.\n- **Token**: `bridgeid`\n  - **Scopes**: stp\n  - **Syntax**: `bridgeid \"<text>\"`\n  - **Value / Range**: Bridge ID string (\"<prio>:<mac>\" or \"<mac>\")\n  - **Default**: \"32768:<src_mac>\"\n  - **Summary**: Encodes the 8-byte Bridge Identifier of the transmitting switch.\n- **Token**: `button`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... button <u32>`\n  - **Value / Range**: Parameter <u32>\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `button` PDU selector or header field on `sccp`\n  frames.\n- **Token**: `bye`\n  - **Scopes**: sip, rtcp\n  - **Syntax**: `invite | ack | bye | cancel | register | options | method\n  \"<text>\"`\n  - **Value / Range**: SIP request method\n  - **Default**: invite\n  - **Summary**: Used across `sip`, `rtcp`: Sets the SIP request verb on the start\n  line and inside the `CSeq` header.\n- **Token**: `c2hdata`\n  - **Scopes**: nvmetcp\n  - **Syntax**: `icreq | icresp | read | write | response | h2cdata | c2hdata |\n  r2t | msgtype \"<text>\" | cmd \"<text>\"`\n  - **Value / Range**: NVMe/TCP PDU Type or NVMe Command selector\n  - **Default**: icreq (0x00)\n  - **Summary**: Selects `0x00` ICReq, `0x01` ICResp, `0x04` CapsuleCmd (`read`\n  NVMe `0x02`, `write` NVMe `0x01`), `0x05` CapsuleResp, `0x06` H2CData, `0x07`\n  C2HData, or `0x09` R2T.\n- **Token**: `ca`\n  - **Scopes**: iec104\n  - **Syntax**: `ca <0..65535> | ioa <0..16777215>`\n  - **Value / Range**: 16-bit Common Address of ASDU & 24-bit Information Object\n  Address\n  - **Default**: ca 1, ioa 1\n  - **Summary**: Writes the 2-byte little-endian station `CA` and 3-byte\n  little-endian data-point `IOA`.\n- **Token**: `cachereset`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `serialnotify | serialquery | resetquery | cacheresponse |\n  ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport`\n  - **Value / Range**: RPKI-RTR PDU type keyword\n  - **Default**: ipv4prefix (Type 4)\n  - **Summary**: Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset\n  Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data,\n  `8`=Cache Reset, `10`=Error Report).\n- **Token**: `cacheresponse`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `serialnotify | serialquery | resetquery | cacheresponse |\n  ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport`\n  - **Value / Range**: RPKI-RTR PDU type keyword\n  - **Default**: ipv4prefix (Type 4)\n  - **Summary**: Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset\n  Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data,\n  `8`=Cache Reset, `10`=Error Report).\n- **Token**: `calledap`\n  - **Scopes**: c1222\n  - **Syntax**: `callingap <oid> | calledap <oid>`\n  - **Value / Range**: Dotted ASN.1 OID (unquoted `1.3.6.1...` or quoted\n  `\"1.3.6.1...\"`)\n  - **Default**: 1.3.6.1.4.1.9999.1 / 1.3.6.1.4.1.9999.2\n  - **Summary**: Encodes `Calling-AP-title` (`0xa6`) and `Called-AP-title`\n  (`0xa2`) universal ApTitles.\n- **Token**: `calledid`\n  - **Scopes**: c1222\n  - **Syntax**: `callingid <number> | calledid <number>`\n  - **Value / Range**: 32-bit `AP-invocation-id` integers\n  - **Default**: callingid 1\n  - **Summary**: Encodes `Calling-AP-invocation-id` (`0xa8`) and optional\n  `Called-AP-invocation-id` (`0xa4`).\n- **Token**: `calledparty`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... calledparty <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `calledparty` PDU selector or header field on\n  `h323` frames.\n- **Token**: `callid`\n  - **Scopes**: sip, sccp, mgcp, dcerpc\n  - **Syntax**: `callid \"<text>\" | cseq <number>`\n  - **Value / Range**: Quoted Call-ID string + sequence number\n  - **Default**: callid \"call-1\", cseq 1\n  - **Summary**: Used across `sip`, `sccp`, `mgcp`, `dcerpc`: Links all messages\n  belonging to the same VoIP dialog (`Call-ID:`) and transaction (`CSeq:`).\n- **Token**: `callingap`\n  - **Scopes**: c1222\n  - **Syntax**: `callingap <oid> | calledap <oid>`\n  - **Value / Range**: Dotted ASN.1 OID (unquoted `1.3.6.1...` or quoted\n  `\"1.3.6.1...\"`)\n  - **Default**: 1.3.6.1.4.1.9999.1 / 1.3.6.1.4.1.9999.2\n  - **Summary**: Encodes `Calling-AP-title` (`0xa6`) and `Called-AP-title`\n  (`0xa2`) universal ApTitles.\n- **Token**: `callingid`\n  - **Scopes**: c1222\n  - **Syntax**: `callingid <number> | calledid <number>`\n  - **Value / Range**: 32-bit `AP-invocation-id` integers\n  - **Default**: callingid 1\n  - **Summary**: Encodes `Calling-AP-invocation-id` (`0xa8`) and optional\n  `Called-AP-invocation-id` (`0xa4`).\n- **Token**: `callingparty`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... callingparty <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `callingparty` PDU selector or header field on\n  `h323` frames.\n- **Token**: `callproceeding`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... callproceeding`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `callproceeding` PDU selector or header field on\n  `h323` frames.\n- **Token**: `callref`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... callref <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `callref` PDU selector or header field on `h323`\n  frames.\n- **Token**: `callstate`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... callstate`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `callstate` PDU selector or header field on `sccp`\n  frames.\n- **Token**: `cancel`\n  - **Scopes**: sip\n  - **Syntax**: `invite | ack | bye | cancel | register | options | method\n  \"<text>\"`\n  - **Value / Range**: SIP request method\n  - **Default**: invite\n  - **Summary**: Sets the SIP request verb on the start line and inside the `CSeq`\n  header.\n- **Token**: `capabilities`\n  - **Scopes**: cdp\n  - **Syntax**: `capabilities <number>`\n  - **Value / Range**: 32-bit capability bitmask\n  - **Default**: 0x00000028 (Switch + IGMP)\n  - **Summary**: Encodes TLV `0x0004` (`0x01` Router, `0x08` Switch, `0x10` Host,\n  `0x20` IGMP, `0x80` VoIP Phone).\n- **Token**: `capability`\n  - **Scopes**: netconf\n  - **Syntax**: `netconf ... capability <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP (830)\n  - **Summary**: Configures the `capability` PDU selector or header field on\n  `netconf` frames.\n- **Token**: `cas`\n  - **Scopes**: memcached\n  - **Syntax**: `opcode <hex_or_num> [opaque <hex_or_num>] [cas <hex_or_num>]`\n  - **Value / Range**: Binary protocol opcode (`0x00` Get, `0x01` Set, `0x07`\n  Quit)\n  - **Default**: Omitted (uses ASCII mode)\n  - **Summary**: Switches the packet to the 24-byte `0x80` Memcached Binary\n  Protocol.\n- **Token**: `cause`\n  - **Scopes**: gtpc, pfcp, h323\n  - **Syntax**: `cause <0..255>`\n  - **Value / Range**: 8-bit GTPv2 Cause value (IE Type 2)\n  - **Default**: 16 (Request accepted) on responses\n  - **Summary**: Used across `gtpc`, `pfcp`, `h323`: Appends the Cause TLV IE\n  (`16` Request accepted, `64` Context not found, `72` No resources available).\n- **Token**: `cca`\n  - **Scopes**: diameter\n  - **Syntax**: `cer | cea | dwr | dwa | ccr | cca | request | response |\n  cmd|command \"<text_or_num>\"`\n  - **Value / Range**: Diameter Command shorthand or 24-bit Command-Code (e.g. 318\n  ULR/ULA)\n  - **Default**: cer (257 Request)\n  - **Summary**: Selects `257` Capabilities-Exchange (`cer`/`cea`), `280`\n  Device-Watchdog (`dwr`/`dwa`), `272` Credit-Control (`ccr`/`cca`), or any custom\n  3GPP Command-Code (e.g. `cmd 316` S6a ULR, `cmd 318` AIA).\n- **Token**: `ccr`\n  - **Scopes**: diameter\n  - **Syntax**: `cer | cea | dwr | dwa | ccr | cca | request | response |\n  cmd|command \"<text_or_num>\"`\n  - **Value / Range**: Diameter Command shorthand or 24-bit Command-Code (e.g. 318\n  ULR/ULA)\n  - **Default**: cer (257 Request)\n  - **Summary**: Selects `257` Capabilities-Exchange (`cer`/`cea`), `280`\n  Device-Watchdog (`dwr`/`dwa`), `272` Credit-Control (`ccr`/`cca`), or any custom\n  3GPP Command-Code (e.g. `cmd 316` S6a ULR, `cmd 318` AIA).\n- **Token**: `cea`\n  - **Scopes**: diameter\n  - **Syntax**: `cer | cea | dwr | dwa | ccr | cca | request | response |\n  cmd|command \"<text_or_num>\"`\n  - **Value / Range**: Diameter Command shorthand or 24-bit Command-Code (e.g. 318\n  ULR/ULA)\n  - **Default**: cer (257 Request)\n  - **Summary**: Selects `257` Capabilities-Exchange (`cer`/`cea`), `280`\n  Device-Watchdog (`dwr`/`dwa`), `272` Credit-Control (`ccr`/`cca`), or any custom\n  3GPP Command-Code (e.g. `cmd 316` S6a ULR, `cmd 318` AIA).\n- **Token**: `cer`\n  - **Scopes**: diameter\n  - **Syntax**: `cer | cea | dwr | dwa | ccr | cca | request | response |\n  cmd|command \"<text_or_num>\"`\n  - **Value / Range**: Diameter Command shorthand or 24-bit Command-Code (e.g. 318\n  ULR/ULA)\n  - **Default**: cer (257 Request)\n  - **Summary**: Selects `257` Capabilities-Exchange (`cer`/`cea`), `280`\n  Device-Watchdog (`dwr`/`dwa`), `272` Credit-Control (`ccr`/`cca`), or any custom\n  3GPP Command-Code (e.g. `cmd 316` S6a ULR, `cmd 318` AIA).\n- **Token**: `certificate`\n  - **Scopes**: tls\n  - **Syntax**: `clienthello | serverhello | certificate | finished | appdata |\n  alert`\n  - **Value / Range**: TLS record / handshake message type\n  - **Default**: clienthello\n  - **Summary**: Selects Handshake (`22`: `clienthello`, `serverhello`,\n  `certificate`, `finished`), Application Data (`23`: `appdata`), or Alert (`21`:\n  `alert`).\n- **Token**: `chaddr`\n  - **Scopes**: dhcp\n  - **Syntax**: `chaddr <mac>`\n  - **Value / Range**: Colon, hyphen, or Cisco dot MAC\n  - **Default**: Source host MAC\n  - **Summary**: Populates the 16-byte Client Hardware Address field in DHCPv4.\n- **Token**: `challenge`\n  - **Scopes**: ntlm\n  - **Syntax**: `ntlm ... challenge`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (80)\n  - **Summary**: Configures the `challenge` PDU selector or header field on `ntlm`\n  frames.\n- **Token**: `changed`\n  - **Scopes**: coap\n  - **Syntax**: `get | post | put | delete | created | changed | notfound | code\n  \"<c.dd>\"`\n  - **Value / Range**: Shorthand keyword OR dotted code (`\"0.01\"`..`\"5.05\"`,\n  choose one)\n  - **Default**: get (\"0.01\")\n  - **Summary**: Encodes byte 1 (`(class << 5) | detail`, e.g. `\"2.05\"` Content =\n  `0x45`).\n- **Token**: `channel`\n  - **Scopes**: amqp, knxnetip, irc, turn\n  - **Syntax**: `channel <0..65535>`\n  - **Value / Range**: 16-bit AMQP channel number (`0` for connection/heartbeat,\n  `>= 1` for work channels)\n  - **Default**: 1 (0 on connectionstart/heartbeat)\n  - **Summary**: Used across `amqp`, `knxnetip`, `irc`, `turn`: Sets bytes 1..2 of\n  the 7-byte AMQP frame header.\n- **Token**: `channelbind`\n  - **Scopes**: turn\n  - **Syntax**: `turn ... channelbind`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Configures the `channelbind` PDU selector or header field on\n  `turn` frames.\n- **Token**: `channeldata`\n  - **Scopes**: turn\n  - **Syntax**: `turn ... channeldata`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Configures the `channeldata` PDU selector or header field on\n  `turn` frames.\n- **Token**: `channelopen`\n  - **Scopes**: amqp\n  - **Syntax**: `protocolheader | connectionstart | channelopen | basicpublish |\n  basicdeliver | heartbeat`\n  - **Value / Range**: AMQP 0-9-1 frame/method selector\n  - **Default**: basicpublish (channel 1)\n  - **Summary**: Selects the 8-byte AMQP header, Method frame (`Type 1`), or\n  Heartbeat frame (`Type 8`).\n- **Token**: `chassisid`\n  - **Scopes**: lldp\n  - **Syntax**: `chassisid \"<text>\"`\n  - **Value / Range**: Quoted string or identifier\n  - **Default**: \"switch\"\n  - **Summary**: Encodes Mandatory TLV Type 1 (Chassis ID) with Locally Assigned\n  subtype.\n- **Token**: `checksum`\n  - **Scopes**: gre\n  - **Syntax**: `checksum`\n  - **Value / Range**: Bare boolean flag\n  - **Default**: Omitted (C=0)\n  - **Summary**: Sets Checksum Present bit (`0x8000`) and inserts the computed\n  2-byte GRE Checksum + 2-byte Reserved1 (`0x0000`).\n- **Token**: `chunk`\n  - **Scopes**: sctp\n  - **Syntax**: `sctp [chunk <type> | data | init | initack | sack | heartbeat |\n  heartbeatack | abort | shutdown | shutdownack | shutdowncomplete | cookieecho |\n  cookieack] [vtag <number>] [tsn <number>] [stream <0..65535>] [ssn <0..65535>]\n  [ppid <number>]`\n  - **Value / Range**: SCTP (CRC-32c) modifier\n  - **Default**: IP Proto 132 (38412 NGAP / 36412 S1AP)\n  - **Summary**: Sets `chunk` on `sctp` frames.\n- **Token**: `chunked`\n  - **Scopes**: netconf\n  - **Syntax**: `netconf ... chunked`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (830)\n  - **Summary**: Configures the `chunked` PDU selector or header field on\n  `netconf` frames.\n- **Token**: `chunktype`\n  - **Scopes**: opcua\n  - **Syntax**: `chunktype \"<F|C|A>\"`\n  - **Value / Range**: `\"F\"` Final chunk, `\"C\"` Intermediate chunk, `\"A\"` Abort\n  - **Default**: \"F\"\n  - **Summary**: Sets byte 3 (`IsFinal`) of the 8-byte OPC UA Binary header.\n- **Token**: `ciaddr`\n  - **Scopes**: dhcp\n  - **Syntax**: `ciaddr <ipv4> | yiaddr <ipv4> | siaddr <ipv4>`\n  - **Value / Range**: IPv4 dotted-quad literals\n  - **Default**: 0.0.0.0\n  - **Summary**: Sets Client IP, Your (offered) IP, and Next Server IP in the\n  DHCPv4 BOOTP header.\n- **Token**: `cipattr`\n  - **Scopes**: ethernetip\n  - **Syntax**: `cipclass <hex_or_num> | cipinstance <number> | cipattr <number>`\n  - **Value / Range**: CIP Object Class (`0x01` Identity, `0x04` Assembly, `0x6b`\n  Symbol), Instance, and Attribute\n  - **Default**: cipclass 0x01, cipinstance 1, cipattr 1\n  - **Summary**: Encodes the logical EPATH segments targeting the PLC CIP object.\n- **Token**: `cipclass`\n  - **Scopes**: ethernetip\n  - **Syntax**: `cipclass <hex_or_num> | cipinstance <number> | cipattr <number>`\n  - **Value / Range**: CIP Object Class (`0x01` Identity, `0x04` Assembly, `0x6b`\n  Symbol), Instance, and Attribute\n  - **Default**: cipclass 0x01, cipinstance 1, cipattr 1\n  - **Summary**: Encodes the logical EPATH segments targeting the PLC CIP object.\n- **Token**: `ciphersuite`\n  - **Scopes**: tls\n  - **Syntax**: `ciphersuite <hex>`\n  - **Value / Range**: 16-bit IANA cipher code (`0x1301` AES-128-GCM, `0x1302`\n  AES-256-GCM, `0x1303` ChaCha20)\n  - **Default**: 0x1301\n  - **Summary**: Sets the offered or selected Cipher Suite in `clienthello` /\n  `serverhello`.\n- **Token**: `cipinstance`\n  - **Scopes**: ethernetip\n  - **Syntax**: `cipclass <hex_or_num> | cipinstance <number> | cipattr <number>`\n  - **Value / Range**: CIP Object Class (`0x01` Identity, `0x04` Assembly, `0x6b`\n  Symbol), Instance, and Attribute\n  - **Default**: cipclass 0x01, cipinstance 1, cipattr 1\n  - **Summary**: Encodes the logical EPATH segments targeting the PLC CIP object.\n- **Token**: `cipservice`\n  - **Scopes**: ethernetip\n  - **Syntax**: `cipservice <hex_or_num>`\n  - **Value / Range**: CIP Service Code (`0x01` Get_Attributes_All, `0x0e`\n  Get_Attribute_Single, `0x10` Set_Attribute_Single, `0x4c` Read_Tag)\n  - **Default**: 0x0e (Get_Attribute_Single)\n  - **Summary**: Sets the CIP Service byte inside `sendrrdata` / `sendunitdata`.\n- **Token**: `circuittype`\n  - **Scopes**: isis\n  - **Syntax**: `circuittype <0..255>`\n  - **Value / Range**: Circuit Type (1=L1, 2=L2, 3=L1/L2)\n  - **Default**: Matches PDU level (1, 2, or 3)\n  - **Summary**: Sets the 8-bit Circuit Type field inside IIH and LSP headers.\n- **Token**: `clienthello`\n  - **Scopes**: tls\n  - **Syntax**: `clienthello | serverhello | certificate | finished | appdata |\n  alert`\n  - **Value / Range**: TLS record / handshake message type\n  - **Default**: clienthello\n  - **Summary**: Selects Handshake (`22`: `clienthello`, `serverhello`,\n  `certificate`, `finished`), Application Data (`23`: `appdata`), or Alert (`21`:\n  `alert`).\n- **Token**: `clientid`\n  - **Scopes**: mqtt, someip, kafka\n  - **Syntax**: `clientid \"<text>\" | keepalive <0..65535>`\n  - **Value / Range**: Quoted Client ID + keepalive seconds on `connect`\n  - **Default**: clientid \"frameassembly\", keepalive 60\n  - **Summary**: Used across `mqtt`, `someip`, `kafka`: Populates the `CONNECT`\n  payload Client Identifier and Keep Alive timer.\n- **Token**: `clockid`\n  - **Scopes**: ptp\n  - **Syntax**: `clockid \"<text>\"`\n  - **Value / Range**: 16-char EUI-64 hex (\"001c73fffe000001\") or 8B string\n  - **Default**: Derived from source MAC (EUI-64 fffe)\n  - **Summary**: Populates the 8-byte `ClockIdentity` inside the 10-byte\n  `sourcePortIdentity` field.\n- **Token**: `close`\n  - **Scopes**: websocket, smb, hartip\n  - **Syntax**: `text | binary | close | ping | pong | opcode \"<text>\"`\n  - **Value / Range**: WebSocket frame opcode\n  - **Default**: text (0x1)\n  - **Summary**: Used across `websocket`, `smb`, `hartip`: Selects RFC 6455 opcode\n  `0x1` (`text`), `0x2` (`binary`), `0x8` (`close`), `0x9` (`ping`), `0xa`\n  (`pong`), or `\"continuation\"` (`0x0`).\n- **Token**: `cmd`\n  - **Scopes**: ethercat, ftp, diameter, smtp, imap, pop3 (+13 more)\n  - **Syntax**: `nop | read | write | cmd \"<text>\"`\n  - **Value / Range**: Command keyword or ETG mnemonic\n  (\"APRD\",\"APWR\",\"FPRD\",\"FPWR\",\"BRD\",\"BWR\",\"LRD\",\"LWR\",\"LRW\")\n  - **Default**: read (APRD 0x01)\n  - **Summary**: Used across `ethercat`, `ftp`, `diameter`, `smtp`, `imap`,\n  `pop3`, `iscsi`, `nvmetcp`, `redis`, `memcached`, `synchrophasor`, `hartip`,\n  `fins`, `melsec`, `ipmi`, `socks`, `irc`, `mongodb`, `ethernetip`: Sets the\n  8-bit EtherCAT Datagram Command byte (`0x00` NOP, `0x01` APRD, `0x02` APWR,\n  `0x04` FPRD, `0x05` FPWR, `0x07` BRD, `0x0a` LRD, `0x0b` LWR, `0x0c` LRW).\n- **Token**: `cmdsn`\n  - **Scopes**: iscsi\n  - **Syntax**: `itt <number> | cmdsn <number> | statsn <number>`\n  - **Value / Range**: 32-bit Initiator Task Tag, Command SeqNum, and Status\n  SeqNum\n  - **Default**: itt 1, cmdsn 1, statsn 1\n  - **Summary**: Populates BHS bytes 16..19 (`ITT`) and 24..31 (`CmdSN` /\n  `ExpStatSN` / `StatSN`).\n- **Token**: `cname`\n  - **Scopes**: kerberos, rtcp\n  - **Syntax**: `cname \"<text>\" | sname \"<text>\"`\n  - **Value / Range**: Quoted Client Principal Name or Service Principal Name\n  (SPN)\n  - **Default**: cname \"alice\", sname \"krbtgt/EXAMPLE.COM\"\n  - **Summary**: Used across `kerberos`, `rtcp`: Encodes `PrincipalName`\n  components in `KDC-REQ-BODY` / `KDC-REP`.\n- **Token**: `code`\n  - **Scopes**: icmp, ftp, smtp, coap, doip, radius\n  - **Syntax**: `type <0..255> | code <0..255>`\n  - **Value / Range**: 8-bit unsigned integers\n  - **Default**: Derived from shorthand (code 0)\n  - **Summary**: Used across `icmp`, `ftp`, `smtp`, `coap`, `doip`, `radius`:\n  Explicitly overrides the 1-byte ICMP/ICMPv6 Type and Code fields (e.g., `type 2\n  code 0` for ICMPv6 Packet Too Big).\n- **Token**: `collection`\n  - **Scopes**: mongodb\n  - **Syntax**: `mongodb ... collection <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP (27017)\n  - **Summary**: Configures the `collection` PDU selector or header field on\n  `mongodb` frames.\n- **Token**: `command`\n  - **Scopes**: rip, diameter, smb\n  - **Syntax**: `request | response | reply | command <1|2>`\n  - **Value / Range**: RIP Command selector\n  - **Default**: response (Command 2)\n  - **Summary**: Used across `rip`, `diameter`, `smb`: Selects Command `1`\n  (`request`) or Command `2` (`response` / `reply`).\n- **Token**: `commandcomplete`\n  - **Scopes**: postgres\n  - **Syntax**: `startup | authok | query | commandcomplete | readyforquery |\n  errorresponse`\n  - **Value / Range**: PostgreSQL v3.0 message type\n  - **Default**: query ('Q')\n  - **Summary**: Selects untagged `StartupMessage` (`startup`), `'R'` AuthOK\n  (`authok`), `'Q'` Simple Query (`query`), `'C'` CommandComplete, `'Z'`\n  ReadyForQuery, or `'E'` ErrorResponse.\n- **Token**: `community`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `community \"<text>\"`\n  - **Value / Range**: Double-quoted OCTET STRING\n  - **Default**: \"public\"\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Sets the cleartext SNMPv1\n  community string.\n- **Token**: `complexack`\n  - **Scopes**: bacnet\n  - **Syntax**: `bacnet ... complexack`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP (47808)\n  - **Summary**: Configures the `complexack` PDU selector or header field on\n  `bacnet` frames.\n- **Token**: `compound`\n  - **Scopes**: nfs\n  - **Syntax**: `compound | proc \"<text>\"`\n  - **Value / Range**: `compound` or procedure name (`\"NULL\"`, `\"GETATTR\"`,\n  `\"LOOKUP\"`, `\"READ\"`, `\"WRITE\"`)\n  - **Default**: compound\n  - **Summary**: Selects RPC procedure `1` (`COMPOUND` on NFSv4) or named NFSv3/v4\n  procedure.\n- **Token**: `con`\n  - **Scopes**: coap\n  - **Syntax**: `con | non | ack | rst | msgtype \"<text>\"`\n  - **Value / Range**: CoAP Message Type (`0` CON, `1` NON, `2` ACK, `3` RST)\n  - **Default**: con (Confirmable)\n  - **Summary**: Sets the 2-bit `T` field in byte 0 (`ack` and `rst` are CoAP UDP\n  message types, not TCP flags).\n- **Token**: `conclude`\n  - **Scopes**: mms\n  - **Syntax**: `init | initack | getnamelist | read | write | report | conclude |\n  service \"<text>\"`\n  - **Value / Range**: ISO 9506 MMS Service selector\n  - **Default**: read\n  - **Summary**: Selects `Initiate-RequestPDU` (`init`), `Initiate-ResponsePDU`\n  (`initack`), `GetNameList` (`1`), `Read` (`4`), `Write` (`5`),\n  `InformationReport` (`report`), or `Conclude`.\n- **Token**: `confirm`\n  - **Scopes**: dnp3, iec104\n  - **Syntax**: `read | write | select | operate | directoperate | confirm |\n  response | unsolicitedresponse | func \"<text>\"`\n  - **Value / Range**: DNP3 Application Function Code\n  - **Default**: read (0x01)\n  - **Summary**: Used across `dnp3`, `iec104`: Selects `0x00` Confirm, `0x01`\n  Read, `0x02` Write, `0x03` Select, `0x04` Operate, `0x05` Direct Operate, `0x81`\n  Response, or `0x82` Unsolicited Response.\n- **Token**: `confrev`\n  - **Scopes**: goose, sv\n  - **Syntax**: `confrev <number>`\n  - **Value / Range**: Configuration Revision counter\n  - **Default**: 1\n  - **Summary**: Used across `goose`, `sv`: Encodes BER context tag `[8]`\n  (`confRev` SCL configuration revision).\n- **Token**: `connack`\n  - **Scopes**: mqtt, knxnetip\n  - **Syntax**: `connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect`\n  - **Value / Range**: MQTT Control Packet type (or `pkttype \"<text>\"`)\n  - **Default**: publish\n  - **Summary**: Used across `mqtt`, `knxnetip`: Sets the upper 4-bit Control\n  Packet Type (`1`..`14`) in byte 0 of the MQTT header.\n- **Token**: `connect`\n  - **Scopes**: profinet, mqtt, knxnetip, socks, h323, tns\n  - **Syntax**: `service \"<text>\" | get | set | read | write | connect | release`\n  - **Value / Range**: DCP / IO service selector\n  - **Default**: Cyclic RT when omitted\n  - **Summary**: Used across `profinet`, `mqtt`, `knxnetip`, `socks`, `h323`,\n  `tns`: Selects DCP `get`/`set`/`identify` or IO\n  `read`/`write`/`connect`/`release` PDU encoding.\n- **Token**: `connectionstart`\n  - **Scopes**: amqp\n  - **Syntax**: `protocolheader | connectionstart | channelopen | basicpublish |\n  basicdeliver | heartbeat`\n  - **Value / Range**: AMQP 0-9-1 frame/method selector\n  - **Default**: basicpublish (channel 1)\n  - **Summary**: Selects the 8-byte AMQP header, Method frame (`Type 1`), or\n  Heartbeat frame (`Type 8`).\n- **Token**: `connid`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... connid <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `connid` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `contact`\n  - **Scopes**: sip\n  - **Syntax**: `uri \"<text>\" | from \"<text>\" | to \"<text>\" | contact \"<text>\" |\n  via \"<text>\"`\n  - **Value / Range**: Quoted SIP URIs / header values\n  - **Default**: RFC 3261 defaults\n  - **Summary**: Populates the request URI and corresponding SIP signaling\n  headers.\n- **Token**: `contentformat`\n  - **Scopes**: coap\n  - **Syntax**: `contentformat <0..65535>`\n  - **Value / Range**: IANA CoAP Content-Format (`0` text/plain, `40` link-format,\n  `50` JSON, `60` CBOR)\n  - **Default**: Omitted unless set\n  - **Summary**: Encodes CoAP Option `12` (`Content-Format`).\n- **Token**: `contenttype`\n  - **Scopes**: http, sip\n  - **Syntax**: `useragent \"<text>\" | contenttype \"<text>\"`\n  - **Value / Range**: Quoted header values\n  - **Default**: Omitted unless set\n  - **Summary**: Used across `http`, `sip`: Writes `User-Agent:` and\n  `Content-Type:` headers.\n- **Token**: `context`\n  - **Scopes**: nsh, ethernetip\n  - **Syntax**: `context \"<hex>\"`\n  - **Value / Range**: Quoted hex bytes (16B on mdtype 1)\n  - **Default**: 16 zero bytes on mdtype 1\n  - **Summary**: Used across `nsh`, `ethernetip`: Populates the NSH Mandatory\n  Context Header (`mdtype 1`) or variable metadata (`mdtype 2`).\n- **Token**: `contextname`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `contextname \"<text>\"`\n  - **Value / Range**: Quoted text\n  - **Default**: \"\" (default context)\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Sets `contextName` inside\n  the `ScopedPDU` (e.g. `\"vlan-10\"` per-VLAN bridge MIB contexts).\n- **Token**: `cookie`\n  - **Scopes**: wireguard, ssh, rdp\n  - **Syntax**: `initiation | response | cookie | data | type <...>`\n  - **Value / Range**: WireGuard message type keyword\n  - **Default**: initiation (Type 1)\n  - **Summary**: Used across `wireguard`, `ssh`, `rdp`: Selects Type `1` Handshake\n  Initiation (`148B`), Type `2` Handshake Response (`92B`), Type `3` Cookie Reply\n  (`64B`), or Type `4` Transport Data (`>= 32B`).\n- **Token**: `cookieack`\n  - **Scopes**: sctp\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Selects the RFC 9260 SCTP chunk type (`0`=DATA, `1`=INIT,\n  `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT, `5`=HEARTBEAT_ACK, `6`=ABORT,\n  `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO, `11`=COOKIE_ACK,\n  `14`=SHUTDOWN_COMPLETE).\n- **Token**: `cookieecho`\n  - **Scopes**: sctp\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Selects the RFC 9260 SCTP chunk type (`0`=DATA, `1`=INIT,\n  `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT, `5`=HEARTBEAT_ACK, `6`=ABORT,\n  `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO, `11`=COOKIE_ACK,\n  `14`=SHUTDOWN_COMPLETE).\n- **Token**: `correlationid`\n  - **Scopes**: kafka\n  - **Syntax**: `kafka ... correlationid <i32>`\n  - **Value / Range**: Parameter <i32>\n  - **Default**: TCP / UDP (9092)\n  - **Summary**: Configures the `correlationid` PDU selector or header field on\n  `kafka` frames.\n- **Token**: `cos`\n  - **Scopes**: erspan\n  - **Syntax**: `cos <0..7>`\n  - **Value / Range**: 3-bit mirrored Class of Service (0..7)\n  - **Default**: 0\n  - **Summary**: Records the original 802.1p CoS priority bits inside the ERSPAN\n  metadata header.\n- **Token**: `cost`\n  - **Scopes**: stp\n  - **Syntax**: `cost <number>`\n  - **Value / Range**: Whole number\n  - **Default**: 0\n  - **Summary**: Sets the 4-byte Root Path Cost (`20000` = 1GbE, `2000` = 10GbE).\n- **Token**: `cot`\n  - **Scopes**: iec104\n  - **Syntax**: `cot \"<text_or_num>\"`\n  - **Value / Range**: Cause of Transmission (`3` Spont, `6` Act, `7` ActCon, `10`\n  ActTerm, `20` Interrogated)\n  - **Default**: 3 (Spontaneous)\n  - **Summary**: Writes the 16-bit Cause of Transmission field in the ASDU header.\n- **Token**: `count`\n  - **Scopes**: nvmetcp, rocev2, modbus, s7comm, fins, melsec (+3 more)\n  - **Syntax**: `offset <number> | count <number>`\n  - **Value / Range**: Starting LBA / Data Offset and Block / Byte Transfer Count\n  - **Default**: offset 0, count 1 (or payload len)\n  - **Summary**: Used across `nvmetcp`, `rocev2`, `modbus`, `s7comm`, `fins`,\n  `melsec`, `gesrtp`, `bsap`, `twamp`: Sets SQE `SLBA` + `NLB` on `read`/`write`,\n  or `DATAO` + `DATAL` on `h2cdata`/`c2hdata`/`r2t`.\n- **Token**: `counter`\n  - **Scopes**: wireguard\n  - **Syntax**: `counter <number>`\n  - **Value / Range**: Whole number\n  - **Default**: 0\n  - **Summary**: Sets the 64-bit ChaCha20-Poly1305 AEAD nonce counter in Type `4`\n  `data` packets.\n- **Token**: `counter32`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `counter64`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `crc`\n  - **Scopes**: rocev2, dnp3, synchrophasor, rocplus\n  - **Syntax**: `crc <number>`\n  - **Value / Range**: Optional 32-bit Invariant CRC override\n  - **Default**: Auto-computed IBTA Annex A17 ICRC\n  - **Summary**: Used across `rocev2`, `dnp3`, `synchrophasor`, `rocplus`:\n  Overrides the trailing 4-byte little-endian `ICRC` for negative NIC drop\n  testing.\n- **Token**: `crcx`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... crcx`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `crcx` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `create`\n  - **Scopes**: smb\n  - **Syntax**: `negotiate | sessionsetup | treeconnect | treedisconnect | create\n  | close | read | write | logoff`\n  - **Value / Range**: SMB2/3 command keyword (or `command \"<text>\"`)\n  - **Default**: negotiate (0x0000)\n  - **Summary**: Selects the 16-bit MS-SMB2 command (`0x00` Negotiate, `0x01`\n  SessionSetup, `0x02` Logoff, `0x03` TreeConnect, `0x04` TreeDisconnect, `0x05`\n  Create, `0x06` Close, `0x08` Read, `0x09` Write).\n- **Token**: `createchildsa`\n  - **Scopes**: ikev2\n  - **Syntax**: `sainit | auth | createchildsa | informational | exchange <...>`\n  - **Value / Range**: RFC 7296 Exchange Type keyword or u8\n  - **Default**: sainit (34)\n  - **Summary**: Sets Exchange Type: `sainit` (`34` IKE_SA_INIT), `auth` (`35`\n  IKE_AUTH), `createchildsa` (`36` CREATE_CHILD_SA), `informational` (`37`\n  INFORMATIONAL).\n- **Token**: `created`\n  - **Scopes**: coap\n  - **Syntax**: `get | post | put | delete | created | changed | notfound | code\n  \"<c.dd>\"`\n  - **Value / Range**: Shorthand keyword OR dotted code (`\"0.01\"`..`\"5.05\"`,\n  choose one)\n  - **Default**: get (\"0.01\")\n  - **Summary**: Encodes byte 1 (`(class << 5) | detail`, e.g. `\"2.05\"` Content =\n  `0x45`).\n- **Token**: `createpermission`\n  - **Scopes**: turn\n  - **Syntax**: `turn ... createpermission`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Configures the `createpermission` PDU selector or header field on\n  `turn` frames.\n- **Token**: `createsessionrequest`\n  - **Scopes**: gtpc\n  - **Syntax**: `echorequest | echoreply | echoresponse | createsessionrequest |\n  createsessionresponse | modifybearerrequest | modifybearerresponse |\n  deletesessionrequest | deletesessionresponse | msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.274 Message Type keyword or name\n  - **Default**: echorequest (1)\n  - **Summary**: Sets byte 1 of the GTPv2-C header (`1` Echo Req, `2` Echo Resp,\n  `32`/`33` Create Session, `34`/`35` Modify Bearer, `36`/`37` Delete Session).\n- **Token**: `createsessionresponse`\n  - **Scopes**: gtpc\n  - **Syntax**: `echorequest | echoreply | echoresponse | createsessionrequest |\n  createsessionresponse | modifybearerrequest | modifybearerresponse |\n  deletesessionrequest | deletesessionresponse | msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.274 Message Type keyword or name\n  - **Default**: echorequest (1)\n  - **Summary**: Sets byte 1 of the GTPv2-C header (`1` Echo Req, `2` Echo Resp,\n  `32`/`33` Create Session, `34`/`35` Modify Bearer, `36`/`37` Delete Session).\n- **Token**: `criticality`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `msgtype \"<text>\" | proccode <0..255> | criticality \"<text>\"`\n  - **Value / Range**: Explicit APER PDU class, ProcedureCode (0..255), and\n  Criticality (\"reject\"|\"ignore\"|\"notify\")\n  - **Default**: Derived from procedure keyword\n  - **Summary**: Used across `ngap`, `s1ap`: Overrides the outer ASN.1 APER\n  `procedureCode` and `criticality` enum (`0` reject, `1` ignore, `2` notify).\n- **Token**: `cseq`\n  - **Scopes**: sip, rtsp\n  - **Syntax**: `callid \"<text>\" | cseq <number>`\n  - **Value / Range**: Quoted Call-ID string + sequence number\n  - **Default**: callid \"call-1\", cseq 1\n  - **Summary**: Used across `sip`, `rtsp`: Links all messages belonging to the\n  same VoIP dialog (`Call-ID:`) and transaction (`CSeq:`).\n- **Token**: `ctxid`\n  - **Scopes**: dcerpc\n  - **Syntax**: `dcerpc ... ctxid <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP (135)\n  - **Summary**: Configures the `ctxid` PDU selector or header field on `dcerpc`\n  frames.\n- **Token**: `cycle`\n  - **Scopes**: profinet\n  - **Syntax**: `cycle <0..65535>`\n  - **Value / Range**: 16-bit 31.25us Cycle Counter\n  - **Default**: 0\n  - **Summary**: Sets the 16-bit CycleCounter in the 4-byte cyclic PROFINET RT\n  trailer.\n- **Token**: `da1`\n  - **Scopes**: fins\n  - **Syntax**: `dna <0..255> | da1 <0..255> | da2 <0..255> | sna <0..255> | sa1\n  <0..255> | sa2 <0..255>`\n  - **Value / Range**: Destination & Source `(Network, Node, Unit)` FINS routing\n  triples\n  - **Default**: dna 0, da1 1, da2 0, sna 0, sa1 10, sa2 0\n  - **Summary**: Writes bytes 3..8 of the 10-byte FINS header (`da1`/`sa1`\n  typically match the last IPv4 octet).\n- **Token**: `da2`\n  - **Scopes**: fins\n  - **Syntax**: `dna <0..255> | da1 <0..255> | da2 <0..255> | sna <0..255> | sa1\n  <0..255> | sa2 <0..255>`\n  - **Value / Range**: Destination & Source `(Network, Node, Unit)` FINS routing\n  triples\n  - **Default**: dna 0, da1 1, da2 0, sna 0, sa1 10, sa2 0\n  - **Summary**: Writes bytes 3..8 of the 10-byte FINS header (`da1`/`sa1`\n  typically match the last IPv4 octet).\n- **Token**: `data`\n  - **Scopes**: wireguard, l2tp, lisp, sctp, tacacs, http2 (+5 more)\n  - **Syntax**: `initiation | response | cookie | data | type <...>`\n  - **Value / Range**: WireGuard message type keyword\n  - **Default**: initiation (Type 1)\n  - **Summary**: Used across `wireguard`, `l2tp`, `lisp`, `sctp`, `tacacs`,\n  `http2`, `telnet`, `tftp`, `smtp`, `iscsi`, `tns`: Selects Type `1` Handshake\n  Initiation (`148B`), Type `2` Handshake Response (`92B`), Type `3` Cookie Reply\n  (`64B`), or Type `4` Transport Data (`>= 32B`).\n- **Token**: `dataindication`\n  - **Scopes**: turn\n  - **Syntax**: `turn ... dataindication`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Configures the `dataindication` PDU selector or header field on\n  `turn` frames.\n- **Token**: `datastatus`\n  - **Scopes**: profinet\n  - **Syntax**: `datastatus <0..255>`\n  - **Value / Range**: 8-bit RT DataStatus flags\n  - **Default**: 0x35 (State=Primary, DataValid, ProviderRun, StationOK)\n  - **Summary**: Sets the DataStatus byte in the cyclic RT trailer (`0x35`\n  healthy; clear bit `0x04` to simulate invalid I/O).\n- **Token**: `datset`\n  - **Scopes**: goose, sv\n  - **Syntax**: `datset \"<text>\"`\n  - **Value / Range**: Dataset ObjectReference string\n  - **Default**: \"IED1/LLN0$dataset01\"\n  - **Summary**: Used across `goose`, `sv`: Encodes BER context tag `[2]`\n  (`datSet`).\n- **Token**: `db`\n  - **Scopes**: mysql, postgres, mssql, mongodb\n  - **Syntax**: `user \"<text>\" | db \"<text>\"`\n  - **Value / Range**: Quoted MySQL username and schema name on `login`\n  - **Default**: user \"root\", db \"\"\n  - **Summary**: Used across `mysql`, `postgres`, `mssql`, `mongodb`: Populates\n  username and initial database inside `login` packets.\n- **Token**: `dbd`\n  - **Scopes**: ospf\n  - **Syntax**: `hello | dbd | lsr | lsu | lsack`\n  - **Value / Range**: OSPF Packet Type keyword\n  - **Default**: hello (Type 1)\n  - **Summary**: Selects Type `1` Hello, Type `2` Database Description (`dbd`),\n  Type `3` Link State Request (`lsr`), Type `4` Link State Update (`lsu`), or Type\n  `5` Link State Acknowledgment (`lsack`).\n- **Token**: `dbnum`\n  - **Scopes**: s7comm\n  - **Syntax**: `area <hex_or_str> | dbnum <0..65535>`\n  - **Value / Range**: `0x84` Data Blocks (`DB`), `0x81` Inputs (`I`), `0x82`\n  Outputs (`Q`), `0x83` Merkers (`M`) + DB number\n  - **Default**: area 0x84 (DB), dbnum 1\n  - **Summary**: Sets the memory area and Data Block number in S7Any item\n  addressing.\n- **Token**: `dcf`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... dcf`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `dcf` PDU selector or header field on `h323`\n  frames.\n- **Token**: `dcid`\n  - **Scopes**: quic\n  - **Syntax**: `dcid <hex_or_num> | scid <hex_or_num>`\n  - **Value / Range**: 64-bit Connection IDs (e.g. 0x1122334455667788)\n  - **Default**: Deterministic 8-byte IDs\n  - **Summary**: Sets the 8-byte Destination Connection ID (`dcid`) and Source\n  Connection ID (`scid`, Long Header only).\n- **Token**: `deadinterval`\n  - **Scopes**: ospf\n  - **Syntax**: `hellointerval <0..65535> | deadinterval <number>`\n  - **Value / Range**: Timers in seconds\n  - **Default**: hellointerval 10, deadinterval 40\n  - **Summary**: Sets the Hello Interval (`u16` seconds) and Router Dead Interval\n  (`u32` OSPFv2 / `u16` OSPFv3) in `hello` packets.\n- **Token**: `delayreq`\n  - **Scopes**: ptp\n  - **Syntax**: `sync | delayreq | followup | delayresp | announce | msgtype\n  \"<text>\"`\n  - **Value / Range**: PTPv2 message type keyword\n  - **Default**: sync (0x0 on UDP 319)\n  - **Summary**: Selects lower nibble of byte 0 and target UDP port (`0x0`\n  Sync/319, `0x1` Delay_Req/319, `0x8` Follow_Up/320, `0x9` Delay_Resp/320, `0xb`\n  Announce/320).\n- **Token**: `delayresp`\n  - **Scopes**: ptp\n  - **Syntax**: `sync | delayreq | followup | delayresp | announce | msgtype\n  \"<text>\"`\n  - **Value / Range**: PTPv2 message type keyword\n  - **Default**: sync (0x0 on UDP 319)\n  - **Summary**: Selects lower nibble of byte 0 and target UDP port (`0x0`\n  Sync/319, `0x1` Delay_Req/319, `0x8` Follow_Up/320, `0x9` Delay_Resp/320, `0xb`\n  Announce/320).\n- **Token**: `delete`\n  - **Scopes**: http, coap\n  - **Syntax**: `get | post | put | delete | head | options | patch | method\n  \"<text>\"`\n  - **Value / Range**: HTTP request method\n  - **Default**: get\n  - **Summary**: Used across `http`, `coap`: Sets the HTTP request verb at the\n  start of the request line.\n- **Token**: `deletesessionrequest`\n  - **Scopes**: gtpc\n  - **Syntax**: `echorequest | echoreply | echoresponse | createsessionrequest |\n  createsessionresponse | modifybearerrequest | modifybearerresponse |\n  deletesessionrequest | deletesessionresponse | msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.274 Message Type keyword or name\n  - **Default**: echorequest (1)\n  - **Summary**: Sets byte 1 of the GTPv2-C header (`1` Echo Req, `2` Echo Resp,\n  `32`/`33` Create Session, `34`/`35` Modify Bearer, `36`/`37` Delete Session).\n- **Token**: `deletesessionresponse`\n  - **Scopes**: gtpc\n  - **Syntax**: `echorequest | echoreply | echoresponse | createsessionrequest |\n  createsessionresponse | modifybearerrequest | modifybearerresponse |\n  deletesessionrequest | deletesessionresponse | msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.274 Message Type keyword or name\n  - **Default**: echorequest (1)\n  - **Summary**: Sets byte 1 of the GTPv2-C header (`1` Echo Req, `2` Echo Resp,\n  `32`/`33` Create Session, `34`/`35` Modify Bearer, `36`/`37` Delete Session).\n- **Token**: `des`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `priv des | aes \"<password>\"`\n  - **Value / Range**: `des` (CBC-DES) or `aes` (AES-128-CFB) + passphrase\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Encrypts the `ScopedPDU`\n  (`authPriv`, requires `auth`) and populates the 8-byte `msgPrivacyParameters`\n  salt/IV.\n- **Token**: `describe`\n  - **Scopes**: rtsp\n  - **Syntax**: `options | describe | setup | play | teardown | method \"<text>\"`\n  - **Value / Range**: RTSP request verb\n  - **Default**: options\n  - **Summary**: Sets the RTSP command method on the request line.\n- **Token**: `desktop`\n  - **Scopes**: vnc\n  - **Syntax**: `vnc ... desktop <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP (5900)\n  - **Summary**: Configures the `desktop` PDU selector or header field on `vnc`\n  frames.\n- **Token**: `destqp`\n  - **Scopes**: rocev2\n  - **Syntax**: `destqp <0..16777215>`\n  - **Value / Range**: 24-bit Destination Queue Pair number\n  - **Default**: 0x000100\n  - **Summary**: Writes bytes 5..7 of the BTH identifying the remote HCA Queue\n  Pair.\n- **Token**: `destunreach`\n  - **Scopes**: icmp\n  - **Syntax**: `echorequest | echoreply | destunreach | timeexceeded | redirect`\n  - **Value / Range**: Named ICMP message shorthand\n  - **Default**: echorequest\n  - **Summary**: Maps to IPv4/ICMPv6 Type codes: `8`/`128` (`echorequest`),\n  `0`/`129` (`echoreply`), `3`/`1` (`destunreach`), `11`/`3` (`timeexceeded`),\n  `5`/`137` (`redirect`).\n- **Token**: `device`\n  - **Scopes**: melsec\n  - **Syntax**: `device \"<text_or_num>\" | addr <0..16777215> | count <0..65535> |\n  value <0..65535>`\n  - **Value / Range**: Device Code (\"D\",\"M\",\"X\",\"Y\",\"W\",\"R\",\"B\"), 24-bit Head\n  Address, Point Count, and 16-bit Word Value\n  - **Default**: device \"D\" (0xa8), addr 0, count 1, value 0\n  - **Summary**: Writes the 3-byte little-endian `addr`, 1-byte `Device Code`,\n  2-byte `count`, and write/read word data.\n- **Token**: `deviceid`\n  - **Scopes**: cdp\n  - **Syntax**: `deviceid \"<text>\"`\n  - **Value / Range**: Quoted text or identifier\n  - **Default**: \"switch\"\n  - **Summary**: Encodes TLV `0x0001` (Device-ID hostname string).\n- **Token**: `devicename`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... devicename <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `devicename` PDU selector or header field on\n  `sccp` frames.\n- **Token**: `diag`\n  - **Scopes**: bfd\n  - **Syntax**: `diag <0..31>`\n  - **Value / Range**: 5-bit RFC 5880 Diagnostic code (0..31)\n  - **Default**: 0 (No Diagnostic)\n  - **Summary**: Sets failure reason (`0` None, `1` Control Detection Time\n  Expired, `3` Neighbor Signaled Session Down, `7` Administratively Down).\n- **Token**: `diagack`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `diagnack`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `diagnostic`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `direction`\n  - **Scopes**: erspan\n  - **Syntax**: `direction <0|1>`\n  - **Value / Range**: 1-bit mirror direction (0 = Ingress, 1 = Egress)\n  - **Default**: 0 (Ingress)\n  - **Summary**: Sets the `T` / Direction bit in ERSPAN (`0` incoming to port, `1`\n  outgoing from port).\n- **Token**: `directoperate`\n  - **Scopes**: dnp3\n  - **Syntax**: `read | write | select | operate | directoperate | confirm |\n  response | unsolicitedresponse | func \"<text>\"`\n  - **Value / Range**: DNP3 Application Function Code\n  - **Default**: read (0x01)\n  - **Summary**: Selects `0x00` Confirm, `0x01` Read, `0x02` Write, `0x03` Select,\n  `0x04` Operate, `0x05` Direct Operate, `0x81` Response, or `0x82` Unsolicited\n  Response.\n- **Token**: `disconnect`\n  - **Scopes**: mqtt, knxnetip\n  - **Syntax**: `connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect`\n  - **Value / Range**: MQTT Control Packet type (or `pkttype \"<text>\"`)\n  - **Default**: publish\n  - **Summary**: Used across `mqtt`, `knxnetip`: Sets the upper 4-bit Control\n  Packet Type (`1`..`14`) in byte 0 of the MQTT header.\n- **Token**: `discover`\n  - **Scopes**: dhcp\n  - **Syntax**: `discover | offer | request | ack | release | solicit | advertise\n  | reply`\n  - **Value / Range**: DHCPv4 / DHCPv6 message type keyword\n  - **Default**: discover (IPv4) / solicit (IPv6)\n  - **Summary**: Sets DHCPv4 Option `53` + BOOTP `op` (`1` request, `2` reply) or\n  DHCPv6 `msg-type` (`1` Solicit, `2` Advertise, `3` Request, `7` Reply, `8`\n  Release).\n- **Token**: `dlcx`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... dlcx`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `dlcx` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `dna`\n  - **Scopes**: fins\n  - **Syntax**: `dna <0..255> | da1 <0..255> | da2 <0..255> | sna <0..255> | sa1\n  <0..255> | sa2 <0..255>`\n  - **Value / Range**: Destination & Source `(Network, Node, Unit)` FINS routing\n  triples\n  - **Default**: dna 0, da1 1, da2 0, sna 0, sa1 10, sa2 0\n  - **Summary**: Writes bytes 3..8 of the 10-byte FINS header (`da1`/`sa1`\n  typically match the last IPv4 octet).\n- **Token**: `dnsserver`\n  - **Scopes**: dhcp\n  - **Syntax**: `subnetmask <ipv4> | router <ipv4> | dnsserver <ip>`\n  - **Value / Range**: IPv4/IPv6 address literals\n  - **Default**: Omitted\n  - **Summary**: Appends Option `1` (Subnet Mask), Option `3` (Router), and Option\n  `6` / DHCPv6 Option `23` (DNS Recursive Name Server).\n- **Token**: `do`\n  - **Scopes**: telnet\n  - **Syntax**: `do <0..255> | dont <0..255> | will <0..255> | wont <0..255>`\n  - **Value / Range**: Telnet option code (`1` Echo, `3` Suppress Go Ahead, `24`\n  Terminal Type, `31` Window Size)\n  - **Default**: Omitted\n  - **Summary**: Emits the 3-byte `0xff <CMD> <OPT>` IAC negotiation triplet.\n- **Token**: `dobit`\n  - **Scopes**: dns, mdns, doh\n  - **Syntax**: `dns ... dobit`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (53)\n  - **Summary**: Used across `dns`, `mdns`, `doh`: Configures the `dobit` PDU\n  selector or header field across `dns`, `mdns`, `doh` frames.\n- **Token**: `domain`\n  - **Scopes**: ptp, whois, mms, ntlm\n  - **Syntax**: `domain <0..255>`\n  - **Value / Range**: Whole number (0..255)\n  - **Default**: 0\n  - **Summary**: Used across `ptp`, `whois`, `mms`, `ntlm`: Sets `domainNumber` in\n  byte 4 (`0` default IEEE 1588, `24`/`44` telecom G.8275, `127` SMPTE ST 2059).\n- **Token**: `domainid`\n  - **Scopes**: ipfix\n  - **Syntax**: `domainid <number>`\n  - **Value / Range**: 32-bit Observation Domain ID\n  - **Default**: 1\n  - **Summary**: Sets the 4-byte Observation Domain ID in bytes 12..15 of the\n  IPFIX header.\n- **Token**: `done`\n  - **Scopes**: mld\n  - **Syntax**: `query | report | done`\n  - **Value / Range**: MLD message selector\n  - **Default**: query (Type 130)\n  - **Summary**: Selects MLD Multicast Listener Query (`130`), Multicast Listener\n  Report (`131`), or Multicast Listener Done (`132`).\n- **Token**: `dont`\n  - **Scopes**: telnet\n  - **Syntax**: `do <0..255> | dont <0..255> | will <0..255> | wont <0..255>`\n  - **Value / Range**: Telnet option code (`1` Echo, `3` Suppress Go Ahead, `24`\n  Terminal Type, `31` Window Size)\n  - **Default**: Omitted\n  - **Summary**: Emits the 3-byte `0xff <CMD> <OPT>` IAC negotiation triplet.\n- **Token**: `downlinknastransport`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `ngsetuprequest | ngsetupresponse | ngsetupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 38.413 NGAP Elementary Procedure\n  - **Default**: ngsetuprequest\n  - **Summary**: Used across `ngap`, `s1ap`: Selects both the APER PDU Choice\n  (`InitiatingMessage` / `SuccessfulOutcome` / `UnsuccessfulOutcome`) and\n  mandatory 3GPP TS 38.413 Procedure Code + ProtocolIEs.\n- **Token**: `dpid`\n  - **Scopes**: openflow\n  - **Syntax**: `dpid <number>`\n  - **Value / Range**: Whole number (0x hex recommended)\n  - **Default**: 1\n  - **Summary**: Sets the 8-byte Datapath ID in `featuresreply` (`upper 16 bits`\n  vendor/ID + `lower 48 bits` switch MAC).\n- **Token**: `drpriority`\n  - **Scopes**: pim\n  - **Syntax**: `drpriority <number>`\n  - **Value / Range**: Whole number\n  - **Default**: 1\n  - **Summary**: Encodes Designated Router Priority Option TLV `19` in `pim hello`\n  messages.\n- **Token**: `drq`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... drq`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `drq` PDU selector or header field on `h323`\n  frames.\n- **Token**: `dst`\n  - **Scopes**: dnp3, doip, rocplus, bsap, knxnetip\n  - **Syntax**: `src <0..65535> | dst <0..65535>`\n  - **Value / Range**: 16-bit DNP3 Data Link station addresses\n  - **Default**: src 1, dst 10\n  - **Summary**: Used across `dnp3`, `doip`, `rocplus`, `bsap`, `knxnetip`: Sets\n  the 2-byte little-endian DNP3 Source and Destination outstation/master\n  addresses.\n- **Token**: `dsthost`\n  - **Scopes**: diameter\n  - **Syntax**: `dsthost \"<text>\" | dstrealm \"<text>\"`\n  - **Value / Range**: DiameterIdentity strings (AVPs 293 & 283)\n  - **Default**: Omitted\n  - **Summary**: Appends `Destination-Host` (AVP `293`) and `Destination-Realm`\n  (AVP `283`) for DRA realm routing.\n- **Token**: `dstip`\n  - **Scopes**: ipip, rsvp, netflow, ipfix\n  - **Syntax**: `srcip <ip> | dstip <ip>`\n  - **Value / Range**: IPv4 or IPv6 literal matching inner version\n  - **Default**: 10.0.0.1 -> 10.0.0.2 (v4) or 2001:db8::1 -> 2001:db8::2 (v6)\n  - **Summary**: Used across `ipip`, `rsvp`, `netflow`, `ipfix`: Writes the inner\n  encapsulated source and destination IP addresses.\n- **Token**: `dstrealm`\n  - **Scopes**: diameter\n  - **Syntax**: `dsthost \"<text>\" | dstrealm \"<text>\"`\n  - **Value / Range**: DiameterIdentity strings (AVPs 293 & 283)\n  - **Default**: Omitted\n  - **Summary**: Appends `Destination-Host` (AVP `293`) and `Destination-Realm`\n  (AVP `283`) for DRA realm routing.\n- **Token**: `dwa`\n  - **Scopes**: diameter\n  - **Syntax**: `cer | cea | dwr | dwa | ccr | cca | request | response |\n  cmd|command \"<text_or_num>\"`\n  - **Value / Range**: Diameter Command shorthand or 24-bit Command-Code (e.g. 318\n  ULR/ULA)\n  - **Default**: cer (257 Request)\n  - **Summary**: Selects `257` Capabilities-Exchange (`cer`/`cea`), `280`\n  Device-Watchdog (`dwr`/`dwa`), `272` Credit-Control (`ccr`/`cca`), or any custom\n  3GPP Command-Code (e.g. `cmd 316` S6a ULR, `cmd 318` AIA).\n- **Token**: `dwr`\n  - **Scopes**: diameter\n  - **Syntax**: `cer | cea | dwr | dwa | ccr | cca | request | response |\n  cmd|command \"<text_or_num>\"`\n  - **Value / Range**: Diameter Command shorthand or 24-bit Command-Code (e.g. 318\n  ULR/ULA)\n  - **Default**: cer (257 Request)\n  - **Summary**: Selects `257` Capabilities-Exchange (`cer`/`cea`), `280`\n  Device-Watchdog (`dwr`/`dwa`), `272` Credit-Control (`ccr`/`cca`), or any custom\n  3GPP Command-Code (e.g. `cmd 316` S6a ULR, `cmd 318` AIA).\n- **Token**: `eapcode`\n  - **Scopes**: eapol\n  - **Syntax**: `eapcode <1..4>`\n  - **Value / Range**: 8-bit RFC 3748 EAP Code\n  - **Default**: 2 (Response)\n  - **Summary**: Sets the inner EAP Code when `eappacket` is active: `1` Request,\n  `2` Response, `3` Success, `4` Failure.\n- **Token**: `eapid`\n  - **Scopes**: eapol\n  - **Syntax**: `eapid <0..255>`\n  - **Value / Range**: 8-bit EAP Identifier\n  - **Default**: 1\n  - **Summary**: Matches an EAP Response (`eapcode 2`) to its corresponding EAP\n  Request (`eapcode 1`).\n- **Token**: `eapmethod`\n  - **Scopes**: eapol\n  - **Syntax**: `eapmethod <0..255>`\n  - **Value / Range**: 8-bit EAP Method Type\n  - **Default**: 1 (Identity)\n  - **Summary**: Sets EAP Method on Request/Response: `1` Identity, `4`\n  MD5-Challenge, `13` EAP-TLS, `25` PEAP.\n- **Token**: `eappacket`\n  - **Scopes**: eapol\n  - **Syntax**: `eappacket | start | logoff | key | type <...>`\n  - **Value / Range**: EAPOL packet type keyword or u8\n  - **Default**: eappacket (type 0)\n  - **Summary**: Selects EAPOL Packet Type: `eappacket` (`0`), `start` (`1`,\n  0-byte body), `logoff` (`2`, 0-byte body), or `key` (`3`, EAPOL-Key descriptor).\n- **Token**: `echoreply`\n  - **Scopes**: icmp, openflow, gtpu, gtpc\n  - **Syntax**: `echorequest | echoreply | destunreach | timeexceeded | redirect`\n  - **Value / Range**: Named ICMP message shorthand\n  - **Default**: echorequest\n  - **Summary**: Used across `icmp`, `openflow`, `gtpu`, `gtpc`: Maps to\n  IPv4/ICMPv6 Type codes: `8`/`128` (`echorequest`), `0`/`129` (`echoreply`),\n  `3`/`1` (`destunreach`), `11`/`3` (`timeexceeded`), `5`/`137` (`redirect`).\n- **Token**: `echoreq`\n  - **Scopes**: openflow\n  - **Syntax**: `hello | echoreq | echorequest | echoreply | featuresreq |\n  featuresreply | packetin | packetout | flowmod | type <0..255>`\n  - **Value / Range**: OpenFlow message type keyword or u8\n  - **Default**: hello (Type 0)\n  - **Summary**: Maps to OpenFlow 1.3 types: `hello` (`0`),\n  `echoreq`/`echorequest` (`2`), `echoreply` (`3`), `featuresreq` (`5`),\n  `featuresreply` (`6`), `packetin` (`10`), `packetout` (`13`), `flowmod` (`14`).\n- **Token**: `echorequest`\n  - **Scopes**: icmp, openflow, gtpu, gtpc\n  - **Syntax**: `echorequest | echoreply | destunreach | timeexceeded | redirect`\n  - **Value / Range**: Named ICMP message shorthand\n  - **Default**: echorequest\n  - **Summary**: Used across `icmp`, `openflow`, `gtpu`, `gtpc`: Maps to\n  IPv4/ICMPv6 Type codes: `8`/`128` (`echorequest`), `0`/`129` (`echoreply`),\n  `3`/`1` (`destunreach`), `11`/`3` (`timeexceeded`), `5`/`137` (`redirect`).\n- **Token**: `echoresponse`\n  - **Scopes**: gtpc\n  - **Syntax**: `echorequest | echoreply | echoresponse | createsessionrequest |\n  createsessionresponse | modifybearerrequest | modifybearerresponse |\n  deletesessionrequest | deletesessionresponse | msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.274 Message Type keyword or name\n  - **Default**: echorequest (1)\n  - **Summary**: Sets byte 1 of the GTPv2-C header (`1` Echo Req, `2` Echo Resp,\n  `32`/`33` Create Session, `34`/`35` Modify Bearer, `36`/`37` Delete Session).\n- **Token**: `ecm`\n  - **Scopes**: lisp\n  - **Syntax**: `data | maprequest | mapreply | mapregister | mapnotify | ecm`\n  - **Value / Range**: LISP data or control message mode\n  - **Default**: maprequest (UDP 4342)\n  - **Summary**: Selects UDP `4341` Data encapsulation or UDP `4342` Control Type\n  (`1`=Map-Request, `2`=Map-Reply, `3`=Map-Register, `4`=Map-Notify,\n  `8`=Encapsulated Control Message).\n- **Token**: `edclass`\n  - **Scopes**: c1222\n  - **Syntax**: `epsemctrl <0..255> | edclass <number>`\n  - **Value / Range**: 8-bit EPSEM Control byte & optional 32-bit End-Device Class\n  - **Default**: epsemctrl 0x80 (Reserved bit, cleartext)\n  - **Summary**: Writes the EPSEM Control header byte and optional 4-byte\n  `ED-Class` when bit `0x10` is set.\n- **Token**: `edns0`\n  - **Scopes**: dns, mdns, doh\n  - **Syntax**: `dns ... edns0`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (53)\n  - **Summary**: Used across `dns`, `mdns`, `doh`: Configures the `edns0` PDU\n  selector or header field across `dns`, `mdns`, `doh` frames.\n- **Token**: `ehlo`\n  - **Scopes**: smtp\n  - **Syntax**: `ehlo [\"<domain>\"] | helo [\"<domain>\"]`\n  - **Value / Range**: Extended or classic SMTP greeting + client hostname\n  - **Default**: \"localhost\"\n  - **Summary**: Writes `EHLO <domain>\\r\\n` or `HELO <domain>\\r\\n`.\n- **Token**: `eid`\n  - **Scopes**: lisp, doip\n  - **Syntax**: `eid \"<cidr>\" | rloc <ip>`\n  - **Value / Range**: Quoted IPv4/IPv6 EID prefix & RLOC locator IP\n  - **Default**: \"10.0.0.0/24\", source/dest host IP\n  - **Summary**: Used across `lisp`, `doip`: Populates the Endpoint ID prefix\n  record and Routing Locator address in Map-Request/Reply/Register/Notify records.\n- **Token**: `enable`\n  - **Scopes**: pfc\n  - **Syntax**: `enable <0..65535>`\n  - **Value / Range**: 8-bit Class-Enable bitmask in low byte (0x00..0xff)\n  - **Default**: Auto bitmask from q0..q7 (or 0x00ff with quanta)\n  - **Summary**: Sets the 16-bit Class-Enable Vector (`0x0008` = Priority 3,\n  `0x00ff` = all 8 classes).\n- **Token**: `enbid`\n  - **Scopes**: s1ap\n  - **Syntax**: `enbid <number> | tac <0..65535> | enbname \"<text>\"`\n  - **Value / Range**: 20-bit Macro eNB-ID, 16-bit LTE TAC (0..65535), and\n  PrintableString eNBname\n  - **Default**: enbid 1, tac 1, enbname \"eNB-01\"\n  - **Summary**: Populates IE `59` (`Global-ENB-ID`), IE `64` (`SupportedTAs`), IE\n  `67` (`TAI`), and IE `60` (`eNBname`).\n- **Token**: `enbname`\n  - **Scopes**: s1ap\n  - **Syntax**: `enbid <number> | tac <0..65535> | enbname \"<text>\"`\n  - **Value / Range**: 20-bit Macro eNB-ID, 16-bit LTE TAC (0..65535), and\n  PrintableString eNBname\n  - **Default**: enbid 1, tac 1, enbname \"eNB-01\"\n  - **Summary**: Populates IE `59` (`Global-ENB-ID`), IE `64` (`SupportedTAs`), IE\n  `67` (`TAI`), and IE `60` (`eNBname`).\n- **Token**: `enbueid`\n  - **Scopes**: s1ap\n  - **Syntax**: `mmeueid <number> | enbueid <0..16777215>`\n  - **Value / Range**: 32-bit MME-UE-S1AP-ID (IE 0) & 24-bit eNB-UE-S1AP-ID (IE 8)\n  - **Default**: mmeueid 1, enbueid 1 on UE messages\n  - **Summary**: Writes the APER integer UE context identifiers pairing eNB and\n  MME state machines.\n- **Token**: `endcode`\n  - **Scopes**: melsec\n  - **Syntax**: `endcode <0..65535> | errcode <0..65535> | transport <tcp|udp>`\n  - **Value / Range**: 16-bit Response End Code (`0x0000` Success) & L4 transport\n  - **Default**: endcode 0x0000, transport tcp\n  - **Summary**: Writes the 2-byte little-endian `End Code` in `d0 00` responses\n  or toggles TCP/UDP.\n- **Token**: `endid`\n  - **Scopes**: diameter\n  - **Syntax**: `hopid <number> | endid <number>`\n  - **Value / Range**: 32-bit Hop-by-Hop and End-to-End Identifiers\n  - **Default**: Auto-populated non-zero IDs\n  - **Summary**: Writes bytes 12..19 used by peers and DRAs to match Answers to\n  Requests.\n- **Token**: `endmarker`\n  - **Scopes**: gtpu\n  - **Syntax**: `gpdu | echorequest | echoreply | errorindication | endmarker`\n  - **Value / Range**: GTPv1-U message type keyword\n  - **Default**: gpdu (0xff)\n  - **Summary**: Selects 3GPP TS 29.281 Message Type (`1`=Echo Request, `2`=Echo\n  Response, `26`=Error Indication, `254`=End Marker, `255`=T-PDU / G-PDU).\n- **Token**: `endofdata`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `serialnotify | serialquery | resetquery | cacheresponse |\n  ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport`\n  - **Value / Range**: RPKI-RTR PDU type keyword\n  - **Default**: ipv4prefix (Type 4)\n  - **Summary**: Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset\n  Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data,\n  `8`=Cache Reset, `10`=Error Report).\n- **Token**: `endpoint`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... endpoint <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `endpoint` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `endpointip`\n  - **Scopes**: someip\n  - **Syntax**: `endpointip <ip> | endpointport <0..65535> | flags <0..255>`\n  - **Value / Range**: IPv4/IPv6 SD Endpoint Option address + L4 port + 8-bit SD\n  Flags\n  - **Default**: Host IP / port 30509 / flags 0x80\n  - **Summary**: Appends an IPv4 (`12-byte`) or IPv6 (`24-byte`) Endpoint Option\n  to `offerservice` / `subscribe` SD messages.\n- **Token**: `endpointport`\n  - **Scopes**: someip\n  - **Syntax**: `endpointip <ip> | endpointport <0..65535> | flags <0..255>`\n  - **Value / Range**: IPv4/IPv6 SD Endpoint Option address + L4 port + 8-bit SD\n  Flags\n  - **Default**: Host IP / port 30509 / flags 0x80\n  - **Summary**: Appends an IPv4 (`12-byte`) or IPv6 (`24-byte`) Endpoint Option\n  to `offerservice` / `subscribe` SD messages.\n- **Token**: `endpointurl`\n  - **Scopes**: opcua\n  - **Syntax**: `endpointurl \"<text>\"`\n  - **Value / Range**: Quoted `opc.tcp://...` endpoint URL on `\"HEL\"`\n  - **Default**: \"opc.tcp://localhost:4840\"\n  - **Summary**: Writes the length-prefixed `EndpointUrl` string inside `\"HEL\"`\n  messages.\n- **Token**: `engineboots`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `engineboots <number> | enginetime <number>`\n  - **Value / Range**: Whole number\n  - **Default**: engineboots 1, enginetime 100\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Sets\n  `msgAuthoritativeEngineBoots` and `msgAuthoritativeEngineTime` (also used in the\n  AES-128-CFB IV).\n- **Token**: `engineid`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `engineid \"<even_hex>\"`\n  - **Value / Range**: Even-length ASCII hex string (e.g. \"80001f880431\")\n  - **Default**: \"80001f888000000001\"\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Sets\n  `msgAuthoritativeEngineID` and `contextEngineID` and localizes `Ku -> Kul` USM\n  keys.\n- **Token**: `enginetime`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `engineboots <number> | enginetime <number>`\n  - **Value / Range**: Whole number\n  - **Default**: engineboots 1, enginetime 100\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Sets\n  `msgAuthoritativeEngineBoots` and `msgAuthoritativeEngineTime` (also used in the\n  AES-128-CFB IV).\n- **Token**: `enterprise`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `enterprise <oid>`\n  - **Value / Range**: Dotted numeric OID (>= 2 arcs)\n  - **Default**: 1.3.6.1.4.1.8072.3.2.10\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Sets the `enterprise`\n  OBJECT IDENTIFIER inside SNMPv1 `trap` PDUs.\n- **Token**: `eof`\n  - **Scopes**: mysql\n  - **Syntax**: `greeting | login | query | ok | err | eof`\n  - **Value / Range**: MySQL packet type keyword\n  - **Default**: query (COM_QUERY 0x03)\n  - **Summary**: Selects Server Greeting v10 (`greeting`), Client\n  HandshakeResponse41 (`login`), SQL Query (`query`), `0x00` OK (`ok`), `0xff`\n  Error (`err`), or `0xfe` EOF (`eof`).\n- **Token**: `epsemctrl`\n  - **Scopes**: c1222\n  - **Syntax**: `epsemctrl <0..255> | edclass <number>`\n  - **Value / Range**: 8-bit EPSEM Control byte & optional 32-bit End-Device Class\n  - **Default**: epsemctrl 0x80 (Reserved bit, cleartext)\n  - **Summary**: Writes the EPSEM Control header byte and optional 4-byte\n  `ED-Class` when bit `0x10` is set.\n- **Token**: `err`\n  - **Scopes**: tftp, pop3, mysql, mssql, mongodb\n  - **Syntax**: `rrq | wrq | data | ack | error | err`\n  - **Value / Range**: TFTP opcode keyword\n  - **Default**: rrq (Opcode 1)\n  - **Summary**: Used across `tftp`, `pop3`, `mysql`, `mssql`, `mongodb`: Selects\n  Opcode `1` Read Request (`rrq`), `2` Write Request (`wrq`), `3` Data (`data`),\n  `4` Acknowledgment (`ack`), or `5` Error (`error` / `err`).\n- **Token**: `errcode`\n  - **Scopes**: rsvp, rpkirtr, tftp, mysql, fins, melsec (+7 more)\n  - **Syntax**: `errcode <0..255>`\n  - **Value / Range**: 8-bit RSVP Error Code\n  - **Default**: 24 (Routing Problem)\n  - **Summary**: Used across `rsvp`, `rpkirtr`, `tftp`, `mysql`, `fins`, `melsec`,\n  `c1222`, `turn`, `mssql`, `mongodb`, `tns`, `kafka`, `modbus`: Sets the Error\n  Code inside `ERROR_SPEC` (`Class 6`) on `patherr` and `resverr` frames.\n- **Token**: `errmsg`\n  - **Scopes**: rpkirtr, tftp, mongodb\n  - **Syntax**: `errcode <0..65535> | errmsg \"<text>\"`\n  - **Value / Range**: 16-bit error code & UTF-8 diagnostic text\n  - **Default**: errcode 0, \"\"\n  - **Summary**: Used across `rpkirtr`, `tftp`, `mongodb`: Populates Error Code\n  (`0..8`) and length-prefixed UTF-8 Error Text inside `errorreport` (`Type 10`)\n  PDUs.\n- **Token**: `error`\n  - **Scopes**: tftp, someip, rocplus, turn\n  - **Syntax**: `rrq | wrq | data | ack | error | err`\n  - **Value / Range**: TFTP opcode keyword\n  - **Default**: rrq (Opcode 1)\n  - **Summary**: Used across `tftp`, `someip`, `rocplus`, `turn`: Selects Opcode\n  `1` Read Request (`rrq`), `2` Write Request (`wrq`), `3` Data (`data`), `4`\n  Acknowledgment (`ack`), or `5` Error (`error` / `err`).\n- **Token**: `errorestimate`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... errorestimate <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `errorestimate` PDU selector or header field on\n  `twamp` frames.\n- **Token**: `errorindication`\n  - **Scopes**: gtpu, ngap, s1ap\n  - **Syntax**: `gpdu | echorequest | echoreply | errorindication | endmarker`\n  - **Value / Range**: GTPv1-U message type keyword\n  - **Default**: gpdu (0xff)\n  - **Summary**: Used across `gtpu`, `ngap`, `s1ap`: Selects 3GPP TS 29.281\n  Message Type (`1`=Echo Request, `2`=Echo Response, `26`=Error Indication,\n  `254`=End Marker, `255`=T-PDU / G-PDU).\n- **Token**: `errorreport`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `serialnotify | serialquery | resetquery | cacheresponse |\n  ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport`\n  - **Value / Range**: RPKI-RTR PDU type keyword\n  - **Default**: ipv4prefix (Type 4)\n  - **Summary**: Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset\n  Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data,\n  `8`=Cache Reset, `10`=Error Report).\n- **Token**: `errorresponse`\n  - **Scopes**: postgres\n  - **Syntax**: `startup | authok | query | commandcomplete | readyforquery |\n  errorresponse`\n  - **Value / Range**: PostgreSQL v3.0 message type\n  - **Default**: query ('Q')\n  - **Summary**: Selects untagged `StartupMessage` (`startup`), `'R'` AuthOK\n  (`authok`), `'Q'` Simple Query (`query`), `'C'` CommandComplete, `'Z'`\n  ReadyForQuery, or `'E'` ErrorResponse.\n- **Token**: `etype`\n  - **Scopes**: kerberos\n  - **Syntax**: `etype <number>`\n  - **Value / Range**: RFC 3961 encryption ID (`18` AES256, `17` AES128, `23`\n  RC4-HMAC; negative vendor IDs allowed)\n  - **Default**: 18 (aes256-cts-hmac-sha1-96)\n  - **Summary**: Sets the requested or encrypted-part `etype` integer.\n- **Token**: `exchange`\n  - **Scopes**: ikev2, amqp\n  - **Syntax**: `sainit | auth | createchildsa | informational | exchange <...>`\n  - **Value / Range**: RFC 7296 Exchange Type keyword or u8\n  - **Default**: sainit (34)\n  - **Summary**: Used across `ikev2`, `amqp`: Sets Exchange Type: `sainit` (`34`\n  IKE_SA_INIT), `auth` (`35` IKE_AUTH), `createchildsa` (`36` CREATE_CHILD_SA),\n  `informational` (`37` INFORMATIONAL).\n- **Token**: `expire`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `refresh <number> | retry <number> | expire <number>`\n  - **Value / Range**: 32-bit intervals in seconds (v1 endofdata)\n  - **Default**: refresh 3600, retry 600, expire 7200\n  - **Summary**: Populates the three RFC 8210 timing parameters at the end of\n  `version 1` `endofdata` PDUs.\n- **Token**: `exptime`\n  - **Scopes**: memcached\n  - **Syntax**: `flags <number> | exptime <number>`\n  - **Value / Range**: 32-bit client flags + TTL expiration in seconds\n  - **Default**: flags 0, exptime 0\n  - **Summary**: Sets `flags` and `exptime` in `set` requests.\n- **Token**: `facility`\n  - **Scopes**: syslog\n  - **Syntax**: `facility <0..23>`\n  - **Value / Range**: Facility code 0..23 (`4` auth, `10` authpriv, `16..23`\n  local0..local7)\n  - **Default**: 16 (local0)\n  - **Summary**: Sets the RFC 5424 Facility number multiplied by `8` inside\n  `<PRI>`.\n- **Token**: `fault`\n  - **Scopes**: dcerpc\n  - **Syntax**: `dcerpc ... fault`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (135)\n  - **Summary**: Configures the `fault` PDU selector or header field on `dcerpc`\n  frames.\n- **Token**: `featuresreply`\n  - **Scopes**: openflow\n  - **Syntax**: `hello | echoreq | echorequest | echoreply | featuresreq |\n  featuresreply | packetin | packetout | flowmod | type <0..255>`\n  - **Value / Range**: OpenFlow message type keyword or u8\n  - **Default**: hello (Type 0)\n  - **Summary**: Maps to OpenFlow 1.3 types: `hello` (`0`),\n  `echoreq`/`echorequest` (`2`), `echoreply` (`3`), `featuresreq` (`5`),\n  `featuresreply` (`6`), `packetin` (`10`), `packetout` (`13`), `flowmod` (`14`).\n- **Token**: `featuresreq`\n  - **Scopes**: openflow\n  - **Syntax**: `hello | echoreq | echorequest | echoreply | featuresreq |\n  featuresreply | packetin | packetout | flowmod | type <0..255>`\n  - **Value / Range**: OpenFlow message type keyword or u8\n  - **Default**: hello (Type 0)\n  - **Summary**: Maps to OpenFlow 1.3 types: `hello` (`0`),\n  `echoreq`/`echorequest` (`2`), `echoreply` (`3`), `featuresreq` (`5`),\n  `featuresreply` (`6`), `packetin` (`10`), `packetout` (`13`), `flowmod` (`14`).\n- **Token**: `fetch`\n  - **Scopes**: kafka\n  - **Syntax**: `kafka ... fetch`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP / UDP (9092)\n  - **Summary**: Configures the `fetch` PDU selector or header field on `kafka`\n  frames.\n- **Token**: `filename`\n  - **Scopes**: tftp, smb\n  - **Syntax**: `filename \"<text>\" | mode \"<text>\"`\n  - **Value / Range**: Quoted filename and mode (`\"octet\"` or `\"netascii\"`)\n  - **Default**: filename \"boot.bin\", mode \"octet\"\n  - **Summary**: Used across `tftp`, `smb`: Writes NUL-terminated filename and\n  transfer mode strings in `rrq` and `wrq` packets.\n- **Token**: `filter`\n  - **Scopes**: ldap, mongodb\n  - **Syntax**: `filter \"<text>\"`\n  - **Value / Range**: Quoted LDAP search filter (`\"(objectClass=*)\"`,\n  `\"(sAMAccountName=jdoe)\"`)\n  - **Default**: \"(objectClass=*)\"\n  - **Summary**: Used across `ldap`, `mongodb`: Encodes the filter inside\n  `searchreq` frames.\n- **Token**: `finbit`\n  - **Scopes**: websocket\n  - **Syntax**: `finbit <0|1>`\n  - **Value / Range**: `1` (final frame) or `0` (more fragments follow)\n  - **Default**: 1\n  - **Summary**: Sets the `FIN` bit in byte 0 of the WebSocket header.\n- **Token**: `findservice`\n  - **Scopes**: someip\n  - **Syntax**: `findservice | offerservice | subscribe | subscribeack | request |\n  requestnoreply | notification | response | error | msgtype \"<text_or_num>\"`\n  - **Value / Range**: SOME/IP-SD Entry selector or SOME/IP Message Type\n  (`0x00`..`0x81`)\n  - **Default**: request (0x00)\n  - **Summary**: Selects either a full `0xffff:0x8100` SOME/IP-SD frame\n  (`findservice`/`offerservice`/`subscribe`/`subscribeack`) or standard SOME/IP\n  `Message Type`.\n- **Token**: `finished`\n  - **Scopes**: tls\n  - **Syntax**: `clienthello | serverhello | certificate | finished | appdata |\n  alert`\n  - **Value / Range**: TLS record / handshake message type\n  - **Default**: clienthello\n  - **Summary**: Selects Handshake (`22`: `clienthello`, `serverhello`,\n  `certificate`, `finished`), Application Data (`23`: `appdata`), or Alert (`21`:\n  `alert`).\n- **Token**: `flags`\n  - **Scopes**: stp, srv6, ikev2, bmp, rpkirtr, l2tp (+17 more)\n  - **Syntax**: `flags <0..255>`\n  - **Value / Range**: 8-bit bitmask\n  - **Default**: 0 (or RSTP role bits)\n  - **Summary**: Used across `stp`, `srv6`, `ikev2`, `bmp`, `rpkirtr`, `l2tp`,\n  `lisp`, `gtpu`, `tacacs`, `diameter`, `iscsi`, `nvmetcp`, `memcached`,\n  `s7commplus`, `someip`, `llmnr`, `nbns`, `rdp`, `vnc`, `ntlm`, `dcerpc`,\n  `mongodb`, `tns`: Sets Topology Change (`0x01`), Proposal (`0x02`), Port Role\n  (`bits 2..3`), Learning (`0x10`), Forwarding (`0x20`), Agreement (`0x40`), and\n  TCA (`0x80`).\n- **Token**: `flowmod`\n  - **Scopes**: openflow\n  - **Syntax**: `hello | echoreq | echorequest | echoreply | featuresreq |\n  featuresreply | packetin | packetout | flowmod | type <0..255>`\n  - **Value / Range**: OpenFlow message type keyword or u8\n  - **Default**: hello (Type 0)\n  - **Summary**: Maps to OpenFlow 1.3 types: `hello` (`0`),\n  `echoreq`/`echorequest` (`2`), `echoreply` (`3`), `featuresreq` (`5`),\n  `featuresreply` (`6`), `packetin` (`10`), `packetout` (`13`), `flowmod` (`14`).\n- **Token**: `followup`\n  - **Scopes**: ptp\n  - **Syntax**: `sync | delayreq | followup | delayresp | announce | msgtype\n  \"<text>\"`\n  - **Value / Range**: PTPv2 message type keyword\n  - **Default**: sync (0x0 on UDP 319)\n  - **Summary**: Selects lower nibble of byte 0 and target UDP port (`0x0`\n  Sync/319, `0x1` Delay_Req/319, `0x8` Follow_Up/320, `0x9` Delay_Resp/320, `0xb`\n  Announce/320).\n- **Token**: `forwarddelay`\n  - **Scopes**: stp\n  - **Syntax**: `maxage <0..65535> | hellotime <0..65535> | forwarddelay\n  <0..65535>`\n  - **Value / Range**: 16-bit unsigned integers (seconds)\n  - **Default**: maxage 20, hellotime 2, forwarddelay 15\n  - **Summary**: Encodes BPDU timers scaled to IEEE 802.1D `1/256`s increments.\n- **Token**: `forwarder`\n  - **Scopes**: glbp\n  - **Syntax**: `state <0..255> | forwarder <0..255>`\n  - **Value / Range**: GLBP state code and AVF slot index (1..4)\n  - **Default**: state 32 (Active), forwarder 1\n  - **Summary**: Sets gateway/forwarder state (`4`=Speak, `8`=Standby,\n  `16`=Listen, `32`=Active) and AVF index.\n- **Token**: `fracsec`\n  - **Scopes**: synchrophasor\n  - **Syntax**: `timestamp <number> | fracsec <number>`\n  - **Value / Range**: 32-bit UTC Second-of-Century (`SOC`) & 32-bit `FRACSEC`\n  (Time Quality + 24-bit fraction)\n  - **Default**: timestamp 1700000000, fracsec 0\n  - **Summary**: Writes bytes 6..13 (`SOC` and `FRACSEC`) used by PDCs to\n  time-align phasors across substations.\n- **Token**: `fraction`\n  - **Scopes**: rtcp\n  - **Syntax**: `rtcp ... fraction <u8>`\n  - **Value / Range**: Parameter <u8>\n  - **Default**: UDP (5005)\n  - **Summary**: Configures the `fraction` PDU selector or header field on `rtcp`\n  frames.\n- **Token**: `framedip`\n  - **Scopes**: radius\n  - **Syntax**: `framedip <ipv4>`\n  - **Value / Range**: IPv4 address (e.g. 10.250.0.25)\n  - **Default**: Omitted unless set\n  - **Summary**: Adds Attribute `8` (`Framed-IP-Address`) carrying the client’s\n  assigned IPv4 address.\n- **Token**: `frameid`\n  - **Scopes**: profinet\n  - **Syntax**: `frameid <0..65535>`\n  - **Value / Range**: 16-bit PROFINET FrameID (e.g. 0x8000, 0xfefe)\n  - **Default**: 0x8000 (RT_CLASS_1 cyclic)\n  - **Summary**: Writes the 2-byte PROFINET FrameID ahead of the RT or DCP\n  payload.\n- **Token**: `from`\n  - **Scopes**: sip\n  - **Syntax**: `uri \"<text>\" | from \"<text>\" | to \"<text>\" | contact \"<text>\" |\n  via \"<text>\"`\n  - **Value / Range**: Quoted SIP URIs / header values\n  - **Default**: RFC 3261 defaults\n  - **Summary**: Populates the request URI and corresponding SIP signaling\n  headers.\n- **Token**: `func`\n  - **Scopes**: modbus, dnp3, s7comm, s7commplus, gesrtp, rocplus (+1 more)\n  - **Syntax**: `readcoils | readdiscreteinputs | readholdingregisters |\n  readinputregisters | writesinglecoil | writesingleregister |\n  writemultipleregisters | func \"<fc>\"`\n  - **Value / Range**: Function Code keyword or number (`\"1\"`, `\"2\"`, `\"3\"`,\n  `\"4\"`, `\"5\"`, `\"6\"`, `\"15\"`, `\"16\"`)\n  - **Default**: readholdingregisters (FC 3)\n  - **Summary**: Used across `modbus`, `dnp3`, `s7comm`, `s7commplus`, `gesrtp`,\n  `rocplus`, `bsap`: Sets the 1-byte Modbus Function Code immediately after\n  `unitid`.\n- **Token**: `garp`\n  - **Scopes**: arp\n  - **Syntax**: `request | reply | gratuitous | garp`\n  - **Value / Range**: Operation mode flag\n  - **Default**: request\n  - **Summary**: Selects Opcode `1` broadcast Who-Has (`request`), Opcode `2`\n  unicast Is-At (`reply`), or broadcast Gratuitous ARP (`gratuitous`/`garp` with\n  `tpa = spa` and `ff:ff:ff:ff:ff:ff`).\n- **Token**: `gateway`\n  - **Scopes**: icmp\n  - **Syntax**: `gateway <ipv4>`\n  - **Value / Range**: IPv4 address literal\n  - **Default**: 0.0.0.0 (or source router IPv4)\n  - **Summary**: Sets the 4-byte Redirect Gateway Internet Address on IPv4 `icmp\n  redirect` messages.\n- **Token**: `gauge32`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `gcf`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... gcf`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `gcf` PDU selector or header field on `h323`\n  frames.\n- **Token**: `gentrap`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `gentrap <0..6> | spectrap <number>`\n  - **Value / Range**: gentrap: 0..6, spectrap: u32\n  - **Default**: gentrap 6, spectrap 1\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Sets `generic-trap`\n  (`0`=coldStart, `1`=warmStart, `2`=linkDown, `3`=linkUp, `4`=authFailure,\n  `5`=egpNeighborLoss, `6`=enterpriseSpecific) and `specific-trap`.\n- **Token**: `get`\n  - **Scopes**: profinet, snmp1, snmp2, snmp3, http, redis (+3 more)\n  - **Syntax**: `service \"<text>\" | get | set | read | write | connect | release`\n  - **Value / Range**: DCP / IO service selector\n  - **Default**: Cyclic RT when omitted\n  - **Summary**: Used across `profinet`, `snmp1`, `snmp2`, `snmp3`, `http`,\n  `redis`, `memcached`, `coap`, `doh`: Selects DCP `get`/`set`/`identify` or IO\n  `read`/`write`/`connect`/`release` PDU encoding.\n- **Token**: `getbulk`\n  - **Scopes**: snmp2, snmp3, snmp1\n  - **Syntax**: `trap | inform | report | get | getnext | getbulk | set |\n  response`\n  - **Value / Range**: SNMPv2c PDU type keyword\n  - **Default**: trap (PDU 0xa7 on UDP 162)\n  - **Summary**: Used across `snmp2`, `snmp3`, `snmp1`: Selects RFC 3416 BER PDU\n  tag (`0xa0`..`0xa3` or `0xa5` GetBulk, `0xa6` Inform, `0xa7` SNMPv2-Trap, `0xa8`\n  Report).\n- **Token**: `getnamelist`\n  - **Scopes**: mms\n  - **Syntax**: `init | initack | getnamelist | read | write | report | conclude |\n  service \"<text>\"`\n  - **Value / Range**: ISO 9506 MMS Service selector\n  - **Default**: read\n  - **Summary**: Selects `Initiate-RequestPDU` (`init`), `Initiate-ResponsePDU`\n  (`initack`), `GetNameList` (`1`), `Read` (`4`), `Write` (`5`),\n  `InformationReport` (`report`), or `Conclude`.\n- **Token**: `getnext`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `trap | get | getnext | set | response`\n  - **Value / Range**: SNMPv1 PDU type keyword\n  - **Default**: trap (PDU 0xa4 on UDP 162)\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Selects ASN.1 BER PDU\n  context tag (`0xa0` GetRequest, `0xa1` GetNextRequest, `0xa2` GetResponse,\n  `0xa3` SetRequest, `0xa4` v1 Trap).\n- **Token**: `gid`\n  - **Scopes**: doip\n  - **Syntax**: `vin \"<text>\" | eid <mac_or_hex> | gid <mac_or_hex>`\n  - **Value / Range**: 17-char ASCII VIN and 6-byte Entity ID / Group ID\n  - **Default**: \"00000000000000000\", 00:00:00:00:00:00\n  - **Summary**: Populates `Vehicle Identification Response / Announcement`\n  (`0x0004`) and `vehiclevin`/`vehicleeid` filters.\n- **Token**: `gnbid`\n  - **Scopes**: ngap\n  - **Syntax**: `gnbid <number> | tac <0..16777215> | ranname \"<text>\"`\n  - **Value / Range**: gNB-ID integer, 24-bit Tracking Area Code, and\n  PrintableString RANNodeName\n  - **Default**: gnbid 1, tac 1, ranname \"gNB-01\"\n  - **Summary**: Populates IE `27` (`GlobalRANNodeID`), IE `102`\n  (`SupportedTAList`), IE `121` (`UserLocationInformation`), and IE `82`\n  (`RANNodeName`).\n- **Token**: `goaway`\n  - **Scopes**: http2\n  - **Syntax**: `preface | settings | headers | data | windowupdate | ping |\n  goaway`\n  - **Value / Range**: HTTP/2 frame type keyword\n  - **Default**: settings (Type 0x04, streamid 0)\n  - **Summary**: Selects the RFC 9113 HTTP/2 binary frame type (`0x0` DATA, `0x1`\n  HEADERS, `0x4` SETTINGS, `0x6` PING, `0x7` GOAWAY, `0x8` WINDOW_UPDATE, or\n  connection `preface`).\n- **Token**: `gocbref`\n  - **Scopes**: goose\n  - **Syntax**: `gocbref \"<text>\"`\n  - **Value / Range**: GOOSE Control Block Reference string\n  - **Default**: \"IED1/LLN0$GO$gcb01\"\n  - **Summary**: Encodes BER context tag `[0]` (`gocbRef`).\n- **Token**: `goid`\n  - **Scopes**: goose\n  - **Syntax**: `goid \"<text>\"`\n  - **Value / Range**: GOOSE Identifier string\n  - **Default**: \"GOOSE1\"\n  - **Summary**: Encodes BER context tag `[3]` (`goID`).\n- **Token**: `gpdu`\n  - **Scopes**: gtpu\n  - **Syntax**: `gpdu | echorequest | echoreply | errorindication | endmarker`\n  - **Value / Range**: GTPv1-U message type keyword\n  - **Default**: gpdu (0xff)\n  - **Summary**: Selects 3GPP TS 29.281 Message Type (`1`=Echo Request, `2`=Echo\n  Response, `26`=Error Indication, `254`=End Marker, `255`=T-PDU / G-PDU).\n- **Token**: `gratuitous`\n  - **Scopes**: arp\n  - **Syntax**: `request | reply | gratuitous | garp`\n  - **Value / Range**: Operation mode flag\n  - **Default**: request\n  - **Summary**: Selects Opcode `1` broadcast Who-Has (`request`), Opcode `2`\n  unicast Is-At (`reply`), or broadcast Gratuitous ARP (`gratuitous`/`garp` with\n  `tpa = spa` and `ff:ff:ff:ff:ff:ff`).\n- **Token**: `greeting`\n  - **Scopes**: mysql, twamp, socks\n  - **Syntax**: `greeting | login | query | ok | err | eof`\n  - **Value / Range**: MySQL packet type keyword\n  - **Default**: query (COM_QUERY 0x03)\n  - **Summary**: Used across `mysql`, `twamp`, `socks`: Selects Server Greeting\n  v10 (`greeting`), Client HandshakeResponse41 (`login`), SQL Query (`query`),\n  `0x00` OK (`ok`), `0xff` Error (`err`), or `0xfe` EOF (`eof`).\n- **Token**: `grekey`\n  - **Scopes**: gre\n  - **Syntax**: `grekey <number> | key <number>`\n  - **Value / Range**: Whole number\n  - **Default**: Omitted (K=0)\n  - **Summary**: Sets Key Present bit (`0x2000`) and inserts the 4-byte RFC 2890\n  Tunnel Key (or 24-bit NVGRE VSID + 8-bit FlowID).\n- **Token**: `greproto`\n  - **Scopes**: gre\n  - **Syntax**: `greproto <0..65535>`\n  - **Value / Range**: 16-bit EtherType (decimal or 0x hex)\n  - **Default**: 0x0800\n  - **Summary**: Sets the 2-byte GRE Protocol Type (`0x0800` IPv4, `0x86dd` IPv6,\n  `0x6558` TEB/GRETAP, `0x88be` ERSPAN).\n- **Token**: `greseq`\n  - **Scopes**: gre, erspan\n  - **Syntax**: `greseq <number>`\n  - **Value / Range**: Whole number\n  - **Default**: Omitted (S=0)\n  - **Summary**: Used across `gre`, `erspan`: Sets Sequence Number Present bit\n  (`0x1000`) and inserts the 4-byte GRE Sequence Number.\n- **Token**: `group`\n  - **Scopes**: igmp, pim, hsrp, glbp, dnp3, rocplus (+2 more)\n  - **Syntax**: `group <ipv4>`\n  - **Value / Range**: IPv4 multicast address\n  - **Default**: 224.0.0.1 (or 0.0.0.0 general query)\n  - **Summary**: Used across `igmp`, `pim`, `hsrp`, `glbp`, `dnp3`, `rocplus`,\n  `nbns`, `kafka`: Sets the 4-byte Group Address in v1/v2 headers or the Multicast\n  Address inside the v3 Group Record.\n- **Token**: `grpcstatus`\n  - **Scopes**: grpc\n  - **Syntax**: `grpcstatus <number>`\n  - **Value / Range**: gRPC status code (`0` OK, `3` INVALID_ARGUMENT, `7`\n  PERMISSION_DENIED, `14` UNAVAILABLE, `16` UNAUTHENTICATED)\n  - **Default**: Omitted on requests\n  - **Summary**: Switches the packet to a gRPC Trailers response frame carrying\n  `grpc-status`.\n- **Token**: `grq`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... grq`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `grq` PDU selector or header field on `h323`\n  frames.\n- **Token**: `h2cdata`\n  - **Scopes**: nvmetcp\n  - **Syntax**: `icreq | icresp | read | write | response | h2cdata | c2hdata |\n  r2t | msgtype \"<text>\" | cmd \"<text>\"`\n  - **Value / Range**: NVMe/TCP PDU Type or NVMe Command selector\n  - **Default**: icreq (0x00)\n  - **Summary**: Selects `0x00` ICReq, `0x01` ICResp, `0x04` CapsuleCmd (`read`\n  NVMe `0x02`, `write` NVMe `0x01`), `0x05` CapsuleResp, `0x06` H2CData, `0x07`\n  C2HData, or `0x09` R2T.\n- **Token**: `handshake`\n  - **Scopes**: quic\n  - **Syntax**: `initial | zerortt | handshake | retry | short`\n  - **Value / Range**: QUIC packet header type\n  - **Default**: initial\n  - **Summary**: Selects Long Header (`initial`, `zerortt`, `handshake`, `retry`)\n  or 1-RTT Short Header (`short`).\n- **Token**: `handshakeversion`\n  - **Scopes**: tls\n  - **Syntax**: `recordversion <hex> | handshakeversion <hex>`\n  - **Value / Range**: 16-bit TLS version (`0x0301` TLS 1.0, `0x0303` TLS 1.2/1.3\n  record)\n  - **Default**: 0x0303\n  - **Summary**: Overrides the outer 5-byte TLS Record version or inner Handshake\n  legacy version.\n- **Token**: `head`\n  - **Scopes**: http\n  - **Syntax**: `get | post | put | delete | head | options | patch | method\n  \"<text>\"`\n  - **Value / Range**: HTTP request method\n  - **Default**: get\n  - **Summary**: Sets the HTTP request verb at the start of the request line.\n- **Token**: `header`\n  - **Scopes**: http\n  - **Syntax**: `header \"<name>\" \"<value>\"`\n  - **Value / Range**: Repeatable header name + value pair\n  - **Default**: Omitted\n  - **Summary**: Appends one or more custom HTTP headers (`Authorization`,\n  `Cookie`, `X-Forwarded-For`, etc.).\n- **Token**: `headers`\n  - **Scopes**: http2\n  - **Syntax**: `preface | settings | headers | data | windowupdate | ping |\n  goaway`\n  - **Value / Range**: HTTP/2 frame type keyword\n  - **Default**: settings (Type 0x04, streamid 0)\n  - **Summary**: Selects the RFC 9113 HTTP/2 binary frame type (`0x0` DATA, `0x1`\n  HEADERS, `0x4` SETTINGS, `0x6` PING, `0x7` GOAWAY, `0x8` WINDOW_UPDATE, or\n  connection `preface`).\n- **Token**: `heartbeat`\n  - **Scopes**: sctp, amqp, kafka\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Used across `sctp`, `amqp`, `kafka`: Selects the RFC 9260 SCTP\n  chunk type (`0`=DATA, `1`=INIT, `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT,\n  `5`=HEARTBEAT_ACK, `6`=ABORT, `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO,\n  `11`=COOKIE_ACK, `14`=SHUTDOWN_COMPLETE).\n- **Token**: `heartbeatack`\n  - **Scopes**: sctp\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Selects the RFC 9260 SCTP chunk type (`0`=DATA, `1`=INIT,\n  `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT, `5`=HEARTBEAT_ACK, `6`=ABORT,\n  `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO, `11`=COOKIE_ACK,\n  `14`=SHUTDOWN_COMPLETE).\n- **Token**: `heartbeatrequest`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `heartbeatresponse`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `height`\n  - **Scopes**: rdp, vnc\n  - **Syntax**: `rdp ... height <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP (3389)\n  - **Summary**: Used across `rdp`, `vnc`: Configures the `height` PDU selector or\n  header field across `rdp`, `vnc` frames.\n- **Token**: `hello`\n  - **Scopes**: ospf, pim, glbp, openflow, rsvp, ldp (+4 more)\n  - **Syntax**: `hello | dbd | lsr | lsu | lsack`\n  - **Value / Range**: OSPF Packet Type keyword\n  - **Default**: hello (Type 1)\n  - **Summary**: Used across `ospf`, `pim`, `glbp`, `openflow`, `rsvp`, `ldp`,\n  `l2tp`, `isis`, `netconf`, `wsdiscovery`: Selects Type `1` Hello, Type `2`\n  Database Description (`dbd`), Type `3` Link State Request (`lsr`), Type `4` Link\n  State Update (`lsu`), or Type `5` Link State Acknowledgment (`lsack`).\n- **Token**: `hellointerval`\n  - **Scopes**: ospf\n  - **Syntax**: `hellointerval <0..65535> | deadinterval <number>`\n  - **Value / Range**: Timers in seconds\n  - **Default**: hellointerval 10, deadinterval 40\n  - **Summary**: Sets the Hello Interval (`u16` seconds) and Router Dead Interval\n  (`u32` OSPFv2 / `u16` OSPFv3) in `hello` packets.\n- **Token**: `hellotime`\n  - **Scopes**: stp, hsrp, glbp\n  - **Syntax**: `maxage <0..65535> | hellotime <0..65535> | forwarddelay\n  <0..65535>`\n  - **Value / Range**: 16-bit unsigned integers (seconds)\n  - **Default**: maxage 20, hellotime 2, forwarddelay 15\n  - **Summary**: Used across `stp`, `hsrp`, `glbp`: Encodes BPDU timers scaled to\n  IEEE 802.1D `1/256`s increments.\n- **Token**: `helo`\n  - **Scopes**: smtp\n  - **Syntax**: `ehlo [\"<domain>\"] | helo [\"<domain>\"]`\n  - **Value / Range**: Extended or classic SMTP greeting + client hostname\n  - **Default**: \"localhost\"\n  - **Summary**: Writes `EHLO <domain>\\r\\n` or `HELO <domain>\\r\\n`.\n- **Token**: `holdtime`\n  - **Scopes**: isis, bgp, pim, hsrp, glbp, ldp (+1 more)\n  - **Syntax**: `holdtime <0..65535>`\n  - **Value / Range**: Seconds (0..65535)\n  - **Default**: 30\n  - **Summary**: Used across `isis`, `bgp`, `pim`, `hsrp`, `glbp`, `ldp`,\n  `hartip`: Sets the 16-bit Holding Timer inside `l1iih`, `l2iih`, and `p2piih`\n  headers.\n- **Token**: `hopid`\n  - **Scopes**: diameter\n  - **Syntax**: `hopid <number> | endid <number>`\n  - **Value / Range**: 32-bit Hop-by-Hop and End-to-End Identifiers\n  - **Default**: Auto-populated non-zero IDs\n  - **Summary**: Writes bytes 12..19 used by peers and DRAs to match Answers to\n  Requests.\n- **Token**: `hosthdr`\n  - **Scopes**: http, ssdp, doh, ntlm\n  - **Syntax**: `hosthdr \"<text>\"`\n  - **Value / Range**: Quoted hostname (e.g. \"api.internal\")\n  - **Default**: Destination IP\n  - **Summary**: Used across `http`, `ssdp`, `doh`, `ntlm`: Writes the `Host:`\n  HTTP header (named `hosthdr` so it never conflicts with the top-level `host`\n  block keyword).\n- **Token**: `hostname`\n  - **Scopes**: isis, dhcp, syslog\n  - **Syntax**: `hostname \"<text>\"`\n  - **Value / Range**: Quoted router hostname\n  - **Default**: Omitted unless set\n  - **Summary**: Used across `isis`, `dhcp`, `syslog`: Appends RFC 5301 Dynamic\n  Hostname TLV (`137`) so Wireshark resolves System IDs symbolically.\n- **Token**: `hostuniq`\n  - **Scopes**: pppoe\n  - **Syntax**: `hostuniq \"<hex>\"`\n  - **Value / Range**: Quoted hex byte string\n  - **Default**: Omitted unless set\n  - **Summary**: Encodes Discovery Tag `0x0103` (`Host-Uniq` client correlation\n  token).\n- **Token**: `iam`\n  - **Scopes**: bacnet\n  - **Syntax**: `whois | iam | readproperty | writeproperty`\n  - **Value / Range**: BACnet APDU service selector\n  - **Default**: whois\n  - **Summary**: Selects Unconfirmed `Who-Is` (`8`), Unconfirmed `I-Am` (`0`),\n  Confirmed `ReadProperty` (`12`), or Confirmed `WriteProperty` (`15`).\n- **Token**: `icf`\n  - **Scopes**: fins\n  - **Syntax**: `icf <0..255> | sid <0..255>`\n  - **Value / Range**: 8-bit Information Control Field & 8-bit Service ID\n  - **Default**: icf 0x80 (or 0xc0), sid 1\n  - **Summary**: Writes byte 0 (`ICF`) and byte 9 (`SID` transaction correlation\n  byte) of the 10-byte FINS header.\n- **Token**: `icreq`\n  - **Scopes**: nvmetcp\n  - **Syntax**: `icreq | icresp | read | write | response | h2cdata | c2hdata |\n  r2t | msgtype \"<text>\" | cmd \"<text>\"`\n  - **Value / Range**: NVMe/TCP PDU Type or NVMe Command selector\n  - **Default**: icreq (0x00)\n  - **Summary**: Selects `0x00` ICReq, `0x01` ICResp, `0x04` CapsuleCmd (`read`\n  NVMe `0x02`, `write` NVMe `0x01`), `0x05` CapsuleResp, `0x06` H2CData, `0x07`\n  C2HData, or `0x09` R2T.\n- **Token**: `icresp`\n  - **Scopes**: nvmetcp\n  - **Syntax**: `icreq | icresp | read | write | response | h2cdata | c2hdata |\n  r2t | msgtype \"<text>\" | cmd \"<text>\"`\n  - **Value / Range**: NVMe/TCP PDU Type or NVMe Command selector\n  - **Default**: icreq (0x00)\n  - **Summary**: Selects `0x00` ICReq, `0x01` ICResp, `0x04` CapsuleCmd (`read`\n  NVMe `0x02`, `write` NVMe `0x01`), `0x05` CapsuleResp, `0x06` H2CData, `0x07`\n  C2HData, or `0x09` R2T.\n- **Token**: `icv`\n  - **Scopes**: macsec, ipsec, esp, ah\n  - **Syntax**: `icv \"<hex>\"`\n  - **Value / Range**: 16-byte hex string (32 hex digits)\n  - **Default**: 16-byte deterministic tag\n  - **Summary**: Used across `macsec`, `ipsec`, `esp`, `ah`: Appends the 128-bit\n  AES-GCM Integrity Check Value trailer at the end of the frame.\n- **Token**: `id`\n  - **Scopes**: icmp, radius, s7commplus, synchrophasor\n  - **Syntax**: `id <0..65535> | seq <0..65535>`\n  - **Value / Range**: 16-bit unsigned integers\n  - **Default**: id 1, seq 1\n  - **Summary**: Used across `icmp`, `radius`, `s7commplus`, `synchrophasor`: Sets\n  the 16-bit Echo Identifier and Echo Sequence Number in the 4-byte\n  rest-of-header.\n- **Token**: `identify`\n  - **Scopes**: c1222\n  - **Syntax**: `read | write | identify | logon | logoff | terminate | response |\n  ok | service \"<text_or_num>\"`\n  - **Value / Range**: EPSEM PSEM Service Code (`0x20` Identify, `0x21` Terminate,\n  `0x30` Read, `0x40` Write, `0x50` Logon, `0x52` Logoff, `0x00` OK)\n  - **Default**: read (0x30)\n  - **Summary**: Selects the EPSEM Request or Response service byte inside the\n  ACSE `user-information` block.\n- **Token**: `identity`\n  - **Scopes**: eapol\n  - **Syntax**: `identity \"<text>\"`\n  - **Value / Range**: UTF-8 string\n  - **Default**: \"user\" (on Identity)\n  - **Summary**: Populates the EAP-Identity Type-Data string (escape backslashes\n  as `\"corp\\\\alice\"`).\n- **Token**: `idx`\n  - **Scopes**: ethercat\n  - **Syntax**: `idx <0..255>`\n  - **Value / Range**: 8-bit Datagram Index\n  - **Default**: 0\n  - **Summary**: Sets the 1-byte master correlation `Index` in byte 1 of the\n  datagram header.\n- **Token**: `ifacever`\n  - **Scopes**: someip\n  - **Syntax**: `protover <0..255> | ifacever <0..255> | returncode <0..255>`\n  - **Value / Range**: 8-bit Protocol Version (`1`), Interface Major Version, and\n  Return Code (`0x00` E_OK)\n  - **Default**: protover 1, ifacever 1, returncode 0\n  - **Summary**: Writes bytes 12, 13, and 15 of the 16-byte SOME/IP header.\n- **Token**: `iid`\n  - **Scopes**: lisp\n  - **Syntax**: `iid <0..16777215>`\n  - **Value / Range**: 24-bit LISP Instance ID / Virtual Network ID\n  - **Default**: 0 (omitted unless specified)\n  - **Summary**: Sets the 24-bit Instance ID (`I=1` bit on `data` shim, or LCAF\n  Type `2` Instance-ID wrapper on control EIDs).\n- **Token**: `imsi`\n  - **Scopes**: gtpc\n  - **Syntax**: `imsi \"<text>\"`\n  - **Value / Range**: 15-digit International Mobile Subscriber Identity string\n  (IE Type 1)\n  - **Default**: Omitted (or default on Create Session)\n  - **Summary**: Encodes the subscriber IMSI in 3GPP TBCD nibble-swapped format\n  inside IE Type `1`.\n- **Token**: `index`\n  - **Scopes**: erspan\n  - **Syntax**: `index <number>`\n  - **Value / Range**: 20-bit switch port index\n  - **Default**: 1\n  - **Summary**: Identifies the source/destination physical switch port index in\n  the ERSPAN header.\n- **Token**: `inform`\n  - **Scopes**: snmp2, snmp3, snmp1\n  - **Syntax**: `trap | inform | report | get | getnext | getbulk | set |\n  response`\n  - **Value / Range**: SNMPv2c PDU type keyword\n  - **Default**: trap (PDU 0xa7 on UDP 162)\n  - **Summary**: Used across `snmp2`, `snmp3`, `snmp1`: Selects RFC 3416 BER PDU\n  tag (`0xa0`..`0xa3` or `0xa5` GetBulk, `0xa6` Inform, `0xa7` SNMPv2-Trap, `0xa8`\n  Report).\n- **Token**: `informational`\n  - **Scopes**: ikev2\n  - **Syntax**: `sainit | auth | createchildsa | informational | exchange <...>`\n  - **Value / Range**: RFC 7296 Exchange Type keyword or u8\n  - **Default**: sainit (34)\n  - **Summary**: Sets Exchange Type: `sainit` (`34` IKE_SA_INIT), `auth` (`35`\n  IKE_AUTH), `createchildsa` (`36` CREATE_CHILD_SA), `informational` (`37`\n  INFORMATIONAL).\n- **Token**: `init`\n  - **Scopes**: ldp, sctp, mms, hartip, gesrtp\n  - **Syntax**: `hello | init | keepalive | notification | labelmapping |\n  labelrequest | labelwithdraw | labelrelease`\n  - **Value / Range**: LDP message type keyword\n  - **Default**: hello (0x0100) or labelmapping\n  - **Summary**: Used across `ldp`, `sctp`, `mms`, `hartip`, `gesrtp`: Selects RFC\n  5036 Message Type (`0x0001`=Notification, `0x0100`=Hello,\n  `0x0200`=Initialization, `0x0201`=KeepAlive, `0x0400`=Label Mapping,\n  `0x0401`=Request, `0x0402`=Withdraw, `0x0403`=Release).\n- **Token**: `initack`\n  - **Scopes**: sctp, mms, gesrtp\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Used across `sctp`, `mms`, `gesrtp`: Selects the RFC 9260 SCTP\n  chunk type (`0`=DATA, `1`=INIT, `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT,\n  `5`=HEARTBEAT_ACK, `6`=ABORT, `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO,\n  `11`=COOKIE_ACK, `14`=SHUTDOWN_COMPLETE).\n- **Token**: `initial`\n  - **Scopes**: quic\n  - **Syntax**: `initial | zerortt | handshake | retry | short`\n  - **Value / Range**: QUIC packet header type\n  - **Default**: initial\n  - **Summary**: Selects Long Header (`initial`, `zerortt`, `handshake`, `retry`)\n  or 1-RTT Short Header (`short`).\n- **Token**: `initialuemessage`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `ngsetuprequest | ngsetupresponse | ngsetupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 38.413 NGAP Elementary Procedure\n  - **Default**: ngsetuprequest\n  - **Summary**: Used across `ngap`, `s1ap`: Selects both the APER PDU Choice\n  (`InitiatingMessage` / `SuccessfulOutcome` / `UnsuccessfulOutcome`) and\n  mandatory 3GPP TS 38.413 Procedure Code + ProtocolIEs.\n- **Token**: `initiation`\n  - **Scopes**: wireguard, bmp\n  - **Syntax**: `initiation | response | cookie | data | type <...>`\n  - **Value / Range**: WireGuard message type keyword\n  - **Default**: initiation (Type 1)\n  - **Summary**: Used across `wireguard`, `bmp`: Selects Type `1` Handshake\n  Initiation (`148B`), Type `2` Handshake Response (`92B`), Type `3` Cookie Reply\n  (`64B`), or Type `4` Transport Data (`>= 32B`).\n- **Token**: `initiator`\n  - **Scopes**: iscsi\n  - **Syntax**: `initiator \"<text>\" | target \"<text>\"`\n  - **Value / Range**: iSCSI Qualified Name (IQN / EUI) strings\n  - **Default**: \"iqn.2026-01.com.example:initiator\" / \"...:target\"\n  - **Summary**: Appends `InitiatorName=\"<text>\"` and `TargetName=\"<text>\"`\n  key-value pairs in Login/Text DataSegments.\n- **Token**: `initiatorspi`\n  - **Scopes**: ikev2\n  - **Syntax**: `initiatorspi <u64|\"hex\"> | responderspi <u64|\"hex\">`\n  - **Value / Range**: 64-bit integer or hex string\n  - **Default**: Deterministic initiator SPI; responderspi 0 on sainit\n  - **Summary**: Populates the 8-byte Initiator SPI and 8-byte Responder SPI in\n  the IKEv2 header.\n- **Token**: `innerdscp`\n  - **Scopes**: ipip\n  - **Syntax**: `innerdscp <0..63>`\n  - **Value / Range**: 6-bit inner DiffServ codepoint (0..63)\n  - **Default**: 0\n  - **Summary**: Sets the upper 6 bits of the inner IPv4 TOS byte or inner IPv6\n  Traffic Class.\n- **Token**: `innerttl`\n  - **Scopes**: ipip\n  - **Syntax**: `innerttl <0..255>`\n  - **Value / Range**: 8-bit inner TTL / Hop Limit (0..255)\n  - **Default**: 64\n  - **Summary**: Sets the inner IPv4 TTL or inner IPv6 Hop Limit independently of\n  outer `ttl`.\n- **Token**: `instanceid`\n  - **Scopes**: someip\n  - **Syntax**: `sdservice <0..65535> | instanceid <0..65535> | majorver <0..255>\n  | minorver <number> | sdttl <0..16777215>`\n  - **Value / Range**: SOME/IP-SD 16-byte Service/Eventgroup Entry fields\n  - **Default**: sdservice 0x1234, instanceid 1, majorver 1, minorver 0, sdttl 3\n  - **Summary**: Populates the SOME/IP-SD Entry (`sdttl 0` signifies\n  `StopOfferService` / `StopSubscribeEventgroup`).\n- **Token**: `int`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `invite`\n  - **Scopes**: sip\n  - **Syntax**: `invite | ack | bye | cancel | register | options | method\n  \"<text>\"`\n  - **Value / Range**: SIP request method\n  - **Default**: invite\n  - **Summary**: Sets the SIP request verb on the start line and inside the `CSeq`\n  header.\n- **Token**: `invokeid`\n  - **Scopes**: bacnet, mms\n  - **Syntax**: `invokeid <0..255>`\n  - **Value / Range**: 1-byte Confirmed-Request Invoke ID\n  - **Default**: 1\n  - **Summary**: Used across `bacnet`, `mms`: Matches Confirmed `readproperty` /\n  `writeproperty` requests with Complex-ACK / Simple-ACK replies.\n- **Token**: `invversion`\n  - **Scopes**: doip\n  - **Syntax**: `version <0..255> | invversion <0..255>`\n  - **Value / Range**: DoIP Protocol Version (`2` = 2012, `3` = 2019, `0xff`\n  default discovery) & Inverse Version\n  - **Default**: version 2, invversion 0xfd (auto version ^ 0xff)\n  - **Summary**: Writes bytes 0 and 1 of the 8-byte Generic DoIP Header.\n- **Token**: `io`\n  - **Scopes**: melsec\n  - **Syntax**: `network <0..255> | pc <0..255> | io <0..65535> | station <0..255>\n  | timer <0..65535>`\n  - **Value / Range**: 3E Routing Path + Monitoring Timer (in 250 ms units)\n  - **Default**: network 0, pc 0xff, io 0x03ff, station 0, timer 16\n  - **Summary**: Populates bytes 2..6 (Access Route) and bytes 9..10 (CPU\n  Monitoring Timer) of the 3E header.\n- **Token**: `ioa`\n  - **Scopes**: iec104\n  - **Syntax**: `ca <0..65535> | ioa <0..16777215>`\n  - **Value / Range**: 16-bit Common Address of ASDU & 24-bit Information Object\n  Address\n  - **Default**: ca 1, ioa 1\n  - **Summary**: Writes the 2-byte little-endian station `CA` and 3-byte\n  little-endian data-point `IOA`.\n- **Token**: `ipv4prefix`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `serialnotify | serialquery | resetquery | cacheresponse |\n  ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport`\n  - **Value / Range**: RPKI-RTR PDU type keyword\n  - **Default**: ipv4prefix (Type 4)\n  - **Summary**: Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset\n  Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data,\n  `8`=Cache Reset, `10`=Error Report).\n- **Token**: `ipv6prefix`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `serialnotify | serialquery | resetquery | cacheresponse |\n  ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport`\n  - **Value / Range**: RPKI-RTR PDU type keyword\n  - **Default**: ipv4prefix (Type 4)\n  - **Summary**: Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset\n  Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data,\n  `8`=Cache Reset, `10`=Error Report).\n- **Token**: `ipval`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `irq`\n  - **Scopes**: ethercat\n  - **Syntax**: `irq <0..65535>`\n  - **Value / Range**: 16-bit EtherCAT Event Request mask\n  - **Default**: 0\n  - **Summary**: Sets the little-endian 16-bit `IRQ` field ahead of the datagram\n  payload.\n- **Token**: `isresponse`\n  - **Scopes**: modbus, s7commplus, mms, hartip, fins, melsec (+2 more)\n  - **Syntax**: `isresponse`\n  - **Value / Range**: Keyword flag on PLC replies\n  - **Default**: Request format when omitted\n  - **Summary**: Used across `modbus`, `s7commplus`, `mms`, `hartip`, `fins`,\n  `melsec`, `rocplus`, `bsap`: Formats `FC 1..4` packets as PLC responses\n  (`[FC][ByteCount][Data...]`) so Wireshark dissects the reply without\n  malformed-length warnings.\n- **Token**: `item`\n  - **Scopes**: mms\n  - **Syntax**: `domain \"<text>\" | item \"<text>\"`\n  - **Value / Range**: IEC 61850 Logical Device `domainId` & `$`-separated\n  `itemId`\n  - **Default**: domain \"LD0\", item \"LLN0$ST$Mod\"\n  - **Summary**: Populates the `domain-specific` `(VisibleString domainId,\n  VisibleString itemId)` variable specification.\n- **Token**: `itt`\n  - **Scopes**: iscsi\n  - **Syntax**: `itt <number> | cmdsn <number> | statsn <number>`\n  - **Value / Range**: 32-bit Initiator Task Tag, Command SeqNum, and Status\n  SeqNum\n  - **Default**: itt 1, cmdsn 1, statsn 1\n  - **Summary**: Populates BHS bytes 16..19 (`ITT`) and 24..31 (`CmdSN` /\n  `ExpStatSN` / `StatSN`).\n- **Token**: `iv`\n  - **Scopes**: ipsec, esp\n  - **Syntax**: `iv \"<hex>\"`\n  - **Value / Range**: Double-quoted even-length hex octets\n  - **Default**: 8-byte deterministic IV\n  - **Summary**: Used across `ipsec`, `esp`: Writes the explicit Initialization\n  Vector octets immediately after `spi` + `seq`.\n- **Token**: `jitter`\n  - **Scopes**: rtcp\n  - **Syntax**: `rtcp ... jitter <u32>`\n  - **Value / Range**: Parameter <u32>\n  - **Default**: UDP (5005)\n  - **Summary**: Configures the `jitter` PDU selector or header field on `rtcp`\n  frames.\n- **Token**: `join`\n  - **Scopes**: irc\n  - **Syntax**: `irc ... join`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (6667)\n  - **Summary**: Configures the `join` PDU selector or header field on `irc`\n  frames.\n- **Token**: `joinprune`\n  - **Scopes**: pim\n  - **Syntax**: `hello | joinprune | register`\n  - **Value / Range**: PIMv2 Message Type keyword\n  - **Default**: hello (Type 0)\n  - **Summary**: Selects Type `0` Hello, Type `1` unicast Register (to RP), or\n  Type `3` Join/Prune.\n- **Token**: `keepalive`\n  - **Scopes**: bgp, ldp, mqtt, hartip, sccp\n  - **Syntax**: `open | update | notification | keepalive`\n  - **Value / Range**: BGP message type keyword\n  - **Default**: keepalive (Type 4)\n  - **Summary**: Used across `bgp`, `ldp`, `mqtt`, `hartip`, `sccp`: Selects Type\n  `1` OPEN, Type `2` UPDATE, Type `3` NOTIFICATION (Cease error), or Type `4`\n  19-byte KEEPALIVE.\n- **Token**: `keepaliveack`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... keepaliveack`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `keepaliveack` PDU selector or header field on\n  `sccp` frames.\n- **Token**: `kexinit`\n  - **Scopes**: ssh\n  - **Syntax**: `kexinit`\n  - **Value / Range**: Keyword flag\n  - **Default**: Omitted\n  - **Summary**: Emits a binary RFC 4253 `SSH_MSG_KEXINIT` (`20`) packet with\n  16-byte cookie and KEX algorithm lists.\n- **Token**: `key`\n  - **Scopes**: eapol, gre, rocev2, redis, memcached, vnc (+1 more)\n  - **Syntax**: `eappacket | start | logoff | key | type <...>`\n  - **Value / Range**: EAPOL packet type keyword or u8\n  - **Default**: eappacket (type 0)\n  - **Summary**: Used across `eapol`, `gre`, `rocev2`, `redis`, `memcached`,\n  `vnc`, `kafka`: Selects EAPOL Packet Type: `eappacket` (`0`), `start` (`1`,\n  0-byte body), `logoff` (`2`, 0-byte body), or `key` (`3`, EAPOL-Key descriptor).\n- **Token**: `keypadbutton`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... keypadbutton`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `keypadbutton` PDU selector or header field on\n  `sccp` frames.\n- **Token**: `krberror`\n  - **Scopes**: kerberos\n  - **Syntax**: `asreq | asrep | tgsreq | tgsrep | krberror`\n  - **Value / Range**: Kerberos v5 message type\n  - **Default**: asreq (msg-type 10)\n  - **Summary**: Selects Authentication Service Request/Reply (`10`/`11`),\n  Ticket-Granting Service Request/Reply (`12`/`13`), or Error (`30`).\n- **Token**: `l1csnp`\n  - **Scopes**: isis\n  - **Syntax**: `l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp | l1psnp\n  | l2psnp`\n  - **Value / Range**: IS-IS PDU type keyword (or `type \"<pdu>\"`)\n  - **Default**: l2iih (PDU Type 16)\n  - **Summary**: Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP\n  (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`).\n- **Token**: `l1iih`\n  - **Scopes**: isis\n  - **Syntax**: `l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp | l1psnp\n  | l2psnp`\n  - **Value / Range**: IS-IS PDU type keyword (or `type \"<pdu>\"`)\n  - **Default**: l2iih (PDU Type 16)\n  - **Summary**: Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP\n  (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`).\n- **Token**: `l1lsp`\n  - **Scopes**: isis\n  - **Syntax**: `l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp | l1psnp\n  | l2psnp`\n  - **Value / Range**: IS-IS PDU type keyword (or `type \"<pdu>\"`)\n  - **Default**: l2iih (PDU Type 16)\n  - **Summary**: Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP\n  (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`).\n- **Token**: `l1psnp`\n  - **Scopes**: isis\n  - **Syntax**: `l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp | l1psnp\n  | l2psnp`\n  - **Value / Range**: IS-IS PDU type keyword (or `type \"<pdu>\"`)\n  - **Default**: l2iih (PDU Type 16)\n  - **Summary**: Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP\n  (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`).\n- **Token**: `l2csnp`\n  - **Scopes**: isis\n  - **Syntax**: `l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp | l1psnp\n  | l2psnp`\n  - **Value / Range**: IS-IS PDU type keyword (or `type \"<pdu>\"`)\n  - **Default**: l2iih (PDU Type 16)\n  - **Summary**: Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP\n  (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`).\n- **Token**: `l2iih`\n  - **Scopes**: isis\n  - **Syntax**: `l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp | l1psnp\n  | l2psnp`\n  - **Value / Range**: IS-IS PDU type keyword (or `type \"<pdu>\"`)\n  - **Default**: l2iih (PDU Type 16)\n  - **Summary**: Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP\n  (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`).\n- **Token**: `l2lsp`\n  - **Scopes**: isis\n  - **Syntax**: `l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp | l1psnp\n  | l2psnp`\n  - **Value / Range**: IS-IS PDU type keyword (or `type \"<pdu>\"`)\n  - **Default**: l2iih (PDU Type 16)\n  - **Summary**: Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP\n  (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`).\n- **Token**: `l2psnp`\n  - **Scopes**: isis\n  - **Syntax**: `l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp | l1psnp\n  | l2psnp`\n  - **Value / Range**: IS-IS PDU type keyword (or `type \"<pdu>\"`)\n  - **Default**: l2iih (PDU Type 16)\n  - **Summary**: Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP\n  (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`).\n- **Token**: `labelmapping`\n  - **Scopes**: ldp\n  - **Syntax**: `hello | init | keepalive | notification | labelmapping |\n  labelrequest | labelwithdraw | labelrelease`\n  - **Value / Range**: LDP message type keyword\n  - **Default**: hello (0x0100) or labelmapping\n  - **Summary**: Selects RFC 5036 Message Type (`0x0001`=Notification,\n  `0x0100`=Hello, `0x0200`=Initialization, `0x0201`=KeepAlive, `0x0400`=Label\n  Mapping, `0x0401`=Request, `0x0402`=Withdraw, `0x0403`=Release).\n- **Token**: `labelrelease`\n  - **Scopes**: ldp\n  - **Syntax**: `hello | init | keepalive | notification | labelmapping |\n  labelrequest | labelwithdraw | labelrelease`\n  - **Value / Range**: LDP message type keyword\n  - **Default**: hello (0x0100) or labelmapping\n  - **Summary**: Selects RFC 5036 Message Type (`0x0001`=Notification,\n  `0x0100`=Hello, `0x0200`=Initialization, `0x0201`=KeepAlive, `0x0400`=Label\n  Mapping, `0x0401`=Request, `0x0402`=Withdraw, `0x0403`=Release).\n- **Token**: `labelrequest`\n  - **Scopes**: ldp\n  - **Syntax**: `hello | init | keepalive | notification | labelmapping |\n  labelrequest | labelwithdraw | labelrelease`\n  - **Value / Range**: LDP message type keyword\n  - **Default**: hello (0x0100) or labelmapping\n  - **Summary**: Selects RFC 5036 Message Type (`0x0001`=Notification,\n  `0x0100`=Hello, `0x0200`=Initialization, `0x0201`=KeepAlive, `0x0400`=Label\n  Mapping, `0x0401`=Request, `0x0402`=Withdraw, `0x0403`=Release).\n- **Token**: `labelspace`\n  - **Scopes**: ldp\n  - **Syntax**: `lsrid <ipv4> [labelspace <0..65535>]`\n  - **Value / Range**: 32-bit dotted-quad LSR Router ID & 16-bit Label Space\n  - **Default**: Source IPv4 (or 1.1.1.1 on IPv6), labelspace 0\n  - **Summary**: Writes the 6-byte LDP Identifier (`4B LSR ID : 2B Label Space`)\n  in the 10-byte LDP PDU header.\n- **Token**: `labelwithdraw`\n  - **Scopes**: ldp\n  - **Syntax**: `hello | init | keepalive | notification | labelmapping |\n  labelrequest | labelwithdraw | labelrelease`\n  - **Value / Range**: LDP message type keyword\n  - **Default**: hello (0x0100) or labelmapping\n  - **Summary**: Selects RFC 5036 Message Type (`0x0001`=Notification,\n  `0x0100`=Hello, `0x0200`=Initialization, `0x0201`=KeepAlive, `0x0400`=Label\n  Mapping, `0x0401`=Request, `0x0402`=Withdraw, `0x0403`=Release).\n- **Token**: `lanid`\n  - **Scopes**: isis\n  - **Syntax**: `lanid \"<text>\"`\n  - **Value / Range**: 7-byte LAN ID (System ID + Pseudonode)\n  - **Default**: sysid + \".01\"\n  - **Summary**: Sets the 7-octet Designated IS LAN ID field inside `l1iih` and\n  `l2iih` PDUs.\n- **Token**: `leasetime`\n  - **Scopes**: dhcp\n  - **Syntax**: `leasetime <number> | hostname \"<text>\"`\n  - **Value / Range**: u32 seconds, UTF-8 string\n  - **Default**: leasetime 86400\n  - **Summary**: Appends Option `51` (IP Address Lease Time) and Option `12` (Host\n  Name).\n- **Token**: `leave`\n  - **Scopes**: igmp\n  - **Syntax**: `query | report | leave`\n  - **Value / Range**: IGMP message type\n  - **Default**: query\n  - **Summary**: Selects Membership Query (`0x11`), Membership Report (`0x12` v1 /\n  `0x16` v2 / `0x22` v3), or Leave Group (`0x17`).\n- **Token**: `li`\n  - **Scopes**: ntp\n  - **Syntax**: `li <0..3>`\n  - **Value / Range**: 2-bit Leap Indicator\n  - **Default**: 0 (no warning)\n  - **Summary**: Sets bits 7..6 of byte 0 (`0`=no leap, `1`=61s minute, `2`=59s\n  minute, `3`=unsynchronized/alarm).\n- **Token**: `lifetime`\n  - **Scopes**: isis, turn\n  - **Syntax**: `lifetime <0..65535>`\n  - **Value / Range**: Remaining Lifetime in seconds\n  - **Default**: 1200\n  - **Summary**: Used across `isis`, `turn`: Sets the 16-bit Remaining Lifetime\n  inside `l1lsp` and `l2lsp` PDUs (`0` purges an LSP).\n- **Token**: `line`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... line <u32>`\n  - **Value / Range**: Parameter <u32>\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `line` PDU selector or header field on `sccp`\n  frames.\n- **Token**: `listidentity`\n  - **Scopes**: ethernetip\n  - **Syntax**: `nop | listservices | listidentity | listinterfaces |\n  registersession | unregistersession | sendrrdata | sendunitdata`\n  - **Value / Range**: EtherNet/IP encapsulation command (or `cmd \"<text>\"`)\n  - **Default**: listidentity (0x0063)\n  - **Summary**: Selects Encapsulation Command `0x0000` NOP, `0x0004`\n  ListServices, `0x0063` ListIdentity, `0x0064` ListInterfaces, `0x0065`\n  RegisterSession, `0x0066` UnRegisterSession, `0x006f` SendRRData, or `0x0070`\n  SendUnitData.\n- **Token**: `listinterfaces`\n  - **Scopes**: ethernetip\n  - **Syntax**: `nop | listservices | listidentity | listinterfaces |\n  registersession | unregistersession | sendrrdata | sendunitdata`\n  - **Value / Range**: EtherNet/IP encapsulation command (or `cmd \"<text>\"`)\n  - **Default**: listidentity (0x0063)\n  - **Summary**: Selects Encapsulation Command `0x0000` NOP, `0x0004`\n  ListServices, `0x0063` ListIdentity, `0x0064` ListInterfaces, `0x0065`\n  RegisterSession, `0x0066` UnRegisterSession, `0x006f` SendRRData, or `0x0070`\n  SendUnitData.\n- **Token**: `listservices`\n  - **Scopes**: ethernetip\n  - **Syntax**: `nop | listservices | listidentity | listinterfaces |\n  registersession | unregistersession | sendrrdata | sendunitdata`\n  - **Value / Range**: EtherNet/IP encapsulation command (or `cmd \"<text>\"`)\n  - **Default**: listidentity (0x0063)\n  - **Summary**: Selects Encapsulation Command `0x0000` NOP, `0x0004`\n  ListServices, `0x0063` ListIdentity, `0x0064` ListInterfaces, `0x0065`\n  RegisterSession, `0x0066` UnRegisterSession, `0x006f` SendRRData, or `0x0070`\n  SendUnitData.\n- **Token**: `localopts`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... localopts <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `localopts` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `location`\n  - **Scopes**: ssdp\n  - **Syntax**: `nt \"<text>\" | nts \"<text>\" | usn \"<text>\" | location \"<text>\"`\n  - **Value / Range**: NOTIFY advertisement headers (`NTS` `\"ssdp:alive\"` or\n  `\"ssdp:byebye\"`)\n  - **Default**: nts \"ssdp:alive\"\n  - **Summary**: Populates Notification Type, Sub-Type, Unique Service Name, and\n  XML `LOCATION` URL on `notify` packets.\n- **Token**: `login`\n  - **Scopes**: iscsi, mysql, mssql\n  - **Syntax**: `login | logout | read | write | nop | response | data | text |\n  cmd \"<text>\"`\n  - **Value / Range**: iSCSI BHS PDU type shorthand\n  - **Default**: nop (0x00)\n  - **Summary**: Used across `iscsi`, `mysql`, `mssql`: Selects `0x00` NOP-Out,\n  `0x01` SCSI Command (`read`/`write`), `0x03` Login Request, `0x04` Text Request,\n  `0x05` SCSI Data-Out, `0x06` Logout, `0x21` SCSI Response, `0x23` Login\n  Response, or `0x25` SCSI Data-In.\n- **Token**: `logoff`\n  - **Scopes**: eapol, smb, c1222\n  - **Syntax**: `eappacket | start | logoff | key | type <...>`\n  - **Value / Range**: EAPOL packet type keyword or u8\n  - **Default**: eappacket (type 0)\n  - **Summary**: Used across `eapol`, `smb`, `c1222`: Selects EAPOL Packet Type:\n  `eappacket` (`0`), `start` (`1`, 0-byte body), `logoff` (`2`, 0-byte body), or\n  `key` (`3`, EAPOL-Key descriptor).\n- **Token**: `logon`\n  - **Scopes**: c1222\n  - **Syntax**: `read | write | identify | logon | logoff | terminate | response |\n  ok | service \"<text_or_num>\"`\n  - **Value / Range**: EPSEM PSEM Service Code (`0x20` Identify, `0x21` Terminate,\n  `0x30` Read, `0x40` Write, `0x50` Logon, `0x52` Logoff, `0x00` OK)\n  - **Default**: read (0x30)\n  - **Summary**: Selects the EPSEM Request or Response service byte inside the\n  ACSE `user-information` block.\n- **Token**: `logout`\n  - **Scopes**: iscsi\n  - **Syntax**: `login | logout | read | write | nop | response | data | text |\n  cmd \"<text>\"`\n  - **Value / Range**: iSCSI BHS PDU type shorthand\n  - **Default**: nop (0x00)\n  - **Summary**: Selects `0x00` NOP-Out, `0x01` SCSI Command (`read`/`write`),\n  `0x03` Login Request, `0x04` Text Request, `0x05` SCSI Data-Out, `0x06` Logout,\n  `0x21` SCSI Response, `0x23` Login Response, or `0x25` SCSI Data-In.\n- **Token**: `lost`\n  - **Scopes**: rtcp\n  - **Syntax**: `rtcp ... lost <u32>`\n  - **Value / Range**: Parameter <u32>\n  - **Default**: UDP (5005)\n  - **Summary**: Configures the `lost` PDU selector or header field on `rtcp`\n  frames.\n- **Token**: `lsack`\n  - **Scopes**: ospf\n  - **Syntax**: `hello | dbd | lsr | lsu | lsack`\n  - **Value / Range**: OSPF Packet Type keyword\n  - **Default**: hello (Type 1)\n  - **Summary**: Selects Type `1` Hello, Type `2` Database Description (`dbd`),\n  Type `3` Link State Request (`lsr`), Type `4` Link State Update (`lsu`), or Type\n  `5` Link State Acknowledgment (`lsack`).\n- **Token**: `lspid`\n  - **Scopes**: rsvp\n  - **Syntax**: `tunnelid <0..65535> | lspid <0..65535>`\n  - **Value / Range**: 16-bit TE Tunnel ID and 16-bit LSP ID\n  - **Default**: tunnelid 1, lspid 1\n  - **Summary**: Populates the RFC 3209 `SESSION` Tunnel ID and `SENDER_TEMPLATE`\n  / `FILTER_SPEC` LSP ID.\n- **Token**: `lsr`\n  - **Scopes**: ospf\n  - **Syntax**: `hello | dbd | lsr | lsu | lsack`\n  - **Value / Range**: OSPF Packet Type keyword\n  - **Default**: hello (Type 1)\n  - **Summary**: Selects Type `1` Hello, Type `2` Database Description (`dbd`),\n  Type `3` Link State Request (`lsr`), Type `4` Link State Update (`lsu`), or Type\n  `5` Link State Acknowledgment (`lsack`).\n- **Token**: `lsrid`\n  - **Scopes**: ldp\n  - **Syntax**: `lsrid <ipv4> [labelspace <0..65535>]`\n  - **Value / Range**: 32-bit dotted-quad LSR Router ID & 16-bit Label Space\n  - **Default**: Source IPv4 (or 1.1.1.1 on IPv6), labelspace 0\n  - **Summary**: Writes the 6-byte LDP Identifier (`4B LSR ID : 2B Label Space`)\n  in the 10-byte LDP PDU header.\n- **Token**: `lsu`\n  - **Scopes**: ospf\n  - **Syntax**: `hello | dbd | lsr | lsu | lsack`\n  - **Value / Range**: OSPF Packet Type keyword\n  - **Default**: hello (Type 1)\n  - **Summary**: Selects Type `1` Hello, Type `2` Database Description (`dbd`),\n  Type `3` Link State Request (`lsr`), Type `4` Link State Update (`lsu`), or Type\n  `5` Link State Acknowledgment (`lsack`).\n- **Token**: `lun`\n  - **Scopes**: iscsi, ipmi\n  - **Syntax**: `lun <0..65535>`\n  - **Value / Range**: 16-bit single-level Logical Unit Number\n  - **Default**: 0\n  - **Summary**: Used across `iscsi`, `ipmi`: Writes the big-endian LUN in bytes\n  8..15 of the 48-byte BHS.\n- **Token**: `mailfrom`\n  - **Scopes**: smtp\n  - **Syntax**: `mailfrom \"<addr>\" | rcptto \"<addr>\"`\n  - **Value / Range**: Quoted sender or recipient email address\n  - **Default**: Omitted unless set\n  - **Summary**: Writes `MAIL FROM:<addr>\\r\\n` or `RCPT TO:<addr>\\r\\n`.\n- **Token**: `majorver`\n  - **Scopes**: someip\n  - **Syntax**: `sdservice <0..65535> | instanceid <0..65535> | majorver <0..255>\n  | minorver <number> | sdttl <0..16777215>`\n  - **Value / Range**: SOME/IP-SD 16-byte Service/Eventgroup Entry fields\n  - **Default**: sdservice 0x1234, instanceid 1, majorver 1, minorver 0, sdttl 3\n  - **Summary**: Populates the SOME/IP-SD Entry (`sdttl 0` signifies\n  `StopOfferService` / `StopSubscribeEventgroup`).\n- **Token**: `man`\n  - **Scopes**: ssdp\n  - **Syntax**: `man \"<text>\" | mx <0..255> | st \"<text>\"`\n  - **Value / Range**: M-SEARCH discovery headers (`MX` max wait seconds, `ST`\n  Search Target)\n  - **Default**: man \"\\\"ssdp:discover\\\"\", mx 3, st \"ssdp:all\"\n  - **Summary**: Populates mandatory UPnP discovery request headers on `msearch`\n  packets.\n- **Token**: `mapnotify`\n  - **Scopes**: lisp\n  - **Syntax**: `data | maprequest | mapreply | mapregister | mapnotify | ecm`\n  - **Value / Range**: LISP data or control message mode\n  - **Default**: maprequest (UDP 4342)\n  - **Summary**: Selects UDP `4341` Data encapsulation or UDP `4342` Control Type\n  (`1`=Map-Request, `2`=Map-Reply, `3`=Map-Register, `4`=Map-Notify,\n  `8`=Encapsulated Control Message).\n- **Token**: `mapregister`\n  - **Scopes**: lisp\n  - **Syntax**: `data | maprequest | mapreply | mapregister | mapnotify | ecm`\n  - **Value / Range**: LISP data or control message mode\n  - **Default**: maprequest (UDP 4342)\n  - **Summary**: Selects UDP `4341` Data encapsulation or UDP `4342` Control Type\n  (`1`=Map-Request, `2`=Map-Reply, `3`=Map-Register, `4`=Map-Notify,\n  `8`=Encapsulated Control Message).\n- **Token**: `mapreply`\n  - **Scopes**: lisp\n  - **Syntax**: `data | maprequest | mapreply | mapregister | mapnotify | ecm`\n  - **Value / Range**: LISP data or control message mode\n  - **Default**: maprequest (UDP 4342)\n  - **Summary**: Selects UDP `4341` Data encapsulation or UDP `4342` Control Type\n  (`1`=Map-Request, `2`=Map-Reply, `3`=Map-Register, `4`=Map-Notify,\n  `8`=Encapsulated Control Message).\n- **Token**: `maprequest`\n  - **Scopes**: lisp\n  - **Syntax**: `data | maprequest | mapreply | mapregister | mapnotify | ecm`\n  - **Value / Range**: LISP data or control message mode\n  - **Default**: maprequest (UDP 4342)\n  - **Summary**: Selects UDP `4341` Data encapsulation or UDP `4342` Control Type\n  (`1`=Map-Request, `2`=Map-Reply, `3`=Map-Register, `4`=Map-Notify,\n  `8`=Encapsulated Control Message).\n- **Token**: `marker`\n  - **Scopes**: rtp, tns\n  - **Syntax**: `marker <0|1>`\n  - **Value / Range**: `1` (talkspurt start / end-of-video-frame) or `0`\n  - **Default**: 0\n  - **Summary**: Used across `rtp`, `tns`: Sets the 1-bit `M` flag at the top of\n  byte 1.\n- **Token**: `maskkey`\n  - **Scopes**: websocket\n  - **Syntax**: `maskkey <number>`\n  - **Value / Range**: 32-bit masking key (e.g. 0x37fa213d)\n  - **Default**: Unmasked (MASK=0)\n  - **Summary**: Sets `MASK=1`, inserts the 4-byte Masking-Key in the header, and\n  XOR-masks payload bytes on the wire.\n- **Token**: `maxage`\n  - **Scopes**: stp\n  - **Syntax**: `maxage <0..65535> | hellotime <0..65535> | forwarddelay\n  <0..65535>`\n  - **Value / Range**: 16-bit unsigned integers (seconds)\n  - **Default**: maxage 20, hellotime 2, forwarddelay 15\n  - **Summary**: Encodes BPDU timers scaled to IEEE 802.1D `1/256`s increments.\n- **Token**: `maxlen`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `prefix \"<cidr>\" | maxlen <0..128> | asn <number>`\n  - **Value / Range**: Quoted IPv4/IPv6 CIDR, Max Length & 32-bit Origin ASN\n  - **Default**: \"192.0.2.0/24\", maxlen = prefix_len, asn 65001\n  - **Summary**: Writes the Prefix Length, Max Length, IPv4/IPv6 prefix bytes, and\n  4-byte Origin AS Number.\n- **Token**: `maxrepetitions`\n  - **Scopes**: snmp2, snmp3, snmp1\n  - **Syntax**: `nonrepeaters <number> | maxrepetitions <number>`\n  - **Value / Range**: Whole number\n  - **Default**: nonrepeaters 0, maxrepetitions 10\n  - **Summary**: Used across `snmp2`, `snmp3`, `snmp1`: Sets scalar\n  `non-repeaters` count and tabular `max-repetitions` row count on `getbulk` PDUs.\n- **Token**: `maxresp`\n  - **Scopes**: igmp\n  - **Syntax**: `maxresp <0..255>`\n  - **Value / Range**: Whole number (0..255) (1/10th seconds)\n  - **Default**: 100 (10.0 seconds)\n  - **Summary**: Sets the Max Response Time byte in IGMPv2/v3 Queries (`0` in\n  IGMPv1 and Reports).\n- **Token**: `maxrespdelay`\n  - **Scopes**: mld\n  - **Syntax**: `maxrespdelay <0..65535>`\n  - **Value / Range**: Whole number (0..65535) (milliseconds)\n  - **Default**: 10000 (10 seconds)\n  - **Summary**: Sets the Maximum Response Delay in milliseconds on MLD Queries\n  (`0` on Reports and Done messages).\n- **Token**: `mcs`\n  - **Scopes**: rdp\n  - **Syntax**: `rdp ... mcs`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (3389)\n  - **Summary**: Configures the `mcs` PDU selector or header field on `rdp`\n  frames.\n- **Token**: `md5`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `auth md5 | sha | sha256 | sha384 | sha512 \"<password>\"`\n  - **Value / Range**: HMAC algorithm keyword + passphrase string\n  - **Default**: Omitted (noAuthNoPriv)\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Enables USM authentication\n  (`authNoPriv` or `authPriv`) and writes the live RFC 3414 / RFC 7860 HMAC\n  digest.\n- **Token**: `mdcx`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... mdcx`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `mdcx` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `mdtype`\n  - **Scopes**: nsh\n  - **Syntax**: `mdtype <1|2>`\n  - **Value / Range**: Metadata Type (1 = Fixed 16B, 2 = Variable)\n  - **Default**: 1\n  - **Summary**: Selects Fixed 4x32-bit Context Header (`1`, `Length=6`) or\n  Variable Context (`2`).\n- **Token**: `mediaport`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... mediaport <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `mediaport` PDU selector or header field on `sccp`\n  frames.\n- **Token**: `metadata`\n  - **Scopes**: kafka\n  - **Syntax**: `kafka ... metadata`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP / UDP (9092)\n  - **Summary**: Configures the `metadata` PDU selector or header field on `kafka`\n  frames.\n- **Token**: `method`\n  - **Scopes**: http, grpc, sip, rtsp, doh, socks (+2 more)\n  - **Syntax**: `get | post | put | delete | head | options | patch | method\n  \"<text>\"`\n  - **Value / Range**: HTTP request method\n  - **Default**: get\n  - **Summary**: Used across `http`, `grpc`, `sip`, `rtsp`, `doh`, `socks`,\n  `mgcp`, `ntlm`: Sets the HTTP request verb at the start of the request line.\n- **Token**: `methodid`\n  - **Scopes**: someip\n  - **Syntax**: `serviceid <0..65535> | methodid <0..65535>`\n  - **Value / Range**: 16-bit Service ID & Method/Event ID (`0x8000+` for Events)\n  - **Default**: serviceid 0x1234, methodid 0x0001 (or 0xffff/0x8100 on SD)\n  - **Summary**: Writes the 32-bit SOME/IP `Message ID` (`Service ID << 16 |\n  Method ID`) in bytes 0..3.\n- **Token**: `metric`\n  - **Scopes**: rip\n  - **Syntax**: `metric <1..16>`\n  - **Value / Range**: Hop count integer (1..16)\n  - **Default**: 1\n  - **Summary**: Sets the route hop-count metric (`1..15` reachable hops, `16`\n  infinity / unreachable).\n- **Token**: `minorver`\n  - **Scopes**: someip\n  - **Syntax**: `sdservice <0..65535> | instanceid <0..65535> | majorver <0..255>\n  | minorver <number> | sdttl <0..16777215>`\n  - **Value / Range**: SOME/IP-SD 16-byte Service/Eventgroup Entry fields\n  - **Default**: sdservice 0x1234, instanceid 1, majorver 1, minorver 0, sdttl 3\n  - **Summary**: Populates the SOME/IP-SD Entry (`sdttl 0` signifies\n  `StopOfferService` / `StopSubscribeEventgroup`).\n- **Token**: `minrx`\n  - **Scopes**: bfd\n  - **Syntax**: `mintx <number> | minrx <number>`\n  - **Value / Range**: Whole number (microseconds)\n  - **Default**: 100000 (100 ms)\n  - **Summary**: Sets Desired Min TX Interval and Required Min RX Interval in\n  **microseconds** (`50000` = `50ms`, `1000000` = `1s`).\n- **Token**: `mintx`\n  - **Scopes**: bfd\n  - **Syntax**: `mintx <number> | minrx <number>`\n  - **Value / Range**: Whole number (microseconds)\n  - **Default**: 100000 (100 ms)\n  - **Summary**: Sets Desired Min TX Interval and Required Min RX Interval in\n  **microseconds** (`50000` = `50ms`, `1000000` = `1s`).\n- **Token**: `mmeueid`\n  - **Scopes**: s1ap\n  - **Syntax**: `mmeueid <number> | enbueid <0..16777215>`\n  - **Value / Range**: 32-bit MME-UE-S1AP-ID (IE 0) & 24-bit eNB-UE-S1AP-ID (IE 8)\n  - **Default**: mmeueid 1, enbueid 1 on UE messages\n  - **Summary**: Writes the APER integer UE context identifiers pairing eNB and\n  MME state machines.\n- **Token**: `mode`\n  - **Scopes**: ntp, tftp, hartip, twamp, mgcp\n  - **Syntax**: `mode <0..7>`\n  - **Value / Range**: 3-bit Association Mode\n  - **Default**: 3 (Client)\n  - **Summary**: Used across `ntp`, `tftp`, `hartip`, `twamp`, `mgcp`: Sets bits\n  2..0 of byte 0 (`1`=Symmetric Active, `2`=Passive, `3`=Client, `4`=Server,\n  `5`=Broadcast, `6`=Control, `7`=Private).\n- **Token**: `modifybearerrequest`\n  - **Scopes**: gtpc\n  - **Syntax**: `echorequest | echoreply | echoresponse | createsessionrequest |\n  createsessionresponse | modifybearerrequest | modifybearerresponse |\n  deletesessionrequest | deletesessionresponse | msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.274 Message Type keyword or name\n  - **Default**: echorequest (1)\n  - **Summary**: Sets byte 1 of the GTPv2-C header (`1` Echo Req, `2` Echo Resp,\n  `32`/`33` Create Session, `34`/`35` Modify Bearer, `36`/`37` Delete Session).\n- **Token**: `modifybearerresponse`\n  - **Scopes**: gtpc\n  - **Syntax**: `echorequest | echoreply | echoresponse | createsessionrequest |\n  createsessionresponse | modifybearerrequest | modifybearerresponse |\n  deletesessionrequest | deletesessionresponse | msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.274 Message Type keyword or name\n  - **Default**: echorequest (1)\n  - **Summary**: Sets byte 1 of the GTPv2-C header (`1` Echo Req, `2` Echo Resp,\n  `32`/`33` Create Session, `34`/`35` Modify Bearer, `36`/`37` Delete Session).\n- **Token**: `msearch`\n  - **Scopes**: ssdp\n  - **Syntax**: `msearch | notify`\n  - **Value / Range**: SSDP HTTPU method\n  - **Default**: msearch\n  - **Summary**: Selects `M-SEARCH * HTTP/1.1` active discovery or `NOTIFY *\n  HTTP/1.1` multicast announcement.\n- **Token**: `msg`\n  - **Scopes**: syslog, irc\n  - **Syntax**: `msg \"<text>\"`\n  - **Value / Range**: Quoted log message text\n  - **Default**: \"FrameAssembly syslog message\"\n  - **Summary**: Used across `syslog`, `irc`: Sets the UTF-8 log message text at\n  the end of the syslog record.\n- **Token**: `msgcode`\n  - **Scopes**: ssh\n  - **Syntax**: `msgcode <0..255>`\n  - **Value / Range**: RFC 4253 message number (e.g. `5` SERVICE_REQUEST, `50`\n  USERAUTH_REQUEST)\n  - **Default**: Omitted\n  - **Summary**: Emits a properly length-prefixed and block-padded SSH binary\n  packet with the chosen message code.\n- **Token**: `msgid`\n  - **Scopes**: ikev2, ldp, syslog, ldap, smb, rocev2 (+4 more)\n  - **Syntax**: `msgid <number>`\n  - **Value / Range**: Whole number\n  - **Default**: 0\n  - **Summary**: Used across `ikev2`, `ldp`, `syslog`, `ldap`, `smb`, `rocev2`,\n  `coap`, `hartip`, `netconf`, `wsdiscovery`: Sets the 4-byte IKEv2 Message ID\n  (`0` for `sainit`, `1` for initial `auth`, incrementing per request/response\n  pair).\n- **Token**: `msgtype`\n  - **Scopes**: l2tp, ptp, gtpc, pfcp, ngap, s1ap (+20 more)\n  - **Syntax**: `sccrq | sccrp | scccn | stopccn | hello | data | msgtype\n  <0..65535|\"<text>\">`\n  - **Value / Range**: Control AVP message type or data mode\n  - **Default**: sccrq (Control Type 1) or data\n  - **Summary**: Used across `l2tp`, `ptp`, `gtpc`, `pfcp`, `ngap`, `s1ap`,\n  `nvmetcp`, `coap`, `opcua`, `iec104`, `synchrophasor`, `hartip`, `someip`,\n  `doip`, `ipmi`, `netconf`, `twamp`, `wsdiscovery`, `rdp`, `vnc`, `turn`, `h323`,\n  `sccp`, `ntlm`, `dcerpc`, `tns`: Selects L2TP control AVP 0 (`1`=SCCRQ,\n  `2`=SCCRP, `3`=SCCCN, `4`=StopCCN, `6`=Hello) or `T=0` `data` encapsulation.\n- **Token**: `mult`\n  - **Scopes**: bfd\n  - **Syntax**: `mult <1..255>`\n  - **Value / Range**: 8-bit Detect Multiplier\n  - **Default**: 3\n  - **Summary**: Sets the missed-packet multiplier (`Detection Time = mult *\n  max(minrx, peer_mintx)`).\n- **Token**: `multicastaddr`\n  - **Scopes**: mld\n  - **Syntax**: `multicastaddr <ipv6>`\n  - **Value / Range**: 128-bit IPv6 multicast address (or ::)\n  - **Default**: :: (General Query)\n  - **Summary**: Sets the 16-byte Multicast Address field (`::` in General\n  Queries, specific `ffxx::` group in Group-Specific Queries, Reports, and Done\n  messages).\n- **Token**: `mx`\n  - **Scopes**: ssdp\n  - **Syntax**: `man \"<text>\" | mx <0..255> | st \"<text>\"`\n  - **Value / Range**: M-SEARCH discovery headers (`MX` max wait seconds, `ST`\n  Search Target)\n  - **Default**: man \"\\\"ssdp:discover\\\"\", mx 3, st \"ssdp:all\"\n  - **Summary**: Populates mandatory UPnP discovery request headers on `msearch`\n  packets.\n- **Token**: `mydisc`\n  - **Scopes**: bfd\n  - **Syntax**: `mydisc <number> | yourdisc <number>`\n  - **Value / Range**: 32-bit non-zero / peer session discriminators\n  - **Default**: mydisc 1, yourdisc 0\n  - **Summary**: Sets My Discriminator and Your Discriminator (`0` until learned\n  from peer).\n- **Token**: `nack`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `nasip`\n  - **Scopes**: radius\n  - **Syntax**: `nasip <ipv4>`\n  - **Value / Range**: IPv4 address (e.g. 10.20.0.10)\n  - **Default**: Omitted unless set\n  - **Summary**: Adds Attribute `4` (`NAS-IP-Address`) identifying the switch,\n  WLC, or VPN concentrator.\n- **Token**: `naspdu`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `naspdu \"<hex>\"`\n  - **Value / Range**: Even-length hex byte string (IE 38 NAS-PDU)\n  - **Default**: \"7e0041\" (5GS Registration stub)\n  - **Summary**: Used across `ngap`, `s1ap`: Embeds raw `3GPP TS 24.501` 5G-NAS\n  message octets inside IE `38` (`NAS-PDU`) for full Wireshark `nas-5gs` decoding.\n- **Token**: `nativevlan`\n  - **Scopes**: cdp\n  - **Syntax**: `nativevlan <0..65535>`\n  - **Value / Range**: VLAN ID (0..4095)\n  - **Default**: Omitted unless set\n  - **Summary**: Encodes TLV `0x000a` (16-bit Native VLAN ID for trunk mismatch\n  detection).\n- **Token**: `nbtype`\n  - **Scopes**: nbns\n  - **Syntax**: `nbns ... nbtype <u8>`\n  - **Value / Range**: Parameter <u8>\n  - **Default**: UDP (137)\n  - **Summary**: Configures the `nbtype` PDU selector or header field on `nbns`\n  frames.\n- **Token**: `ndscom`\n  - **Scopes**: goose\n  - **Syntax**: `ndscom`\n  - **Value / Range**: Needs Commissioning boolean flag\n  - **Default**: false\n  - **Summary**: Sets BER context tag `[9]` (`ndsCom = true`).\n- **Token**: `negotiate`\n  - **Scopes**: smb, ntlm\n  - **Syntax**: `negotiate | sessionsetup | treeconnect | treedisconnect | create\n  | close | read | write | logoff`\n  - **Value / Range**: SMB2/3 command keyword (or `command \"<text>\"`)\n  - **Default**: negotiate (0x0000)\n  - **Summary**: Used across `smb`, `ntlm`: Selects the 16-bit MS-SMB2 command\n  (`0x00` Negotiate, `0x01` SessionSetup, `0x02` Logoff, `0x03` TreeConnect,\n  `0x04` TreeDisconnect, `0x05` Create, `0x06` Close, `0x08` Read, `0x09` Write).\n- **Token**: `neighboradvert`\n  - **Scopes**: ndp\n  - **Syntax**: `routersolicit | routeradvert | neighborsolicit | neighboradvert |\n  redirect`\n  - **Value / Range**: NDP message selector\n  - **Default**: neighborsolicit (Type 135)\n  - **Summary**: Selects ICMPv6 Type `133` (`routersolicit`), `134`\n  (`routeradvert`), `135` (`neighborsolicit`), `136` (`neighboradvert`), or `137`\n  (`redirect`).\n- **Token**: `neighborsolicit`\n  - **Scopes**: ndp\n  - **Syntax**: `routersolicit | routeradvert | neighborsolicit | neighboradvert |\n  redirect`\n  - **Value / Range**: NDP message selector\n  - **Default**: neighborsolicit (Type 135)\n  - **Summary**: Selects ICMPv6 Type `133` (`routersolicit`), `134`\n  (`routeradvert`), `135` (`neighborsolicit`), `136` (`neighboradvert`), or `137`\n  (`redirect`).\n- **Token**: `netfn`\n  - **Scopes**: ipmi\n  - **Syntax**: `ipmi ... netfn <u8>`\n  - **Value / Range**: Parameter <u8>\n  - **Default**: UDP (623)\n  - **Summary**: Configures the `netfn` PDU selector or header field on `ipmi`\n  frames.\n- **Token**: `network`\n  - **Scopes**: melsec\n  - **Syntax**: `network <0..255> | pc <0..255> | io <0..65535> | station <0..255>\n  | timer <0..65535>`\n  - **Value / Range**: 3E Routing Path + Monitoring Timer (in 250 ms units)\n  - **Default**: network 0, pc 0xff, io 0x03ff, station 0, timer 16\n  - **Summary**: Populates bytes 2..6 (Access Route) and bytes 9..10 (CPU\n  Monitoring Timer) of the 3E header.\n- **Token**: `newkeys`\n  - **Scopes**: ssh\n  - **Syntax**: `newkeys`\n  - **Value / Range**: Keyword flag\n  - **Default**: Omitted\n  - **Summary**: Emits a binary `SSH_MSG_NEWKEYS` (`21`) packet signaling\n  transition to negotiated keys.\n- **Token**: `nextheader`\n  - **Scopes**: srv6, ipsec, esp, ah, ikev2\n  - **Syntax**: `nextheader <0..255>`\n  - **Value / Range**: 8-bit IANA protocol number (0..255)\n  - **Default**: 59 (IPv6 No Next Header)\n  - **Summary**: Used across `srv6`, `ipsec`, `esp`, `ah`, `ikev2`: Sets byte 0 of\n  the SRH (`4`=IPv4-in-SRv6, `41`=IPv6-in-SRv6, `58`=ICMPv6, `59`=No Next Header,\n  `143`=Ethernet L2VPN).\n- **Token**: `nexthop`\n  - **Scopes**: bgp, rip\n  - **Syntax**: `nexthop <ip>`\n  - **Value / Range**: IPv4 or IPv6 address literal\n  - **Default**: Source host IP\n  - **Summary**: Used across `bgp`, `rip`: Sets the `NEXT_HOP` path attribute\n  inside `bgp update` messages.\n- **Token**: `nextpayload`\n  - **Scopes**: ikev2\n  - **Syntax**: `nextpayload <0..255> | nextheader <0..255>`\n  - **Value / Range**: 8-bit IKEv2 Payload Type\n  - **Default**: 33 (SA) or 0 (None)\n  - **Summary**: Sets the first chained IKEv2 Payload Type (`33` SA, `34` KE, `40`\n  Nonce, `46` Encrypted SK, `0` None).\n- **Token**: `nextproto`\n  - **Scopes**: nsh\n  - **Syntax**: `nextproto <\"ipv4\"|\"ipv6\"|\"ethernet\"|\"nsh\"|\"mpls\"|0..255>`\n  - **Value / Range**: Protocol name or 8-bit code\n  - **Default**: \"ipv4\" (0x01)\n  - **Summary**: Sets Next Protocol (`1`=IPv4, `2`=IPv6, `3`=Ethernet, `4`=NSH,\n  `5`=MPLS).\n- **Token**: `ngsetupfailure`\n  - **Scopes**: ngap\n  - **Syntax**: `ngsetuprequest | ngsetupresponse | ngsetupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 38.413 NGAP Elementary Procedure\n  - **Default**: ngsetuprequest\n  - **Summary**: Selects both the APER PDU Choice (`InitiatingMessage` /\n  `SuccessfulOutcome` / `UnsuccessfulOutcome`) and mandatory 3GPP TS 38.413\n  Procedure Code + ProtocolIEs.\n- **Token**: `ngsetuprequest`\n  - **Scopes**: ngap\n  - **Syntax**: `ngsetuprequest | ngsetupresponse | ngsetupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 38.413 NGAP Elementary Procedure\n  - **Default**: ngsetuprequest\n  - **Summary**: Selects both the APER PDU Choice (`InitiatingMessage` /\n  `SuccessfulOutcome` / `UnsuccessfulOutcome`) and mandatory 3GPP TS 38.413\n  Procedure Code + ProtocolIEs.\n- **Token**: `ngsetupresponse`\n  - **Scopes**: ngap\n  - **Syntax**: `ngsetuprequest | ngsetupresponse | ngsetupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 38.413 NGAP Elementary Procedure\n  - **Default**: ngsetuprequest\n  - **Summary**: Selects both the APER PDU Choice (`InitiatingMessage` /\n  `SuccessfulOutcome` / `UnsuccessfulOutcome`) and mandatory 3GPP TS 38.413\n  Procedure Code + ProtocolIEs.\n- **Token**: `nick`\n  - **Scopes**: irc\n  - **Syntax**: `irc ... nick [<str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP (6667)\n  - **Summary**: Configures the `nick` PDU selector or header field on `irc`\n  frames.\n- **Token**: `nlri`\n  - **Scopes**: bgp\n  - **Syntax**: `prefix <str|ip> | nlri <str|ip>`\n  - **Value / Range**: CIDR string (\"10.20.0.0/16\") or IP literal\n  - **Default**: \"10.0.0.0/24\"\n  - **Summary**: Encodes Network Layer Reachability Information (`nlri` is an\n  exact alias for `prefix`) in `update` messages.\n- **Token**: `nodeid`\n  - **Scopes**: pfcp, opcua\n  - **Syntax**: `nodeid <ip_or_text>`\n  - **Value / Range**: IPv4, IPv6, or FQDN string (IE Type 60)\n  - **Default**: Source host IP on setup/establishment\n  - **Summary**: Used across `pfcp`, `opcua`: Appends IE Type `60` (`Node ID`)\n  identifying the originating SMF or UPF control plane.\n- **Token**: `non`\n  - **Scopes**: coap\n  - **Syntax**: `con | non | ack | rst | msgtype \"<text>\"`\n  - **Value / Range**: CoAP Message Type (`0` CON, `1` NON, `2` ACK, `3` RST)\n  - **Default**: con (Confirmable)\n  - **Summary**: Sets the 2-bit `T` field in byte 0 (`ack` and `rst` are CoAP UDP\n  message types, not TCP flags).\n- **Token**: `nonce`\n  - **Scopes**: lisp, ntlm\n  - **Syntax**: `nonce <number>`\n  - **Value / Range**: 64-bit unsigned echo/replay nonce\n  - **Default**: 0x0102030405060708\n  - **Summary**: Used across `lisp`, `ntlm`: Writes the 8-byte Nonce field\n  correlating Map-Request <-> Map-Reply and Map-Register <-> Map-Notify.\n- **Token**: `nonrepeaters`\n  - **Scopes**: snmp2, snmp3, snmp1\n  - **Syntax**: `nonrepeaters <number> | maxrepetitions <number>`\n  - **Value / Range**: Whole number\n  - **Default**: nonrepeaters 0, maxrepetitions 10\n  - **Summary**: Used across `snmp2`, `snmp3`, `snmp1`: Sets scalar\n  `non-repeaters` count and tabular `max-repetitions` row count on `getbulk` PDUs.\n- **Token**: `nop`\n  - **Scopes**: ethercat, iscsi, ethernetip\n  - **Syntax**: `nop | read | write | cmd \"<text>\"`\n  - **Value / Range**: Command keyword or ETG mnemonic\n  (\"APRD\",\"APWR\",\"FPRD\",\"FPWR\",\"BRD\",\"BWR\",\"LRD\",\"LWR\",\"LRW\")\n  - **Default**: read (APRD 0x01)\n  - **Summary**: Used across `ethercat`, `iscsi`, `ethernetip`: Sets the 8-bit\n  EtherCAT Datagram Command byte (`0x00` NOP, `0x01` APRD, `0x02` APWR, `0x04`\n  FPRD, `0x05` FPWR, `0x07` BRD, `0x0a` LRD, `0x0b` LWR, `0x0c` LRW).\n- **Token**: `notfound`\n  - **Scopes**: coap\n  - **Syntax**: `get | post | put | delete | created | changed | notfound | code\n  \"<c.dd>\"`\n  - **Value / Range**: Shorthand keyword OR dotted code (`\"0.01\"`..`\"5.05\"`,\n  choose one)\n  - **Default**: get (\"0.01\")\n  - **Summary**: Encodes byte 1 (`(class << 5) | detail`, e.g. `\"2.05\"` Content =\n  `0x45`).\n- **Token**: `notification`\n  - **Scopes**: bgp, ldp, someip, netconf\n  - **Syntax**: `open | update | notification | keepalive`\n  - **Value / Range**: BGP message type keyword\n  - **Default**: keepalive (Type 4)\n  - **Summary**: Used across `bgp`, `ldp`, `someip`, `netconf`: Selects Type `1`\n  OPEN, Type `2` UPDATE, Type `3` NOTIFICATION (Cease error), or Type `4` 19-byte\n  KEEPALIVE.\n- **Token**: `notify`\n  - **Scopes**: ssdp\n  - **Syntax**: `msearch | notify`\n  - **Value / Range**: SSDP HTTPU method\n  - **Default**: msearch\n  - **Summary**: Selects `M-SEARCH * HTTP/1.1` active discovery or `NOTIFY *\n  HTTP/1.1` multicast announcement.\n- **Token**: `npdu`\n  - **Scopes**: gtpu\n  - **Syntax**: `seqnum <0..65535> | npdu <0..255>`\n  - **Value / Range**: 16-bit GTP-U Sequence Number & 8-bit N-PDU Number\n  - **Default**: Omitted on gpdu (seqnum 1 on echo)\n  - **Summary**: Enables the 4-byte optional GTPv1-U header extension (`S=1` /\n  `PN=1`) and writes Sequence / N-PDU fields.\n- **Token**: `nr`\n  - **Scopes**: l2tp\n  - **Syntax**: `ns <0..65535> | nr <0..65535>`\n  - **Value / Range**: 16-bit Send (Ns) and Next Expected (Nr) sequence counters\n  - **Default**: ns 0, nr 0\n  - **Summary**: Writes the 16-bit `Ns` and `Nr` reliable control-channel sequence\n  numbers.\n- **Token**: `nsid`\n  - **Scopes**: nvmetcp\n  - **Syntax**: `nsid <number>`\n  - **Value / Range**: 32-bit NVMe Namespace Identifier (`1..0xffffffff`)\n  - **Default**: 1\n  - **Summary**: Writes little-endian `NSID` in bytes 4..7 of the NVMe SQE.\n- **Token**: `nt`\n  - **Scopes**: ssdp\n  - **Syntax**: `nt \"<text>\" | nts \"<text>\" | usn \"<text>\" | location \"<text>\"`\n  - **Value / Range**: NOTIFY advertisement headers (`NTS` `\"ssdp:alive\"` or\n  `\"ssdp:byebye\"`)\n  - **Default**: nts \"ssdp:alive\"\n  - **Summary**: Populates Notification Type, Sub-Type, Unique Service Name, and\n  XML `LOCATION` URL on `notify` packets.\n- **Token**: `ntfy`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... ntfy`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `ntfy` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `nts`\n  - **Scopes**: ssdp\n  - **Syntax**: `nt \"<text>\" | nts \"<text>\" | usn \"<text>\" | location \"<text>\"`\n  - **Value / Range**: NOTIFY advertisement headers (`NTS` `\"ssdp:alive\"` or\n  `\"ssdp:byebye\"`)\n  - **Default**: nts \"ssdp:alive\"\n  - **Summary**: Populates Notification Type, Sub-Type, Unique Service Name, and\n  XML `LOCATION` URL on `notify` packets.\n- **Token**: `null`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `nullval`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `numdatsetentries`\n  - **Scopes**: goose\n  - **Syntax**: `numdatsetentries <number>`\n  - **Value / Range**: Number of dataset members\n  - **Default**: 1\n  - **Summary**: Encodes BER context tag `[10]` (`numDatSetEntries`) and matching\n  `allData` `[11]` entries.\n- **Token**: `oam`\n  - **Scopes**: nsh\n  - **Syntax**: `oam`\n  - **Value / Range**: Boolean flag\n  - **Default**: Unset (0)\n  - **Summary**: Sets the `O` (Operations, Administration, and Maintenance) bit in\n  the NSH Base Header.\n- **Token**: `objectinstance`\n  - **Scopes**: bacnet\n  - **Syntax**: `objecttype <0..1023> | objectinstance <number>`\n  - **Value / Range**: `0` Analog-Input, `1` Analog-Output, `2` Analog-Value, `3`\n  Binary-Input, `8` Device + 22-bit instance\n  - **Default**: objecttype 0, objectinstance 1 (or 8 / 1000 on iam)\n  - **Summary**: Packs the 4-byte `BACnetObjectIdentifier` (`(objecttype << 22) |\n  objectinstance`).\n- **Token**: `objecttype`\n  - **Scopes**: bacnet\n  - **Syntax**: `objecttype <0..1023> | objectinstance <number>`\n  - **Value / Range**: `0` Analog-Input, `1` Analog-Output, `2` Analog-Value, `3`\n  Binary-Input, `8` Device + 22-bit instance\n  - **Default**: objecttype 0, objectinstance 1 (or 8 / 1000 on iam)\n  - **Summary**: Packs the 4-byte `BACnetObjectIdentifier` (`(objecttype << 22) |\n  objectinstance`).\n- **Token**: `octets`\n  - **Scopes**: netflow, ipfix, rtcp\n  - **Syntax**: `octets <number>`\n  - **Value / Range**: 32-bit byte count\n  - **Default**: 1500\n  - **Summary**: Used across `netflow`, `ipfix`, `rtcp`: Sets the `dOctets` 32-bit\n  Layer 3 byte counter for the flow.\n- **Token**: `offer`\n  - **Scopes**: dhcp\n  - **Syntax**: `discover | offer | request | ack | release | solicit | advertise\n  | reply`\n  - **Value / Range**: DHCPv4 / DHCPv6 message type keyword\n  - **Default**: discover (IPv4) / solicit (IPv6)\n  - **Summary**: Sets DHCPv4 Option `53` + BOOTP `op` (`1` request, `2` reply) or\n  DHCPv6 `msg-type` (`1` Solicit, `2` Advertise, `3` Request, `7` Reply, `8`\n  Release).\n- **Token**: `offerservice`\n  - **Scopes**: someip\n  - **Syntax**: `findservice | offerservice | subscribe | subscribeack | request |\n  requestnoreply | notification | response | error | msgtype \"<text_or_num>\"`\n  - **Value / Range**: SOME/IP-SD Entry selector or SOME/IP Message Type\n  (`0x00`..`0x81`)\n  - **Default**: request (0x00)\n  - **Summary**: Selects either a full `0xffff:0x8100` SOME/IP-SD frame\n  (`findservice`/`offerservice`/`subscribe`/`subscribeack`) or standard SOME/IP\n  `Message Type`.\n- **Token**: `offhook`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... offhook`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `offhook` PDU selector or header field on `sccp`\n  frames.\n- **Token**: `offset`\n  - **Scopes**: ethercat, iscsi, nvmetcp, s7comm, kafka\n  - **Syntax**: `ado <0..65535> | offset <0..65535>`\n  - **Value / Range**: 16-bit ESC Register / High Word Offset (e.g. 0x0130)\n  - **Default**: 0\n  - **Summary**: Used across `ethercat`, `iscsi`, `nvmetcp`, `s7comm`, `kafka`:\n  Sets the little-endian 16-bit `ADO` physical memory/register offset (`offset` is\n  an exact alias).\n- **Token**: `oid`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `oid <oid>`\n  - **Value / Range**: Dotted numeric OID\n  - **Default**: 1.3.6.1.2.1.1.1.0\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Shorthand that appends a\n  `NULL`-valued varbind (`<oid> = NULL`) for `get` / `getnext` requests.\n- **Token**: `oidval`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `ok`\n  - **Scopes**: pop3, mysql, c1222, mssql, mongodb\n  - **Syntax**: `ok | err`\n  - **Value / Range**: POP3 server status indicator\n  - **Default**: Omitted on client commands\n  - **Summary**: Used across `pop3`, `mysql`, `c1222`, `mssql`, `mongodb`: Emits\n  `+OK` (`ok`) or `-ERR` (`err`) at the start of a server reply.\n- **Token**: `onhook`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... onhook`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `onhook` PDU selector or header field on `sccp`\n  frames.\n- **Token**: `opaque`\n  - **Scopes**: memcached\n  - **Syntax**: `opcode <hex_or_num> [opaque <hex_or_num>] [cas <hex_or_num>]`\n  - **Value / Range**: Binary protocol opcode (`0x00` Get, `0x01` Set, `0x07`\n  Quit)\n  - **Default**: Omitted (uses ASCII mode)\n  - **Summary**: Switches the packet to the 24-byte `0x80` Memcached Binary\n  Protocol.\n- **Token**: `opcode`\n  - **Scopes**: websocket, iscsi, nvmetcp, rocev2, memcached, s7commplus (+2 more)\n  - **Syntax**: `text | binary | close | ping | pong | opcode \"<text>\"`\n  - **Value / Range**: WebSocket frame opcode\n  - **Default**: text (0x1)\n  - **Summary**: Used across `websocket`, `iscsi`, `nvmetcp`, `rocev2`,\n  `memcached`, `s7commplus`, `rocplus`, `nbns`: Selects RFC 6455 opcode `0x1`\n  (`text`), `0x2` (`binary`), `0x8` (`close`), `0x9` (`ping`), `0xa` (`pong`), or\n  `\"continuation\"` (`0x0`).\n- **Token**: `open`\n  - **Scopes**: bgp\n  - **Syntax**: `open | update | notification | keepalive`\n  - **Value / Range**: BGP message type keyword\n  - **Default**: keepalive (Type 4)\n  - **Summary**: Selects Type `1` OPEN, Type `2` UPDATE, Type `3` NOTIFICATION\n  (Cease error), or Type `4` 19-byte KEEPALIVE.\n- **Token**: `openreceivechannel`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... openreceivechannel`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `openreceivechannel` PDU selector or header field\n  on `sccp` frames.\n- **Token**: `openreceivechannelack`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... openreceivechannelack`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `openreceivechannelack` PDU selector or header\n  field on `sccp` frames.\n- **Token**: `operate`\n  - **Scopes**: dnp3\n  - **Syntax**: `read | write | select | operate | directoperate | confirm |\n  response | unsolicitedresponse | func \"<text>\"`\n  - **Value / Range**: DNP3 Application Function Code\n  - **Default**: read (0x01)\n  - **Summary**: Selects `0x00` Confirm, `0x01` Read, `0x02` Write, `0x03` Select,\n  `0x04` Operate, `0x05` Direct Operate, `0x81` Response, or `0x82` Unsolicited\n  Response.\n- **Token**: `operation`\n  - **Scopes**: netconf\n  - **Syntax**: `netconf ... operation <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP (830)\n  - **Summary**: Configures the `operation` PDU selector or header field on\n  `netconf` frames.\n- **Token**: `opnum`\n  - **Scopes**: dcerpc\n  - **Syntax**: `dcerpc ... opnum <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP (135)\n  - **Summary**: Configures the `opnum` PDU selector or header field on `dcerpc`\n  frames.\n- **Token**: `optclass`\n  - **Scopes**: geneve\n  - **Syntax**: `optclass <0..65535>`\n  - **Value / Range**: 16-bit IANA Option Class (hex or decimal)\n  - **Default**: Omitted (OptLen 0 unless set)\n  - **Summary**: Appends a GENEVE TLV Option with the given namespace (`0x0102`\n  OVN, `0x0104` Cilium, `0x0108` AWS) and increments `OptLen`.\n- **Token**: `option`\n  - **Scopes**: telnet\n  - **Syntax**: `option <0..255>`\n  - **Value / Range**: 1-byte option number\n  - **Default**: Omitted\n  - **Summary**: Specifies an auxiliary Telnet option code.\n- **Token**: `options`\n  - **Scopes**: http, sip, rtsp\n  - **Syntax**: `get | post | put | delete | head | options | patch | method\n  \"<text>\"`\n  - **Value / Range**: HTTP request method\n  - **Default**: get\n  - **Summary**: Used across `http`, `sip`, `rtsp`: Sets the HTTP request verb at\n  the start of the request line.\n- **Token**: `opttype`\n  - **Scopes**: geneve\n  - **Syntax**: `opttype <0..255>`\n  - **Value / Range**: 8-bit Option Type (bit 7 = Critical bit)\n  - **Default**: 1 (when optclass set)\n  - **Summary**: Sets the 8-bit Option Type inside the GENEVE TLV (`>= 0x80` marks\n  a Critical option per RFC 8926 §3.5).\n- **Token**: `originhost`\n  - **Scopes**: diameter\n  - **Syntax**: `originhost \"<text>\" | realm \"<text>\"`\n  - **Value / Range**: DiameterIdentity strings (AVPs 264 & 296)\n  - **Default**: \"client.example.com\" / \"example.com\"\n  - **Summary**: Encodes mandatory `Origin-Host` (AVP `264`, M-bit `0x40`) and\n  `Origin-Realm` (AVP `296`, M-bit `0x40`).\n- **Token**: `ownerid`\n  - **Scopes**: glbp\n  - **Syntax**: `vip <ip> | vmac <mac> | ownerid <mac>`\n  - **Value / Range**: Virtual IP, Virtual Forwarder MAC & Owner MAC\n  - **Default**: Host IP / 00:07:b4:00:01:01 / source MAC\n  - **Summary**: Populates the Virtual IP in Hello TLVs, the `00:07:b4` AVF MAC,\n  and the 6-byte Owner ID.\n- **Token**: `p2piih`\n  - **Scopes**: isis\n  - **Syntax**: `l1iih | l2iih | p2piih | l1lsp | l2lsp | l1csnp | l2csnp | l1psnp\n  | l2psnp`\n  - **Value / Range**: IS-IS PDU type keyword (or `type \"<pdu>\"`)\n  - **Default**: l2iih (PDU Type 16)\n  - **Summary**: Selects L1/L2 LAN Hello (`15`/`16`), P2P Hello (`17`), L1/L2 LSP\n  (`18`/`20`), L1/L2 CSNP (`24`/`25`), or L1/L2 PSNP (`26`/`27`).\n- **Token**: `packetin`\n  - **Scopes**: openflow\n  - **Syntax**: `hello | echoreq | echorequest | echoreply | featuresreq |\n  featuresreply | packetin | packetout | flowmod | type <0..255>`\n  - **Value / Range**: OpenFlow message type keyword or u8\n  - **Default**: hello (Type 0)\n  - **Summary**: Maps to OpenFlow 1.3 types: `hello` (`0`),\n  `echoreq`/`echorequest` (`2`), `echoreply` (`3`), `featuresreq` (`5`),\n  `featuresreply` (`6`), `packetin` (`10`), `packetout` (`13`), `flowmod` (`14`).\n- **Token**: `packetout`\n  - **Scopes**: openflow\n  - **Syntax**: `hello | echoreq | echorequest | echoreply | featuresreq |\n  featuresreply | packetin | packetout | flowmod | type <0..255>`\n  - **Value / Range**: OpenFlow message type keyword or u8\n  - **Default**: hello (Type 0)\n  - **Summary**: Maps to OpenFlow 1.3 types: `hello` (`0`),\n  `echoreq`/`echorequest` (`2`), `echoreply` (`3`), `featuresreq` (`5`),\n  `featuresreply` (`6`), `packetin` (`10`), `packetout` (`13`), `flowmod` (`14`).\n- **Token**: `packets`\n  - **Scopes**: netflow, ipfix, rtcp\n  - **Syntax**: `packets <number>`\n  - **Value / Range**: 32-bit packet count\n  - **Default**: 10\n  - **Summary**: Used across `netflow`, `ipfix`, `rtcp`: Sets the `dPkts` 32-bit\n  packet counter for the flow.\n- **Token**: `padding`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... padding <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `padding` PDU selector or header field on `twamp`\n  frames.\n- **Token**: `padi`\n  - **Scopes**: pppoe\n  - **Syntax**: `padi | pado | padr | pads | padt | session`\n  - **Value / Range**: PPPoE stage keyword (or `type <stage>`)\n  - **Default**: padi (Discovery 0x09)\n  - **Summary**: Selects Discovery codes `0x09` (`padi`), `0x07` (`pado`), `0x19`\n  (`padr`), `0x65` (`pads`), `0xa7` (`padt`) on `0x8863`, or `session` (`0x00`) on\n  `0x8864`.\n- **Token**: `pado`\n  - **Scopes**: pppoe\n  - **Syntax**: `padi | pado | padr | pads | padt | session`\n  - **Value / Range**: PPPoE stage keyword (or `type <stage>`)\n  - **Default**: padi (Discovery 0x09)\n  - **Summary**: Selects Discovery codes `0x09` (`padi`), `0x07` (`pado`), `0x19`\n  (`padr`), `0x65` (`pads`), `0xa7` (`padt`) on `0x8863`, or `session` (`0x00`) on\n  `0x8864`.\n- **Token**: `padr`\n  - **Scopes**: pppoe\n  - **Syntax**: `padi | pado | padr | pads | padt | session`\n  - **Value / Range**: PPPoE stage keyword (or `type <stage>`)\n  - **Default**: padi (Discovery 0x09)\n  - **Summary**: Selects Discovery codes `0x09` (`padi`), `0x07` (`pado`), `0x19`\n  (`padr`), `0x65` (`pads`), `0xa7` (`padt`) on `0x8863`, or `session` (`0x00`) on\n  `0x8864`.\n- **Token**: `pads`\n  - **Scopes**: pppoe\n  - **Syntax**: `padi | pado | padr | pads | padt | session`\n  - **Value / Range**: PPPoE stage keyword (or `type <stage>`)\n  - **Default**: padi (Discovery 0x09)\n  - **Summary**: Selects Discovery codes `0x09` (`padi`), `0x07` (`pado`), `0x19`\n  (`padr`), `0x65` (`pads`), `0xa7` (`padt`) on `0x8863`, or `session` (`0x00`) on\n  `0x8864`.\n- **Token**: `padt`\n  - **Scopes**: pppoe\n  - **Syntax**: `padi | pado | padr | pads | padt | session`\n  - **Value / Range**: PPPoE stage keyword (or `type <stage>`)\n  - **Default**: padi (Discovery 0x09)\n  - **Summary**: Selects Discovery codes `0x09` (`padi`), `0x07` (`pado`), `0x19`\n  (`padr`), `0x65` (`pads`), `0xa7` (`padt`) on `0x8863`, or `session` (`0x00`) on\n  `0x8864`.\n- **Token**: `param`\n  - **Scopes**: smtp, rocplus, irc\n  - **Syntax**: `data | quit | cmd \"<verb>\" [param \"<text>\"]`\n  - **Value / Range**: Envelope command or custom verb (e.g. `cmd \"STARTTLS\"`)\n  - **Default**: Omitted\n  - **Summary**: Used across `smtp`, `rocplus`, `irc`: Writes `DATA\\r\\n`,\n  `QUIT\\r\\n`, or `<verb> <param>\\r\\n`.\n- **Token**: `partition`\n  - **Scopes**: kafka\n  - **Syntax**: `kafka ... partition <i32>`\n  - **Value / Range**: Parameter <i32>\n  - **Default**: TCP / UDP (9092)\n  - **Summary**: Configures the `partition` PDU selector or header field on\n  `kafka` frames.\n- **Token**: `partnerkey`\n  - **Scopes**: lacp\n  - **Syntax**: `partnerkey <0..65535> | partnerport <0..65535>`\n  - **Value / Range**: 16-bit unsigned integers\n  - **Default**: partnerkey 1, partnerport 1\n  - **Summary**: Sets the Partner Operational Key and Partner Port Number.\n- **Token**: `partnerport`\n  - **Scopes**: lacp\n  - **Syntax**: `partnerkey <0..65535> | partnerport <0..65535>`\n  - **Value / Range**: 16-bit unsigned integers\n  - **Default**: partnerkey 1, partnerport 1\n  - **Summary**: Sets the Partner Operational Key and Partner Port Number.\n- **Token**: `partnerstate`\n  - **Scopes**: lacp\n  - **Syntax**: `partnerstate <0..255>`\n  - **Value / Range**: 8-bit IEEE 802.1AX state bitmask\n  - **Default**: 0x3d\n  - **Summary**: Sets the 8-bit Partner State bitmask recorded by the sender.\n- **Token**: `partnersys`\n  - **Scopes**: lacp\n  - **Syntax**: `partnersys <mac>`\n  - **Value / Range**: 48-bit MAC address\n  - **Default**: Destination host MAC\n  - **Summary**: Sets the 6-byte Partner System MAC identifier inside TLV `0x02`.\n- **Token**: `password`\n  - **Scopes**: socks\n  - **Syntax**: `socks ... password <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP (1080)\n  - **Summary**: Configures the `password` PDU selector or header field on `socks`\n  frames.\n- **Token**: `patch`\n  - **Scopes**: http\n  - **Syntax**: `get | post | put | delete | head | options | patch | method\n  \"<text>\"`\n  - **Value / Range**: HTTP request method\n  - **Default**: get\n  - **Summary**: Sets the HTTP request verb at the start of the request line.\n- **Token**: `path`\n  - **Scopes**: rsvp, nfs\n  - **Syntax**: `path | resv | patherr | resverr | pathtear | resvtear | resvconf\n  | hello`\n  - **Value / Range**: RSVP-TE message type keyword\n  - **Default**: path (Type 1)\n  - **Summary**: Used across `rsvp`, `nfs`: Selects RSVP Message Type (`1`=Path,\n  `2`=Resv, `3`=PathErr, `4`=ResvErr, `5`=PathTear, `6`=ResvTear, `7`=ResvConf,\n  `20`=Hello).\n- **Token**: `patherr`\n  - **Scopes**: rsvp\n  - **Syntax**: `path | resv | patherr | resverr | pathtear | resvtear | resvconf\n  | hello`\n  - **Value / Range**: RSVP-TE message type keyword\n  - **Default**: path (Type 1)\n  - **Summary**: Selects RSVP Message Type (`1`=Path, `2`=Resv, `3`=PathErr,\n  `4`=ResvErr, `5`=PathTear, `6`=ResvTear, `7`=ResvConf, `20`=Hello).\n- **Token**: `pathtear`\n  - **Scopes**: rsvp\n  - **Syntax**: `path | resv | patherr | resverr | pathtear | resvtear | resvconf\n  | hello`\n  - **Value / Range**: RSVP-TE message type keyword\n  - **Default**: path (Type 1)\n  - **Summary**: Selects RSVP Message Type (`1`=Path, `2`=Resv, `3`=PathErr,\n  `4`=ResvErr, `5`=PathTear, `6`=ResvTear, `7`=ResvConf, `20`=Hello).\n- **Token**: `pc`\n  - **Scopes**: melsec\n  - **Syntax**: `network <0..255> | pc <0..255> | io <0..65535> | station <0..255>\n  | timer <0..65535>`\n  - **Value / Range**: 3E Routing Path + Monitoring Timer (in 250 ms units)\n  - **Default**: network 0, pc 0xff, io 0x03ff, station 0, timer 16\n  - **Summary**: Populates bytes 2..6 (Access Route) and bytes 9..10 (CPU\n  Monitoring Timer) of the 3E header.\n- **Token**: `pduref`\n  - **Scopes**: s7comm\n  - **Syntax**: `pduref <0..65535>`\n  - **Value / Range**: 16-bit PDU Reference ID\n  - **Default**: 1\n  - **Summary**: Correlates each PLC `ackdata` response with its initiating `job`.\n- **Token**: `peerdown`\n  - **Scopes**: bmp\n  - **Syntax**: `routemon | statsreport | peerdown | peerup | initiation |\n  termination`\n  - **Value / Range**: BMP v3 message type keyword\n  - **Default**: initiation (Type 4) or routemon (Type 0)\n  - **Summary**: Selects RFC 7854 Message Type (`0`=Route Monitoring, `1`=Stats\n  Report, `2`=Peer Down, `3`=Peer Up, `4`=Initiation, `5`=Termination).\n- **Token**: `peerip`\n  - **Scopes**: bmp\n  - **Syntax**: `peerip <ip> | asn <number> | bgpid <ipv4>`\n  - **Value / Range**: Monitored BGP neighbor IP, 32-bit ASN & 4-byte BGP ID\n  - **Default**: 192.0.2.2, asn 65001, bgpid 192.0.2.2\n  - **Summary**: Populates the 16-byte Peer Address, 4-byte Peer AS, and 4-byte\n  Peer BGP ID inside the 42-byte Per-Peer Header.\n- **Token**: `peertype`\n  - **Scopes**: bmp\n  - **Syntax**: `peertype <0..255> | flags <0..255>`\n  - **Value / Range**: Per-Peer Header Type & Flags\n  - **Default**: peertype 0 (Global), flags auto (0x80 if IPv6 peerip)\n  - **Summary**: `peertype` selects Global (`0`), RD Instance (`1`), Local (`2`),\n  or Loc-RIB (`3`); `flags` sets `V`/`L`/`A` bits (`0x40` = Post-Policy).\n- **Token**: `peerup`\n  - **Scopes**: bmp\n  - **Syntax**: `routemon | statsreport | peerdown | peerup | initiation |\n  termination`\n  - **Value / Range**: BMP v3 message type keyword\n  - **Default**: initiation (Type 4) or routemon (Type 0)\n  - **Summary**: Selects RFC 7854 Message Type (`0`=Route Monitoring, `1`=Stats\n  Report, `2`=Peer Down, `3`=Peer Up, `4`=Initiation, `5`=Termination).\n- **Token**: `ping`\n  - **Scopes**: http2, websocket, ipmi, irc, mongodb\n  - **Syntax**: `preface | settings | headers | data | windowupdate | ping |\n  goaway`\n  - **Value / Range**: HTTP/2 frame type keyword\n  - **Default**: settings (Type 0x04, streamid 0)\n  - **Summary**: Used across `http2`, `websocket`, `ipmi`, `irc`, `mongodb`:\n  Selects the RFC 9113 HTTP/2 binary frame type (`0x0` DATA, `0x1` HEADERS, `0x4`\n  SETTINGS, `0x6` PING, `0x7` GOAWAY, `0x8` WINDOW_UPDATE, or connection\n  `preface`).\n- **Token**: `pingreq`\n  - **Scopes**: mqtt\n  - **Syntax**: `connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect`\n  - **Value / Range**: MQTT Control Packet type (or `pkttype \"<text>\"`)\n  - **Default**: publish\n  - **Summary**: Sets the upper 4-bit Control Packet Type (`1`..`14`) in byte 0 of\n  the MQTT header.\n- **Token**: `pingresp`\n  - **Scopes**: mqtt\n  - **Syntax**: `connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect`\n  - **Value / Range**: MQTT Control Packet type (or `pkttype \"<text>\"`)\n  - **Default**: publish\n  - **Summary**: Sets the upper 4-bit Control Packet Type (`1`..`14`) in byte 0 of\n  the MQTT header.\n- **Token**: `pkey`\n  - **Scopes**: rocev2\n  - **Syntax**: `pkey <0..65535>`\n  - **Value / Range**: 16-bit Partition Key\n  - **Default**: 0xffff (Default full-member partition)\n  - **Summary**: Writes bytes 2..3 of the BTH.\n- **Token**: `pktid`\n  - **Scopes**: mqtt, mssql\n  - **Syntax**: `pktid <0..65535>`\n  - **Value / Range**: 16-bit Packet Identifier\n  - **Default**: 1 (when qos > 0 or subscribe/puback)\n  - **Summary**: Used across `mqtt`, `mssql`: Matches `publish` <-> `puback` and\n  `subscribe` <-> `suback`.\n- **Token**: `pktnum`\n  - **Scopes**: quic\n  - **Syntax**: `pktnum <number>`\n  - **Value / Range**: Packet Number\n  - **Default**: 1\n  - **Summary**: Sets the packet number field in `initial`, `zerortt`,\n  `handshake`, and `short` frames.\n- **Token**: `pkttype`\n  - **Scopes**: mqtt, mssql\n  - **Syntax**: `mqtt [connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect | pkttype \"<text>\"] [clientid \"<text>\"] [topic\n  \"<text>\"] [qos <0..2>] [retain] [pktid <0..65535>] [keepalive <0..65535>]\n  [returncode <0..255>]`\n  - **Value / Range**: MQTT modifier\n  - **Default**: TCP 1883 (or transport udp)\n  - **Summary**: Used across `mqtt`, `mssql`: Sets `pkttype` on `mqtt` frames.\n- **Token**: `platform`\n  - **Scopes**: cdp\n  - **Syntax**: `platform \"<text>\"`\n  - **Value / Range**: Quoted text\n  - **Default**: \"Cisco\"\n  - **Summary**: Encodes TLV `0x0006` (hardware chassis model string such as\n  `\"C9300\"`).\n- **Token**: `play`\n  - **Scopes**: rtsp\n  - **Syntax**: `options | describe | setup | play | teardown | method \"<text>\"`\n  - **Value / Range**: RTSP request verb\n  - **Default**: options\n  - **Summary**: Sets the RTSP command method on the request line.\n- **Token**: `plccontrol`\n  - **Scopes**: s7comm\n  - **Syntax**: `setupcomm | readvar | writevar | plccontrol | func \"<text>\"`\n  - **Value / Range**: S7 Parameter Function (`0xf0` Setup, `0x04` ReadVar, `0x05`\n  WriteVar, `0x28` PLCControl)\n  - **Default**: setupcomm (0xf0)\n  - **Summary**: Selects the S7comm Parameter Function code.\n- **Token**: `plmn`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `plmn \"<text>\"`\n  - **Value / Range**: 5- or 6-digit MCC+MNC string (e.g. \"00101\", \"310260\",\n  \"99970\")\n  - **Default**: \"00101\"\n  - **Summary**: Used across `ngap`, `s1ap`: Packs the 3-octet 3GPP `PLMNIdentity`\n  inside GlobalRANNodeID, BroadcastPLMNList, and UserLocationInformation IEs.\n- **Token**: `pn`\n  - **Scopes**: macsec\n  - **Syntax**: `pn <number>`\n  - **Value / Range**: 32-bit Packet Number (>= 1)\n  - **Default**: 1\n  - **Summary**: Sets the big-endian 32-bit replay-protection Packet Number in\n  bytes 4..7 of SecTAG.\n- **Token**: `poll`\n  - **Scopes**: ntp, bsap\n  - **Syntax**: `poll <0..255> | precision <-128..127>`\n  - **Value / Range**: poll: u8 log2 seconds, precision: signed i8 (-128..127)\n  - **Default**: poll 6 (64s), precision -20 (~1us)\n  - **Summary**: Used across `ntp`, `bsap`: Sets 8-bit Poll Interval exponent and\n  signed 8-bit two's-complement Clock Precision.\n- **Token**: `pong`\n  - **Scopes**: websocket, ipmi, irc\n  - **Syntax**: `text | binary | close | ping | pong | opcode \"<text>\"`\n  - **Value / Range**: WebSocket frame opcode\n  - **Default**: text (0x1)\n  - **Summary**: Used across `websocket`, `ipmi`, `irc`: Selects RFC 6455 opcode\n  `0x1` (`text`), `0x2` (`binary`), `0x8` (`close`), `0x9` (`ping`), `0xa`\n  (`pong`), or `\"continuation\"` (`0x0`).\n- **Token**: `port`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... port <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `port` PDU selector or header field on `twamp`\n  frames.\n- **Token**: `portid`\n  - **Scopes**: lldp, stp, cdp\n  - **Syntax**: `portid <str|u16>`\n  - **Value / Range**: Interface string or port number\n  - **Default**: \"eth0\"\n  - **Summary**: Used across `lldp`, `stp`, `cdp`: Encodes Mandatory TLV Type 2\n  (Port ID, e.g. `\"Gi1/0/48\"` or `\"Ethernet1\"`).\n- **Token**: `post`\n  - **Scopes**: http, coap, doh\n  - **Syntax**: `get | post | put | delete | head | options | patch | method\n  \"<text>\"`\n  - **Value / Range**: HTTP request method\n  - **Default**: get\n  - **Summary**: Used across `http`, `coap`, `doh`: Sets the HTTP request verb at\n  the start of the request line.\n- **Token**: `ppid`\n  - **Scopes**: sctp\n  - **Syntax**: `ppid <number>`\n  - **Value / Range**: 32-bit IANA Payload Protocol Identifier\n  - **Default**: 0\n  - **Summary**: Sets the big-endian Payload Protocol ID in `data` chunks\n  (`60`=NGAP, `18`=S1AP, `46`=Diameter, `3`=M3UA) so Wireshark auto-dissects upper\n  layers.\n- **Token**: `pppproto`\n  - **Scopes**: pppoe\n  - **Syntax**: `pppproto <0..65535>`\n  - **Value / Range**: 16-bit PPP Protocol ID (e.g. 0xc021, 0x0021, 0x0057)\n  - **Default**: 0x0021 (IPv4)\n  - **Summary**: Sets the 2-byte PPP Protocol field immediately following the\n  `0x8864` PPPoE Session header.\n- **Token**: `precision`\n  - **Scopes**: ntp\n  - **Syntax**: `poll <0..255> | precision <-128..127>`\n  - **Value / Range**: poll: u8 log2 seconds, precision: signed i8 (-128..127)\n  - **Default**: poll 6 (64s), precision -20 (~1us)\n  - **Summary**: Sets 8-bit Poll Interval exponent and signed 8-bit\n  two's-complement Clock Precision.\n- **Token**: `preface`\n  - **Scopes**: http2\n  - **Syntax**: `preface | settings | headers | data | windowupdate | ping |\n  goaway`\n  - **Value / Range**: HTTP/2 frame type keyword\n  - **Default**: settings (Type 0x04, streamid 0)\n  - **Summary**: Selects the RFC 9113 HTTP/2 binary frame type (`0x0` DATA, `0x1`\n  HEADERS, `0x4` SETTINGS, `0x6` PING, `0x7` GOAWAY, `0x8` WINDOW_UPDATE, or\n  connection `preface`).\n- **Token**: `prefix`\n  - **Scopes**: bgp, rip, ldp, rpkirtr, irc\n  - **Syntax**: `prefix <str|ip> | nlri <str|ip>`\n  - **Value / Range**: CIDR string (\"10.20.0.0/16\") or IP literal\n  - **Default**: \"10.0.0.0/24\"\n  - **Summary**: Used across `bgp`, `rip`, `ldp`, `rpkirtr`, `irc`: Encodes\n  Network Layer Reachability Information (`nlri` is an exact alias for `prefix`)\n  in `update` messages.\n- **Token**: `prelogin`\n  - **Scopes**: mssql\n  - **Syntax**: `mssql ... prelogin`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP / UDP (1433)\n  - **Summary**: Configures the `prelogin` PDU selector or header field on `mssql`\n  frames.\n- **Token**: `pri`\n  - **Scopes**: syslog\n  - **Syntax**: `pri <0..191>`\n  - **Value / Range**: Combined Priority value (0..191)\n  - **Default**: Computed from facility * 8 + severity\n  - **Summary**: Directly sets the `<PRI>` value, overriding `facility` and\n  `severity`.\n- **Token**: `priority`\n  - **Scopes**: isis, ospf, vrrp, hsrp, glbp, openflow (+1 more)\n  - **Syntax**: `priority <0..255>`\n  - **Value / Range**: DIS Priority (0..127)\n  - **Default**: 64\n  - **Summary**: Used across `isis`, `ospf`, `vrrp`, `hsrp`, `glbp`, `openflow`,\n  `lisp`: Sets the 7-bit Designated Intermediate System (DIS) election priority in\n  LAN IIH headers.\n- **Token**: `priv`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `priv des | aes \"<password>\"`\n  - **Value / Range**: `des` (CBC-DES) or `aes` (AES-128-CFB) + passphrase\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Encrypts the `ScopedPDU`\n  (`authPriv`, requires `auth`) and populates the 8-byte `msgPrivacyParameters`\n  salt/IV.\n- **Token**: `privmsg`\n  - **Scopes**: irc\n  - **Syntax**: `irc ... privmsg`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (6667)\n  - **Summary**: Configures the `privmsg` PDU selector or header field on `irc`\n  frames.\n- **Token**: `probe`\n  - **Scopes**: wsdiscovery\n  - **Syntax**: `wsdiscovery ... probe`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP (3702)\n  - **Summary**: Configures the `probe` PDU selector or header field on\n  `wsdiscovery` frames.\n- **Token**: `proc`\n  - **Scopes**: nfs\n  - **Syntax**: `compound | proc \"<text>\"`\n  - **Value / Range**: `compound` or procedure name (`\"NULL\"`, `\"GETATTR\"`,\n  `\"LOOKUP\"`, `\"READ\"`, `\"WRITE\"`)\n  - **Default**: compound\n  - **Summary**: Selects RPC procedure `1` (`COMPOUND` on NFSv4) or named NFSv3/v4\n  procedure.\n- **Token**: `proccode`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `msgtype \"<text>\" | proccode <0..255> | criticality \"<text>\"`\n  - **Value / Range**: Explicit APER PDU class, ProcedureCode (0..255), and\n  Criticality (\"reject\"|\"ignore\"|\"notify\")\n  - **Default**: Derived from procedure keyword\n  - **Summary**: Used across `ngap`, `s1ap`: Overrides the outer ASN.1 APER\n  `procedureCode` and `criticality` enum (`0` reject, `1` ignore, `2` notify).\n- **Token**: `procid`\n  - **Scopes**: syslog\n  - **Syntax**: `hostname \"<text>\" | app \"<text>\" | procid \"<text>\" | msgid\n  \"<text>\"`\n  - **Value / Range**: Quoted text fields\n  - **Default**: Standard RFC 5424 defaults\n  - **Summary**: Populates the structured RFC 5424 header fields before the log\n  message body.\n- **Token**: `produce`\n  - **Scopes**: kafka\n  - **Syntax**: `kafka ... produce`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP / UDP (9092)\n  - **Summary**: Configures the `produce` PDU selector or header field on `kafka`\n  frames.\n- **Token**: `propertyid`\n  - **Scopes**: bacnet\n  - **Syntax**: `propertyid <number>`\n  - **Value / Range**: `85` Present-Value, `77` Object-Name, `28` Description\n  - **Default**: 85 (Present-Value)\n  - **Summary**: Encodes Context Tag `[1]` (`Property-Identifier`) in\n  `readproperty` / `writeproperty`.\n- **Token**: `proto`\n  - **Scopes**: ipip, netflow, ipfix, rdp\n  - **Syntax**: `proto <0..255>`\n  - **Value / Range**: 8-bit IANA protocol number (0..255)\n  - **Default**: 59 (No Next Header on v6) / 6 or 17 / raw payload\n  - **Summary**: Used across `ipip`, `netflow`, `ipfix`, `rdp`: Sets the inner\n  IPv4 Protocol or inner IPv6 Next Header byte (`1`=ICMP, `6`=TCP, `17`=UDP,\n  `58`=ICMPv6).\n- **Token**: `protocolheader`\n  - **Scopes**: amqp\n  - **Syntax**: `protocolheader | connectionstart | channelopen | basicpublish |\n  basicdeliver | heartbeat`\n  - **Value / Range**: AMQP 0-9-1 frame/method selector\n  - **Default**: basicpublish (channel 1)\n  - **Summary**: Selects the 8-byte AMQP header, Method frame (`Type 1`), or\n  Heartbeat frame (`Type 8`).\n- **Token**: `protocoltype`\n  - **Scopes**: geneve\n  - **Syntax**: `protocoltype <0..65535>`\n  - **Value / Range**: 16-bit IEEE EtherType\n  - **Default**: 0x6558 (Transparent Ethernet Bridging)\n  - **Summary**: Sets the inner encapsulated EtherType (`0x6558` Ethernet L2\n  frame, `0x0800` raw IPv4, `0x86dd` raw IPv6).\n- **Token**: `protoid`\n  - **Scopes**: modbus\n  - **Syntax**: `txid <0..65535> | protoid <0..65535> | unitid <0..255>`\n  - **Value / Range**: MBAP Transaction ID, Protocol ID (`0` = Modbus), and\n  Slave/Unit ID\n  - **Default**: txid 1, protoid 0, unitid 1\n  - **Summary**: Populates the 7-byte MBAP header preceding the Modbus PDU.\n- **Token**: `protover`\n  - **Scopes**: someip\n  - **Syntax**: `protover <0..255> | ifacever <0..255> | returncode <0..255>`\n  - **Value / Range**: 8-bit Protocol Version (`1`), Interface Major Version, and\n  Return Code (`0x00` E_OK)\n  - **Default**: protover 1, ifacever 1, returncode 0\n  - **Summary**: Writes bytes 12, 13, and 15 of the 16-byte SOME/IP header.\n- **Token**: `pt`\n  - **Scopes**: rtp, rtcp\n  - **Syntax**: `pt <0..127>`\n  - **Value / Range**: 7-bit RTP Payload Type (`0` PCMU, `8` PCMA, `9` G.722, `96`\n  Opus/H.264, `101` DTMF)\n  - **Default**: 0 (G.711 PCMU)\n  - **Summary**: Used across `rtp`, `rtcp`: Sets the lower 7 bits of byte 1 in the\n  12-byte RTP header.\n- **Token**: `puback`\n  - **Scopes**: mqtt\n  - **Syntax**: `connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect`\n  - **Value / Range**: MQTT Control Packet type (or `pkttype \"<text>\"`)\n  - **Default**: publish\n  - **Summary**: Sets the upper 4-bit Control Packet Type (`1`..`14`) in byte 0 of\n  the MQTT header.\n- **Token**: `publish`\n  - **Scopes**: mqtt\n  - **Syntax**: `connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect`\n  - **Value / Range**: MQTT Control Packet type (or `pkttype \"<text>\"`)\n  - **Default**: publish\n  - **Summary**: Sets the upper 4-bit Control Packet Type (`1`..`14`) in byte 0 of\n  the MQTT header.\n- **Token**: `put`\n  - **Scopes**: http, coap\n  - **Syntax**: `get | post | put | delete | head | options | patch | method\n  \"<text>\"`\n  - **Value / Range**: HTTP request method\n  - **Default**: get\n  - **Summary**: Used across `http`, `coap`: Sets the HTTP request verb at the\n  start of the request line.\n- **Token**: `q0`\n  - **Scopes**: pfc\n  - **Syntax**: `q0 <0..65535> .. q7 <0..65535>`\n  - **Value / Range**: Per-priority pause quanta (0..65535)\n  - **Default**: 0 (or quanta)\n  - **Summary**: Sets the 16-bit Time[0..7] pause timer for IEEE 802.1p Traffic\n  Class `0` through `7` (`0` = XON unpause).\n- **Token**: `q1`\n  - **Scopes**: pfc\n  - **Syntax**: `pfc [enable <0..65535>] [quanta <0..65535>] [q0 <0..65535>] [q1\n  <0..65535>] [q2 <0..65535>] [q3 <0..65535>] [q4 <0..65535>] [q5 <0..65535>] [q6\n  <0..65535>] [q7 <0..65535>]`\n  - **Value / Range**: PFC (802.1Qbb) modifier\n  - **Default**: EtherType 0x8808 (Opcode 0x0101)\n  - **Summary**: Sets `q1` on `pfc` frames.\n- **Token**: `q2`\n  - **Scopes**: pfc\n  - **Syntax**: `pfc [enable <0..65535>] [quanta <0..65535>] [q0 <0..65535>] [q1\n  <0..65535>] [q2 <0..65535>] [q3 <0..65535>] [q4 <0..65535>] [q5 <0..65535>] [q6\n  <0..65535>] [q7 <0..65535>]`\n  - **Value / Range**: PFC (802.1Qbb) modifier\n  - **Default**: EtherType 0x8808 (Opcode 0x0101)\n  - **Summary**: Sets `q2` on `pfc` frames.\n- **Token**: `q3`\n  - **Scopes**: pfc\n  - **Syntax**: `pfc [enable <0..65535>] [quanta <0..65535>] [q0 <0..65535>] [q1\n  <0..65535>] [q2 <0..65535>] [q3 <0..65535>] [q4 <0..65535>] [q5 <0..65535>] [q6\n  <0..65535>] [q7 <0..65535>]`\n  - **Value / Range**: PFC (802.1Qbb) modifier\n  - **Default**: EtherType 0x8808 (Opcode 0x0101)\n  - **Summary**: Sets `q3` on `pfc` frames.\n- **Token**: `q4`\n  - **Scopes**: pfc\n  - **Syntax**: `pfc [enable <0..65535>] [quanta <0..65535>] [q0 <0..65535>] [q1\n  <0..65535>] [q2 <0..65535>] [q3 <0..65535>] [q4 <0..65535>] [q5 <0..65535>] [q6\n  <0..65535>] [q7 <0..65535>]`\n  - **Value / Range**: PFC (802.1Qbb) modifier\n  - **Default**: EtherType 0x8808 (Opcode 0x0101)\n  - **Summary**: Sets `q4` on `pfc` frames.\n- **Token**: `q5`\n  - **Scopes**: pfc\n  - **Syntax**: `pfc [enable <0..65535>] [quanta <0..65535>] [q0 <0..65535>] [q1\n  <0..65535>] [q2 <0..65535>] [q3 <0..65535>] [q4 <0..65535>] [q5 <0..65535>] [q6\n  <0..65535>] [q7 <0..65535>]`\n  - **Value / Range**: PFC (802.1Qbb) modifier\n  - **Default**: EtherType 0x8808 (Opcode 0x0101)\n  - **Summary**: Sets `q5` on `pfc` frames.\n- **Token**: `q6`\n  - **Scopes**: pfc\n  - **Syntax**: `pfc [enable <0..65535>] [quanta <0..65535>] [q0 <0..65535>] [q1\n  <0..65535>] [q2 <0..65535>] [q3 <0..65535>] [q4 <0..65535>] [q5 <0..65535>] [q6\n  <0..65535>] [q7 <0..65535>]`\n  - **Value / Range**: PFC (802.1Qbb) modifier\n  - **Default**: EtherType 0x8808 (Opcode 0x0101)\n  - **Summary**: Sets `q6` on `pfc` frames.\n- **Token**: `q7`\n  - **Scopes**: pfc\n  - **Syntax**: `q0 <0..65535> .. q7 <0..65535>`\n  - **Value / Range**: Per-priority pause quanta (0..65535)\n  - **Default**: 0 (or quanta)\n  - **Summary**: Sets the 16-bit Time[0..7] pause timer for IEEE 802.1p Traffic\n  Class `0` through `7` (`0` = XON unpause).\n- **Token**: `qfi`\n  - **Scopes**: gtpu\n  - **Syntax**: `qfi <0..63>`\n  - **Value / Range**: 6-bit 5G QoS Flow Identifier (0..63)\n  - **Default**: Omitted (4G S1-U mode)\n  - **Summary**: Sets `E=1` and appends Next Extension Header `0x85` (5G NR PDU\n  Session Container) carrying the 6-bit QFI.\n- **Token**: `qid`\n  - **Scopes**: nvmetcp\n  - **Syntax**: `qid <0..65535> | reqid <0..65535>`\n  - **Value / Range**: 16-bit Queue ID (`0` Admin, `1+` I/O) & Command ID (`CID`)\n  - **Default**: qid 1, reqid 1\n  - **Summary**: Writes the 16-bit `Command ID` (`CID`) and Completion `SQID`\n  correlating capsules and data PDUs.\n- **Token**: `qname`\n  - **Scopes**: dns, mdns, llmnr, nbns, doh\n  - **Syntax**: `qname \"<text>\"`\n  - **Value / Range**: Domain string (labels <= 63B, total <= 253B)\n  - **Default**: \"example.com\"\n  - **Summary**: Used across `dns`, `mdns`, `llmnr`, `nbns`, `doh`: Encodes the\n  Question `QNAME` wire labels.\n- **Token**: `qos`\n  - **Scopes**: mqtt\n  - **Syntax**: `qos <0..2> | retain`\n  - **Value / Range**: QoS delivery level (`0`, `1`, or `2`) + `retain` flag\n  - **Default**: qos 0, retain off\n  - **Summary**: Sets QoS bits `1..2` and Retain bit `0` in the Fixed Header.\n- **Token**: `qtype`\n  - **Scopes**: dns, mdns, llmnr, nbns, doh\n  - **Syntax**: `qtype \"<text>\"`\n  - **Value / Range**: \"A\" | \"AAAA\" | \"CNAME\" | \"MX\" | \"NS\" | \"PTR\" | \"SOA\" |\n  \"SRV\" | \"TXT\" | \"AXFR\" | \"ANY\"\n  - **Default**: \"A\"\n  - **Summary**: Used across `dns`, `mdns`, `llmnr`, `nbns`, `doh`: Sets the\n  16-bit `QTYPE` (and Answer RR `TYPE` on responses).\n- **Token**: `quanta`\n  - **Scopes**: pfc\n  - **Syntax**: `quanta <0..65535>`\n  - **Value / Range**: Default pause duration in 512-bit quanta (0..65535)\n  - **Default**: 0\n  - **Summary**: Fills enabled priority queues with a uniform 16-bit pause timer\n  when per-queue `q0`..`q7` are omitted.\n- **Token**: `query`\n  - **Scopes**: igmp, mld, dns, mdns, whois, mysql (+6 more)\n  - **Syntax**: `query | report | leave`\n  - **Value / Range**: IGMP message type\n  - **Default**: query\n  - **Summary**: Used across `igmp`, `mld`, `dns`, `mdns`, `whois`, `mysql`,\n  `postgres`, `llmnr`, `nbns`, `doh`, `mssql`, `mongodb`: Selects Membership Query\n  (`0x11`), Membership Report (`0x12` v1 / `0x16` v2 / `0x22` v3), or Leave Group\n  (`0x17`).\n- **Token**: `quit`\n  - **Scopes**: smtp, irc\n  - **Syntax**: `data | quit | cmd \"<verb>\" [param \"<text>\"]`\n  - **Value / Range**: Envelope command or custom verb (e.g. `cmd \"STARTTLS\"`)\n  - **Default**: Omitted\n  - **Summary**: Used across `smtp`, `irc`: Writes `DATA\\r\\n`, `QUIT\\r\\n`, or\n  `<verb> <param>\\r\\n`.\n- **Token**: `r2t`\n  - **Scopes**: nvmetcp\n  - **Syntax**: `icreq | icresp | read | write | response | h2cdata | c2hdata |\n  r2t | msgtype \"<text>\" | cmd \"<text>\"`\n  - **Value / Range**: NVMe/TCP PDU Type or NVMe Command selector\n  - **Default**: icreq (0x00)\n  - **Summary**: Selects `0x00` ICReq, `0x01` ICResp, `0x04` CapsuleCmd (`read`\n  NVMe `0x02`, `write` NVMe `0x01`), `0x05` CapsuleResp, `0x06` H2CData, `0x07`\n  C2HData, or `0x09` R2T.\n- **Token**: `ranname`\n  - **Scopes**: ngap\n  - **Syntax**: `gnbid <number> | tac <0..16777215> | ranname \"<text>\"`\n  - **Value / Range**: gNB-ID integer, 24-bit Tracking Area Code, and\n  PrintableString RANNodeName\n  - **Default**: gnbid 1, tac 1, ranname \"gNB-01\"\n  - **Summary**: Populates IE `27` (`GlobalRANNodeID`), IE `102`\n  (`SupportedTAList`), IE `121` (`UserLocationInformation`), and IE `82`\n  (`RANNodeName`).\n- **Token**: `ranueid`\n  - **Scopes**: ngap\n  - **Syntax**: `amfueid <number> | ranueid <number>`\n  - **Value / Range**: 40-bit AMF-UE-NGAP-ID (IE 10) & 32-bit RAN-UE-NGAP-ID (IE\n  85)\n  - **Default**: amfueid 1, ranueid 1 on UE messages\n  - **Summary**: Encodes APER integer IEs correlating a specific UE across N2\n  uplink and downlink NAS messages.\n- **Token**: `rasaddr`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... rasaddr <ip> [<u16>`\n  - **Value / Range**: Parameter <ip>\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `rasaddr` PDU selector or header field on `h323`\n  frames.\n- **Token**: `rat`\n  - **Scopes**: gtpc\n  - **Syntax**: `rat <0..255>`\n  - **Value / Range**: 8-bit RAT Type (IE Type 82)\n  - **Default**: 6 (EUTRAN) when set\n  - **Summary**: Appends IE Type `82` (`1` UTRAN, `2` GERAN, `3` WLAN, `6`\n  EUTRAN/LTE, `8` NR/5G).\n- **Token**: `rcf`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... rcf`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `rcf` PDU selector or header field on `h323`\n  frames.\n- **Token**: `rcode`\n  - **Scopes**: dns, mdns, llmnr, nbns, doh\n  - **Syntax**: `rcode <0..15>`\n  - **Value / Range**: 4-bit response code\n  - **Default**: 0 (NOERROR)\n  - **Summary**: Used across `dns`, `mdns`, `llmnr`, `nbns`, `doh`: Sets the lower\n  4 bits of DNS Flags (`0`=NOERROR, `1`=FORMERR, `2`=SERVFAIL, `3`=NXDOMAIN,\n  `5`=REFUSED).\n- **Token**: `rcptto`\n  - **Scopes**: smtp\n  - **Syntax**: `mailfrom \"<addr>\" | rcptto \"<addr>\"`\n  - **Value / Range**: Quoted sender or recipient email address\n  - **Default**: Omitted unless set\n  - **Summary**: Writes `MAIL FROM:<addr>\\r\\n` or `RCPT TO:<addr>\\r\\n`.\n- **Token**: `rdata`\n  - **Scopes**: dns, mdns, llmnr, nbns, doh\n  - **Syntax**: `rdata \"<text>\"`\n  - **Value / Range**: IP string, hostname, or text value\n  - **Default**: Omitted (or 93.184.216.34 on A response)\n  - **Summary**: Used across `dns`, `mdns`, `llmnr`, `nbns`, `doh`: Populates the\n  Answer Resource Record `RDATA` payload on `response` frames.\n- **Token**: `read`\n  - **Scopes**: profinet, ethercat, smb, iscsi, nvmetcp, rocev2 (+9 more)\n  - **Syntax**: `service \"<text>\" | get | set | read | write | connect | release`\n  - **Value / Range**: DCP / IO service selector\n  - **Default**: Cyclic RT when omitted\n  - **Summary**: Used across `profinet`, `ethercat`, `smb`, `iscsi`, `nvmetcp`,\n  `rocev2`, `dnp3`, `mms`, `fins`, `melsec`, `c1222`, `gesrtp`, `rocplus`, `bsap`,\n  `knxnetip`: Selects DCP `get`/`set`/`identify` or IO\n  `read`/`write`/`connect`/`release` PDU encoding.\n- **Token**: `readcoils`\n  - **Scopes**: modbus\n  - **Syntax**: `readcoils | readdiscreteinputs | readholdingregisters |\n  readinputregisters | writesinglecoil | writesingleregister |\n  writemultipleregisters | func \"<fc>\"`\n  - **Value / Range**: Function Code keyword or number (`\"1\"`, `\"2\"`, `\"3\"`,\n  `\"4\"`, `\"5\"`, `\"6\"`, `\"15\"`, `\"16\"`)\n  - **Default**: readholdingregisters (FC 3)\n  - **Summary**: Sets the 1-byte Modbus Function Code immediately after `unitid`.\n- **Token**: `readdiscreteinputs`\n  - **Scopes**: modbus\n  - **Syntax**: `readcoils | readdiscreteinputs | readholdingregisters |\n  readinputregisters | writesinglecoil | writesingleregister |\n  writemultipleregisters | func \"<fc>\"`\n  - **Value / Range**: Function Code keyword or number (`\"1\"`, `\"2\"`, `\"3\"`,\n  `\"4\"`, `\"5\"`, `\"6\"`, `\"15\"`, `\"16\"`)\n  - **Default**: readholdingregisters (FC 3)\n  - **Summary**: Sets the 1-byte Modbus Function Code immediately after `unitid`.\n- **Token**: `readholdingregisters`\n  - **Scopes**: modbus\n  - **Syntax**: `readcoils | readdiscreteinputs | readholdingregisters |\n  readinputregisters | writesinglecoil | writesingleregister |\n  writemultipleregisters | func \"<fc>\"`\n  - **Value / Range**: Function Code keyword or number (`\"1\"`, `\"2\"`, `\"3\"`,\n  `\"4\"`, `\"5\"`, `\"6\"`, `\"15\"`, `\"16\"`)\n  - **Default**: readholdingregisters (FC 3)\n  - **Summary**: Sets the 1-byte Modbus Function Code immediately after `unitid`.\n- **Token**: `readinputregisters`\n  - **Scopes**: modbus\n  - **Syntax**: `readcoils | readdiscreteinputs | readholdingregisters |\n  readinputregisters | writesinglecoil | writesingleregister |\n  writemultipleregisters | func \"<fc>\"`\n  - **Value / Range**: Function Code keyword or number (`\"1\"`, `\"2\"`, `\"3\"`,\n  `\"4\"`, `\"5\"`, `\"6\"`, `\"15\"`, `\"16\"`)\n  - **Default**: readholdingregisters (FC 3)\n  - **Summary**: Sets the 1-byte Modbus Function Code immediately after `unitid`.\n- **Token**: `readproperty`\n  - **Scopes**: bacnet\n  - **Syntax**: `whois | iam | readproperty | writeproperty`\n  - **Value / Range**: BACnet APDU service selector\n  - **Default**: whois\n  - **Summary**: Selects Unconfirmed `Who-Is` (`8`), Unconfirmed `I-Am` (`0`),\n  Confirmed `ReadProperty` (`12`), or Confirmed `WriteProperty` (`15`).\n- **Token**: `readvar`\n  - **Scopes**: s7comm\n  - **Syntax**: `setupcomm | readvar | writevar | plccontrol | func \"<text>\"`\n  - **Value / Range**: S7 Parameter Function (`0xf0` Setup, `0x04` ReadVar, `0x05`\n  WriteVar, `0x28` PLCControl)\n  - **Default**: setupcomm (0xf0)\n  - **Summary**: Selects the S7comm Parameter Function code.\n- **Token**: `readyforquery`\n  - **Scopes**: postgres\n  - **Syntax**: `startup | authok | query | commandcomplete | readyforquery |\n  errorresponse`\n  - **Value / Range**: PostgreSQL v3.0 message type\n  - **Default**: query ('Q')\n  - **Summary**: Selects untagged `StartupMessage` (`startup`), `'R'` AuthOK\n  (`authok`), `'Q'` Simple Query (`query`), `'C'` CommandComplete, `'Z'`\n  ReadyForQuery, or `'E'` ErrorResponse.\n- **Token**: `real`\n  - **Scopes**: iec104, bacnet\n  - **Syntax**: `value <number> | real <decimal>`\n  - **Value / Range**: Integer state/command byte or IEEE 754 floating-point\n  number (e.g. `49.98`, `-12.5`)\n  - **Default**: value 1\n  - **Summary**: Used across `iec104`, `bacnet`: Encodes Single/Double/Measured\n  integer values (`value`) or 4-byte IEEE 754 float + QDS (`real`).\n- **Token**: `realm`\n  - **Scopes**: diameter, kerberos\n  - **Syntax**: `originhost \"<text>\" | realm \"<text>\"`\n  - **Value / Range**: DiameterIdentity strings (AVPs 264 & 296)\n  - **Default**: \"client.example.com\" / \"example.com\"\n  - **Summary**: Used across `diameter`, `kerberos`: Encodes mandatory\n  `Origin-Host` (AVP `264`, M-bit `0x40`) and `Origin-Realm` (AVP `296`, M-bit\n  `0x40`).\n- **Token**: `reason`\n  - **Scopes**: bmp, http, sip, doh, rtcp, mgcp\n  - **Syntax**: `reason <0..65535>`\n  - **Value / Range**: Reason code on peerdown or termination\n  - **Default**: 1\n  - **Summary**: Used across `bmp`, `http`, `sip`, `doh`, `rtcp`, `mgcp`: Sets the\n  Peer Down Reason byte (`1..5`) on `peerdown` or 16-bit Termination Reason TLV on\n  `termination`.\n- **Token**: `receiver`\n  - **Scopes**: wireguard\n  - **Syntax**: `receiver <number>`\n  - **Value / Range**: Whole number\n  - **Default**: 2\n  - **Summary**: Sets the 32-bit Receiver Index in `response`, `cookie`, and\n  `data` messages referencing the peer Sender Index.\n- **Token**: `recordversion`\n  - **Scopes**: tls\n  - **Syntax**: `recordversion <hex> | handshakeversion <hex>`\n  - **Value / Range**: 16-bit TLS version (`0x0301` TLS 1.0, `0x0303` TLS 1.2/1.3\n  record)\n  - **Default**: 0x0303\n  - **Summary**: Overrides the outer 5-byte TLS Record version or inner Handshake\n  legacy version.\n- **Token**: `recovery`\n  - **Scopes**: gtpc, pfcp\n  - **Syntax**: `recovery <0..255>`\n  - **Value / Range**: 8-bit Restart Counter (IE Type 3)\n  - **Default**: Omitted\n  - **Summary**: Used across `gtpc`, `pfcp`: Appends IE Type `3` (`Recovery` node\n  restart counter) for peer reboot detection.\n- **Token**: `redirect`\n  - **Scopes**: icmp, ndp, glbp, tns\n  - **Syntax**: `echorequest | echoreply | destunreach | timeexceeded | redirect`\n  - **Value / Range**: Named ICMP message shorthand\n  - **Default**: echorequest\n  - **Summary**: Used across `icmp`, `ndp`, `glbp`, `tns`: Maps to IPv4/ICMPv6\n  Type codes: `8`/`128` (`echorequest`), `0`/`129` (`echoreply`), `3`/`1`\n  (`destunreach`), `11`/`3` (`timeexceeded`), `5`/`137` (`redirect`).\n- **Token**: `refid`\n  - **Scopes**: ntp\n  - **Syntax**: `refid \"<text>\"`\n  - **Value / Range**: Up to 4 ASCII chars (\"GPS\", \"PPS\", \"ATOM\", \"RATE\")\n  - **Default**: \"LOCL\" / zeroed\n  - **Summary**: Writes the 4-byte Reference Identifier in bytes 12..15.\n- **Token**: `reflector`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... reflector`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `reflector` PDU selector or header field on\n  `twamp` frames.\n- **Token**: `refresh`\n  - **Scopes**: rsvp, rpkirtr, nbns, turn\n  - **Syntax**: `refresh <number>`\n  - **Value / Range**: 32-bit refresh period R in milliseconds\n  - **Default**: 30000 (30s)\n  - **Summary**: Used across `rsvp`, `rpkirtr`, `nbns`, `turn`: Sets the refresh\n  interval inside the `TIME_VALUES` object (`Class 5`).\n- **Token**: `refuse`\n  - **Scopes**: tns\n  - **Syntax**: `tns ... refuse`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (1521)\n  - **Summary**: Configures the `refuse` PDU selector or header field on `tns`\n  frames.\n- **Token**: `register`\n  - **Scopes**: pim, sip, nbns, sccp\n  - **Syntax**: `hello | joinprune | register`\n  - **Value / Range**: PIMv2 Message Type keyword\n  - **Default**: hello (Type 0)\n  - **Summary**: Used across `pim`, `sip`, `nbns`, `sccp`: Selects Type `0` Hello,\n  Type `1` unicast Register (to RP), or Type `3` Join/Prune.\n- **Token**: `registerack`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... registerack`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `registerack` PDU selector or header field on\n  `sccp` frames.\n- **Token**: `registersession`\n  - **Scopes**: ethernetip\n  - **Syntax**: `nop | listservices | listidentity | listinterfaces |\n  registersession | unregistersession | sendrrdata | sendunitdata`\n  - **Value / Range**: EtherNet/IP encapsulation command (or `cmd \"<text>\"`)\n  - **Default**: listidentity (0x0063)\n  - **Summary**: Selects Encapsulation Command `0x0000` NOP, `0x0004`\n  ListServices, `0x0063` ListIdentity, `0x0064` ListInterfaces, `0x0065`\n  RegisterSession, `0x0066` UnRegisterSession, `0x006f` SendRRData, or `0x0070`\n  SendUnitData.\n- **Token**: `registrar`\n  - **Scopes**: whois\n  - **Syntax**: `registrar \"<text>\"`\n  - **Value / Range**: Quoted registrar organization name\n  - **Default**: \"IANA\" on response\n  - **Summary**: Populates the `Registrar:` record line inside `whois response`\n  frames.\n- **Token**: `release`\n  - **Scopes**: profinet, dhcp, nbns\n  - **Syntax**: `service \"<text>\" | get | set | read | write | connect | release`\n  - **Value / Range**: DCP / IO service selector\n  - **Default**: Cyclic RT when omitted\n  - **Summary**: Used across `profinet`, `dhcp`, `nbns`: Selects DCP\n  `get`/`set`/`identify` or IO `read`/`write`/`connect`/`release` PDU encoding.\n- **Token**: `releasecomplete`\n  - **Scopes**: h323\n  - **Syntax**: `h323 ... releasecomplete`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP 1720 / UDP 1719 (1720 / 1719)\n  - **Summary**: Configures the `releasecomplete` PDU selector or header field on\n  `h323` frames.\n- **Token**: `reply`\n  - **Scopes**: arp, rip, dhcp, ftp, smtp, netconf (+1 more)\n  - **Syntax**: `request | reply | gratuitous | garp`\n  - **Value / Range**: Operation mode flag\n  - **Default**: request\n  - **Summary**: Used across `arp`, `rip`, `dhcp`, `ftp`, `smtp`, `netconf`,\n  `socks`: Selects Opcode `1` broadcast Who-Has (`request`), Opcode `2` unicast\n  Is-At (`reply`), or broadcast Gratuitous ARP (`gratuitous`/`garp` with `tpa =\n  spa` and `ff:ff:ff:ff:ff:ff`).\n- **Token**: `replytype`\n  - **Scopes**: redis\n  - **Syntax**: `replytype \"<ok|err|integer|bulk>\"`\n  - **Value / Range**: RESP reply type selector\n  - **Default**: Omitted on client requests\n  - **Summary**: Switches the packet to a server reply using `+`, `-`, `:`, or `$`\n  RESP framing.\n- **Token**: `report`\n  - **Scopes**: igmp, mld, snmp2, snmp3, mms, snmp1\n  - **Syntax**: `query | report | leave`\n  - **Value / Range**: IGMP message type\n  - **Default**: query\n  - **Summary**: Used across `igmp`, `mld`, `snmp2`, `snmp3`, `mms`, `snmp1`:\n  Selects Membership Query (`0x11`), Membership Report (`0x12` v1 / `0x16` v2 /\n  `0x22` v3), or Leave Group (`0x17`).\n- **Token**: `reqid`\n  - **Scopes**: snmp1, snmp2, snmp3, nvmetcp, opcua, mongodb\n  - **Syntax**: `sysuptime <number> | reqid <number>`\n  - **Value / Range**: Whole number\n  - **Default**: sysuptime 1000, reqid 1\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`, `nvmetcp`, `opcua`,\n  `mongodb`: Sets `time-stamp` (`TimeTicks` hundredths of a second) on `trap` or\n  `request-id` on `get`/`getnext`/`set`/`response`.\n- **Token**: `request`\n  - **Scopes**: arp, profinet, rip, glbp, dhcp, diameter (+5 more)\n  - **Syntax**: `request | reply | gratuitous | garp`\n  - **Value / Range**: Operation mode flag\n  - **Default**: request\n  - **Summary**: Used across `arp`, `profinet`, `rip`, `glbp`, `dhcp`, `diameter`,\n  `someip`, `gesrtp`, `ipmi`, `turn`, `dcerpc`: Selects Opcode `1` broadcast\n  Who-Has (`request`), Opcode `2` unicast Is-At (`reply`), or broadcast Gratuitous\n  ARP (`gratuitous`/`garp` with `tpa = spa` and `ff:ff:ff:ff:ff:ff`).\n- **Token**: `requestedtransport`\n  - **Scopes**: turn\n  - **Syntax**: `turn ... requestedtransport <udp|tcp|u8>`\n  - **Value / Range**: Parameter <udp|tcp|u8>\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Configures the `requestedtransport` PDU selector or header field\n  on `turn` frames.\n- **Token**: `requestnoreply`\n  - **Scopes**: someip\n  - **Syntax**: `findservice | offerservice | subscribe | subscribeack | request |\n  requestnoreply | notification | response | error | msgtype \"<text_or_num>\"`\n  - **Value / Range**: SOME/IP-SD Entry selector or SOME/IP Message Type\n  (`0x00`..`0x81`)\n  - **Default**: request (0x00)\n  - **Summary**: Selects either a full `0xffff:0x8100` SOME/IP-SD frame\n  (`findservice`/`offerservice`/`subscribe`/`subscribeack`) or standard SOME/IP\n  `Message Type`.\n- **Token**: `requestsession`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... requestsession`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `requestsession` PDU selector or header field on\n  `twamp` frames.\n- **Token**: `resetquery`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `serialnotify | serialquery | resetquery | cacheresponse |\n  ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport`\n  - **Value / Range**: RPKI-RTR PDU type keyword\n  - **Default**: ipv4prefix (Type 4)\n  - **Summary**: Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset\n  Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data,\n  `8`=Cache Reset, `10`=Error Report).\n- **Token**: `responderspi`\n  - **Scopes**: ikev2\n  - **Syntax**: `initiatorspi <u64|\"hex\"> | responderspi <u64|\"hex\">`\n  - **Value / Range**: 64-bit integer or hex string\n  - **Default**: Deterministic initiator SPI; responderspi 0 on sainit\n  - **Summary**: Populates the 8-byte Initiator SPI and 8-byte Responder SPI in\n  the IKEv2 header.\n- **Token**: `response`\n  - **Scopes**: profinet, wireguard, rip, glbp, snmp1, snmp2 (+27 more)\n  - **Syntax**: `request | response`\n  - **Value / Range**: PDU direction role flag\n  - **Default**: request\n  - **Summary**: Used across `profinet`, `wireguard`, `rip`, `glbp`, `snmp1`,\n  `snmp2`, `snmp3`, `dns`, `mdns`, `whois`, `diameter`, `imap`, `pop3`, `iscsi`,\n  `nvmetcp`, `dnp3`, `s7commplus`, `mms`, `hartip`, `fins`, `melsec`, `someip`,\n  `c1222`, `gesrtp`, `llmnr`, `nbns`, `ipmi`, `doh`, `turn`, `dcerpc`, `mssql`,\n  `mongodb`, `kafka`: Toggles DCP `ServiceType` (`0` Request vs `1` Response\n  Success).\n- **Token**: `responseto`\n  - **Scopes**: mongodb\n  - **Syntax**: `mongodb ... responseto <u32>`\n  - **Value / Range**: Parameter <u32>\n  - **Default**: TCP (27017)\n  - **Summary**: Configures the `responseto` PDU selector or header field on\n  `mongodb` frames.\n- **Token**: `resultcode`\n  - **Scopes**: diameter, ldap\n  - **Syntax**: `resultcode <number>`\n  - **Value / Range**: 32-bit Unsigned32 Result-Code (AVP 268)\n  - **Default**: 2001 (DIAMETER_SUCCESS) on Answers\n  - **Summary**: Used across `diameter`, `ldap`: Appends AVP `268` (`2001`\n  Success, `3002` Unable to Deliver, `5001` AVP Unsupported, `5030` User Unknown).\n- **Token**: `resv`\n  - **Scopes**: rsvp\n  - **Syntax**: `path | resv | patherr | resverr | pathtear | resvtear | resvconf\n  | hello`\n  - **Value / Range**: RSVP-TE message type keyword\n  - **Default**: path (Type 1)\n  - **Summary**: Selects RSVP Message Type (`1`=Path, `2`=Resv, `3`=PathErr,\n  `4`=ResvErr, `5`=PathTear, `6`=ResvTear, `7`=ResvConf, `20`=Hello).\n- **Token**: `resvconf`\n  - **Scopes**: rsvp\n  - **Syntax**: `path | resv | patherr | resverr | pathtear | resvtear | resvconf\n  | hello`\n  - **Value / Range**: RSVP-TE message type keyword\n  - **Default**: path (Type 1)\n  - **Summary**: Selects RSVP Message Type (`1`=Path, `2`=Resv, `3`=PathErr,\n  `4`=ResvErr, `5`=PathTear, `6`=ResvTear, `7`=ResvConf, `20`=Hello).\n- **Token**: `resverr`\n  - **Scopes**: rsvp\n  - **Syntax**: `path | resv | patherr | resverr | pathtear | resvtear | resvconf\n  | hello`\n  - **Value / Range**: RSVP-TE message type keyword\n  - **Default**: path (Type 1)\n  - **Summary**: Selects RSVP Message Type (`1`=Path, `2`=Resv, `3`=PathErr,\n  `4`=ResvErr, `5`=PathTear, `6`=ResvTear, `7`=ResvConf, `20`=Hello).\n- **Token**: `resvtear`\n  - **Scopes**: rsvp\n  - **Syntax**: `path | resv | patherr | resverr | pathtear | resvtear | resvconf\n  | hello`\n  - **Value / Range**: RSVP-TE message type keyword\n  - **Default**: path (Type 1)\n  - **Summary**: Selects RSVP Message Type (`1`=Path, `2`=Resv, `3`=PathErr,\n  `4`=ResvErr, `5`=PathTear, `6`=ResvTear, `7`=ResvConf, `20`=Hello).\n- **Token**: `retain`\n  - **Scopes**: mqtt\n  - **Syntax**: `qos <0..2> | retain`\n  - **Value / Range**: QoS delivery level (`0`, `1`, or `2`) + `retain` flag\n  - **Default**: qos 0, retain off\n  - **Summary**: Sets QoS bits `1..2` and Retain bit `0` in the Fixed Header.\n- **Token**: `retry`\n  - **Scopes**: rpkirtr, quic\n  - **Syntax**: `refresh <number> | retry <number> | expire <number>`\n  - **Value / Range**: 32-bit intervals in seconds (v1 endofdata)\n  - **Default**: refresh 3600, retry 600, expire 7200\n  - **Summary**: Used across `rpkirtr`, `quic`: Populates the three RFC 8210\n  timing parameters at the end of `version 1` `endofdata` PDUs.\n- **Token**: `returncode`\n  - **Scopes**: mqtt, someip\n  - **Syntax**: `returncode <0..255>`\n  - **Value / Range**: CONNACK return code (`0` Accepted, `4` Bad user/pass, `5`\n  Not authorized)\n  - **Default**: 0 (Connection Accepted)\n  - **Summary**: Used across `mqtt`, `someip`: Sets byte 3 (`Connect Return Code`)\n  of `connack`.\n- **Token**: `rloc`\n  - **Scopes**: lisp\n  - **Syntax**: `eid \"<cidr>\" | rloc <ip>`\n  - **Value / Range**: Quoted IPv4/IPv6 EID prefix & RLOC locator IP\n  - **Default**: \"10.0.0.0/24\", source/dest host IP\n  - **Summary**: Populates the Endpoint ID prefix record and Routing Locator\n  address in Map-Request/Reply/Register/Notify records.\n- **Token**: `rootid`\n  - **Scopes**: stp\n  - **Syntax**: `rootid \"<text>\"`\n  - **Value / Range**: Bridge ID string (\"<prio>:<mac>\" or \"<mac>\")\n  - **Default**: \"32768:<src_mac>\"\n  - **Summary**: Encodes the 8-byte Root Identifier (2-byte priority + 6-byte\n  MAC).\n- **Token**: `rosctr`\n  - **Scopes**: s7comm\n  - **Syntax**: `rosctr \"<job|ack|ackdata|userdata>\"`\n  - **Value / Range**: Remote Operating Service Control type\n  - **Default**: \"job\" (0x01)\n  - **Summary**: Sets `0x01` Job (HMI/engineering request), `0x02` Ack, `0x03`\n  Ack_Data (PLC reply with 2-byte error status), or `0x07` Userdata.\n- **Token**: `routemon`\n  - **Scopes**: bmp\n  - **Syntax**: `routemon | statsreport | peerdown | peerup | initiation |\n  termination`\n  - **Value / Range**: BMP v3 message type keyword\n  - **Default**: initiation (Type 4) or routemon (Type 0)\n  - **Summary**: Selects RFC 7854 Message Type (`0`=Route Monitoring, `1`=Stats\n  Report, `2`=Peer Down, `3`=Peer Up, `4`=Initiation, `5`=Termination).\n- **Token**: `router`\n  - **Scopes**: dhcp\n  - **Syntax**: `subnetmask <ipv4> | router <ipv4> | dnsserver <ip>`\n  - **Value / Range**: IPv4/IPv6 address literals\n  - **Default**: Omitted\n  - **Summary**: Appends Option `1` (Subnet Mask), Option `3` (Router), and Option\n  `6` / DHCPv6 Option `23` (DNS Recursive Name Server).\n- **Token**: `routeradvert`\n  - **Scopes**: ndp\n  - **Syntax**: `routersolicit | routeradvert | neighborsolicit | neighboradvert |\n  redirect`\n  - **Value / Range**: NDP message selector\n  - **Default**: neighborsolicit (Type 135)\n  - **Summary**: Selects ICMPv6 Type `133` (`routersolicit`), `134`\n  (`routeradvert`), `135` (`neighborsolicit`), `136` (`neighboradvert`), or `137`\n  (`redirect`).\n- **Token**: `routerid`\n  - **Scopes**: ospf\n  - **Syntax**: `routerid <ipv4>`\n  - **Value / Range**: 32-bit dotted-quad IPv4 format (e.g. 1.1.1.1)\n  - **Default**: Source IPv4 (or 1.1.1.1 on IPv6)\n  - **Summary**: Sets the 32-bit OSPF Router ID in both OSPFv2 and OSPFv3 headers.\n- **Token**: `routerlifetime`\n  - **Scopes**: ndp\n  - **Syntax**: `routerlifetime <0..65535>`\n  - **Value / Range**: Whole number (0..65535) (seconds)\n  - **Default**: 1800\n  - **Summary**: Sets the 16-bit Router Lifetime in `routeradvert` (`0` indicates\n  the router is not a default gateway).\n- **Token**: `routersolicit`\n  - **Scopes**: ndp\n  - **Syntax**: `routersolicit | routeradvert | neighborsolicit | neighboradvert |\n  redirect`\n  - **Value / Range**: NDP message selector\n  - **Default**: neighborsolicit (Type 135)\n  - **Summary**: Selects ICMPv6 Type `133` (`routersolicit`), `134`\n  (`routeradvert`), `135` (`neighborsolicit`), `136` (`neighboradvert`), or `137`\n  (`redirect`).\n- **Token**: `routingkey`\n  - **Scopes**: amqp\n  - **Syntax**: `exchange \"<text>\" | routingkey \"<text>\"`\n  - **Value / Range**: Quoted exchange name and routing key\n  - **Default**: exchange \"\", routingkey \"test\"\n  - **Summary**: Populates the Exchange and Routing-Key short strings in\n  `basicpublish` and `basicdeliver`.\n- **Token**: `routingreq`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `routingresp`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `rp`\n  - **Scopes**: pim\n  - **Syntax**: `group <ip> | source <ip> | rp <ip>`\n  - **Value / Range**: IPv4 or IPv6 address literals\n  - **Default**: 239.1.1.1 / endpoint IPs\n  - **Summary**: Sets the multicast Group, unicast Source `(S,G)`, and Rendezvous\n  Point addresses in `joinprune` and `register` packets.\n- **Token**: `rpc`\n  - **Scopes**: netconf\n  - **Syntax**: `netconf ... rpc`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (830)\n  - **Summary**: Configures the `rpc` PDU selector or header field on `netconf`\n  frames.\n- **Token**: `rpcreply`\n  - **Scopes**: netconf\n  - **Syntax**: `netconf ... rpcreply`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (830)\n  - **Summary**: Configures the `rpcreply` PDU selector or header field on\n  `netconf` frames.\n- **Token**: `rqnt`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... rqnt`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `rqnt` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `rqseq`\n  - **Scopes**: ipmi\n  - **Syntax**: `ipmi ... rqseq <u8>`\n  - **Value / Range**: Parameter <u8>\n  - **Default**: UDP (623)\n  - **Summary**: Configures the `rqseq` PDU selector or header field on `ipmi`\n  frames.\n- **Token**: `rr`\n  - **Scopes**: rtcp\n  - **Syntax**: `rtcp ... rr`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP (5005)\n  - **Summary**: Configures the `rr` PDU selector or header field on `rtcp`\n  frames.\n- **Token**: `rrq`\n  - **Scopes**: tftp, h323\n  - **Syntax**: `rrq | wrq | data | ack | error | err`\n  - **Value / Range**: TFTP opcode keyword\n  - **Default**: rrq (Opcode 1)\n  - **Summary**: Used across `tftp`, `h323`: Selects Opcode `1` Read Request\n  (`rrq`), `2` Write Request (`wrq`), `3` Data (`data`), `4` Acknowledgment\n  (`ack`), or `5` Error (`error` / `err`).\n- **Token**: `rsip`\n  - **Scopes**: mgcp\n  - **Syntax**: `mgcp ... rsip`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (2427)\n  - **Summary**: Configures the `rsip` PDU selector or header field on `mgcp`\n  frames.\n- **Token**: `rstp`\n  - **Scopes**: stp\n  - **Syntax**: `rstp`\n  - **Value / Range**: Bare boolean flag\n  - **Default**: Omitted (classic 802.1D v0)\n  - **Summary**: Emits IEEE 802.1w Rapid STP BPDU (`Protocol Version 2`, `BPDU\n  Type 0x02`, plus trailing 1-byte Version 1 Length `0x00`).\n- **Token**: `rxseq`\n  - **Scopes**: iec104\n  - **Syntax**: `txseq <0..32767> | rxseq <0..32767>`\n  - **Value / Range**: 15-bit Send `N(S)` & Receive `N(R)` sequence numbers\n  - **Default**: txseq 0, rxseq 0\n  - **Summary**: Encodes `(txseq << 1)` and `(rxseq << 1)` in APCI control octets\n  1..4.\n- **Token**: `s1setupfailure`\n  - **Scopes**: s1ap\n  - **Syntax**: `s1setuprequest | s1setupresponse | s1setupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 36.413 S1AP Elementary Procedure\n  - **Default**: s1setuprequest\n  - **Summary**: Selects the ASN.1 APER PDU Choice and TS 36.413 Procedure Code +\n  mandatory ProtocolIE sequence.\n- **Token**: `s1setuprequest`\n  - **Scopes**: s1ap\n  - **Syntax**: `s1setuprequest | s1setupresponse | s1setupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 36.413 S1AP Elementary Procedure\n  - **Default**: s1setuprequest\n  - **Summary**: Selects the ASN.1 APER PDU Choice and TS 36.413 Procedure Code +\n  mandatory ProtocolIE sequence.\n- **Token**: `s1setupresponse`\n  - **Scopes**: s1ap\n  - **Syntax**: `s1setuprequest | s1setupresponse | s1setupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 36.413 S1AP Elementary Procedure\n  - **Default**: s1setuprequest\n  - **Summary**: Selects the ASN.1 APER PDU Choice and TS 36.413 Procedure Code +\n  mandatory ProtocolIE sequence.\n- **Token**: `sa1`\n  - **Scopes**: fins\n  - **Syntax**: `dna <0..255> | da1 <0..255> | da2 <0..255> | sna <0..255> | sa1\n  <0..255> | sa2 <0..255>`\n  - **Value / Range**: Destination & Source `(Network, Node, Unit)` FINS routing\n  triples\n  - **Default**: dna 0, da1 1, da2 0, sna 0, sa1 10, sa2 0\n  - **Summary**: Writes bytes 3..8 of the 10-byte FINS header (`da1`/`sa1`\n  typically match the last IPv4 octet).\n- **Token**: `sa2`\n  - **Scopes**: fins\n  - **Syntax**: `dna <0..255> | da1 <0..255> | da2 <0..255> | sna <0..255> | sa1\n  <0..255> | sa2 <0..255>`\n  - **Value / Range**: Destination & Source `(Network, Node, Unit)` FINS routing\n  triples\n  - **Default**: dna 0, da1 1, da2 0, sna 0, sa1 10, sa2 0\n  - **Summary**: Writes bytes 3..8 of the 10-byte FINS header (`da1`/`sa1`\n  typically match the last IPv4 octet).\n- **Token**: `sack`\n  - **Scopes**: sctp\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Selects the RFC 9260 SCTP chunk type (`0`=DATA, `1`=INIT,\n  `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT, `5`=HEARTBEAT_ACK, `6`=ABORT,\n  `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO, `11`=COOKIE_ACK,\n  `14`=SHUTDOWN_COMPLETE).\n- **Token**: `sainit`\n  - **Scopes**: ikev2\n  - **Syntax**: `sainit | auth | createchildsa | informational | exchange <...>`\n  - **Value / Range**: RFC 7296 Exchange Type keyword or u8\n  - **Default**: sainit (34)\n  - **Summary**: Sets Exchange Type: `sainit` (`34` IKE_SA_INIT), `auth` (`35`\n  IKE_AUTH), `createchildsa` (`36` CREATE_CHILD_SA), `informational` (`37`\n  INFORMATIONAL).\n- **Token**: `samples`\n  - **Scopes**: sflow\n  - **Syntax**: `samples <number>`\n  - **Value / Range**: Sample count\n  - **Default**: 1\n  - **Summary**: Sets the number of sample records carried in the sFlow datagram.\n- **Token**: `scccn`\n  - **Scopes**: l2tp\n  - **Syntax**: `sccrq | sccrp | scccn | stopccn | hello | data | msgtype\n  <0..65535|\"<text>\">`\n  - **Value / Range**: Control AVP message type or data mode\n  - **Default**: sccrq (Control Type 1) or data\n  - **Summary**: Selects L2TP control AVP 0 (`1`=SCCRQ, `2`=SCCRP, `3`=SCCCN,\n  `4`=StopCCN, `6`=Hello) or `T=0` `data` encapsulation.\n- **Token**: `sccrp`\n  - **Scopes**: l2tp\n  - **Syntax**: `sccrq | sccrp | scccn | stopccn | hello | data | msgtype\n  <0..65535|\"<text>\">`\n  - **Value / Range**: Control AVP message type or data mode\n  - **Default**: sccrq (Control Type 1) or data\n  - **Summary**: Selects L2TP control AVP 0 (`1`=SCCRQ, `2`=SCCRP, `3`=SCCCN,\n  `4`=StopCCN, `6`=Hello) or `T=0` `data` encapsulation.\n- **Token**: `sccrq`\n  - **Scopes**: l2tp\n  - **Syntax**: `sccrq | sccrp | scccn | stopccn | hello | data | msgtype\n  <0..65535|\"<text>\">`\n  - **Value / Range**: Control AVP message type or data mode\n  - **Default**: sccrq (Control Type 1) or data\n  - **Summary**: Selects L2TP control AVP 0 (`1`=SCCRQ, `2`=SCCRP, `3`=SCCCN,\n  `4`=StopCCN, `6`=Hello) or `T=0` `data` encapsulation.\n- **Token**: `sci`\n  - **Scopes**: macsec\n  - **Syntax**: `sci <number>`\n  - **Value / Range**: 64-bit hex/decimal Secure Channel ID\n  - **Default**: Omitted unless set (6-byte MAC + 2-byte port)\n  - **Summary**: Appends the 8-byte Secure Channel Identifier\n  (`0x001b21aa00010001`) to SecTAG.\n- **Token**: `scid`\n  - **Scopes**: quic\n  - **Syntax**: `dcid <hex_or_num> | scid <hex_or_num>`\n  - **Value / Range**: 64-bit Connection IDs (e.g. 0x1122334455667788)\n  - **Default**: Deterministic 8-byte IDs\n  - **Summary**: Sets the 8-byte Destination Connection ID (`dcid`) and Source\n  Connection ID (`scid`, Long Header only).\n- **Token**: `scope`\n  - **Scopes**: nbns\n  - **Syntax**: `nbns ... scope <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: UDP (137)\n  - **Summary**: Configures the `scope` PDU selector or header field on `nbns`\n  frames.\n- **Token**: `scopes`\n  - **Scopes**: wsdiscovery\n  - **Syntax**: `wsdiscovery ... scopes <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: UDP (3702)\n  - **Summary**: Configures the `scopes` PDU selector or header field on\n  `wsdiscovery` frames.\n- **Token**: `sdes`\n  - **Scopes**: rtcp\n  - **Syntax**: `rtcp ... sdes`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP (5005)\n  - **Summary**: Configures the `sdes` PDU selector or header field on `rtcp`\n  frames.\n- **Token**: `sdservice`\n  - **Scopes**: someip\n  - **Syntax**: `sdservice <0..65535> | instanceid <0..65535> | majorver <0..255>\n  | minorver <number> | sdttl <0..16777215>`\n  - **Value / Range**: SOME/IP-SD 16-byte Service/Eventgroup Entry fields\n  - **Default**: sdservice 0x1234, instanceid 1, majorver 1, minorver 0, sdttl 3\n  - **Summary**: Populates the SOME/IP-SD Entry (`sdttl 0` signifies\n  `StopOfferService` / `StopSubscribeEventgroup`).\n- **Token**: `sdttl`\n  - **Scopes**: someip\n  - **Syntax**: `sdservice <0..65535> | instanceid <0..65535> | majorver <0..255>\n  | minorver <number> | sdttl <0..16777215>`\n  - **Value / Range**: SOME/IP-SD 16-byte Service/Eventgroup Entry fields\n  - **Default**: sdservice 0x1234, instanceid 1, majorver 1, minorver 0, sdttl 3\n  - **Summary**: Populates the SOME/IP-SD Entry (`sdttl 0` signifies\n  `StopOfferService` / `StopSubscribeEventgroup`).\n- **Token**: `searchdone`\n  - **Scopes**: ldap\n  - **Syntax**: `bindreq | bindres | searchreq | searchentry | searchdone |\n  unbindreq`\n  - **Value / Range**: LDAPv3 protocol operation keyword\n  - **Default**: searchreq\n  - **Summary**: Selects the ASN.1 BER `protocolOp` tag inside `LDAPMessage`.\n- **Token**: `searchentry`\n  - **Scopes**: ldap\n  - **Syntax**: `bindreq | bindres | searchreq | searchentry | searchdone |\n  unbindreq`\n  - **Value / Range**: LDAPv3 protocol operation keyword\n  - **Default**: searchreq\n  - **Summary**: Selects the ASN.1 BER `protocolOp` tag inside `LDAPMessage`.\n- **Token**: `searchreq`\n  - **Scopes**: ldap\n  - **Syntax**: `bindreq | bindres | searchreq | searchentry | searchdone |\n  unbindreq`\n  - **Value / Range**: LDAPv3 protocol operation keyword\n  - **Default**: searchreq\n  - **Summary**: Selects the ASN.1 BER `protocolOp` tag inside `LDAPMessage`.\n- **Token**: `securechannelid`\n  - **Scopes**: opcua\n  - **Syntax**: `securechannelid <number> | tokenid <number> | seqnum <number> |\n  reqid <number>`\n  - **Value / Range**: 32-bit little-endian channel, token, sequence, and request\n  IDs\n  - **Default**: 1\n  - **Summary**: Populates the Secure Conversation and Sequence headers on\n  `\"OPN\"`, `\"MSG\"`, and `\"CLO\"` frames.\n- **Token**: `securitytype`\n  - **Scopes**: vnc\n  - **Syntax**: `vnc ... securitytype <u8>`\n  - **Value / Range**: Parameter <u8>\n  - **Default**: TCP (5900)\n  - **Summary**: Configures the `securitytype` PDU selector or header field on\n  `vnc` frames.\n- **Token**: `segleft`\n  - **Scopes**: srv6\n  - **Syntax**: `segleft <0..255>`\n  - **Value / Range**: 8-bit Segments Left index (0..255)\n  - **Default**: 0 (or SidCount - 1)\n  - **Summary**: Sets the active segment index pointer in byte 3 of the SRH.\n- **Token**: `seid`\n  - **Scopes**: pfcp\n  - **Syntax**: `seid <number>`\n  - **Value / Range**: 64-bit Session Endpoint Identifier\n  - **Default**: 1 (on session messages)\n  - **Summary**: Writes the 8-byte big-endian `SEID` in bytes 4..11 of\n  session-related (`S=1`) PFCP headers.\n- **Token**: `select`\n  - **Scopes**: dnp3\n  - **Syntax**: `read | write | select | operate | directoperate | confirm |\n  response | unsolicitedresponse | func \"<text>\"`\n  - **Value / Range**: DNP3 Application Function Code\n  - **Default**: read (0x01)\n  - **Summary**: Selects `0x00` Confirm, `0x01` Read, `0x02` Write, `0x03` Select,\n  `0x04` Operate, `0x05` Direct Operate, `0x81` Response, or `0x82` Unsolicited\n  Response.\n- **Token**: `sender`\n  - **Scopes**: wireguard, twamp\n  - **Syntax**: `sender <number>`\n  - **Value / Range**: Whole number\n  - **Default**: 1\n  - **Summary**: Used across `wireguard`, `twamp`: Sets the 32-bit Sender Index in\n  `initiation` and `response` messages identifying the local session slot.\n- **Token**: `senderip`\n  - **Scopes**: arp\n  - **Syntax**: `senderip <ipv4> | spa <ipv4>`\n  - **Value / Range**: IPv4 literal\n  - **Default**: Source host IPv4 (or 0.0.0.0 on MAC-only host)\n  - **Summary**: Sets the 4-byte ARP Sender Protocol Address (`spa`).\n- **Token**: `sendermac`\n  - **Scopes**: arp\n  - **Syntax**: `sendermac <mac> | sha <mac>`\n  - **Value / Range**: 48-bit MAC (colon, hyphen, or Cisco dot)\n  - **Default**: Source host MAC\n  - **Summary**: Sets the 6-byte ARP Sender Hardware Address (`sha`) independently\n  of the outer Ethernet II `srcmac`.\n- **Token**: `senderttl`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... senderttl <u8>`\n  - **Value / Range**: Parameter <u8>\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `senderttl` PDU selector or header field on\n  `twamp` frames.\n- **Token**: `sendindication`\n  - **Scopes**: turn\n  - **Syntax**: `turn ... sendindication`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Configures the `sendindication` PDU selector or header field on\n  `turn` frames.\n- **Token**: `sendrrdata`\n  - **Scopes**: ethernetip\n  - **Syntax**: `nop | listservices | listidentity | listinterfaces |\n  registersession | unregistersession | sendrrdata | sendunitdata`\n  - **Value / Range**: EtherNet/IP encapsulation command (or `cmd \"<text>\"`)\n  - **Default**: listidentity (0x0063)\n  - **Summary**: Selects Encapsulation Command `0x0000` NOP, `0x0004`\n  ListServices, `0x0063` ListIdentity, `0x0064` ListInterfaces, `0x0065`\n  RegisterSession, `0x0066` UnRegisterSession, `0x006f` SendRRData, or `0x0070`\n  SendUnitData.\n- **Token**: `sendunitdata`\n  - **Scopes**: ethernetip\n  - **Syntax**: `nop | listservices | listidentity | listinterfaces |\n  registersession | unregistersession | sendrrdata | sendunitdata`\n  - **Value / Range**: EtherNet/IP encapsulation command (or `cmd \"<text>\"`)\n  - **Default**: listidentity (0x0063)\n  - **Summary**: Selects Encapsulation Command `0x0000` NOP, `0x0004`\n  ListServices, `0x0063` ListIdentity, `0x0064` ListInterfaces, `0x0065`\n  RegisterSession, `0x0066` UnRegisterSession, `0x006f` SendRRData, or `0x0070`\n  SendUnitData.\n- **Token**: `seqid`\n  - **Scopes**: ptp\n  - **Syntax**: `seqid <0..65535>`\n  - **Value / Range**: Whole number (0..65535)\n  - **Default**: 1\n  - **Summary**: Sets `sequenceId` in bytes 30..31 pairing `sync` with `followup`\n  and `delayreq` with `delayresp`.\n- **Token**: `seqnum`\n  - **Scopes**: isis, gtpu, gtpc, pfcp, rocev2, s7commplus (+8 more)\n  - **Syntax**: `seqnum <number>`\n  - **Value / Range**: Whole number (32-bit LSP sequence)\n  - **Default**: 1\n  - **Summary**: Used across `isis`, `gtpu`, `gtpc`, `pfcp`, `rocev2`,\n  `s7commplus`, `opcua`, `gesrtp`, `bsap`, `knxnetip`, `ipmi`, `twamp`, `rtcp`,\n  `h323`: Sets the 32-bit Sequence Number in `l1lsp` and `l2lsp` headers and\n  recalculates Fletcher-16.\n- **Token**: `serial`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `sessionid <0..65535> | serial <number>`\n  - **Value / Range**: 16-bit Cache Session ID & 32-bit Serial Number\n  - **Default**: sessionid 1, serial 1\n  - **Summary**: Tracks cache epoch (`sessionid`) and monotonic serial state\n  across `serialnotify`, `serialquery`, `cacheresponse`, and `endofdata`.\n- **Token**: `serialnotify`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `serialnotify | serialquery | resetquery | cacheresponse |\n  ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport`\n  - **Value / Range**: RPKI-RTR PDU type keyword\n  - **Default**: ipv4prefix (Type 4)\n  - **Summary**: Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset\n  Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data,\n  `8`=Cache Reset, `10`=Error Report).\n- **Token**: `serialquery`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `serialnotify | serialquery | resetquery | cacheresponse |\n  ipv4prefix | ipv6prefix | endofdata | cachereset | errorreport`\n  - **Value / Range**: RPKI-RTR PDU type keyword\n  - **Default**: ipv4prefix (Type 4)\n  - **Summary**: Selects PDU Type (`0`=Serial Notify, `1`=Serial Query, `2`=Reset\n  Query, `3`=Cache Response, `4`=IPv4 Prefix, `6`=IPv6 Prefix, `7`=End of Data,\n  `8`=Cache Reset, `10`=Error Report).\n- **Token**: `serverhello`\n  - **Scopes**: tls\n  - **Syntax**: `clienthello | serverhello | certificate | finished | appdata |\n  alert`\n  - **Value / Range**: TLS record / handshake message type\n  - **Default**: clienthello\n  - **Summary**: Selects Handshake (`22`: `clienthello`, `serverhello`,\n  `certificate`, `finished`), Application Data (`23`: `appdata`), or Alert (`21`:\n  `alert`).\n- **Token**: `serverstart`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... serverstart`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `serverstart` PDU selector or header field on\n  `twamp` frames.\n- **Token**: `serverversion`\n  - **Scopes**: mysql\n  - **Syntax**: `serverversion \"<text>\"`\n  - **Value / Range**: Quoted version banner on `greeting`\n  - **Default**: \"8.0.36\"\n  - **Summary**: Sets the NUL-terminated server version string in `greeting`\n  packets.\n- **Token**: `service`\n  - **Scopes**: profinet, grpc, mms, c1222, knxnetip, tns\n  - **Syntax**: `service \"<text>\" | get | set | read | write | connect | release`\n  - **Value / Range**: DCP / IO service selector\n  - **Default**: Cyclic RT when omitted\n  - **Summary**: Used across `profinet`, `grpc`, `mms`, `c1222`, `knxnetip`,\n  `tns`: Selects DCP `get`/`set`/`identify` or IO\n  `read`/`write`/`connect`/`release` PDU encoding.\n- **Token**: `serviceid`\n  - **Scopes**: someip\n  - **Syntax**: `serviceid <0..65535> | methodid <0..65535>`\n  - **Value / Range**: 16-bit Service ID & Method/Event ID (`0x8000+` for Events)\n  - **Default**: serviceid 0x1234, methodid 0x0001 (or 0xffff/0x8100 on SD)\n  - **Summary**: Writes the 32-bit SOME/IP `Message ID` (`Service ID << 16 |\n  Method ID`) in bytes 0..3.\n- **Token**: `servicename`\n  - **Scopes**: pppoe\n  - **Syntax**: `servicename \"<text>\"`\n  - **Value / Range**: Quoted ISP service string\n  - **Default**: \"\" (empty wildcard Service-Name tag)\n  - **Summary**: Encodes Discovery Tag `0x0101` (`Service-Name`).\n- **Token**: `servicetype`\n  - **Scopes**: radius\n  - **Syntax**: `servicetype <number>`\n  - **Value / Range**: Whole number (`1` Login, `2` Framed, `6` Administrative)\n  - **Default**: Omitted unless set\n  - **Summary**: Adds Attribute `6` (`Service-Type`) as a 4-byte integer.\n- **Token**: `session`\n  - **Scopes**: pppoe, rtsp\n  - **Syntax**: `padi | pado | padr | pads | padt | session`\n  - **Value / Range**: PPPoE stage keyword (or `type <stage>`)\n  - **Default**: padi (Discovery 0x09)\n  - **Summary**: Used across `pppoe`, `rtsp`: Selects Discovery codes `0x09`\n  (`padi`), `0x07` (`pado`), `0x19` (`padr`), `0x65` (`pads`), `0xa7` (`padt`) on\n  `0x8863`, or `session` (`0x00`) on `0x8864`.\n- **Token**: `sessiondeletionrequest`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `sessiondeletionresponse`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `sessionestablishmentrequest`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `sessionestablishmentresponse`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `sessionhandle`\n  - **Scopes**: ethernetip\n  - **Syntax**: `sessionhandle <hex_or_num> | status <number> | context\n  <hex_or_str>`\n  - **Value / Range**: 32-bit Session Handle, 32-bit Status (`0` Success), 64-bit\n  Sender Context\n  - **Default**: sessionhandle 0, status 0\n  - **Summary**: Populates the 24-byte EtherNet/IP Encapsulation Header fields.\n- **Token**: `sessionid`\n  - **Scopes**: pppoe, erspan, rpkirtr, l2tp, tacacs, diameter (+6 more)\n  - **Syntax**: `sessionid <0..65535>`\n  - **Value / Range**: 16-bit PPPoE Session ID\n  - **Default**: 0 on PADI/PADO/PADR; 1 on PADS/Session\n  - **Summary**: Used across `pppoe`, `erspan`, `rpkirtr`, `l2tp`, `tacacs`,\n  `diameter`, `smb`, `s7commplus`, `someip`, `ipmi`, `netconf`, `rdp`: Sets the\n  big-endian 16-bit Session_ID in bytes 2..3 of the 6-byte PPPoE header.\n- **Token**: `sessionmodificationrequest`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `sessionmodificationresponse`\n  - **Scopes**: pfcp\n  - **Syntax**: `heartbeatrequest | heartbeatresponse | associationsetuprequest |\n  associationsetupresponse | sessionestablishmentrequest |\n  sessionestablishmentresponse | sessionmodificationrequest |\n  sessionmodificationresponse | sessiondeletionrequest | sessiondeletionresponse |\n  msgtype \"<text>\"`\n  - **Value / Range**: 3GPP TS 29.244 PFCP Message Type\n  - **Default**: heartbeatrequest (1)\n  - **Summary**: Sets byte 1 (`1`/`2` Heartbeat, `5`/`6` Association Setup,\n  `50`/`51` Session Establishment, `52`/`53` Modification, `54`/`55` Deletion) and\n  `S` flag.\n- **Token**: `sessionsetup`\n  - **Scopes**: smb\n  - **Syntax**: `negotiate | sessionsetup | treeconnect | treedisconnect | create\n  | close | read | write | logoff`\n  - **Value / Range**: SMB2/3 command keyword (or `command \"<text>\"`)\n  - **Default**: negotiate (0x0000)\n  - **Summary**: Selects the 16-bit MS-SMB2 command (`0x00` Negotiate, `0x01`\n  SessionSetup, `0x02` Logoff, `0x03` TreeConnect, `0x04` TreeDisconnect, `0x05`\n  Create, `0x06` Close, `0x08` Read, `0x09` Write).\n- **Token**: `set`\n  - **Scopes**: profinet, snmp1, snmp2, snmp3, redis, memcached\n  - **Syntax**: `service \"<text>\" | get | set | read | write | connect | release`\n  - **Value / Range**: DCP / IO service selector\n  - **Default**: Cyclic RT when omitted\n  - **Summary**: Used across `profinet`, `snmp1`, `snmp2`, `snmp3`, `redis`,\n  `memcached`: Selects DCP `get`/`set`/`identify` or IO\n  `read`/`write`/`connect`/`release` PDU encoding.\n- **Token**: `settings`\n  - **Scopes**: http2\n  - **Syntax**: `preface | settings | headers | data | windowupdate | ping |\n  goaway`\n  - **Value / Range**: HTTP/2 frame type keyword\n  - **Default**: settings (Type 0x04, streamid 0)\n  - **Summary**: Selects the RFC 9113 HTTP/2 binary frame type (`0x0` DATA, `0x1`\n  HEADERS, `0x4` SETTINGS, `0x6` PING, `0x7` GOAWAY, `0x8` WINDOW_UPDATE, or\n  connection `preface`).\n- **Token**: `setup`\n  - **Scopes**: rtsp, h323\n  - **Syntax**: `options | describe | setup | play | teardown | method \"<text>\"`\n  - **Value / Range**: RTSP request verb\n  - **Default**: options\n  - **Summary**: Used across `rtsp`, `h323`: Sets the RTSP command method on the\n  request line.\n- **Token**: `setupcomm`\n  - **Scopes**: s7comm\n  - **Syntax**: `setupcomm | readvar | writevar | plccontrol | func \"<text>\"`\n  - **Value / Range**: S7 Parameter Function (`0xf0` Setup, `0x04` ReadVar, `0x05`\n  WriteVar, `0x28` PLCControl)\n  - **Default**: setupcomm (0xf0)\n  - **Summary**: Selects the S7comm Parameter Function code.\n- **Token**: `setupresponse`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... setupresponse`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `setupresponse` PDU selector or header field on\n  `twamp` frames.\n- **Token**: `severity`\n  - **Scopes**: syslog\n  - **Syntax**: `severity <0..7>`\n  - **Value / Range**: Severity 0..7 (`0` emerg, `2` crit, `3` err, `4` warn, `6`\n  info, `7` debug)\n  - **Default**: 6 (Informational)\n  - **Summary**: Sets the 3-bit Severity level (`0` is highest urgency, `7` is\n  debug).\n- **Token**: `sframe`\n  - **Scopes**: iec104\n  - **Syntax**: `startdt | stopdt | testfr | sframe | msgtype \"<text>\" |\n  [confirm]`\n  - **Value / Range**: APCI frame format (`U-Frame` STARTDT/STOPDT/TESTFR,\n  `S-Frame`, or default `I-Frame` when ASDU fields are present)\n  - **Default**: I-Frame (or U-Frame when startdt/stopdt/testfr is set)\n  - **Summary**: Selects U-Frame (`0x07`/`0x0b` STARTDT, `0x13`/`0x23` STOPDT,\n  `0x43`/`0x83` TESTFR with `confirm`), S-Frame (`0x01`), or I-Frame\n  (`N(S)`/`N(R)` + ASDU).\n- **Token**: `sha`\n  - **Scopes**: arp, snmp3, snmp1, snmp2\n  - **Syntax**: `sendermac <mac> | sha <mac>`\n  - **Value / Range**: 48-bit MAC (colon, hyphen, or Cisco dot)\n  - **Default**: Source host MAC\n  - **Summary**: Used across `arp`, `snmp3`, `snmp1`, `snmp2`: Sets the 6-byte ARP\n  Sender Hardware Address (`sha`) independently of the outer Ethernet II `srcmac`.\n- **Token**: `sha256`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `auth md5 | sha | sha256 | sha384 | sha512 \"<password>\"`\n  - **Value / Range**: HMAC algorithm keyword + passphrase string\n  - **Default**: Omitted (noAuthNoPriv)\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Enables USM authentication\n  (`authNoPriv` or `authPriv`) and writes the live RFC 3414 / RFC 7860 HMAC\n  digest.\n- **Token**: `sha384`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `auth md5 | sha | sha256 | sha384 | sha512 \"<password>\"`\n  - **Value / Range**: HMAC algorithm keyword + passphrase string\n  - **Default**: Omitted (noAuthNoPriv)\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Enables USM authentication\n  (`authNoPriv` or `authPriv`) and writes the live RFC 3414 / RFC 7860 HMAC\n  digest.\n- **Token**: `sha512`\n  - **Scopes**: snmp3, snmp1, snmp2\n  - **Syntax**: `auth md5 | sha | sha256 | sha384 | sha512 \"<password>\"`\n  - **Value / Range**: HMAC algorithm keyword + passphrase string\n  - **Default**: Omitted (noAuthNoPriv)\n  - **Summary**: Used across `snmp3`, `snmp1`, `snmp2`: Enables USM authentication\n  (`authNoPriv` or `authPriv`) and writes the live RFC 3414 / RFC 7860 HMAC\n  digest.\n- **Token**: `share`\n  - **Scopes**: smb\n  - **Syntax**: `share \"<unc_path>\"`\n  - **Value / Range**: Quoted UNC share path (`\"\\\\server\\IPC$\"`)\n  - **Default**: \"\\\\server\\IPC$\" on treeconnect\n  - **Summary**: Encodes the UTF-16LE share path inside `treeconnect` requests.\n- **Token**: `short`\n  - **Scopes**: quic\n  - **Syntax**: `initial | zerortt | handshake | retry | short`\n  - **Value / Range**: QUIC packet header type\n  - **Default**: initial\n  - **Summary**: Selects Long Header (`initial`, `zerortt`, `handshake`, `retry`)\n  or 1-RTT Short Header (`short`).\n- **Token**: `shutdown`\n  - **Scopes**: sctp\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Selects the RFC 9260 SCTP chunk type (`0`=DATA, `1`=INIT,\n  `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT, `5`=HEARTBEAT_ACK, `6`=ABORT,\n  `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO, `11`=COOKIE_ACK,\n  `14`=SHUTDOWN_COMPLETE).\n- **Token**: `shutdownack`\n  - **Scopes**: sctp\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Selects the RFC 9260 SCTP chunk type (`0`=DATA, `1`=INIT,\n  `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT, `5`=HEARTBEAT_ACK, `6`=ABORT,\n  `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO, `11`=COOKIE_ACK,\n  `14`=SHUTDOWN_COMPLETE).\n- **Token**: `shutdowncomplete`\n  - **Scopes**: sctp\n  - **Syntax**: `data | init | initack | sack | heartbeat | heartbeatack | abort |\n  shutdown | shutdownack | shutdowncomplete | cookieecho | cookieack`\n  - **Value / Range**: Bare chunk keyword (or `chunk <type>`)\n  - **Default**: data (Chunk Type 0)\n  - **Summary**: Selects the RFC 9260 SCTP chunk type (`0`=DATA, `1`=INIT,\n  `2`=INIT_ACK, `3`=SACK, `4`=HEARTBEAT, `5`=HEARTBEAT_ACK, `6`=ABORT,\n  `7`=SHUTDOWN, `8`=SHUTDOWN_ACK, `10`=COOKIE_ECHO, `11`=COOKIE_ACK,\n  `14`=SHUTDOWN_COMPLETE).\n- **Token**: `si`\n  - **Scopes**: nsh\n  - **Syntax**: `si <0..255>`\n  - **Value / Range**: 8-bit Service Index\n  - **Default**: 255\n  - **Summary**: Writes the 8-bit Service Index hop counter in byte 7 of the NSH\n  header.\n- **Token**: `siaddr`\n  - **Scopes**: dhcp\n  - **Syntax**: `ciaddr <ipv4> | yiaddr <ipv4> | siaddr <ipv4>`\n  - **Value / Range**: IPv4 dotted-quad literals\n  - **Default**: 0.0.0.0\n  - **Summary**: Sets Client IP, Your (offered) IP, and Next Server IP in the\n  DHCPv4 BOOTP header.\n- **Token**: `sid`\n  - **Scopes**: srv6, fins, tns\n  - **Syntax**: `sid <ipv6> (repeatable)`\n  - **Value / Range**: 128-bit IPv6 Segment Identifier (repeatable)\n  - **Default**: Single default SID (2001:db8::1)\n  - **Summary**: Used across `srv6`, `fins`, `tns`: Appends each 16-byte IPv6 SID\n  into `Segment List[0..n]` and updates `Hdr Ext Len` and `Last Entry`.\n- **Token**: `simulation`\n  - **Scopes**: goose, sv\n  - **Syntax**: `simulation`\n  - **Value / Range**: Boolean test-mode flag\n  - **Default**: false (0x00)\n  - **Summary**: Used across `goose`, `sv`: Sets BER context tag `[7]`\n  (`simulation = true`) so live relays ignore test-bench GOOSE frames.\n- **Token**: `sl`\n  - **Scopes**: macsec\n  - **Syntax**: `sl <0..63>`\n  - **Value / Range**: 6-bit Short Length (0..63)\n  - **Default**: 0\n  - **Summary**: Sets Short Length in byte 3 of SecTAG (`1..47` octets for short\n  frames; `0` otherwise).\n- **Token**: `slla`\n  - **Scopes**: ndp\n  - **Syntax**: `slla <mac> | tlla <mac>`\n  - **Value / Range**: 48-bit MAC address\n  - **Default**: Omitted unless set\n  - **Summary**: Appends 8-byte NDP Option Type `1` (Source Link-Layer Address,\n  `slla`) or Option Type `2` (Target Link-Layer Address, `tlla`).\n- **Token**: `smpcnt`\n  - **Scopes**: sv\n  - **Syntax**: `smpcnt <0..65535>`\n  - **Value / Range**: 16-bit Sample Counter (0..3999 or 0..4799)\n  - **Default**: 0\n  - **Summary**: Encodes ASDU context tag `[2]` (`smpCnt`, resets to `0` on each\n  1-PPS second boundary).\n- **Token**: `smprate`\n  - **Scopes**: sv\n  - **Syntax**: `smprate <0..65535>`\n  - **Value / Range**: Samples per nominal period (e.g. 80 or 256)\n  - **Default**: Omitted unless set\n  - **Summary**: Encodes optional ASDU context tag `[6]` (`smpRate`).\n- **Token**: `smpsynch`\n  - **Scopes**: sv\n  - **Syntax**: `smpsynch <0|1|2>`\n  - **Value / Range**: Clock sync state (0=None, 1=Local, 2=Global PTP)\n  - **Default**: 2 (Global synchronized)\n  - **Summary**: Encodes ASDU context tag `[5]` (`smpSynch` synchronization status\n  byte).\n- **Token**: `sna`\n  - **Scopes**: fins\n  - **Syntax**: `dna <0..255> | da1 <0..255> | da2 <0..255> | sna <0..255> | sa1\n  <0..255> | sa2 <0..255>`\n  - **Value / Range**: Destination & Source `(Network, Node, Unit)` FINS routing\n  triples\n  - **Default**: dna 0, da1 1, da2 0, sna 0, sa1 10, sa2 0\n  - **Summary**: Writes bytes 3..8 of the 10-byte FINS header (`da1`/`sa1`\n  typically match the last IPv4 octet).\n- **Token**: `sname`\n  - **Scopes**: kerberos\n  - **Syntax**: `cname \"<text>\" | sname \"<text>\"`\n  - **Value / Range**: Quoted Client Principal Name or Service Principal Name\n  (SPN)\n  - **Default**: cname \"alice\", sname \"krbtgt/EXAMPLE.COM\"\n  - **Summary**: Encodes `PrincipalName` components in `KDC-REQ-BODY` / `KDC-REP`.\n- **Token**: `sni`\n  - **Scopes**: tls\n  - **Syntax**: `sni \"<text>\"`\n  - **Value / Range**: Quoted hostname (e.g. \"api.example.com\")\n  - **Default**: Omitted unless set\n  - **Summary**: Adds TLS Extension `0x0000` (`server_name`) to `clienthello` for\n  proxy/firewall SNI inspection.\n- **Token**: `software`\n  - **Scopes**: stun, turn\n  - **Syntax**: `software \"<text>\"`\n  - **Value / Range**: Quoted agent/server string\n  - **Default**: Omitted unless set\n  - **Summary**: Used across `stun`, `turn`: Adds 4-byte-padded Attribute `0x8022`\n  (`SOFTWARE`).\n- **Token**: `solicit`\n  - **Scopes**: dhcp\n  - **Syntax**: `discover | offer | request | ack | release | solicit | advertise\n  | reply`\n  - **Value / Range**: DHCPv4 / DHCPv6 message type keyword\n  - **Default**: discover (IPv4) / solicit (IPv6)\n  - **Summary**: Sets DHCPv4 Option `53` + BOOTP `op` (`1` request, `2` reply) or\n  DHCPv6 `msg-type` (`1` Solicit, `2` Advertise, `3` Request, `7` Reply, `8`\n  Release).\n- **Token**: `source`\n  - **Scopes**: pim\n  - **Syntax**: `group <ip> | source <ip> | rp <ip>`\n  - **Value / Range**: IPv4 or IPv6 address literals\n  - **Default**: 239.1.1.1 / endpoint IPs\n  - **Summary**: Sets the multicast Group, unicast Source `(S,G)`, and Rendezvous\n  Point addresses in `joinprune` and `register` packets.\n- **Token**: `spa`\n  - **Scopes**: arp\n  - **Syntax**: `senderip <ipv4> | spa <ipv4>`\n  - **Value / Range**: IPv4 literal\n  - **Default**: Source host IPv4 (or 0.0.0.0 on MAC-only host)\n  - **Summary**: Sets the 4-byte ARP Sender Protocol Address (`spa`).\n- **Token**: `spectrap`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `gentrap <0..6> | spectrap <number>`\n  - **Value / Range**: gentrap: 0..6, spectrap: u32\n  - **Default**: gentrap 6, spectrap 1\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Sets `generic-trap`\n  (`0`=coldStart, `1`=warmStart, `2`=linkDown, `3`=linkUp, `4`=authFailure,\n  `5`=egpNeighborLoss, `6`=enterpriseSpecific) and `specific-trap`.\n- **Token**: `spi`\n  - **Scopes**: nsh, ipsec, esp, ah\n  - **Syntax**: `spi <0..16777215>`\n  - **Value / Range**: 24-bit Service Path Identifier\n  - **Default**: 1\n  - **Summary**: Used across `nsh`, `ipsec`, `esp`, `ah`: Writes the big-endian\n  24-bit Service Path ID in bytes 4..6 of the NSH header.\n- **Token**: `spid`\n  - **Scopes**: mssql\n  - **Syntax**: `mssql ... spid <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP / UDP (1433)\n  - **Summary**: Configures the `spid` PDU selector or header field on `mssql`\n  frames.\n- **Token**: `sql`\n  - **Scopes**: mysql, postgres, mssql, tns\n  - **Syntax**: `sql \"<text>\"`\n  - **Value / Range**: Quoted SQL statement on `query`\n  - **Default**: \"SELECT 1\"\n  - **Summary**: Used across `mysql`, `postgres`, `mssql`, `tns`: Writes the SQL\n  query string following `COM_QUERY` (`0x03`).\n- **Token**: `sqnum`\n  - **Scopes**: goose\n  - **Syntax**: `sqnum <number>`\n  - **Value / Range**: Sequence Number counter (>= 0)\n  - **Default**: 0\n  - **Summary**: Encodes BER context tag `[6]` (`sqNum`, increments on heartbeats;\n  resets to `0` on state change).\n- **Token**: `sr`\n  - **Scopes**: rtcp\n  - **Syntax**: `rtcp ... sr`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP (5005)\n  - **Summary**: Configures the `sr` PDU selector or header field on `rtcp`\n  frames.\n- **Token**: `src`\n  - **Scopes**: dnp3, doip, rocplus, bsap, knxnetip\n  - **Syntax**: `src <0..65535> | dst <0..65535>`\n  - **Value / Range**: 16-bit DNP3 Data Link station addresses\n  - **Default**: src 1, dst 10\n  - **Summary**: Used across `dnp3`, `doip`, `rocplus`, `bsap`, `knxnetip`: Sets\n  the 2-byte little-endian DNP3 Source and Destination outstation/master\n  addresses.\n- **Token**: `srcip`\n  - **Scopes**: ipip, rsvp, netflow, ipfix\n  - **Syntax**: `srcip <ip> | dstip <ip>`\n  - **Value / Range**: IPv4 or IPv6 literal matching inner version\n  - **Default**: 10.0.0.1 -> 10.0.0.2 (v4) or 2001:db8::1 -> 2001:db8::2 (v6)\n  - **Summary**: Used across `ipip`, `rsvp`, `netflow`, `ipfix`: Writes the inner\n  encapsulated source and destination IP addresses.\n- **Token**: `ssn`\n  - **Scopes**: sctp\n  - **Syntax**: `ssn <0..65535>`\n  - **Value / Range**: Whole number (0..65535)\n  - **Default**: 0\n  - **Summary**: Sets the 16-bit Stream Sequence Number inside `data` chunks.\n- **Token**: `ssrc`\n  - **Scopes**: rtp, rtcp\n  - **Syntax**: `ssrc <hex_or_num>`\n  - **Value / Range**: 32-bit Synchronization Source ID\n  - **Default**: 0x12345678\n  - **Summary**: Used across `rtp`, `rtcp`: Uniquely identifies the unidirectional\n  RTP media stream in bytes 8..11.\n- **Token**: `st`\n  - **Scopes**: ssdp\n  - **Syntax**: `man \"<text>\" | mx <0..255> | st \"<text>\"`\n  - **Value / Range**: M-SEARCH discovery headers (`MX` max wait seconds, `ST`\n  Search Target)\n  - **Default**: man \"\\\"ssdp:discover\\\"\", mx 3, st \"ssdp:all\"\n  - **Summary**: Populates mandatory UPnP discovery request headers on `msearch`\n  packets.\n- **Token**: `start`\n  - **Scopes**: eapol\n  - **Syntax**: `eappacket | start | logoff | key | type <...>`\n  - **Value / Range**: EAPOL packet type keyword or u8\n  - **Default**: eappacket (type 0)\n  - **Summary**: Selects EAPOL Packet Type: `eappacket` (`0`), `start` (`1`,\n  0-byte body), `logoff` (`2`, 0-byte body), or `key` (`3`, EAPOL-Key descriptor).\n- **Token**: `startack`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... startack`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `startack` PDU selector or header field on `twamp`\n  frames.\n- **Token**: `startdt`\n  - **Scopes**: iec104\n  - **Syntax**: `startdt | stopdt | testfr | sframe | msgtype \"<text>\" |\n  [confirm]`\n  - **Value / Range**: APCI frame format (`U-Frame` STARTDT/STOPDT/TESTFR,\n  `S-Frame`, or default `I-Frame` when ASDU fields are present)\n  - **Default**: I-Frame (or U-Frame when startdt/stopdt/testfr is set)\n  - **Summary**: Selects U-Frame (`0x07`/`0x0b` STARTDT, `0x13`/`0x23` STOPDT,\n  `0x43`/`0x83` TESTFR with `confirm`), S-Frame (`0x01`), or I-Frame\n  (`N(S)`/`N(R)` + ASDU).\n- **Token**: `startsessions`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... startsessions`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `startsessions` PDU selector or header field on\n  `twamp` frames.\n- **Token**: `starttone`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... starttone`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `starttone` PDU selector or header field on `sccp`\n  frames.\n- **Token**: `startup`\n  - **Scopes**: postgres\n  - **Syntax**: `startup | authok | query | commandcomplete | readyforquery |\n  errorresponse`\n  - **Value / Range**: PostgreSQL v3.0 message type\n  - **Default**: query ('Q')\n  - **Summary**: Selects untagged `StartupMessage` (`startup`), `'R'` AuthOK\n  (`authok`), `'Q'` Simple Query (`query`), `'C'` CommandComplete, `'Z'`\n  ReadyForQuery, or `'E'` ErrorResponse.\n- **Token**: `state`\n  - **Scopes**: hsrp, glbp, bfd, sccp\n  - **Syntax**: `state <0..255>`\n  - **Value / Range**: 8-bit RFC 2281 HSRP state code\n  - **Default**: 16 (Active)\n  - **Summary**: Used across `hsrp`, `glbp`, `bfd`, `sccp`: Sets router state: `0`\n  Initial, `1` Learn, `2` Listen, `4` Speak, `8` Standby, `16` Active.\n- **Token**: `station`\n  - **Scopes**: synchrophasor, melsec\n  - **Syntax**: `status <0..65535> | station \"<text>\"`\n  - **Value / Range**: 16-bit Data Frame `STAT` bitmask & 16-char ASCII `STN`\n  Station Name (on `cfg1`/`cfg2`)\n  - **Default**: status 0x0000 (Valid/Locked), station \"PMU_STATION_01\"\n  - **Summary**: Used across `synchrophasor`, `melsec`: Writes PMU `STAT` flags in\n  Data frames or the space-padded 16-byte `STN` field in Configuration frames.\n- **Token**: `statsn`\n  - **Scopes**: iscsi\n  - **Syntax**: `itt <number> | cmdsn <number> | statsn <number>`\n  - **Value / Range**: 32-bit Initiator Task Tag, Command SeqNum, and Status\n  SeqNum\n  - **Default**: itt 1, cmdsn 1, statsn 1\n  - **Summary**: Populates BHS bytes 16..19 (`ITT`) and 24..31 (`CmdSN` /\n  `ExpStatSN` / `StatSN`).\n- **Token**: `statsreport`\n  - **Scopes**: bmp\n  - **Syntax**: `routemon | statsreport | peerdown | peerup | initiation |\n  termination`\n  - **Value / Range**: BMP v3 message type keyword\n  - **Default**: initiation (Type 4) or routemon (Type 0)\n  - **Summary**: Selects RFC 7854 Message Type (`0`=Route Monitoring, `1`=Stats\n  Report, `2`=Peer Down, `3`=Peer Up, `4`=Initiation, `5`=Termination).\n- **Token**: `status`\n  - **Scopes**: ldp, http, sip, rtsp, imap, smb (+15 more)\n  - **Syntax**: `status <number>`\n  - **Value / Range**: 32-bit RFC 5036 Status Code\n  - **Default**: 0\n  - **Summary**: Used across `ldp`, `http`, `sip`, `rtsp`, `imap`, `smb`, `iscsi`,\n  `nvmetcp`, `rocev2`, `ethernetip`, `synchrophasor`, `hartip`, `gesrtp`,\n  `knxnetip`, `ipmi`, `twamp`, `doh`, `socks`, `mgcp`, `ntlm`, `dcerpc`: Sets the\n  Status Code inside the `Status TLV` (`0x0300`) on `notification` messages.\n- **Token**: `stnum`\n  - **Scopes**: goose\n  - **Syntax**: `stnum <number>`\n  - **Value / Range**: State Number counter (>= 1)\n  - **Default**: 1\n  - **Summary**: Encodes BER context tag `[5]` (`stNum`, increments on every\n  dataset value transition).\n- **Token**: `stopccn`\n  - **Scopes**: l2tp\n  - **Syntax**: `sccrq | sccrp | scccn | stopccn | hello | data | msgtype\n  <0..65535|\"<text>\">`\n  - **Value / Range**: Control AVP message type or data mode\n  - **Default**: sccrq (Control Type 1) or data\n  - **Summary**: Selects L2TP control AVP 0 (`1`=SCCRQ, `2`=SCCRP, `3`=SCCCN,\n  `4`=StopCCN, `6`=Hello) or `T=0` `data` encapsulation.\n- **Token**: `stopdt`\n  - **Scopes**: iec104\n  - **Syntax**: `startdt | stopdt | testfr | sframe | msgtype \"<text>\" |\n  [confirm]`\n  - **Value / Range**: APCI frame format (`U-Frame` STARTDT/STOPDT/TESTFR,\n  `S-Frame`, or default `I-Frame` when ASDU fields are present)\n  - **Default**: I-Frame (or U-Frame when startdt/stopdt/testfr is set)\n  - **Summary**: Selects U-Frame (`0x07`/`0x0b` STARTDT, `0x13`/`0x23` STOPDT,\n  `0x43`/`0x83` TESTFR with `confirm`), S-Frame (`0x01`), or I-Frame\n  (`N(S)`/`N(R)` + ASDU).\n- **Token**: `stopsessions`\n  - **Scopes**: twamp\n  - **Syntax**: `twamp ... stopsessions`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: UDP / TCP (862)\n  - **Summary**: Configures the `stopsessions` PDU selector or header field on\n  `twamp` frames.\n- **Token**: `stoptone`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... stoptone`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `stoptone` PDU selector or header field on `sccp`\n  frames.\n- **Token**: `stratum`\n  - **Scopes**: ntp\n  - **Syntax**: `stratum <0..16>`\n  - **Value / Range**: Whole number (0..255)\n  - **Default**: 0 (client) / 1 (when refid set)\n  - **Summary**: Sets Clock Stratum (`0`=unspecified/KoD, `1`=primary GPS/PPS,\n  `2..15`=secondary, `16`=unsynchronized).\n- **Token**: `stream`\n  - **Scopes**: sctp\n  - **Syntax**: `stream <0..65535>`\n  - **Value / Range**: Whole number (0..65535)\n  - **Default**: 0\n  - **Summary**: Sets the Stream Identifier S field inside `data` chunks.\n- **Token**: `streamid`\n  - **Scopes**: http2\n  - **Syntax**: `streamid <number>`\n  - **Value / Range**: 31-bit Stream Identifier (`0` for connection control, odd\n  `1, 3, 5` for client streams)\n  - **Default**: 0 on control frames, 1 on headers/data\n  - **Summary**: Sets the 31-bit Stream ID in bytes 5..8 of the 9-byte HTTP/2\n  frame header.\n- **Token**: `string`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `suback`\n  - **Scopes**: mqtt\n  - **Syntax**: `connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect`\n  - **Value / Range**: MQTT Control Packet type (or `pkttype \"<text>\"`)\n  - **Default**: publish\n  - **Summary**: Sets the upper 4-bit Control Packet Type (`1`..`14`) in byte 0 of\n  the MQTT header.\n- **Token**: `subagentid`\n  - **Scopes**: sflow\n  - **Syntax**: `subagentid <number>`\n  - **Value / Range**: 32-bit Sub-Agent ID\n  - **Default**: 0\n  - **Summary**: Disambiguates multiple linecards or virtual switches sharing one\n  `agentip`.\n- **Token**: `subcmd`\n  - **Scopes**: melsec\n  - **Syntax**: `subcmd <0..65535>`\n  - **Value / Range**: 16-bit Subcommand (`0x0000` word units, `0x0001` bit units,\n  `0x0002` iQ-R extended)\n  - **Default**: 0x0000 (word units)\n  - **Summary**: Writes bytes 13..14 of the 3E request header.\n- **Token**: `subnetmask`\n  - **Scopes**: dhcp\n  - **Syntax**: `subnetmask <ipv4> | router <ipv4> | dnsserver <ip>`\n  - **Value / Range**: IPv4/IPv6 address literals\n  - **Default**: Omitted\n  - **Summary**: Appends Option `1` (Subnet Mask), Option `3` (Router), and Option\n  `6` / DHCPv6 Option `23` (DNS Recursive Name Server).\n- **Token**: `subscribe`\n  - **Scopes**: mqtt, someip\n  - **Syntax**: `connect | connack | publish | puback | subscribe | suback |\n  pingreq | pingresp | disconnect`\n  - **Value / Range**: MQTT Control Packet type (or `pkttype \"<text>\"`)\n  - **Default**: publish\n  - **Summary**: Used across `mqtt`, `someip`: Sets the upper 4-bit Control Packet\n  Type (`1`..`14`) in byte 0 of the MQTT header.\n- **Token**: `subscribeack`\n  - **Scopes**: someip\n  - **Syntax**: `findservice | offerservice | subscribe | subscribeack | request |\n  requestnoreply | notification | response | error | msgtype \"<text_or_num>\"`\n  - **Value / Range**: SOME/IP-SD Entry selector or SOME/IP Message Type\n  (`0x00`..`0x81`)\n  - **Default**: request (0x00)\n  - **Summary**: Selects either a full `0xffff:0x8100` SOME/IP-SD frame\n  (`findservice`/`offerservice`/`subscribe`/`subscribeack`) or standard SOME/IP\n  `Message Type`.\n- **Token**: `svid`\n  - **Scopes**: sv\n  - **Syntax**: `svid \"<text>\"`\n  - **Value / Range**: Sampled Values Identifier string (10..34 chars typical)\n  - **Default**: \"MU01\"\n  - **Summary**: Encodes ASDU context tag `[0]` (`svID`).\n- **Token**: `swversion`\n  - **Scopes**: cdp\n  - **Syntax**: `swversion \"<text>\"`\n  - **Value / Range**: Quoted text\n  - **Default**: Omitted unless set\n  - **Summary**: Encodes TLV `0x0005` (NOS release banner string).\n- **Token**: `sync`\n  - **Scopes**: ptp\n  - **Syntax**: `sync | delayreq | followup | delayresp | announce | msgtype\n  \"<text>\"`\n  - **Value / Range**: PTPv2 message type keyword\n  - **Default**: sync (0x0 on UDP 319)\n  - **Summary**: Selects lower nibble of byte 0 and target UDP port (`0x0`\n  Sync/319, `0x1` Delay_Req/319, `0x8` Follow_Up/320, `0x9` Delay_Resp/320, `0xb`\n  Announce/320).\n- **Token**: `sysdesc`\n  - **Scopes**: lldp, bmp\n  - **Syntax**: `sysdesc \"<text>\"`\n  - **Value / Range**: Quoted string\n  - **Default**: Omitted unless set\n  - **Summary**: Used across `lldp`, `bmp`: Appends Optional TLV Type 6 (System\n  Description).\n- **Token**: `sysid`\n  - **Scopes**: isis\n  - **Syntax**: `sysid \"<text>\"`\n  - **Value / Range**: 6-byte hex System ID (e.g. \"1921.6800.1001\")\n  - **Default**: \"0000.0000.0001\"\n  - **Summary**: Writes the 6-octet originating System ID in the IIH, LSP, CSNP,\n  or PSNP header.\n- **Token**: `sysname`\n  - **Scopes**: lldp, bmp\n  - **Syntax**: `sysname \"<text>\"`\n  - **Value / Range**: Quoted string or identifier\n  - **Default**: Omitted unless set\n  - **Summary**: Used across `lldp`, `bmp`: Appends Optional TLV Type 5 (System\n  Name).\n- **Token**: `sysuptime`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `sysuptime <number> | reqid <number>`\n  - **Value / Range**: Whole number\n  - **Default**: sysuptime 1000, reqid 1\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Sets `time-stamp`\n  (`TimeTicks` hundredths of a second) on `trap` or `request-id` on\n  `get`/`getnext`/`set`/`response`.\n- **Token**: `szl`\n  - **Scopes**: s7comm\n  - **Syntax**: `s7comm ... szl`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (102)\n  - **Summary**: Configures the `szl` PDU selector or header field on `s7comm`\n  frames.\n- **Token**: `tableid`\n  - **Scopes**: openflow, c1222\n  - **Syntax**: `tableid <0..255> | priority <0..65535>`\n  - **Value / Range**: 8-bit Table ID, 16-bit Flow Priority\n  - **Default**: tableid 0, priority 100\n  - **Summary**: Used across `openflow`, `c1222`: Populates pipeline Table ID\n  (`flowmod` / `packetin`) and rule match Priority (`flowmod`).\n- **Token**: `tac`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `gnbid <number> | tac <0..16777215> | ranname \"<text>\"`\n  - **Value / Range**: gNB-ID integer, 24-bit Tracking Area Code, and\n  PrintableString RANNodeName\n  - **Default**: gnbid 1, tac 1, ranname \"gNB-01\"\n  - **Summary**: Used across `ngap`, `s1ap`: Populates IE `27`\n  (`GlobalRANNodeID`), IE `102` (`SupportedTAList`), IE `121`\n  (`UserLocationInformation`), and IE `82` (`RANNodeName`).\n- **Token**: `tag`\n  - **Scopes**: srv6, rip, imap, nfs\n  - **Syntax**: `tag <0..65535>`\n  - **Value / Range**: 16-bit unsigned packet group tag (0..65535)\n  - **Default**: 0\n  - **Summary**: Used across `srv6`, `rip`, `imap`, `nfs`: Writes the big-endian\n  16-bit Tag in bytes 6..7 of the SRH.\n- **Token**: `target`\n  - **Scopes**: ndp, iscsi, irc\n  - **Syntax**: `target <ipv6>`\n  - **Value / Range**: 128-bit IPv6 address literal\n  - **Default**: Destination host IPv6 address\n  - **Summary**: Used across `ndp`, `iscsi`, `irc`: Populates the 16-byte Target\n  Address field in Neighbor Solicitation, Neighbor Advertisement, and Redirect\n  messages.\n- **Token**: `targetip`\n  - **Scopes**: arp\n  - **Syntax**: `targetip <ipv4> | tpa <ipv4>`\n  - **Value / Range**: IPv4 literal\n  - **Default**: Destination host IPv4 (or senderip on garp)\n  - **Summary**: Sets the 4-byte ARP Target Protocol Address (`tpa`).\n- **Token**: `targetmac`\n  - **Scopes**: arp\n  - **Syntax**: `targetmac <mac> | tha <mac>`\n  - **Value / Range**: 48-bit MAC (colon, hyphen, or Cisco dot)\n  - **Default**: 00:00:00:00:00:00 on request; peer MAC on reply\n  - **Summary**: Sets the 6-byte ARP Target Hardware Address (`tha`).\n- **Token**: `targetport`\n  - **Scopes**: socks\n  - **Syntax**: `socks ... targetport <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP (1080)\n  - **Summary**: Configures the `targetport` PDU selector or header field on\n  `socks` frames.\n- **Token**: `tci`\n  - **Scopes**: macsec\n  - **Syntax**: `tci <0..255>`\n  - **Value / Range**: Tag Control Information byte (0..255)\n  - **Default**: 0x08 (E=0, C=0) or 0x2c with SCI\n  - **Summary**: Sets SecTAG TCI flags (`0x20` SC present, `0x08` E encryption,\n  `0x04` C changed text).\n- **Token**: `teardown`\n  - **Scopes**: rtsp\n  - **Syntax**: `options | describe | setup | play | teardown | method \"<text>\"`\n  - **Value / Range**: RTSP request verb\n  - **Default**: options\n  - **Summary**: Sets the RTSP command method on the request line.\n- **Token**: `teid`\n  - **Scopes**: gtpu, gtpc\n  - **Syntax**: `teid <number>`\n  - **Value / Range**: 32-bit Tunnel Endpoint Identifier\n  - **Default**: 0 on echo, 1 on gpdu\n  - **Summary**: Used across `gtpu`, `gtpc`: Writes the big-endian 32-bit TEID in\n  bytes 4..7 of the GTPv1-U header.\n- **Token**: `terminate`\n  - **Scopes**: c1222\n  - **Syntax**: `read | write | identify | logon | logoff | terminate | response |\n  ok | service \"<text_or_num>\"`\n  - **Value / Range**: EPSEM PSEM Service Code (`0x20` Identify, `0x21` Terminate,\n  `0x30` Read, `0x40` Write, `0x50` Logon, `0x52` Logoff, `0x00` OK)\n  - **Default**: read (0x30)\n  - **Summary**: Selects the EPSEM Request or Response service byte inside the\n  ACSE `user-information` block.\n- **Token**: `termination`\n  - **Scopes**: bmp\n  - **Syntax**: `routemon | statsreport | peerdown | peerup | initiation |\n  termination`\n  - **Value / Range**: BMP v3 message type keyword\n  - **Default**: initiation (Type 4) or routemon (Type 0)\n  - **Summary**: Selects RFC 7854 Message Type (`0`=Route Monitoring, `1`=Stats\n  Report, `2`=Peer Down, `3`=Peer Up, `4`=Initiation, `5`=Termination).\n- **Token**: `testfr`\n  - **Scopes**: iec104\n  - **Syntax**: `startdt | stopdt | testfr | sframe | msgtype \"<text>\" |\n  [confirm]`\n  - **Value / Range**: APCI frame format (`U-Frame` STARTDT/STOPDT/TESTFR,\n  `S-Frame`, or default `I-Frame` when ASDU fields are present)\n  - **Default**: I-Frame (or U-Frame when startdt/stopdt/testfr is set)\n  - **Summary**: Selects U-Frame (`0x07`/`0x0b` STARTDT, `0x13`/`0x23` STOPDT,\n  `0x43`/`0x83` TESTFR with `confirm`), S-Frame (`0x01`), or I-Frame\n  (`N(S)`/`N(R)` + ASDU).\n- **Token**: `text`\n  - **Scopes**: websocket, iscsi\n  - **Syntax**: `text | binary | close | ping | pong | opcode \"<text>\"`\n  - **Value / Range**: WebSocket frame opcode\n  - **Default**: text (0x1)\n  - **Summary**: Used across `websocket`, `iscsi`: Selects RFC 6455 opcode `0x1`\n  (`text`), `0x2` (`binary`), `0x8` (`close`), `0x9` (`ping`), `0xa` (`pong`), or\n  `\"continuation\"` (`0x0`).\n- **Token**: `tgsrep`\n  - **Scopes**: kerberos\n  - **Syntax**: `asreq | asrep | tgsreq | tgsrep | krberror`\n  - **Value / Range**: Kerberos v5 message type\n  - **Default**: asreq (msg-type 10)\n  - **Summary**: Selects Authentication Service Request/Reply (`10`/`11`),\n  Ticket-Granting Service Request/Reply (`12`/`13`), or Error (`30`).\n- **Token**: `tgsreq`\n  - **Scopes**: kerberos\n  - **Syntax**: `asreq | asrep | tgsreq | tgsrep | krberror`\n  - **Value / Range**: Kerberos v5 message type\n  - **Default**: asreq (msg-type 10)\n  - **Summary**: Selects Authentication Service Request/Reply (`10`/`11`),\n  Ticket-Granting Service Request/Reply (`12`/`13`), or Error (`30`).\n- **Token**: `tha`\n  - **Scopes**: arp\n  - **Syntax**: `targetmac <mac> | tha <mac>`\n  - **Value / Range**: 48-bit MAC (colon, hyphen, or Cisco dot)\n  - **Default**: 00:00:00:00:00:00 on request; peer MAC on reply\n  - **Summary**: Sets the 6-byte ARP Target Hardware Address (`tha`).\n- **Token**: `timeexceeded`\n  - **Scopes**: icmp\n  - **Syntax**: `echorequest | echoreply | destunreach | timeexceeded | redirect`\n  - **Value / Range**: Named ICMP message shorthand\n  - **Default**: echorequest\n  - **Summary**: Maps to IPv4/ICMPv6 Type codes: `8`/`128` (`echorequest`),\n  `0`/`129` (`echoreply`), `3`/`1` (`destunreach`), `11`/`3` (`timeexceeded`),\n  `5`/`137` (`redirect`).\n- **Token**: `timeout`\n  - **Scopes**: glbp\n  - **Syntax**: `redirect <0..65535> | timeout <0..65535>`\n  - **Value / Range**: 16-bit timers in seconds\n  - **Default**: redirect 600, timeout 14400\n  - **Summary**: Sets the AVG ARP redirect timer (`600s`) and secondary AVF\n  forwarder timeout (`14400s` = 4h).\n- **Token**: `timer`\n  - **Scopes**: melsec\n  - **Syntax**: `network <0..255> | pc <0..255> | io <0..65535> | station <0..255>\n  | timer <0..65535>`\n  - **Value / Range**: 3E Routing Path + Monitoring Timer (in 250 ms units)\n  - **Default**: network 0, pc 0xff, io 0x03ff, station 0, timer 16\n  - **Summary**: Populates bytes 2..6 (Access Route) and bytes 9..10 (CPU\n  Monitoring Timer) of the 3E header.\n- **Token**: `timestamp`\n  - **Scopes**: erspan, rtp, synchrophasor, twamp, rtcp\n  - **Syntax**: `timestamp <number>`\n  - **Value / Range**: 32-bit ASIC timestamp (Type III)\n  - **Default**: 0\n  - **Summary**: Used across `erspan`, `rtp`, `synchrophasor`, `twamp`, `rtcp`:\n  Writes the 32-bit lower timestamp word in ERSPAN Type III (`v3`) headers\n  (`100us` / `1ns` granularity).\n- **Token**: `timeticks`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `timetolive`\n  - **Scopes**: goose\n  - **Syntax**: `timetolive <number>`\n  - **Value / Range**: Milliseconds (timeAllowedtoLive)\n  - **Default**: 2000\n  - **Summary**: Encodes BER context tag `[1]` (`timeAllowedtoLive` in\n  milliseconds).\n- **Token**: `tlla`\n  - **Scopes**: ndp\n  - **Syntax**: `slla <mac> | tlla <mac>`\n  - **Value / Range**: 48-bit MAC address\n  - **Default**: Omitted unless set\n  - **Summary**: Appends 8-byte NDP Option Type `1` (Source Link-Layer Address,\n  `slla`) or Option Type `2` (Target Link-Layer Address, `tlla`).\n- **Token**: `to`\n  - **Scopes**: sip\n  - **Syntax**: `uri \"<text>\" | from \"<text>\" | to \"<text>\" | contact \"<text>\" |\n  via \"<text>\"`\n  - **Value / Range**: Quoted SIP URIs / header values\n  - **Default**: RFC 3261 defaults\n  - **Summary**: Populates the request URI and corresponding SIP signaling\n  headers.\n- **Token**: `token`\n  - **Scopes**: quic, coap\n  - **Syntax**: `token \"<text>\"`\n  - **Value / Range**: Quoted Retry / address-validation token\n  - **Default**: Empty (length 0)\n  - **Summary**: Used across `quic`, `coap`: Populates the Token field on\n  `initial` and `retry` packets.\n- **Token**: `tokenid`\n  - **Scopes**: opcua\n  - **Syntax**: `securechannelid <number> | tokenid <number> | seqnum <number> |\n  reqid <number>`\n  - **Value / Range**: 32-bit little-endian channel, token, sequence, and request\n  IDs\n  - **Default**: 1\n  - **Summary**: Populates the Secure Conversation and Sequence headers on\n  `\"OPN\"`, `\"MSG\"`, and `\"CLO\"` frames.\n- **Token**: `tone`\n  - **Scopes**: sccp\n  - **Syntax**: `sccp ... tone <u32>`\n  - **Value / Range**: Parameter <u32>\n  - **Default**: TCP (2000)\n  - **Summary**: Configures the `tone` PDU selector or header field on `sccp`\n  frames.\n- **Token**: `topic`\n  - **Scopes**: mqtt, kafka\n  - **Syntax**: `topic \"<text>\"`\n  - **Value / Range**: Quoted slash-delimited MQTT topic (`\"sensors/temp\"`)\n  - **Default**: \"sensors/temp\"\n  - **Summary**: Used across `mqtt`, `kafka`: Encodes the 2-byte length-prefixed\n  Topic Name in `publish` or Topic Filter in `subscribe`.\n- **Token**: `tpa`\n  - **Scopes**: arp\n  - **Syntax**: `targetip <ipv4> | tpa <ipv4>`\n  - **Value / Range**: IPv4 literal\n  - **Default**: Destination host IPv4 (or senderip on garp)\n  - **Summary**: Sets the 4-byte ARP Target Protocol Address (`tpa`).\n- **Token**: `transferstatus`\n  - **Scopes**: profinet\n  - **Syntax**: `transferstatus <0..255>`\n  - **Value / Range**: 8-bit TransferStatus byte\n  - **Default**: 0x00\n  - **Summary**: Sets the final TransferStatus byte of the cyclic PROFINET RT\n  trailer.\n- **Token**: `transporthdr`\n  - **Scopes**: rtsp\n  - **Syntax**: `transporthdr \"<text>\"`\n  - **Value / Range**: Quoted RTSP `Transport:` header string\n  - **Default**: Omitted unless set\n  - **Summary**: Writes the `Transport:` header (named `transporthdr` so it never\n  collides with Layer 4 `transport tcp|udp`).\n- **Token**: `trap`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `trap | get | getnext | set | response`\n  - **Value / Range**: SNMPv1 PDU type keyword\n  - **Default**: trap (PDU 0xa4 on UDP 162)\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Selects ASN.1 BER PDU\n  context tag (`0xa0` GetRequest, `0xa1` GetNextRequest, `0xa2` GetResponse,\n  `0xa3` SetRequest, `0xa4` v1 Trap).\n- **Token**: `treeconnect`\n  - **Scopes**: smb\n  - **Syntax**: `negotiate | sessionsetup | treeconnect | treedisconnect | create\n  | close | read | write | logoff`\n  - **Value / Range**: SMB2/3 command keyword (or `command \"<text>\"`)\n  - **Default**: negotiate (0x0000)\n  - **Summary**: Selects the 16-bit MS-SMB2 command (`0x00` Negotiate, `0x01`\n  SessionSetup, `0x02` Logoff, `0x03` TreeConnect, `0x04` TreeDisconnect, `0x05`\n  Create, `0x06` Close, `0x08` Read, `0x09` Write).\n- **Token**: `treedisconnect`\n  - **Scopes**: smb\n  - **Syntax**: `negotiate | sessionsetup | treeconnect | treedisconnect | create\n  | close | read | write | logoff`\n  - **Value / Range**: SMB2/3 command keyword (or `command \"<text>\"`)\n  - **Default**: negotiate (0x0000)\n  - **Summary**: Selects the 16-bit MS-SMB2 command (`0x00` Negotiate, `0x01`\n  SessionSetup, `0x02` Logoff, `0x03` TreeConnect, `0x04` TreeDisconnect, `0x05`\n  Create, `0x06` Close, `0x08` Read, `0x09` Write).\n- **Token**: `treeid`\n  - **Scopes**: smb\n  - **Syntax**: `sessionid <hex_or_num> | treeid <number> | msgid <number>`\n  - **Value / Range**: 64-bit SessionId, 32-bit TreeId, 64-bit MessageId\n  - **Default**: 0\n  - **Summary**: Links SMB2 requests and replies across authenticated sessions and\n  mounted shares.\n- **Token**: `tsn`\n  - **Scopes**: sctp\n  - **Syntax**: `tsn <number>`\n  - **Value / Range**: Whole number\n  - **Default**: 1\n  - **Summary**: Sets Initial TSN in `init`/`initack`, Cumulative TSN Ack in\n  `sack`, or chunk TSN in `data`.\n- **Token**: `tunnelid`\n  - **Scopes**: rsvp, l2tp\n  - **Syntax**: `tunnelid <0..65535> | lspid <0..65535>`\n  - **Value / Range**: 16-bit TE Tunnel ID and 16-bit LSP ID\n  - **Default**: tunnelid 1, lspid 1\n  - **Summary**: Used across `rsvp`, `l2tp`: Populates the RFC 3209 `SESSION`\n  Tunnel ID and `SENDER_TEMPLATE` / `FILTER_SPEC` LSP ID.\n- **Token**: `txid`\n  - **Scopes**: dns, mdns, stun, modbus, hartip, llmnr (+4 more)\n  - **Syntax**: `txid <0..65535>`\n  - **Value / Range**: Whole number (0..65535)\n  - **Default**: 0x1234\n  - **Summary**: Used across `dns`, `mdns`, `stun`, `modbus`, `hartip`, `llmnr`,\n  `nbns`, `doh`, `turn`, `mgcp`: Sets the 16-bit DNS Transaction ID matching\n  requests to responses.\n- **Token**: `txseq`\n  - **Scopes**: iec104\n  - **Syntax**: `txseq <0..32767> | rxseq <0..32767>`\n  - **Value / Range**: 15-bit Send `N(S)` & Receive `N(R)` sequence numbers\n  - **Default**: txseq 0, rxseq 0\n  - **Summary**: Encodes `(txseq << 1)` and `(rxseq << 1)` in APCI control octets\n  1..4.\n- **Token**: `txtimestamp`\n  - **Scopes**: ntp\n  - **Syntax**: `txtimestamp <number>`\n  - **Value / Range**: 64-bit NTP timestamp (32b sec since 1900 + 32b frac)\n  - **Default**: Non-zero deterministic epoch\n  - **Summary**: Writes the 8-byte Transmit Timestamp in bytes 40..47.\n- **Token**: `type`\n  - **Scopes**: eapol, icmp, wireguard, openflow, tacacs, gesrtp (+3 more)\n  - **Syntax**: `eappacket | start | logoff | key | type <...>`\n  - **Value / Range**: EAPOL packet type keyword or u8\n  - **Default**: eappacket (type 0)\n  - **Summary**: Used across `eapol`, `icmp`, `wireguard`, `openflow`, `tacacs`,\n  `gesrtp`, `rocplus`, `isis`, `pppoe`: Selects EAPOL Packet Type: `eappacket`\n  (`0`), `start` (`1`, 0-byte body), `logoff` (`2`, 0-byte body), or `key` (`3`,\n  EAPOL-Key descriptor).\n- **Token**: `typeid`\n  - **Scopes**: iec104\n  - **Syntax**: `typeid <0..255>`\n  - **Value / Range**: 8-bit IEC 60870-5-101/104 Type Identification\n  - **Default**: 13 (M_ME_NC_1 when real is set) or 1 (M_SP_NA_1)\n  - **Summary**: Sets ASDU byte 0 (`1` Single-Point, `9` Normalized Meas, `13`\n  Short Float, `36` Float w/ CP56Time2a, `45` Single Cmd, `46` Double Cmd, `100`\n  Interrogation).\n- **Token**: `types`\n  - **Scopes**: wsdiscovery\n  - **Syntax**: `wsdiscovery ... types <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: UDP (3702)\n  - **Summary**: Configures the `types` PDU selector or header field on\n  `wsdiscovery` frames.\n- **Token**: `udpassociate`\n  - **Scopes**: socks\n  - **Syntax**: `socks ... udpassociate`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (1080)\n  - **Summary**: Configures the `udpassociate` PDU selector or header field on\n  `socks` frames.\n- **Token**: `udpsize`\n  - **Scopes**: dns, mdns, doh\n  - **Syntax**: `dns ... udpsize <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: UDP / TCP (53)\n  - **Summary**: Used across `dns`, `mdns`, `doh`: Configures the `udpsize` PDU\n  selector or header field across `dns`, `mdns`, `doh` frames.\n- **Token**: `uecontextreleasecommand`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `ngsetuprequest | ngsetupresponse | ngsetupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 38.413 NGAP Elementary Procedure\n  - **Default**: ngsetuprequest\n  - **Summary**: Used across `ngap`, `s1ap`: Selects both the APER PDU Choice\n  (`InitiatingMessage` / `SuccessfulOutcome` / `UnsuccessfulOutcome`) and\n  mandatory 3GPP TS 38.413 Procedure Code + ProtocolIEs.\n- **Token**: `uecontextreleasecomplete`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `ngsetuprequest | ngsetupresponse | ngsetupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 38.413 NGAP Elementary Procedure\n  - **Default**: ngsetuprequest\n  - **Summary**: Used across `ngap`, `s1ap`: Selects both the APER PDU Choice\n  (`InitiatingMessage` / `SuccessfulOutcome` / `UnsuccessfulOutcome`) and\n  mandatory 3GPP TS 38.413 Procedure Code + ProtocolIEs.\n- **Token**: `unbindreq`\n  - **Scopes**: ldap\n  - **Syntax**: `bindreq | bindres | searchreq | searchentry | searchdone |\n  unbindreq`\n  - **Value / Range**: LDAPv3 protocol operation keyword\n  - **Default**: searchreq\n  - **Summary**: Selects the ASN.1 BER `protocolOp` tag inside `LDAPMessage`.\n- **Token**: `unitid`\n  - **Scopes**: modbus\n  - **Syntax**: `txid <0..65535> | protoid <0..65535> | unitid <0..255>`\n  - **Value / Range**: MBAP Transaction ID, Protocol ID (`0` = Modbus), and\n  Slave/Unit ID\n  - **Default**: txid 1, protoid 0, unitid 1\n  - **Summary**: Populates the 7-byte MBAP header preceding the Modbus PDU.\n- **Token**: `unregistersession`\n  - **Scopes**: ethernetip\n  - **Syntax**: `nop | listservices | listidentity | listinterfaces |\n  registersession | unregistersession | sendrrdata | sendunitdata`\n  - **Value / Range**: EtherNet/IP encapsulation command (or `cmd \"<text>\"`)\n  - **Default**: listidentity (0x0063)\n  - **Summary**: Selects Encapsulation Command `0x0000` NOP, `0x0004`\n  ListServices, `0x0063` ListIdentity, `0x0064` ListInterfaces, `0x0065`\n  RegisterSession, `0x0066` UnRegisterSession, `0x006f` SendRRData, or `0x0070`\n  SendUnitData.\n- **Token**: `unsolicitedresponse`\n  - **Scopes**: dnp3\n  - **Syntax**: `read | write | select | operate | directoperate | confirm |\n  response | unsolicitedresponse | func \"<text>\"`\n  - **Value / Range**: DNP3 Application Function Code\n  - **Default**: read (0x01)\n  - **Summary**: Selects `0x00` Confirm, `0x01` Read, `0x02` Write, `0x03` Select,\n  `0x04` Operate, `0x05` Direct Operate, `0x81` Response, or `0x82` Unsolicited\n  Response.\n- **Token**: `update`\n  - **Scopes**: bgp\n  - **Syntax**: `open | update | notification | keepalive`\n  - **Value / Range**: BGP message type keyword\n  - **Default**: keepalive (Type 4)\n  - **Summary**: Selects Type `1` OPEN, Type `2` UPDATE, Type `3` NOTIFICATION\n  (Cease error), or Type `4` 19-byte KEEPALIVE.\n- **Token**: `uplinknastransport`\n  - **Scopes**: ngap, s1ap\n  - **Syntax**: `ngsetuprequest | ngsetupresponse | ngsetupfailure |\n  initialuemessage | downlinknastransport | uplinknastransport |\n  uecontextreleasecommand | uecontextreleasecomplete | errorindication`\n  - **Value / Range**: 3GPP TS 38.413 NGAP Elementary Procedure\n  - **Default**: ngsetuprequest\n  - **Summary**: Used across `ngap`, `s1ap`: Selects both the APER PDU Choice\n  (`InitiatingMessage` / `SuccessfulOutcome` / `UnsuccessfulOutcome`) and\n  mandatory 3GPP TS 38.413 Procedure Code + ProtocolIEs.\n- **Token**: `uptime`\n  - **Scopes**: sflow\n  - **Syntax**: `uptime <number>`\n  - **Value / Range**: 32-bit milliseconds since boot\n  - **Default**: 1000\n  - **Summary**: Sets `sysUpTime` in milliseconds inside the sFlow v5 header.\n- **Token**: `uri`\n  - **Scopes**: http, sip, rtsp, doh, ntlm\n  - **Syntax**: `uri \"<text>\" | version \"<text>\"`\n  - **Value / Range**: Request path and HTTP version string\n  - **Default**: uri \"/\", version \"HTTP/1.1\"\n  - **Summary**: Used across `http`, `sip`, `rtsp`, `doh`, `ntlm`: Sets the\n  request target path and protocol version (`GET /path HTTP/1.1`).\n- **Token**: `uripath`\n  - **Scopes**: coap\n  - **Syntax**: `uripath \"<text>\"`\n  - **Value / Range**: Slash-separated resource path without leading slash\n  (`\"sensors/temp\"`)\n  - **Default**: Omitted unless set\n  - **Summary**: Encodes repeatable delta-encoded CoAP Option `11` (`Uri-Path`).\n- **Token**: `user`\n  - **Scopes**: snmp3, radius, tacacs, diameter, mysql, postgres (+5 more)\n  - **Syntax**: `user \"<text>\"`\n  - **Value / Range**: Double-quoted USM securityName\n  - **Default**: \"initial\"\n  - **Summary**: Used across `snmp3`, `radius`, `tacacs`, `diameter`, `mysql`,\n  `postgres`, `snmp1`, `snmp2`, `socks`, `ntlm`, `mssql`: Sets `msgUserName` in\n  the USM security parameters header.\n- **Token**: `useragent`\n  - **Scopes**: http, doh\n  - **Syntax**: `useragent \"<text>\" | contenttype \"<text>\"`\n  - **Value / Range**: Quoted header values\n  - **Default**: Omitted unless set\n  - **Summary**: Used across `http`, `doh`: Writes `User-Agent:` and\n  `Content-Type:` headers.\n- **Token**: `usn`\n  - **Scopes**: ssdp\n  - **Syntax**: `nt \"<text>\" | nts \"<text>\" | usn \"<text>\" | location \"<text>\"`\n  - **Value / Range**: NOTIFY advertisement headers (`NTS` `\"ssdp:alive\"` or\n  `\"ssdp:byebye\"`)\n  - **Default**: nts \"ssdp:alive\"\n  - **Summary**: Populates Notification Type, Sub-Type, Unique Service Name, and\n  XML `LOCATION` URL on `notify` packets.\n- **Token**: `uuid`\n  - **Scopes**: dcerpc\n  - **Syntax**: `dcerpc ... uuid <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP (135)\n  - **Summary**: Configures the `uuid` PDU selector or header field on `dcerpc`\n  frames.\n- **Token**: `v1`\n  - **Scopes**: igmp\n  - **Syntax**: `v1 | v2 | v3 | version <1|2|3>`\n  - **Value / Range**: Protocol version selector\n  - **Default**: v2\n  - **Summary**: Selects RFC 1112 IGMPv1, RFC 2236 IGMPv2, or RFC 3376 IGMPv3\n  packet encoding.\n- **Token**: `v2`\n  - **Scopes**: igmp, erspan, l2tp\n  - **Syntax**: `v1 | v2 | v3 | version <1|2|3>`\n  - **Value / Range**: Protocol version selector\n  - **Default**: v2\n  - **Summary**: Used across `igmp`, `erspan`, `l2tp`: Selects RFC 1112 IGMPv1,\n  RFC 2236 IGMPv2, or RFC 3376 IGMPv3 packet encoding.\n- **Token**: `v3`\n  - **Scopes**: igmp, erspan, l2tp\n  - **Syntax**: `v1 | v2 | v3 | version <1|2|3>`\n  - **Value / Range**: Protocol version selector\n  - **Default**: v2\n  - **Summary**: Used across `igmp`, `erspan`, `l2tp`: Selects RFC 1112 IGMPv1,\n  RFC 2236 IGMPv2, or RFC 3376 IGMPv3 packet encoding.\n- **Token**: `v4`\n  - **Scopes**: ipip\n  - **Syntax**: `v4 | v6 | version <4|6>`\n  - **Value / Range**: Inner IP version selector (4 or 6)\n  - **Default**: Matches inner srcip/dstip or outer host family (v4)\n  - **Summary**: Selects a 20-byte inner IPv4 header (outer proto `4`) or 40-byte\n  inner IPv6 header (outer proto `41`).\n- **Token**: `v6`\n  - **Scopes**: ipip\n  - **Syntax**: `v4 | v6 | version <4|6>`\n  - **Value / Range**: Inner IP version selector (4 or 6)\n  - **Default**: Matches inner srcip/dstip or outer host family (v4)\n  - **Summary**: Selects a 20-byte inner IPv4 header (outer proto `4`) or 40-byte\n  inner IPv6 header (outer proto `41`).\n- **Token**: `value`\n  - **Scopes**: redis, memcached, modbus, bacnet, iec104, mms (+8 more)\n  - **Syntax**: `key \"<text>\" | value \"<text>\" | args \"<text>\"`\n  - **Value / Range**: Quoted key, value, or extra arguments\n  - **Default**: key \"mykey\" on get/set\n  - **Summary**: Used across `redis`, `memcached`, `modbus`, `bacnet`, `iec104`,\n  `mms`, `fins`, `melsec`, `c1222`, `gesrtp`, `rocplus`, `bsap`, `knxnetip`,\n  `kafka`: Populates subsequent `$len\\r\\n...` elements in requests or payload text\n  in server replies.\n- **Token**: `varbind`\n  - **Scopes**: snmp1, snmp2, snmp3\n  - **Syntax**: `varbind <oid> string \"<text>\" | int <number> | oidval <oid> |\n  ipval <ipv4> | counter32 <number> | gauge32 <number> | timeticks <number> |\n  counter64 <number> | null | nullval`\n  - **Value / Range**: Repeatable OID + SMI value keyword\n  - **Default**: Omitted\n  - **Summary**: Used across `snmp1`, `snmp2`, `snmp3`: Appends an ASN.1 BER\n  `VarBind` `(OID, SMI-value)` pair to the `VarBindList` SEQUENCE (`null` and\n  `nullval` are interchangeable aliases).\n- **Token**: `variation`\n  - **Scopes**: dnp3\n  - **Syntax**: `group <0..255> | variation <0..255>`\n  - **Value / Range**: DNP3 Object Group (`1` Binary In, `12` CROB, `30` Analog\n  In, `60` Class Data) + Variation\n  - **Default**: group 30, variation 1\n  - **Summary**: Populates the Object Header `(Group, Variation)` inside the\n  Application Layer.\n- **Token**: `vehicleeid`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `vehicleid`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `vehiclevin`\n  - **Scopes**: doip\n  - **Syntax**: `routingreq | routingresp | diagnostic | diagack | diagnack |\n  vehicleid | vehicleeid | vehiclevin | announcement | alivecheckreq |\n  alivecheckresp | nack | msgtype \"<text_or_num>\"`\n  - **Value / Range**: 16-bit ISO 13400-2 Payload Type keyword or number\n  - **Default**: vehicleid (0x0001)\n  - **Summary**: Selects `0x0000` NACK, `0x0001`–`0x0003` Vehicle ID Req, `0x0004`\n  Vehicle Announcement, `0x0005`/`0x0006` Routing Activation, `0x0007`/`0x0008`\n  Alive Check, `0x8001` Diagnostic UDS, or `0x8002`/`0x8003` Diag ACK/NACK.\n- **Token**: `vers`\n  - **Scopes**: nfs, dcerpc\n  - **Syntax**: `vers <3|4>`\n  - **Value / Range**: NFS protocol version (`4` default, or `3`)\n  - **Default**: 4\n  - **Summary**: Used across `nfs`, `dcerpc`: Sets the ONC RPC Program Version\n  (`4` or `3`) for Program `100003`.\n- **Token**: `version`\n  - **Scopes**: eapol, cdp, nsh, igmp, ipip, erspan (+18 more)\n  - **Syntax**: `version <0..255>`\n  - **Value / Range**: Whole number (0..255)\n  - **Default**: 2 (802.1X-2004)\n  - **Summary**: Used across `eapol`, `cdp`, `nsh`, `igmp`, `ipip`, `erspan`,\n  `vrrp`, `openflow`, `bmp`, `rpkirtr`, `l2tp`, `http`, `quic`, `s7commplus`,\n  `synchrophasor`, `hartip`, `doip`, `glbp`, `ipmi`, `socks`, `vnc`, `sccp`,\n  `tns`, `kafka`: Sets the 1-byte EAPOL Protocol Version (`1` = 2001, `2` = 2004,\n  `3` = 2010/2020).\n- **Token**: `via`\n  - **Scopes**: sip\n  - **Syntax**: `uri \"<text>\" | from \"<text>\" | to \"<text>\" | contact \"<text>\" |\n  via \"<text>\"`\n  - **Value / Range**: Quoted SIP URIs / header values\n  - **Default**: RFC 3261 defaults\n  - **Summary**: Populates the request URI and corresponding SIP signaling\n  headers.\n- **Token**: `vid`\n  - **Scopes**: erspan\n  - **Syntax**: `vid <0..4095>`\n  - **Value / Range**: 12-bit mirrored VLAN ID (0..4095)\n  - **Default**: 1\n  - **Summary**: Records the original 802.1Q VLAN ID of the mirrored frame inside\n  the ERSPAN metadata header.\n- **Token**: `vin`\n  - **Scopes**: doip\n  - **Syntax**: `vin \"<text>\" | eid <mac_or_hex> | gid <mac_or_hex>`\n  - **Value / Range**: 17-char ASCII VIN and 6-byte Entity ID / Group ID\n  - **Default**: \"00000000000000000\", 00:00:00:00:00:00\n  - **Summary**: Populates `Vehicle Identification Response / Announcement`\n  (`0x0004`) and `vehiclevin`/`vehicleeid` filters.\n- **Token**: `vip`\n  - **Scopes**: vrrp, hsrp, glbp\n  - **Syntax**: `vip <ip>`\n  - **Value / Range**: IPv4 or IPv6 Virtual IP address\n  - **Default**: Source host IP\n  - **Summary**: Used across `vrrp`, `hsrp`, `glbp`: Populates the Virtual Router\n  IPv4/IPv6 Address field (`Count IPvX Addr = 1`).\n- **Token**: `vmac`\n  - **Scopes**: glbp\n  - **Syntax**: `vip <ip> | vmac <mac> | ownerid <mac>`\n  - **Value / Range**: Virtual IP, Virtual Forwarder MAC & Owner MAC\n  - **Default**: Host IP / 00:07:b4:00:01:01 / source MAC\n  - **Summary**: Populates the Virtual IP in Hello TLVs, the `00:07:b4` AVF MAC,\n  and the 6-byte Owner ID.\n- **Token**: `vn`\n  - **Scopes**: ntp\n  - **Syntax**: `vn <1..4>`\n  - **Value / Range**: 3-bit NTP Version Number\n  - **Default**: 4 (NTPv4)\n  - **Summary**: Sets bits 5..3 of byte 0 (`1`..`4`).\n- **Token**: `vni`\n  - **Scopes**: vxlan, geneve\n  - **Syntax**: `vni <0..16777215> | vnid <0..16777215>`\n  - **Value / Range**: 24-bit unsigned integer (0..16777215)\n  - **Default**: 1\n  - **Summary**: Used across `vxlan`, `geneve`: Sets the 24-bit VXLAN Network\n  Identifier in bytes 4..6 of the 8-byte VXLAN header (`vnid` is an exact alias\n  for `vni`).\n- **Token**: `vnid`\n  - **Scopes**: vxlan, geneve\n  - **Syntax**: `vni <0..16777215> | vnid <0..16777215>`\n  - **Value / Range**: 24-bit unsigned integer (0..16777215)\n  - **Default**: 1\n  - **Summary**: Used across `vxlan`, `geneve`: Sets the 24-bit VXLAN Network\n  Identifier in bytes 4..6 of the 8-byte VXLAN header (`vnid` is an exact alias\n  for `vni`).\n- **Token**: `vrid`\n  - **Scopes**: vrrp\n  - **Syntax**: `vrid <1..255>`\n  - **Value / Range**: 8-bit Virtual Router Identifier (1..255)\n  - **Default**: 1\n  - **Summary**: Sets the VRID (matches standard virtual MAC\n  `00:00:5e:00:01:<vrid_hex>` on v4 or `00:00:5e:00:02:<vrid_hex>` on v6).\n- **Token**: `vtag`\n  - **Scopes**: sctp\n  - **Syntax**: `vtag <number>`\n  - **Value / Range**: Whole number\n  - **Default**: 0 on init, 1 otherwise\n  - **Summary**: Sets the 32-bit Verification Tag in bytes 4..7 of the SCTP Common\n  Header (`0` mandatory on `init`).\n- **Token**: `weight`\n  - **Scopes**: glbp, lisp\n  - **Syntax**: `priority <0..255> | weight <0..255>`\n  - **Value / Range**: 8-bit AVG priority and AVF weight\n  - **Default**: priority 100, weight 100\n  - **Summary**: Used across `glbp`, `lisp`: `priority` governs AVG election;\n  `weight` governs AVF load-sharing eligibility.\n- **Token**: `width`\n  - **Scopes**: rdp, vnc\n  - **Syntax**: `rdp ... width <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP (3389)\n  - **Summary**: Used across `rdp`, `vnc`: Configures the `width` PDU selector or\n  header field across `rdp`, `vnc` frames.\n- **Token**: `will`\n  - **Scopes**: telnet\n  - **Syntax**: `do <0..255> | dont <0..255> | will <0..255> | wont <0..255>`\n  - **Value / Range**: Telnet option code (`1` Echo, `3` Suppress Go Ahead, `24`\n  Terminal Type, `31` Window Size)\n  - **Default**: Omitted\n  - **Summary**: Emits the 3-byte `0xff <CMD> <OPT>` IAC negotiation triplet.\n- **Token**: `windowupdate`\n  - **Scopes**: http2\n  - **Syntax**: `preface | settings | headers | data | windowupdate | ping |\n  goaway`\n  - **Value / Range**: HTTP/2 frame type keyword\n  - **Default**: settings (Type 0x04, streamid 0)\n  - **Summary**: Selects the RFC 9113 HTTP/2 binary frame type (`0x0` DATA, `0x1`\n  HEADERS, `0x4` SETTINGS, `0x6` PING, `0x7` GOAWAY, `0x8` WINDOW_UPDATE, or\n  connection `preface`).\n- **Token**: `withdraw`\n  - **Scopes**: rpkirtr\n  - **Syntax**: `announce | withdraw | flags <0..255>`\n  - **Value / Range**: ROA announcement flag (`1`) or withdrawal (`0`)\n  - **Default**: announce (flags 1)\n  - **Summary**: Sets the `Flags` byte in `ipv4prefix` / `ipv6prefix` PDUs (`1`\n  announce VRP, `0` withdraw VRP).\n- **Token**: `wkc`\n  - **Scopes**: ethercat\n  - **Syntax**: `wkc <0..65535>`\n  - **Value / Range**: 16-bit Working Counter\n  - **Default**: 0\n  - **Summary**: Writes the trailing 16-bit little-endian Working Counter\n  incremented by slaves on the wire.\n- **Token**: `wont`\n  - **Scopes**: telnet\n  - **Syntax**: `do <0..255> | dont <0..255> | will <0..255> | wont <0..255>`\n  - **Value / Range**: Telnet option code (`1` Echo, `3` Suppress Go Ahead, `24`\n  Terminal Type, `31` Window Size)\n  - **Default**: Omitted\n  - **Summary**: Emits the 3-byte `0xff <CMD> <OPT>` IAC negotiation triplet.\n- **Token**: `workstation`\n  - **Scopes**: ntlm\n  - **Syntax**: `ntlm ... workstation <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: TCP (80)\n  - **Summary**: Configures the `workstation` PDU selector or header field on\n  `ntlm` frames.\n- **Token**: `write`\n  - **Scopes**: profinet, ethercat, smb, iscsi, nvmetcp, rocev2 (+9 more)\n  - **Syntax**: `service \"<text>\" | get | set | read | write | connect | release`\n  - **Value / Range**: DCP / IO service selector\n  - **Default**: Cyclic RT when omitted\n  - **Summary**: Used across `profinet`, `ethercat`, `smb`, `iscsi`, `nvmetcp`,\n  `rocev2`, `dnp3`, `mms`, `fins`, `melsec`, `c1222`, `gesrtp`, `rocplus`, `bsap`,\n  `knxnetip`: Selects DCP `get`/`set`/`identify` or IO\n  `read`/`write`/`connect`/`release` PDU encoding.\n- **Token**: `writemultipleregisters`\n  - **Scopes**: modbus\n  - **Syntax**: `readcoils | readdiscreteinputs | readholdingregisters |\n  readinputregisters | writesinglecoil | writesingleregister |\n  writemultipleregisters | func \"<fc>\"`\n  - **Value / Range**: Function Code keyword or number (`\"1\"`, `\"2\"`, `\"3\"`,\n  `\"4\"`, `\"5\"`, `\"6\"`, `\"15\"`, `\"16\"`)\n  - **Default**: readholdingregisters (FC 3)\n  - **Summary**: Sets the 1-byte Modbus Function Code immediately after `unitid`.\n- **Token**: `writeproperty`\n  - **Scopes**: bacnet\n  - **Syntax**: `whois | iam | readproperty | writeproperty`\n  - **Value / Range**: BACnet APDU service selector\n  - **Default**: whois\n  - **Summary**: Selects Unconfirmed `Who-Is` (`8`), Unconfirmed `I-Am` (`0`),\n  Confirmed `ReadProperty` (`12`), or Confirmed `WriteProperty` (`15`).\n- **Token**: `writesinglecoil`\n  - **Scopes**: modbus\n  - **Syntax**: `readcoils | readdiscreteinputs | readholdingregisters |\n  readinputregisters | writesinglecoil | writesingleregister |\n  writemultipleregisters | func \"<fc>\"`\n  - **Value / Range**: Function Code keyword or number (`\"1\"`, `\"2\"`, `\"3\"`,\n  `\"4\"`, `\"5\"`, `\"6\"`, `\"15\"`, `\"16\"`)\n  - **Default**: readholdingregisters (FC 3)\n  - **Summary**: Sets the 1-byte Modbus Function Code immediately after `unitid`.\n- **Token**: `writesingleregister`\n  - **Scopes**: modbus\n  - **Syntax**: `readcoils | readdiscreteinputs | readholdingregisters |\n  readinputregisters | writesinglecoil | writesingleregister |\n  writemultipleregisters | func \"<fc>\"`\n  - **Value / Range**: Function Code keyword or number (`\"1\"`, `\"2\"`, `\"3\"`,\n  `\"4\"`, `\"5\"`, `\"6\"`, `\"15\"`, `\"16\"`)\n  - **Default**: readholdingregisters (FC 3)\n  - **Summary**: Sets the 1-byte Modbus Function Code immediately after `unitid`.\n- **Token**: `writevar`\n  - **Scopes**: s7comm\n  - **Syntax**: `setupcomm | readvar | writevar | plccontrol | func \"<text>\"`\n  - **Value / Range**: S7 Parameter Function (`0xf0` Setup, `0x04` ReadVar, `0x05`\n  WriteVar, `0x28` PLCControl)\n  - **Default**: setupcomm (0xf0)\n  - **Summary**: Selects the S7comm Parameter Function code.\n- **Token**: `wrq`\n  - **Scopes**: tftp\n  - **Syntax**: `rrq | wrq | data | ack | error | err`\n  - **Value / Range**: TFTP opcode keyword\n  - **Default**: rrq (Opcode 1)\n  - **Summary**: Selects Opcode `1` Read Request (`rrq`), `2` Write Request\n  (`wrq`), `3` Data (`data`), `4` Acknowledgment (`ack`), or `5` Error (`error` /\n  `err`).\n- **Token**: `x224cc`\n  - **Scopes**: rdp\n  - **Syntax**: `rdp ... x224cc`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (3389)\n  - **Summary**: Configures the `x224cc` PDU selector or header field on `rdp`\n  frames.\n- **Token**: `x224cr`\n  - **Scopes**: rdp\n  - **Syntax**: `rdp ... x224cr`\n  - **Value / Range**: Protocol message / flag keyword\n  - **Default**: TCP (3389)\n  - **Summary**: Configures the `x224cr` PDU selector or header field on `rdp`\n  frames.\n- **Token**: `xaddrs`\n  - **Scopes**: wsdiscovery\n  - **Syntax**: `wsdiscovery ... xaddrs <str>`\n  - **Value / Range**: Parameter <str>\n  - **Default**: UDP (3702)\n  - **Summary**: Configures the `xaddrs` PDU selector or header field on\n  `wsdiscovery` frames.\n- **Token**: `xid`\n  - **Scopes**: profinet, openflow, dhcp, nfs\n  - **Syntax**: `xid <number>`\n  - **Value / Range**: 32-bit DCP Transaction ID\n  - **Default**: 1\n  - **Summary**: Used across `profinet`, `openflow`, `dhcp`, `nfs`: Sets the\n  4-byte `Xid` correlation field in PROFINET DCP frames.\n- **Token**: `xormappedaddr`\n  - **Scopes**: stun, turn\n  - **Syntax**: `xormappedaddr <ip>`\n  - **Value / Range**: IPv4 or IPv6 public/reflexive IP address\n  - **Default**: Client IP on bindingresponse\n  - **Summary**: Used across `stun`, `turn`: Adds Attribute `0x0020`\n  (`XOR-MAPPED-ADDRESS`) with RFC 5389 XOR obfuscation applied.\n- **Token**: `xorpeeraddr`\n  - **Scopes**: turn\n  - **Syntax**: `turn ... xorpeeraddr <ip> [<u16>`\n  - **Value / Range**: Parameter <ip>\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Configures the `xorpeeraddr` PDU selector or header field on\n  `turn` frames.\n- **Token**: `xorrelayedaddr`\n  - **Scopes**: turn\n  - **Syntax**: `turn ... xorrelayedaddr <ip> [<u16>`\n  - **Value / Range**: Parameter <ip>\n  - **Default**: UDP / TCP (3478)\n  - **Summary**: Configures the `xorrelayedaddr` PDU selector or header field on\n  `turn` frames.\n- **Token**: `xpos`\n  - **Scopes**: vnc\n  - **Syntax**: `vnc ... xpos <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP (5900)\n  - **Summary**: Configures the `xpos` PDU selector or header field on `vnc`\n  frames.\n- **Token**: `yiaddr`\n  - **Scopes**: dhcp\n  - **Syntax**: `ciaddr <ipv4> | yiaddr <ipv4> | siaddr <ipv4>`\n  - **Value / Range**: IPv4 dotted-quad literals\n  - **Default**: 0.0.0.0\n  - **Summary**: Sets Client IP, Your (offered) IP, and Next Server IP in the\n  DHCPv4 BOOTP header.\n- **Token**: `yourdisc`\n  - **Scopes**: bfd\n  - **Syntax**: `mydisc <number> | yourdisc <number>`\n  - **Value / Range**: 32-bit non-zero / peer session discriminators\n  - **Default**: mydisc 1, yourdisc 0\n  - **Summary**: Sets My Discriminator and Your Discriminator (`0` until learned\n  from peer).\n- **Token**: `ypos`\n  - **Scopes**: vnc\n  - **Syntax**: `vnc ... ypos <u16>`\n  - **Value / Range**: Parameter <u16>\n  - **Default**: TCP (5900)\n  - **Summary**: Configures the `ypos` PDU selector or header field on `vnc`\n  frames.\n- **Token**: `zerortt`\n  - **Scopes**: quic\n  - **Syntax**: `initial | zerortt | handshake | retry | short`\n  - **Value / Range**: QUIC packet header type\n  - **Default**: initial\n  - **Summary**: Selects Long Header (`initial`, `zerortt`, `handshake`, `retry`)\n  or 1-RTT Short Header (`short`).\n"}
{"id":"pretrain-usecase-firewall-acl-testing","kind":"use_case_playbook","title":"Poke Holes in a New Firewall Rulebase Before Live Traffic Does — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/firewall-acl-testing","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","icmp","tcp","tls"],"text":"# Poke Holes in a New Firewall Rulebase Before Live Traffic Does\n\n> **FrameAssembly v3.3.0** · Operational Playbook (SecOps, Firewalls & IDS) ·\n> Canonical URL: https://frameassembly-lang.dev/use-cases/firewall-acl-testing\n\nBundle an allowed TLS 1.3 handshake, a rejected port 3306 probe, a sneaky\nout-of-state SSH ACK, and VLAN 40 ICMP into 1 repeatable .pcap.\n\n- **Category:** SecOps, Firewalls & IDS\n- **Capture Filename:** `firewall_acl_test.frasm` (9 Ethernet frames)\n- **Protocols Exercised:** `vlan`, `tcp`, `tls`, `icmp`\n\n## Operational Problem\n\nYou just rewrote 40 firewall rules and want to know if they actually work before\nflipping DNS. Sadly, curl and ping obey your OS kernel, while single-packet hping3\nSYN blasts get laughed out of the room by any stateful NGFW.\n\nNormal tools like ping, curl, and netcat go through your laptop’s polite OS TCP/IP\nstack: they refuse to spit out an unsolicited mid-stream TCP ACK on port 22, they\ncan’t bundle client probes and firewall rejections into a single baseline file,\nand Windows/macOS NIC drivers happily eat your 802.1Q VLAN tags for breakfast.\n\nMeanwhile, stateless one-packet injectors (hping3 or quick Scapy one-liners)\nbounce straight off Palo Alto, FortiGate, Check Point, and nftables—because\nstateful engines ignore a bare TLS ClientHello SNI unless it rides in behind a\nreal 3-way TCP handshake with matching 4-tuple SEQ/ACK math.\n\n## Scenario & Topology: DMZ Reverse-Proxy Cutover on VLAN 40 (Without Waking Up the Whole Floor)\n\n- **Topology:** `Outside Tester (203.0.113.45) -> Perimeter Firewall (VLAN 40) <->\n  DMZ Proxy (198.51.100.80)`\n\nYou are swapping a crusty router ACL for a stateful zone firewall in front of a\nDMZ proxy (198.51.100.80) on VLAN 40. Instead of crossing your fingers at 2 AM,\none 9-frame .frasm script checks all four cases at once: (1) TCP 443 finishes syn\n-> syn ack -> ack and carries a TLS 1.3 ClientHello SNI for \"portal.corp.example\";\n(2) MySQL TCP 3306 gets slapped back with tcp rst ack; (3) a stray out-of-state\nTCP ACK on SSH port 22 gets dropped cold; and (4) ICMP ping into VLAN 40 gets icmp\ndestunreach code 13 (Administratively Prohibited).\n\n## FrameAssembly Workflow\n\nCompiles 9 VLAN-40 frames covering a full TCP 443 handshake + TLS 1.3 SNI, a\nrejected MySQL 3306 probe, an out-of-state SSH ACK test, and an ICMP Code 13 admin\nblock.\n\n### Adapt It for Your Network\n\n1. Change outside_tester and dmz_proxy to your own source zone and DMZ IPs/MACs.\n2. Tweak vlan 40, the permitted TLS sni string, and whichever dstport numbers your\n  policy is supposed to block.\n3. Run frameassembly firewall_acl_test.frasm, then replay the .pcap across your\n  test interface with tcpreplay.\n\n## Runnable Capture Specification (`firewall_acl_test.frasm`)\n\n```frameassembly\nhost outside_tester { ip 203.0.113.45  mac 00:0c:29:45:11:22 }\nhost dmz_proxy      { ip 198.51.100.80 mac 00:1b:21:80:aa:bb }\n\nflow allow_https_sni(ext, dmz) {\n    // 1. Permitted TCP 443 handshake + TLS 1.3 ClientHello SNI on VLAN 40\n    ext -> dmz vlan 40 tcp syn srcport 52100 dstport 443 win 64240 mss 1460 wscale 7 sackperm wait 1ms\n    ext <- dmz vlan 40 tcp syn ack win 65535 mss 1460 wscale 7 sackperm wait 1ms\n    ext -> dmz vlan 40 tcp ack wait 1ms\n    ext -> dmz vlan 40 tls clienthello sni \"portal.corp.example\" ciphersuite 4865 alpn \"h2\" wait 2ms\n}\n\nflow verify_firewall_blocks(ext, dmz) {\n    // 2. Blocked MySQL port 3306 rejected immediately with TCP RST+ACK\n    ext -> dmz vlan 40 tcp syn srcport 52101 dstport 3306 win 64240 mss 1460 wait 1ms\n    ext <- dmz vlan 40 tcp rst ack wait 5ms\n\n    // 3. Out-of-state TCP ACK probe on SSH port 22 (audits stateful session drop)\n    ext -> dmz vlan 40 tcp ack srcport 52102 dstport 22 seq 85000 acknum 42000 win 1024 wait 5ms\n\n    // 4. Blocked ICMP Echo answered with Code 13 (Administratively Prohibited)\n    ext -> dmz vlan 40 ttl 64 icmp echorequest id 900 seq 1 payload \"DMZ_ACL_AUDIT\" wait 1ms\n    ext <- dmz vlan 40 ttl 64 icmp destunreach code 13 wait 1ms\n}\n\ncompile {\n    allow_https_sni(outside_tester, dmz_proxy)\n    verify_firewall_blocks(outside_tester, dmz_proxy)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Preview the 9-packet stateful firewall audit ladder in your terminal\nframeassembly show firewall_acl_test.frasm\n\n# 2. Compile to .pcap and verify TCP SEQ/ACK, VLAN 40, TLS SNI, and ICMP Code 13 in tshark\nframeassembly firewall_acl_test.frasm firewall_acl_test.pcap\ntshark -r firewall_acl_test.pcap\n\n# 3. Replay into your firewall ingress test port or SPAN sensor\nsudo tcpreplay -i eth0 firewall_acl_test.pcap\n```\n\n## Protocol Reference Links\n\n- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p\n  QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))\n- [`tcp` — Transmission Control Protocol & RFC 7323\n  Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))\n- [`tls` — Transport Layer Security Record & Handshake\n  Layer](https://frameassembly-lang.dev/docs/protocols/tls) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tls.md))\n- [`icmp` — Internet Control Message Protocol v4 & Dual-Stack\n  ICMPv6](https://frameassembly-lang.dev/docs/protocols/icmp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/icmp.md))\n"}
{"id":"pretrain-usecase-simulate-snmpv3-trap","kind":"use_case_playbook","title":"Test Encrypted SNMPv3 Traps Before an Actual Outage — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/simulate-snmpv3-trap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","snmp3"],"text":"# Test Encrypted SNMPv3 Traps Before an Actual Outage\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Telemetry, VoIP & OT) ·\n> Canonical URL: https://frameassembly-lang.dev/use-cases/simulate-snmpv3-trap\n\nVerify Zabbix, PRTG, LibreNMS, or snmptrapd decrypts your SHA-256 + AES-128 traps\nbefore 3 AM finds a passphrase typo.\n\n- **Category:** Telemetry, VoIP & OT\n- **Capture Filename:** `snmpv3_trap_test.frasm` (2 Ethernet frames)\n- **Protocols Exercised:** `vlan`, `snmp3`\n\n## Operational Problem\n\nSNMPv3 traps travel one way (rtr -> nms) with zero handshake—if your EngineID,\nboot counter, or AES passphrase is off by one character, your collector silently\ndrops the packet and nobody gets paged.\n\nWith SNMPv3 GET polling, the collector talks to the router first and learns its\nEngineID automatically. Traps skip that step: a single UDP 162 packet arrives\nunannounced, and if snmptrapd or Zabbix disagrees on one nibble of EngineID or\nSHA-256/AES-128 key localization, nothing shows up in the event log.\n\nTrying to test it with Net-SNMP’s snmptrap CLI usually means fighting missing MIB\ndirectories, only for the packet to leave from your laptop Wi-Fi IP instead of\n10.250.1.1 so the collector ignores it anyway.\n\n## Scenario & Topology: Edge Router linkDown -> 10s Wait -> linkUp Recovery on VLAN 20\n\n- **Topology:** `Edge Router (10.250.1.1, EngineID 8000000903001c73a00001) -> Mgmt\n  VLAN 20 -> Trap Collector (10.250.100.50:162)`\n\nYou moved edge-rtr-01 (10.250.1.1) on VLAN 20 from old SNMPv2c \"public\" to SNMPv3\nauthPriv (SHA-256 + AES-128). Two lines emit the router’s exact IP/MAC, send an\nencrypted TenGigabitEthernet0/1/0 linkDown trap (ifOperStatus = 2), advance 10s on\nthe capture clock, and send the matching linkUp recovery trap (ifOperStatus = 1).\n\n## FrameAssembly Workflow\n\nRuns real RFC 3414/7860 USM key localization + AES-128-CFB encryption to emit a\nVLAN 20 linkDown trap followed 10s later by linkUp.\n\n### Adapt It for Your Network\n\n1. Set edge_router ip to the exact switch or router management IP your monitoring\n  server expects.\n2. Paste your real hex engineid, username, sha256 auth passphrase, and aes priv\n  passphrase.\n3. Compile -> double-check decryption in Wireshark’s SNMP Users table -> replay\n  with tcpreplay.\n\n## Runnable Capture Specification (`snmpv3_trap_test.frasm`)\n\n```frameassembly\nhost edge_router   { ip 10.250.1.1    mac 00:1c:73:a0:00:01 }\nhost nms_collector { ip 10.250.100.50 mac 00:50:56:a0:00:50 }\n\nflow link_flap_snmpv3_traps(rtr, nms) {\n    // 1. Encrypted SNMPv3 authPriv linkDown trap (ifOperStatus = 2 down) on Mgmt VLAN 20\n    rtr -> nms vlan 20 snmp3 trap user \"noc_sha256_aes\" engineid \"8000000903001c73a00001\"\n        engineboots 12 enginetime 86400\n        auth sha256 \"AuthKey_SHA256_99!\" priv aes \"PrivKey_AES128_99!\"\n        oid 1.3.6.1.6.3.1.1.5.3\n        varbind 1.3.6.1.2.1.1.5.0 string \"edge-rtr-01.dc1\"\n        varbind 1.3.6.1.2.1.2.2.1.2.5 string \"TenGigabitEthernet0/1/0\"\n        varbind 1.3.6.1.2.1.2.2.1.8.5 int 2 wait 10s\n\n    // 2. Recovery SNMPv3 authPriv linkUp trap 10s later (ifOperStatus = 1 up)\n    rtr -> nms vlan 20 snmp3 trap user \"noc_sha256_aes\" engineid \"8000000903001c73a00001\"\n        engineboots 12 enginetime 86410\n        auth sha256 \"AuthKey_SHA256_99!\" priv aes \"PrivKey_AES128_99!\"\n        oid 1.3.6.1.6.3.1.1.5.4\n        varbind 1.3.6.1.2.1.1.5.0 string \"edge-rtr-01.dc1\"\n        varbind 1.3.6.1.2.1.2.2.1.2.5 string \"TenGigabitEthernet0/1/0\"\n        varbind 1.3.6.1.2.1.2.2.1.8.5 int 1 wait 5ms\n}\n\ncompile {\n    link_flap_snmpv3_traps(edge_router, nms_collector)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Compile the encrypted SNMPv3 authPriv linkDown + linkUp capture\nframeassembly snmpv3_trap_test.frasm snmpv3_trap_test.pcap\n\n# 2. Inspect SNMPv3 USM EngineID, Boots, Time, and Username in tshark\ntshark -r snmpv3_trap_test.pcap -Y \"snmp\" -V\n\n# 3. Replay the encrypted traps toward Zabbix, PRTG, LibreNMS, or snmptrapd\nsudo tcpreplay -i eth0 snmpv3_trap_test.pcap\n```\n\n## Protocol Reference Links\n\n- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p\n  QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))\n- [`snmp3` — Simple Network Management Protocol v3 with USM Auth &\n  Privacy](https://frameassembly-lang.dev/docs/protocols/snmp3) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/snmp3.md))\n"}
{"id":"pretrain-usecase-network-pentesting-pcap","kind":"use_case_playbook","title":"VLAN Hopping, Kerberoasting & SMB ADMIN$ Without Locking Out AD — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/network-pentesting-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["qinq","icmp","tcp","kerberos","ldap","smb"],"text":"# VLAN Hopping, Kerberoasting & SMB ADMIN$ Without Locking Out AD\n\n> **FrameAssembly v3.3.0** · Operational Playbook (SecOps, Firewalls & IDS) ·\n> Canonical URL: https://frameassembly-lang.dev/use-cases/network-pentesting-pcap\n\nCheck if your SOC and NDR sensors actually wake up—without getting your jump box\nquarantined by EDR or locking out the CEO.\n\n- **Category:** SecOps, Firewalls & IDS\n- **Capture Filename:** `pentest_lateral_audit.frasm` (15 Ethernet frames)\n- **Protocols Exercised:** `qinq`, `icmp`, `tcp`, `kerberos`, `ldap`, `smb`\n\n## Operational Problem\n\nFiring live Impacket, Responder, or CrackMapExec on a Tuesday afternoon is a great\nway to lock out production service accounts, get your laptop quarantined by EDR in\n4 seconds, or drown the SOC in angry alerts.\n\nWhen you just want to verify whether your switches drop double-tagged VLAN-hopping\nframes or whether your NDR sensor spots RC4 Kerberoasting + SMB2 ADMIN$ lateral\nmovement, running live offensive tools on prod subnets is overkill.\n\nAnd hand-rolling ASN.1 DER Kerberos TGS-REQ structures, BER-encoded LDAPv3 SPN\nfilters, and UTF-16LE SMB2 tree-connects in raw Python bytes is a weekend you will\nnever get back.\n\n## Scenario & Topology: User VLAN 10 -> Server VLAN 20 Purple-Team Wake-Up Check\n\n- **Topology:** `Jump Box (10.20.5.101, VLAN 10) -> Switch / Firewall -> Domain\n  Controller (10.20.1.10) & File Server (10.20.1.50)`\n\nIn 15 surgical packets—zero background chatter—you test four classics: (1) an\n802.1ad double-tagged VLAN-hopping probe (outer VLAN 10 -> inner VLAN 20); (2) a\nlit-up TCP Xmas tree scan (fin + psh + urg) against RDP 3389; (3) an RC4-HMAC\n(etype 23) Kerberoast TGS-REQ for \"mssqlsvc/sql01.corp.local\" + stateful LDAP SPN\nsearch; and (4) an SMB2 \"\\\\10.20.1.50\\ADMIN$\" mount attempt slapped down with\nSTATUS_ACCESS_DENIED (0xc0000022).\n\n## FrameAssembly Workflow\n\nPacks 15 frames covering an 802.1ad QinQ VLAN-hop, TCP Xmas scan, Kerberos RC4\nTGS-REQ/REP, stateful LDAP SPN search, and SMB2 ADMIN$ rejection.\n\n### Adapt It for Your Network\n\n1. Point jump_box, corp_dc, and file_srv at the IPs/MACs in your test segment.\n2. Swap the qinq outer/inner VLAN IDs, Kerberos realm/sname, LDAP filter, or SMB\n  share string.\n3. Compile -> feed into suricata -r / zeek -r offline, or replay onto your\n  SPAN/trunk port with tcpreplay.\n\n## Runnable Capture Specification (`pentest_lateral_audit.frasm`)\n\n```frameassembly\nhost jump_box { ip 10.20.5.101 mac 00:50:56:20:05:65 }\nhost corp_dc  { ip 10.20.1.10  mac 00:50:56:20:01:0a }\nhost file_srv { ip 10.20.1.50  mac 00:50:56:20:01:32 }\n\nflow l2_vlan_hop_and_stealth_scan(box, srv) {\n    // 1. 802.1ad double-tagged VLAN-hopping probe (outer VLAN 10 -> inner VLAN 20)\n    box -> srv qinq 10 innervlan 20 icmp echorequest id 404 seq 1 payload \"VLAN_HOP_AUDIT\" wait 2ms\n\n    // 2. Stealth TCP Xmas scan (FIN + PSH + URG) against RDP port 3389\n    box -> srv tcp fin psh urg srcport 59100 dstport 3389 win 1024 urgent 1 wait 5ms\n}\n\nflow ad_kerberoast_and_smb_lateral(box, dc, srv) {\n    // 3. RC4-HMAC (etype 23) Kerberoast TGS-REQ + stateful LDAP SPN enumeration\n    box -> dc kerberos tgsreq realm \"CORP.LOCAL\" cname \"svc_audit\" sname \"mssqlsvc/sql01.corp.local\" etype 23 wait 2ms\n    box <- dc kerberos tgsrep realm \"CORP.LOCAL\" cname \"svc_audit\" sname \"mssqlsvc/sql01.corp.local\" etype 23 wait 2ms\n    box -> dc tcp syn srcport 51389 dstport 389 win 64240 mss 1460 wait 1ms\n    box <- dc tcp syn ack win 64240 mss 1460 wait 1ms\n    box -> dc tcp ack wait 1ms\n    box -> dc ldap searchreq msgid 2 basedn \"dc=corp,dc=local\" filter \"(servicePrincipalName=*)\" wait 2ms\n    box <- dc ldap searchdone msgid 2 resultcode 0 wait 2ms\n\n    // 4. SMB2 lateral-movement probe to ADMIN$ share on TCP 445\n    box -> srv tcp syn srcport 51445 dstport 445 win 64240 mss 1460 wait 1ms\n    box <- srv tcp syn ack win 64240 mss 1460 wait 1ms\n    box -> srv tcp ack wait 1ms\n    box -> srv smb negotiate msgid 0 wait 1ms\n    box -> srv smb treeconnect msgid 1 sessionid 0x0001000000000001 share \"\\\\\\\\10.20.1.50\\\\ADMIN$\" wait 2ms\n    box <- srv smb treeconnect msgid 1 sessionid 0x0001000000000001 treeid 1 status 0xc0000022 wait 1ms\n}\n\ncompile {\n    l2_vlan_hop_and_stealth_scan(jump_box, file_srv)\n    ad_kerberoast_and_smb_lateral(jump_box, corp_dc, file_srv)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Preview all 15 frames (QinQ, Xmas TCP, Kerberos, LDAP, SMB2) in terminal\nframeassembly show pentest_lateral_audit.frasm\n\n# 2. Compile to .pcap and inspect Kerberos SPN, LDAP filter, and SMB2 share in tshark\nframeassembly pentest_lateral_audit.frasm pentest_lateral_audit.pcap\ntshark -r pentest_lateral_audit.pcap\n\n# 3. Validate NDR / IDS detections offline or replay onto an isolated test SPAN port\nsuricata -r pentest_lateral_audit.pcap -k none -l ./suricata_pentest/\nzeek -C -r pentest_lateral_audit.pcap\n```\n\n## Protocol Reference Links\n\n- [`qinq` — IEEE 802.1ad Provider Bridge Double VLAN Tagging (S-Tag +\n  C-Tag)](https://frameassembly-lang.dev/docs/protocols/qinq) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/qinq.md))\n- [`icmp` — Internet Control Message Protocol v4 & Dual-Stack\n  ICMPv6](https://frameassembly-lang.dev/docs/protocols/icmp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/icmp.md))\n- [`tcp` — Transmission Control Protocol & RFC 7323\n  Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))\n- [`kerberos` — Kerberos Network Authentication Service v5 (Active\n  Directory)](https://frameassembly-lang.dev/docs/protocols/kerberos) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/kerberos.md))\n- [`ldap` — Lightweight Directory Access Protocol v3 (ASN.1\n  BER)](https://frameassembly-lang.dev/docs/protocols/ldap) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/ldap.md))\n- [`smb` — Server Message Block SMB2 & SMB3 File\n  Sharing](https://frameassembly-lang.dev/docs/protocols/smb) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/smb.md))\n"}
{"id":"pretrain-usecase-suricata-ids-testing","kind":"use_case_playbook","title":"Feed Suricata, Snort & Zeek Streams They Won’t Silently Drop — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/suricata-ids-testing","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","udp","dns","http","tls"],"text":"# Feed Suricata, Snort & Zeek Streams They Won’t Silently Drop\n\n> **FrameAssembly v3.3.0** · Operational Playbook (SecOps, Firewalls & IDS) ·\n> Canonical URL: https://frameassembly-lang.dev/use-cases/suricata-ids-testing\n\nGive flow:established rules the real 3-way TCP handshake and checksums they\ndemand, with zero background ARP/mDNS clutter.\n\n- **Category:** SecOps, Firewalls & IDS\n- **Capture Filename:** `ids_scan_test.frasm` (16 Ethernet frames)\n- **Protocols Exercised:** `dns`, `tcp`, `tls`, `http`, `udp`\n\n## Operational Problem\n\nClassic IDS headache: you write a shiny new Suricata rule with\nflow:established,to_server, throw one lonely spoofed packet at it, nothing fires\nin eve.json, and you spend an hour blaming your regex when Suricata’s stream\nengine just threw your orphan packet in the trash.\n\nSuricata, Snort 3, and Zeek track full TCP streams and check checksums by default.\nIf your test capture skips syn -> syn ack -> ack or has off-by-one SEQ numbers\nafter editing a payload string, the Layer 7 dissector (tls.sni, http.header,\ndns.query) never even runs.\n\nChecking binary .pcap fixtures into Git isn’t much better: six months later when\nsomeone needs to change \"bad-domain.test\" to a new domain of a different byte\nlength, nobody can edit the binary blob without corrupting the rest of the TCP\nstream.\n\n## Scenario & Topology: One Clean 16-Frame Regression Capture for 4 Suricata / Zeek Detections\n\n- **Topology:** `Scanner / Beacon (172.18.99.10) <-> Sensor / Gateway\n  (172.18.10.50)`\n\nBefore pushing new rules to 40 sensors, this script builds four crisp triggers in\none file: (1) a C2 DNS lookup <-> RCODE 5 (REFUSED) sinkhole reply; (2) an\nestablished TCP 443 stream carrying TLS 1.3 SNI \"shadow-upload.example.net\"; (3)\nan established TCP 80 POST from \"ScannerBot/2.1\" answered by an HTTP 403 WAF\nblock; and (4) rapid SYN scan probes + a 2-piece fragmented IPv4 UDP packet (mf +\nfragoffset 185).\n\n## FrameAssembly Workflow\n\nEmits 16 noise-free frames covering a DNS sinkhole, stateful TLS 1.3 SNI, stateful\nHTTP POST/403, SYN scan, and fragmented IPv4 UDP.\n\n### Adapt It for Your Network\n\n1. Match scanner and target to $HOME_NET / $EXTERNAL_NET in your suricata.yaml.\n2. Edit dns qname, tls clienthello sni, http headers, or fragment offsets in plain\n  text.\n3. Compile -> run suricata -r ids_scan_test.pcap -k none or zeek -C -r\n  ids_scan_test.pcap -> check eve.json.\n\n## Runnable Capture Specification (`ids_scan_test.frasm`)\n\n```frameassembly\nhost scanner { ip 172.18.99.10 }\nhost target  { ip 172.18.10.50 }\n\nflow dns_tls_and_waf_check(src, dst) {\n    src -> dst dns query txid 0x4401 qname \"c2-beacon.bad-domain.test\" qtype \"A\" wait 1ms\n    src <- dst dns response txid 0x4401 qname \"c2-beacon.bad-domain.test\" qtype \"A\" rcode 5 wait 2ms\n    src -> dst tcp syn srcport 53443 dstport 443 win 65535 mss 1460 wait 1ms\n    src <- dst tcp syn ack win 65535 mss 1460 wait 1ms\n    src -> dst tcp ack wait 1ms\n    src -> dst tls clienthello sni \"shadow-upload.example.net\" ciphersuite 4866 alpn \"h2\" wait 2ms\n    src -> dst tcp syn srcport 53080 dstport 80 win 65535 mss 1460 wait 1ms\n    src <- dst tcp syn ack win 65535 mss 1460 wait 1ms\n    src -> dst tcp ack wait 1ms\n    src -> dst http post uri \"/admin/export\" hosthdr \"portal.local\" useragent \"ScannerBot/2.1\" body \"{\\\"dump\\\":true}\" wait 2ms\n    src <- dst http status 403 reason \"Forbidden\" body \"{\\\"error\\\":\\\"blocked_by_waf\\\"}\" wait 2ms\n}\n\nflow syn_scan_and_fragments(src, dst) {\n    src -> dst tcp syn srcport 61001 dstport 21 wait 1ms\n    src -> dst tcp syn srcport 61002 dstport 22 wait 1ms\n    src -> dst tcp syn srcport 61003 dstport 80 wait 1ms\n    src -> dst udp dstport 161 ipid 4421 mf fragoffset 0 wait 1ms\n    src -> dst udp dstport 161 ipid 4421 fragoffset 185 wait 1ms\n}\n\ncompile {\n    dns_tls_and_waf_check(scanner, target)\n    syn_scan_and_fragments(scanner, target)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Build the IDS/WAF validation capture\nframeassembly ids_scan_test.frasm ids_scan_test.pcap\n\n# 2. Run Suricata offline against the generated .pcap (writes eve.json / fast.log)\nsuricata -r ids_scan_test.pcap -k none -l ./suricata_out/\n\n# 3. Or run Zeek offline to generate dns.log, ssl.log, http.log, and conn.log\nzeek -C -r ids_scan_test.pcap\n```\n\n## Protocol Reference Links\n\n- [`dns` — Domain Name System over UDP or\n  TCP](https://frameassembly-lang.dev/docs/protocols/dns) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/dns.md))\n- [`tcp` — Transmission Control Protocol & RFC 7323\n  Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))\n- [`tls` — Transport Layer Security Record & Handshake\n  Layer](https://frameassembly-lang.dev/docs/protocols/tls) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tls.md))\n- [`http` — Hypertext Transfer Protocol\n  HTTP/1.1](https://frameassembly-lang.dev/docs/protocols/http) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/http.md))\n- [`udp` — User Datagram\n  Protocol](https://frameassembly-lang.dev/docs/protocols/udp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/udp.md))\n"}
{"id":"pretrain-usecase-edit-sanitize-pcap","kind":"use_case_playbook","title":"Edit & Sanitize a .pcap File Before Sending It to Vendor Support — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/edit-sanitize-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","radius","tacacs","syslog"],"text":"# Edit & Sanitize a .pcap File Before Sending It to Vendor Support\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Sanitize PCAP & CI/CD) ·\n> Canonical URL: https://frameassembly-lang.dev/use-cases/edit-sanitize-pcap\n\nincident.pcap -> reverse -> Ctrl+H edit & redact -> clean.pcap without slicing off\nthe actual Layer 7 bug.\n\n- **Category:** Sanitize PCAP & CI/CD\n- **Capture Filename:** `redacted_radius.frasm` (3 Ethernet frames)\n- **Protocols Exercised:** `vlan`, `radius`, `syslog`\n\n## Operational Problem\n\nVendor support says \"attach a packet capture of the outage.\" Security says \"if you\nupload internal 10.x subnets or real employee usernames to a third-party ticket\nportal, you’re fired.\" And tcprewrite chokes the moment you try changing\nvariable-length Layer 7 strings.\n\nReal outage captures are full of things you don’t want leaving the building:\ninternal IP schemes, employee RADIUS/LDAP logins, internal Syslog hostnames, and\n4,000 unrelated broadcast packets. Chopping frames at byte 64 with editcap -s 64\nhides the PII—right along with the exact Layer 7 bug the vendor needs to see.\n\nMeanwhile, tcprewrite only swaps outer L2/L3 headers because changing\n\"jsmith@secretcorp.internal\" to \"redacted\" changes the packet’s byte length,\nbreaking IP Total Length, UDP/TCP checksums, and every TCP sequence number\ndownstream.\n\n## Scenario & Topology: outage.pcap -> reverse -> Redact RADIUS & Syslog -> redacted_auth.pcap\n\n- **Topology:** `Branch Switch (192.0.2.1, VLAN 100) <-> AAA Server\n  (198.51.100.10)`\n\nDrop an outage .pcap onto /playground (0 bytes uploaded) or run frameassembly\nreverse, swap private IPs for RFC 5737 documentation space (192.0.2.1 and\n198.51.100.10), replace the employee username with \"redacted_user\", delete stray\nbroadcast lines, and compile a clean 3-frame reproducer.\n\n## FrameAssembly Workflow\n\nReverses .pcap -> .frasm text, lets you redact L2–L7 fields and trim background\nchatter, and rebuilds valid lengths + checksums.\n\n### Adapt It for Your Network\n\n1. Run frameassembly reverse outage.pcap redacted.frasm (or drag-and-drop into\n  /playground).\n2. Replace internal host IPs/MACs with 192.0.2.x / 198.51.100.x and scrub\n  usernames, SNIs, or hostnames.\n3. Rebuild with frameassembly redacted.frasm redacted_auth.pcap and inspect in\n  Wireshark before sharing.\n\n## Runnable Capture Specification (`redacted_radius.frasm`)\n\n```frameassembly\nhost branch_gw { ip 192.0.2.1     mac 0011.22aa.bb01 }\nhost auth_srv  { ip 198.51.100.10 mac 0011.22cc.dd10 }\n\nflow redacted_radius_repro(gw, srv) {\n    gw -> srv vlan 100 radius accessrequest id 10 user \"redacted_user\" nasip 192.0.2.1 wait 10ms\n    gw <- srv vlan 100 radius accessaccept  id 10 wait 5ms\n    gw -> srv vlan 100 syslog facility 1 severity 6 hostname \"branch-gw\" app \"tacacs\" msg \"User authenticated via 802.1X\" wait 2ms\n}\n\ncompile {\n    redacted_radius_repro(branch_gw, auth_srv)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Convert any existing .pcap or .pcapng into editable .frasm text\nframeassembly reverse outage.pcap redacted_radius.frasm\n\n# 2. After editing IPs, VLANs, or strings in .frasm, preview and rebuild to .pcap\nframeassembly show redacted_radius.frasm\nframeassembly redacted_radius.frasm redacted_auth.pcap\n\n# 3. Verify updated IPs, VLAN tags, and valid checksums in tshark\ntshark -r redacted_auth.pcap -V\n```\n\n## Protocol Reference Links\n\n- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p\n  QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))\n- [`radius` — Remote Authentication Dial-In User Service (Auth &\n  Accounting)](https://frameassembly-lang.dev/docs/protocols/radius) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/radius.md))\n- [`syslog` — Syslog Event Logging over UDP or\n  TCP](https://frameassembly-lang.dev/docs/protocols/syslog) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/syslog.md))\n"}
{"id":"pretrain-usecase-shadow-it-detection-pcap","kind":"use_case_playbook","title":"Check Shadow IT & Rogue-Gadget Sensors Without Getting Flagged by HR — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/shadow-it-detection-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","dns","mdns","tls","quic","ssdp"],"text":"# Check Shadow IT & Rogue-Gadget Sensors Without Getting Flagged by HR\n\n> **FrameAssembly v3.3.0** · Operational Playbook (SecOps, Firewalls & IDS) ·\n> Canonical URL: https://frameassembly-lang.dev/use-cases/shadow-it-detection-pcap\n\nVerify your SPAN port mirror sees sketchy DNS, TLS 1.3 SNI, QUIC UDP 443, and\nrogue office NAS broadcasts—without actually visiting sketchy sites.\n\n- **Category:** SecOps, Firewalls & IDS\n- **Capture Filename:** `shadow_it_detection.frasm` (9 Ethernet frames)\n- **Protocols Exercised:** `dns`, `tcp`, `tls`, `quic`, `mdns`, `ssdp`\n\n## Operational Problem\n\nYou wired up a shiny new passive SPAN/Zeek sensor to catch rogue NAS boxes and\nunapproved cloud uploads—except nobody wants to test it by browsing blocked sites\nfrom their corporate laptop or smuggling a consumer IoT toaster into VLAN 30.\n\nPassive SPAN mirrors fail silently all the time (wrong trunk direction, missing\nVLAN in monitor session, or UDP 443 QUIC slipping right past a legacy TCP-only TLS\ninspector).\n\nGenerating synthetic packets lets you test every blind spot—DNS A queries,\nstateful TLS 1.3 ClientHello SNI, HTTP/3 QUIC Initial frames, and RFC 1112\nmulticast mDNS/SSDP broadcasts—without touching a single real external domain.\n\n## Scenario & Topology: Branch SPAN Turn-Up: DNS + TLS 1.3 SNI + QUIC + Rogue NAS Multicast\n\n- **Topology:** `Workstation (10.30.15.42) -> Gateway (10.30.15.1) & LAN Multicast\n  (224.0.0.251 / 239.255.255.250)`\n\nNine packets prove your sensor sees all four tricks: (1) a DNS query <-> reply for\n\"personal-cloud-sync.example.io\"; (2) a full TCP 443 handshake followed by a TLS\n1.3 ClientHello SNI; (3) a UDP 443 QUIC Initial packet trying to dodge TCP\ninspection; and (4) mDNS (224.0.0.251) + SSDP (239.255.255.250) broadcasts from\n\"rogue-office-nas.local\" with auto-derived 01:00:5e:xx:xx:xx multicast MACs.\n\n## FrameAssembly Workflow\n\nEmits 9 frames covering a DNS lookup, stateful TLS 1.3 SNI, UDP 443 QUIC Initial,\nand multicast mDNS + SSDP rogue-device chatter.\n\n### Adapt It for Your Network\n\n1. Change qname and tls clienthello sni to the exact domains on your watchlist.\n2. Compile -> replay into your SPAN/TAP NIC with tcpreplay, or run zeek -C -r\n  shadow_it_detection.pcap.\n\n## Runnable Capture Specification (`shadow_it_detection.frasm`)\n\n```frameassembly\nhost employee_pc { ip 10.30.15.42 }\nhost corp_gw     { ip 10.30.15.1 }\nhost mdns_group  { ip 224.0.0.251 }\nhost ssdp_group  { ip 239.255.255.250 }\n\nflow unmanaged_saas_and_ai(ws, gw) {\n    ws -> gw dns query txid 0x7101 qname \"personal-cloud-sync.example.io\" qtype \"A\" wait 1ms\n    ws <- gw dns response txid 0x7101 qname \"personal-cloud-sync.example.io\" qtype \"A\" rdata \"198.51.100.77\" wait 1ms\n    ws -> gw tcp syn srcport 53443 dstport 443 win 65535 mss 1460 wait 1ms\n    ws <- gw tcp syn ack win 65535 mss 1460 wait 1ms\n    ws -> gw tcp ack wait 1ms\n    ws -> gw tls clienthello sni \"unmanaged-ai-assistant.example.io\" ciphersuite 4865 alpn \"h2\" wait 2ms\n    ws -> gw dstport 443 quic initial version 1 dcid \"a1b2c3d4e5f60708\" scid \"1122334455667788\" pktnum 1 payload \"QUIC_DOH_BYPASS\" wait 2ms\n}\n\nflow rogue_device_discovery(ws, mcast_dns, mcast_upnp) {\n    ws -> mcast_dns mdns query qname \"rogue-office-nas.local\" qtype \"A\" wait 2ms\n    ws -> mcast_upnp ssdp msearch st \"ssdp:all\" mx 3 wait 2ms\n}\n\ncompile {\n    unmanaged_saas_and_ai(employee_pc, corp_gw)\n    rogue_device_discovery(employee_pc, mdns_group, ssdp_group)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Build the Shadow IT & rogue device test capture\nframeassembly shadow_it_detection.frasm shadow_it_detection.pcap\n\n# 2. Verify DNS qname, TLS SNI hostname, QUIC DCID, and mDNS/SSDP fields in tshark\ntshark -r shadow_it_detection.pcap -T fields -e frame.number -e ip.src -e dns.qry.name -e tls.handshake.extensions_server_name\n\n# 3. Replay into your monitoring sensor SPAN/TAP interface or evaluate in Zeek\nsudo tcpreplay -i eth0 shadow_it_detection.pcap\nzeek -C -r shadow_it_detection.pcap\n```\n\n## Protocol Reference Links\n\n- [`dns` — Domain Name System over UDP or\n  TCP](https://frameassembly-lang.dev/docs/protocols/dns) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/dns.md))\n- [`tcp` — Transmission Control Protocol & RFC 7323\n  Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))\n- [`tls` — Transport Layer Security Record & Handshake\n  Layer](https://frameassembly-lang.dev/docs/protocols/tls) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tls.md))\n- [`quic` — QUIC v1 & v2 Encrypted UDP\n  Transport](https://frameassembly-lang.dev/docs/protocols/quic) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/quic.md))\n- [`mdns` — Multicast DNS Zero-Configuration\n  Discovery](https://frameassembly-lang.dev/docs/protocols/mdns) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/mdns.md))\n- [`ssdp` — Simple Service Discovery Protocol & UPnP\n  Multicast](https://frameassembly-lang.dev/docs/protocols/ssdp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/ssdp.md))\n"}
{"id":"pretrain-usecase-vlan-qinq-mpls-qos","kind":"use_case_playbook","title":"Stamp 802.1Q VLAN, Double-Tagged QinQ & MPLS Without an IXIA Rack — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/vlan-qinq-mpls-qos","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","qinq","mpls","tls","rtp"],"text":"# Stamp 802.1Q VLAN, Double-Tagged QinQ & MPLS Without an IXIA Rack\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Routing, VLANs & Overlays) ·\n> Canonical URL: https://frameassembly-lang.dev/use-cases/vlan-qinq-mpls-qos\n\nYour laptop NIC driver loves eating VLAN tags. Writing Ethernet bytes straight to\na .pcap means every 0x88a8 S-Tag and MPLS label survives.\n\n- **Category:** Routing, VLANs & Overlays\n- **Capture Filename:** `qinq_mpls_trunk.frasm` (3 Ethernet frames)\n- **Protocols Exercised:** `vlan`, `rtp`, `qinq`, `mpls`, `tls`\n\n## Operational Problem\n\nNormal OS sockets won’t let unprivileged users emit outer 802.1ad QinQ S-tags,\n20-bit MPLS labels, or 802.1p priority bits—and desktop NIC drivers famously strip\n802.1Q tags before Wireshark even sees them.\n\nWhen a carrier hands you a new Metro Ethernet circuit or you’re tuning VoIP\nstrict-priority queues, you just want to know whether S-VLAN 2000 + C-VLAN 150 +\nMPLS 40960 + DSCP 46 make it to the other side unscathed.\n\nRenting a hardware traffic generator or wiring up three spare lab routers just to\npush four shim bytes onto an Ethernet header is ridiculous when you can type qinq\n2000 innervlan 150 mpls 40960 exp 5 on one line.\n\n## Scenario & Topology: Voice VLAN 110 (DSCP EF) + Carrier QinQ 2000/150 + MPLS 40960 Check\n\n- **Topology:** `Branch CPE (10.220.1.10) <-> Carrier QinQ 2000/150 + MPLS 40960\n  <-> HQ Edge (10.220.1.200)`\n\nThree frames cover the whole trunk check: (1) a Voice VLAN 110 G.711 RTP packet\nstamped with pcp 5 and dscp 46 (EF); followed by (2 & 3) cpe -> hq and cpe <- hq\ndouble-tagged 802.1ad frames (qinq 2000 innervlan 150) carrying MPLS label 40960\n(exp 5) and a TLS handshake.\n\n## FrameAssembly Workflow\n\nWrites raw 802.1Q (0x8100), 802.1ad (0x88a8), MPLS (0x8847), and DSCP EF headers\nstraight into a 3-frame .pcap.\n\n### Adapt It for Your Network\n\n1. Set branch_cpe and hq_gateway to your circuit endpoints.\n2. Drop vlan, pcp, dei, dscp, qinq <outer> innervlan <inner>, and mpls <label>\n  right in front of any protocol.\n3. Compile -> verify tag stacks in tshark -> replay onto your trunk NIC.\n\n## Runnable Capture Specification (`qinq_mpls_trunk.frasm`)\n\n```frameassembly\nhost branch_cpe { ip 10.220.1.10 }\nhost hq_gateway { ip 10.220.1.200 }\n\nflow metro_trunk(cpe, hq) {\n    cpe -> hq vlan 110 pcp 5 dei 0 dscp 46 rtp pt 0 seq 1 timestamp 160 payload \"G711_VOICE_EF\" wait 5ms\n    cpe -> hq qinq 2000 innervlan 150 mpls 40960 exp 5 tls clienthello sni \"wan.example.com\" wait 5ms\n    cpe <- hq qinq 2000 innervlan 150 mpls 40960 exp 5 tls serverhello wait 5ms\n}\n\ncompile {\n    metro_trunk(branch_cpe, hq_gateway)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Build the VLAN, QinQ, MPLS & DSCP QoS capture\nframeassembly qinq_mpls_trunk.frasm qinq_mpls_trunk.pcap\n\n# 2. Verify VLAN IDs, 802.1p PCP priority, DSCP markings, and MPLS labels in tshark\ntshark -r qinq_mpls_trunk.pcap -T fields -e frame.number -e vlan.id -e vlan.priority -e mpls.label -e ip.dsfield.dscp\n\n# 3. Replay onto your 802.1Q / 802.1ad trunk interface\nsudo tcpreplay -i eth0 qinq_mpls_trunk.pcap\n```\n\n## Protocol Reference Links\n\n- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p\n  QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))\n- [`rtp` — Real-time Transport Protocol Audio & Video\n  Streams](https://frameassembly-lang.dev/docs/protocols/rtp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/rtp.md))\n- [`qinq` — IEEE 802.1ad Provider Bridge Double VLAN Tagging (S-Tag +\n  C-Tag)](https://frameassembly-lang.dev/docs/protocols/qinq) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/qinq.md))\n- [`mpls` — Multiprotocol Label Switching Unicast\n  Shim](https://frameassembly-lang.dev/docs/protocols/mpls) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/mpls.md))\n- [`tls` — Transport Layer Security Record & Handshake\n  Layer](https://frameassembly-lang.dev/docs/protocols/tls) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tls.md))\n"}
{"id":"pretrain-usecase-industrial-ot-modbus-dnp3","kind":"use_case_playbook","title":"Poke OT / SCADA Firewalls Without Opening a Substation Breaker — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/industrial-ot-modbus-dnp3","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","udp","modbus","bacnet","dnp3"],"text":"# Poke OT / SCADA Firewalls Without Opening a Substation Breaker\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Telemetry, VoIP & OT) ·\n> Canonical URL:\n> https://frameassembly-lang.dev/use-cases/industrial-ot-modbus-dnp3\n\nProve your OT firewall allows Modbus reads while blocking writes and DNP3 operate\ncommands—far away from real spinning machinery.\n\n- **Category:** Telemetry, VoIP & OT\n- **Capture Filename:** `scada_modbus.frasm` (9 Ethernet frames)\n- **Protocols Exercised:** `tcp`, `modbus`, `dnp3`, `bacnet`\n\n## Operational Problem\n\nOT firewall rules usually say \"Historian may Read Holding Registers (0x03), but\nNEVER Write Single Register (0x06) or DNP3 Operate.\" Testing the block rule\nagainst a live factory PLC is a career-limiting move, and calculating IEEE 1815\nDNP3 16-byte chunk CRCs by hand is pure misery.\n\nOT firewalls and ICS sensors (Claroty, Dragos, Nozomi, Palo Alto/Fortinet OT\nprofiles) dissect deep inside Modbus, DNP3, S7comm, BACnet, EtherNet/IP, and OPC\nUA.\n\nIf your synthetic DNP3 packet has a bad link-layer or data-chunk CRC-16, or your\nModbus TCP packet skips the port 502 3-way handshake, the dissector drops it as\ncorrupt wire noise instead of testing your actual function-code policy.\n\n## Scenario & Topology: Level 3 HMI -> OT Firewall -> Level 1 PLC (Read OK, Write & Operate Blocked)\n\n- **Topology:** `SCADA HMI (10.80.20.10) -> OT Conduit Firewall -> Plant PLC / RTU\n  (10.80.10.50)`\n\nNine frames, zero physical PLCs harmed: a TCP 502 handshake (syn -> syn ack ->\nack), an allowed Modbus Read Holding Registers (40001) <-> response, an\nunauthorized Write Single Register (value 1500), DNP3 Select + Operate (Group 12\nCROB with auto CRC-16), and BACnet ReadProperty.\n\n## FrameAssembly Workflow\n\nBuilds a stateful TCP 502 Modbus read/write check + DNP3 Select/Operate (with\nautomatic IEEE 1815 CRC-16) + BACnet ReadProperty.\n\n### Adapt It for Your Network\n\n1. Point scada_hmi and plc_node at your Level 3 historian and Level 1 controller\n  IPs.\n2. Open TCP 502 with syn -> syn ack -> ack, then mix modbus, dnp3, s7comm, bacnet,\n  ethernetip, or opcua lines.\n3. Compile -> replay across your OT test firewall or feed offline into\n  Claroty/Dragos/Suricata.\n\n## Runnable Capture Specification (`scada_modbus.frasm`)\n\n```frameassembly\nhost scada_hmi { ip 10.80.20.10 }\nhost plc_node  { ip 10.80.10.50 }\n\nflow modbus_and_ot_poll(hmi, plc) {\n    hmi -> plc tcp syn srcport 50200 dstport 502 wait 1ms\n    hmi <- plc tcp syn ack wait 1ms\n    hmi -> plc tcp ack wait 1ms\n    hmi -> plc modbus readholdingregisters txid 101 unitid 1 addr 40001 count 4 wait 5ms\n    hmi <- plc modbus readholdingregisters txid 101 unitid 1 count 4 isresponse wait 5ms\n    hmi -> plc modbus writesingleregister txid 102 unitid 1 addr 40001 value 1500 wait 5ms\n    hmi -> plc transport udp dnp3 select src 1 dst 10 group 12 variation 1 wait 2ms\n    hmi -> plc transport udp dnp3 operate src 1 dst 10 group 12 variation 1 wait 2ms\n    hmi -> plc bacnet readproperty invokeid 10 objecttype 0 objectinstance 1 propertyid 85 wait 2ms\n}\n\ncompile {\n    modbus_and_ot_poll(scada_hmi, plc_node)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Build the Industrial OT / SCADA conduit capture\nframeassembly scada_modbus.frasm scada_modbus.pcap\n\n# 2. Inspect Modbus function codes, DNP3 CRC-16 frames, and BACnet properties in tshark\ntshark -r scada_modbus.pcap\n\n# 3. Replay across your OT zone firewall or passive ICS sensor SPAN port\nsudo tcpreplay -i eth1 scada_modbus.pcap\n```\n\n## Protocol Reference Links\n\n- [`tcp` — Transmission Control Protocol & RFC 7323\n  Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))\n- [`modbus` — Modbus TCP / UDP Industrial Application\n  Protocol](https://frameassembly-lang.dev/docs/protocols/modbus) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/modbus.md))\n- [`dnp3` — Distributed Network Protocol 3 (Electric & Water\n  Utilities)](https://frameassembly-lang.dev/docs/protocols/dnp3) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/dnp3.md))\n- [`bacnet` — BACnet/IP Building Automation & Control\n  Networks](https://frameassembly-lang.dev/docs/protocols/bacnet) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/bacnet.md))\n"}
{"id":"pretrain-usecase-bgp-ospf-bfd-routing-pcap","kind":"use_case_playbook","title":"Test eBGP 4-Byte ASN Peering, OSPF & BFD Without Router VMs — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/bgp-ospf-bfd-routing-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ospf","bgp","bfd","tcp"],"text":"# Test eBGP 4-Byte ASN Peering, OSPF & BFD Without Router VMs\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Routing, VLANs & Overlays) ·\n> Canonical URL:\n> https://frameassembly-lang.dev/use-cases/bgp-ospf-bfd-routing-pcap\n\nCraft TCP 179 BGP OPEN/UPDATE/KEEPALIVE with RFC 6793 AS_TRANS, multicast OSPFv2\nHello, and 50ms BFD Up frames in 12 lines.\n\n- **Category:** Routing, VLANs & Overlays\n- **Capture Filename:** `bgp_ospf_bfd_lab.frasm` (12 Ethernet frames)\n- **Protocols Exercised:** `tcp`, `bgp`, `ospf`, `bfd`\n\n## Operational Problem\n\nSpinning up a 16 GB Containerlab or GNS3 topology with vendor router images just\nto verify a Control Plane Policing (CoPP) ACL, a BGP route-collector parser, or a\nBFD UDP 3784 timer filter eats half an afternoon.\n\nRouter control planes are picky: eBGP expects a valid 3-way TCP 179 handshake at\nTTL 1 and CS6 (DSCP 48), 4-byte ASNs above 65535 require RFC 6793 AS_TRANS (23456)\nplus Capability 65 inside the BGP OPEN message, and BFD control packets get\ndropped immediately unless Hop Limit / TTL equals 255.\n\nHand-coding 16-byte `0xff` BGP markers, variable-length NLRI prefix tuples, and\nOSPF multicast MACs (`01:00:5e:00:00:05`) in raw hex is error-prone. FrameAssembly\ncomputes every marker, capability length, and multicast destination MAC\nautomatically.\n\n## Scenario & Topology: Edge Peering Turn-Up & CoPP Audit (AS 4200000001 <-> ISP AS 64512 + OSPF + BFD)\n\n- **Topology:** `DC Border Router (198.51.100.1, AS 4200000001) <-> ISP Edge\n  (198.51.100.2, AS 64512) & AllSPFRouters (224.0.0.5)`\n\nTwelve CS6-marked (`dscp 48`) control-plane packets exercise your entire routing\nACL and telemetry parser: (1) a stateful TCP 179 handshake followed by 4-byte ASN\n`bgp open`, bidirectional `keepalive`, and an NLRI `update` advertising\n`203.0.113.0/24`; (2) an OSPFv2 multicast `hello` to `224.0.0.5` answered by\nunicast `lsack`; and (3) a sub-second `bfd` `state 3` (Up) session on UDP 3784 at\n`ttl 255`.\n\n## FrameAssembly Workflow\n\nEmits 12 CS6-marked routing frames covering stateful eBGP 4-byte ASN peering +\nNLRI UPDATE, multicast OSPFv2 Hello/LSAck, and TTL-255 BFD Up.\n\n### Adapt It for Your Network\n\n1. Set dc_border and isp_edge to your peering link `/30` or `/31` addresses and\n  replace asn 4200000001 / prefix with your own ASN and subnet.\n2. Keep ttl 1 on eBGP (or change to ttl 2..255 for eBGP multihop checks) and ttl\n  255 on single-hop BFD.\n3. Run frameassembly bgp_ospf_bfd_lab.frasm, inspect Capability 65 and NLRI in\n  tshark, or replay against your router CoPP test port.\n\n## Runnable Capture Specification (`bgp_ospf_bfd_lab.frasm`)\n\n```frameassembly\nhost dc_border { ip 198.51.100.1 mac 00:1c:73:b0:00:01 }\nhost isp_edge  { ip 198.51.100.2 mac 00:1c:73:b0:00:02 }\nhost ospf_all  { ip 224.0.0.5 }\n\nflow ebgp_peering_and_nlri(local_rtr, peer_rtr) {\n    // 1. Stateful TCP 179 handshake + 4-byte ASN eBGP OPEN, KEEPALIVE, and NLRI UPDATE\n    local_rtr -> peer_rtr dscp 48 ttl 1 tcp syn srcport 51179 dstport 179 win 65535 mss 1460 wait 1ms\n    local_rtr <- peer_rtr dscp 48 ttl 1 tcp syn ack win 65535 mss 1460 wait 1ms\n    local_rtr -> peer_rtr dscp 48 ttl 1 tcp ack wait 1ms\n    local_rtr -> peer_rtr dscp 48 ttl 1 bgp open asn 4200000001 holdtime 90 bgpid 198.51.100.1 wait 2ms\n    local_rtr <- peer_rtr dscp 48 ttl 1 bgp open asn 64512 holdtime 90 bgpid 198.51.100.2 wait 2ms\n    local_rtr -> peer_rtr dscp 48 ttl 1 bgp keepalive wait 1ms\n    local_rtr <- peer_rtr dscp 48 ttl 1 bgp keepalive wait 2ms\n    local_rtr -> peer_rtr dscp 48 ttl 1 bgp update asn 4200000001 prefix \"203.0.113.0/24\" nexthop 198.51.100.1 wait 5ms\n}\n\nflow igp_and_bfd_liveness(local_rtr, peer_rtr, mcast_ospf) {\n    // 2. OSPFv2 multicast Hello (224.0.0.5 -> 01:00:5e:00:00:05) + unicast LSAck\n    local_rtr -> mcast_ospf dscp 48 ttl 1 ospf hello routerid 198.51.100.1 areaid 0.0.0.0 hellointerval 10 deadinterval 40 priority 100 wait 2ms\n    local_rtr <- peer_rtr dscp 48 ttl 1 ospf lsack routerid 198.51.100.2 areaid 0.0.0.0 wait 2ms\n\n    // 3. Sub-second BFD Control Up session (state 3, TTL 255) on UDP 3784\n    local_rtr -> peer_rtr dscp 48 ttl 255 bfd state 3 diag 0 mydisc 0x1001 yourdisc 0x2002 mintx 50000 minrx 50000 mult 3 wait 2ms\n    local_rtr <- peer_rtr dscp 48 ttl 255 bfd state 3 diag 0 mydisc 0x2002 yourdisc 0x1001 mintx 50000 minrx 50000 mult 3 wait 2ms\n}\n\ncompile {\n    ebgp_peering_and_nlri(dc_border, isp_edge)\n    igp_and_bfd_liveness(dc_border, isp_edge, ospf_all)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Preview the 12-packet eBGP + OSPF + BFD control-plane timeline\nframeassembly show bgp_ospf_bfd_lab.frasm\n\n# 2. Compile to .pcap and inspect BGP 4-byte ASN, OSPF Area 0, and BFD state in tshark\nframeassembly bgp_ospf_bfd_lab.frasm bgp_ospf_bfd_lab.pcap\ntshark -r bgp_ospf_bfd_lab.pcap -Y \"bgp || ospf || bfd\"\n\n# 3. Replay against a router CoPP interface or feed into Zeek /pmacct\nsudo tcpreplay -i eth0 bgp_ospf_bfd_lab.pcap\n```\n\n## Protocol Reference Links\n\n- [`tcp` — Transmission Control Protocol & RFC 7323\n  Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))\n- [`bgp` — Border Gateway Protocol 4 & 4-Byte ASN\n  Capability](https://frameassembly-lang.dev/docs/protocols/bgp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/bgp.md))\n- [`ospf` — Open Shortest Path First — OSPFv2 & Dual-Stack\n  OSPFv3](https://frameassembly-lang.dev/docs/protocols/ospf) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/ospf.md))\n- [`bfd` — Bidirectional Forwarding Detection Control\n  Packet](https://frameassembly-lang.dev/docs/protocols/bfd) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/bfd.md))\n"}
{"id":"pretrain-usecase-vxlan-wireguard-ipsec-tunnel-pcap","kind":"use_case_playbook","title":"Debug VXLAN, Geneve, WireGuard & IPsec Tunnel MTU Black Holes Offline — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/vxlan-wireguard-ipsec-tunnel-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["icmp","vxlan","geneve","esp","ikev2","wireguard","udp"],"text":"# Debug VXLAN, Geneve, WireGuard & IPsec Tunnel MTU Black Holes Offline\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Routing, VLANs & Overlays) ·\n> Canonical URL:\n> https://frameassembly-lang.dev/use-cases/vxlan-wireguard-ipsec-tunnel-pcap\n\nVerify underlay ACLs allow UDP 4789/6081/4500/51820, IP Proto 50 ESP, and ICMP\nCode 4 Path MTU Discovery before tunnels hang on TLS.\n\n- **Category:** Routing, VLANs & Overlays\n- **Capture Filename:** `overlay_vpn_mtu.frasm` (12 Ethernet frames)\n- **Protocols Exercised:** `vxlan`, `geneve`, `udp`, `icmp`, `ikev2`, `esp`,\n  `wireguard`\n\n## Operational Problem\n\nPings pass across the new cloud tunnel because 64-byte packets fit anywhere, then\nevery real HTTPS or database query freezes solid because an underlay firewall\nblocks ICMP Fragmentation Needed or silently drops IP Protocol 50 ESP.\n\nData-center fabrics (EVPN VXLAN on UDP 4789, Cilium/OVN/GWLB Geneve on UDP 6081)\nand site-to-site VPNs (IKEv2 NAT-T on UDP 500/4500 + ESP Proto 50, WireGuard on\nUDP 51820) shave 50 to 80 bytes off your usable MTU.\n\nTesting all four encapsulations—plus `df` (Don’t Fragment) probes and `icmp\ndestunreach code 4` Path MTU Discovery replies—normally requires deploying\nmulti-cloud gateways and IPsec daemons just to capture twelve packets.\n\n## Scenario & Topology: Hybrid-Cloud Underlay Audit: VXLAN + Geneve + PMTUD + IKEv2/ESP + WireGuard\n\n- **Topology:** `Spine VTEP / Branch VPN (172.16.254.10) <-> Transit Firewall <->\n  Cloud VTEP / Hub (172.16.254.20)`\n\nTwelve packets verify every tunnel pipe and MTU edge case in one capture: (1)\nDF-marked `vxlan` (`vni 10400`) and `geneve` (`vni 20800`); (2) an oversized `df`\nUDP probe answered by `icmp destunreach code 4` (Fragmentation Needed); (3) `ikev2\nsainit` on UDP 500 floating to NAT-T UDP 4500 `auth` + `esp` (`spi 0xc0ffee01`);\nand (4) a 1-RTT `wireguard` Noise_IK handshake (`initiation` -> `response` ->\n`data`).\n\n## FrameAssembly Workflow\n\nCompiles 12 underlay frames covering VXLAN, Geneve, DF/ICMP Code 4 PMTUD, IKEv2\nNAT-T + ESP, and exact-length WireGuard.\n\n### Adapt It for Your Network\n\n1. Replace spine_vtep and remote_vtep with your underlay VTEP or WAN gateway\n  public/transit IPs.\n2. Adjust vni 10400/20800, IKEv2 SPIs, ESP spi, or WireGuard sender/receiver\n  indices to match your lab.\n3. Compile -> inspect VXLAN, Geneve, ISAKMP, ESP, and WireGuard dissectors in\n  Wireshark -> replay across your transit firewall.\n\n## Runnable Capture Specification (`overlay_vpn_mtu.frasm`)\n\n```frameassembly\nhost spine_vtep  { ip 172.16.254.10 mac 00:1c:73:c0:00:10 }\nhost remote_vtep { ip 172.16.254.20 mac 00:1c:73:c0:00:20 }\n\nflow dc_overlays_and_pmtud(local_gw, peer_gw) {\n    // 1. EVPN VXLAN (UDP 4789, VNI 10400) & Cilium/GWLB Geneve (UDP 6081, VNI 20800)\n    local_gw -> peer_gw df vxlan vni 10400 payload \"INNER_TENANT_FRAME\" wait 1ms\n    local_gw -> peer_gw df geneve vni 20800 optclass 0x0104 opttype 1 protocoltype 0x6558 wait 2ms\n\n    // 2. Path MTU Discovery (DF=1 probe -> ICMP Type 3 Code 4 Fragmentation Needed)\n    local_gw -> peer_gw df ipid 9001 udp srcport 54000 dstport 4789 payload \"OVERSIZED_TUNNEL_DF_PROBE\" wait 1ms\n    local_gw <- peer_gw icmp destunreach code 4 wait 3ms\n}\n\nflow site_to_site_ipsec_and_wireguard(local_gw, peer_gw) {\n    // 3. IKEv2 SA_INIT (UDP 500) -> NAT-T float (UDP 4500 AUTH) + IPsec ESP (Proto 50)\n    local_gw -> peer_gw ikev2 sainit initiatorspi 0xa1b2c3d4e5f60102 responderspi 0 msgid 0 flags 0x08 nextpayload 33 wait 2ms\n    local_gw <- peer_gw ikev2 sainit initiatorspi 0xa1b2c3d4e5f60102 responderspi 0x1122334455667788 msgid 0 flags 0x20 nextpayload 33 wait 2ms\n    local_gw -> peer_gw ikev2 auth srcport 4500 dstport 4500 initiatorspi 0xa1b2c3d4e5f60102 responderspi 0x1122334455667788 msgid 1 flags 0x08 nextpayload 46 wait 2ms\n    local_gw <- peer_gw ikev2 auth srcport 4500 dstport 4500 initiatorspi 0xa1b2c3d4e5f60102 responderspi 0x1122334455667788 msgid 1 flags 0x20 nextpayload 46 wait 2ms\n    local_gw -> peer_gw esp spi 0xc0ffee01 seq 1 iv \"0011223344556677\" icv \"8899aabbccddeeff00112233\" wait 2ms\n\n    // 4. WireGuard 1-RTT handshake (148B Initiation -> 92B Response) + AEAD Data\n    local_gw -> peer_gw wireguard initiation sender 0x01020304 wait 1ms\n    local_gw <- peer_gw wireguard response sender 0x05060708 receiver 0x01020304 wait 1ms\n    local_gw -> peer_gw wireguard data receiver 0x05060708 counter 0 payload \"WG_INNER_PACKET\" wait 1ms\n}\n\ncompile {\n    dc_overlays_and_pmtud(spine_vtep, remote_vtep)\n    site_to_site_ipsec_and_wireguard(spine_vtep, remote_vtep)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Compile the VXLAN, Geneve, PMTUD, IPsec & WireGuard capture\nframeassembly overlay_vpn_mtu.frasm overlay_vpn_mtu.pcap\n\n# 2. Verify VXLAN/Geneve VNIs, DF bits, IKEv2 SPIs, ESP, and WireGuard in tshark\ntshark -r overlay_vpn_mtu.pcap\n\n# 3. Replay across underlay switches, cloud GWLB appliances, or Suricata NDR\nsudo tcpreplay -i eth0 overlay_vpn_mtu.pcap\n```\n\n## Protocol Reference Links\n\n- [`vxlan` — Virtual eXtensible Local Area Network\n  Overlay](https://frameassembly-lang.dev/docs/protocols/vxlan) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/vxlan.md))\n- [`geneve` — Generic Network Virtualization\n  Encapsulation](https://frameassembly-lang.dev/docs/protocols/geneve) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/geneve.md))\n- [`udp` — User Datagram\n  Protocol](https://frameassembly-lang.dev/docs/protocols/udp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/udp.md))\n- [`icmp` — Internet Control Message Protocol v4 & Dual-Stack\n  ICMPv6](https://frameassembly-lang.dev/docs/protocols/icmp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/icmp.md))\n- [`ikev2` — Internet Key Exchange Protocol Version\n  2](https://frameassembly-lang.dev/docs/protocols/ikev2) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/ikev2.md))\n- [`esp` — IPsec Encapsulating Security\n  Payload](https://frameassembly-lang.dev/docs/protocols/esp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/esp.md))\n- [`wireguard` — WireGuard Noise_IK Secure Network\n  Tunnel](https://frameassembly-lang.dev/docs/protocols/wireguard) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/wireguard.md))\n"}
{"id":"pretrain-usecase-voip-sip-rtp-qos-pcap","kind":"use_case_playbook","title":"Diagnose One-Way VoIP Audio, SIP ALGs & WAN DSCP Stripping — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/voip-sip-rtp-qos-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","sip","rtp","stun"],"text":"# Diagnose One-Way VoIP Audio, SIP ALGs & WAN DSCP Stripping\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Telemetry, VoIP & OT) ·\n> Canonical URL: https://frameassembly-lang.dev/use-cases/voip-sip-rtp-qos-pcap\n\nBuild a complete STUN + SIP INVITE/SDP + bidirectional G.711 RTP (DSCP 46 EF) call\nladder that opens straight in Wireshark Telephony -> VoIP Calls.\n\n- **Category:** Telemetry, VoIP & OT\n- **Capture Filename:** `voip_sip_rtp_qos.frasm` (10 Ethernet frames)\n- **Protocols Exercised:** `vlan`, `stun`, `sip`, `rtp`\n\n## Operational Problem\n\nPhones ring fine on UDP 5060, somebody picks up, and only one side hears\naudio—usually because a firewall SIP ALG mangled the SDP media IP, UDP 16384+ RTP\nis Asymmetric-NAT blocked, or the WAN carrier bleached DSCP 46 back to 0.\n\nTesting VoIP trunks and SBC policies by placing 30 live test calls annoys everyone\nin earshot, and hand-crafting SIP messages fails fast if you miss the RFC 3261\n`z9hG4bK` Via branch magic cookie or miscalculate SDP `Content-Length`.\n\nFrameAssembly builds valid RFC 5389 XOR-masked STUN bindings, complete RFC 3261\nSIP dialogs with matching `callid` headers, and VLAN-tagged `dscp 46` G.711 RTP\nmedia streams in ten readable lines.\n\n## Scenario & Topology: Voice VLAN 110 Desk Phone <-> NAT Firewall / SBC Call Lifecycle\n\n- **Topology:** `Desk Phone (10.110.20.45, VLAN 110) -> Firewall / WAN -> Cloud\n  SBC & STUN (198.51.100.60)`\n\nTen packets reproduce a full enterprise voice call: (1) RFC 5389 `stun\nbindingrequest` <-> `bindingresponse` discovering public NAT IP `203.0.113.45`;\n(2) CS3-marked (`dscp 24`) `sip invite` with SDP audio offer -> `180 Ringing` ->\n`200 OK` -> `sip ack` sharing `callid \"voip-call-901\"`; (3) bidirectional\nEF-marked (`vlan 110 pcp 5 dscp 46`) G.711 PCMU `rtp` voice frames; and (4) clean\n`sip bye` -> `200 OK` teardown.\n\n## FrameAssembly Workflow\n\nGenerates 10 Voice-VLAN frames covering STUN XOR-MAPPED-ADDRESS discovery, a\nmatched-Call-ID SIP + SDP dialog, bidirectional DSCP-EF RTP, and BYE.\n\n### Adapt It for Your Network\n\n1. Set desk_phone and cloud_sbc to your voice subnet and SBC trunk IPs, and adjust\n  vlan 110 to your Voice VLAN.\n2. Keep callid identical across invite, status, ack, and bye so Wireshark groups\n  the call into one VoIP ladder.\n3. Compile -> open in Wireshark (Telephony -> VoIP Calls) -> replay across your\n  firewall to check SIP ALG and DSCP 46 preservation.\n\n## Runnable Capture Specification (`voip_sip_rtp_qos.frasm`)\n\n```frameassembly\nhost desk_phone { ip 10.110.20.45  mac 00:04:f2:aa:20:45 }\nhost cloud_sbc  { ip 198.51.100.60 mac 00:1c:73:60:00:01 }\n\nflow nat_stun_discovery(phone, sbc) {\n    // 1. RFC 5389 STUN NAT discovery returning XOR-masked public IP 203.0.113.45\n    phone -> sbc vlan 110 stun bindingrequest txid 0x20459001 software \"PolyEdge-B\" wait 2ms\n    phone <- sbc vlan 110 stun bindingresponse txid 0x20459001 xormappedaddr 203.0.113.45 wait 3ms\n}\n\nflow sip_call_and_ef_rtp(phone, sbc) {\n    // 2. SIP call setup (CS3 dscp 24) with SDP offer sharing callid \"voip-call-901\"\n    phone -> sbc vlan 110 pcp 3 dscp 24 sip invite uri \"sip:18005550199@sbc.example.net\" from \"sip:2045@corp.example.net\" to \"sip:18005550199@sbc.example.net\" callid \"voip-call-901\" cseq 1 contenttype \"application/sdp\" body \"v=0\\r\\no=- 1 1 IN IP4 203.0.113.45\\r\\ns=-\\r\\nc=IN IP4 203.0.113.45\\r\\nt=0 0\\r\\nm=audio 16400 RTP/AVP 0\\r\\n\" wait 2ms\n    phone <- sbc vlan 110 pcp 3 dscp 24 sip status 180 reason \"Ringing\" callid \"voip-call-901\" cseq 1 wait 20ms\n    phone <- sbc vlan 110 pcp 3 dscp 24 sip status 200 reason \"OK\" callid \"voip-call-901\" cseq 1 wait 2ms\n    phone -> sbc vlan 110 pcp 3 dscp 24 sip ack uri \"sip:18005550199@sbc.example.net\" callid \"voip-call-901\" cseq 1 wait 5ms\n\n    // 3. Bidirectional G.711 PCMU RTP audio stamped with 802.1p PCP 5 + DSCP 46 (EF)\n    phone -> sbc vlan 110 pcp 5 dscp 46 srcport 16400 dstport 16400 rtp pt 0 seq 100 timestamp 160 ssrc 0x11223344 marker 1 payload \"G711_TX_AUDIO\" wait 20ms\n    phone <- sbc vlan 110 pcp 5 dscp 46 rtp pt 0 seq 500 timestamp 160 ssrc 0x99887766 marker 1 payload \"G711_RX_AUDIO\" wait 20ms\n\n    // 4. Clean call hangup (BYE -> 200 OK)\n    phone -> sbc vlan 110 pcp 3 dscp 24 sip bye uri \"sip:18005550199@sbc.example.net\" callid \"voip-call-901\" cseq 2 wait 2ms\n    phone <- sbc vlan 110 pcp 3 dscp 24 sip status 200 reason \"OK\" callid \"voip-call-901\" cseq 2 wait 1ms\n}\n\ncompile {\n    nat_stun_discovery(desk_phone, cloud_sbc)\n    sip_call_and_ef_rtp(desk_phone, cloud_sbc)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Compile the STUN + SIP + DSCP-EF RTP call capture\nframeassembly voip_sip_rtp_qos.frasm voip_sip_rtp_qos.pcap\n\n# 2. Verify STUN XOR-MAPPED-ADDRESS, SIP Call-ID, and RTP DSCP 46 markings in tshark\ntshark -r voip_sip_rtp_qos.pcap -Y \"stun || sip || rtp\"\n\n# 3. Replay across your WAN edge or firewall to verify SIP ALG & QoS queue mapping\nsudo tcpreplay -i eth0 voip_sip_rtp_qos.pcap\n```\n\n## Protocol Reference Links\n\n- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p\n  QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))\n- [`stun` — Session Traversal Utilities for\n  NAT](https://frameassembly-lang.dev/docs/protocols/stun) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/stun.md))\n- [`sip` — Session Initiation Protocol VoIP\n  Signaling](https://frameassembly-lang.dev/docs/protocols/sip) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/sip.md))\n- [`rtp` — Real-time Transport Protocol Audio & Video\n  Streams](https://frameassembly-lang.dev/docs/protocols/rtp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/rtp.md))\n"}
{"id":"pretrain-usecase-ipv6-ndp-dhcpv6-dual-stack-pcap","kind":"use_case_playbook","title":"Verify IPv6 First-Hop Security (RA Guard, NDP, DHCPv6) & Dual-Stack — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/ipv6-ndp-dhcpv6-dual-stack-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","ndp","tcp","dns","dhcp","http2"],"text":"# Verify IPv6 First-Hop Security (RA Guard, NDP, DHCPv6) & Dual-Stack\n\n> **FrameAssembly v3.3.0** · Operational Playbook (IPv6, DDI & Campus NAC) ·\n> Canonical URL:\n> https://frameassembly-lang.dev/use-cases/ipv6-ndp-dhcpv6-dual-stack-pcap\n\nWrite one parameterized flow(c, s) that runs over both IPv4 and IPv6 hosts—plus\nHop-Limit-255 NDP and DHCPv6 SARR.\n\n- **Category:** IPv6, DDI & Campus NAC\n- **Capture Filename:** `ipv6_ndp_dualstack.frasm` (18 Ethernet frames)\n- **Protocols Exercised:** `vlan`, `ndp`, `dhcp`, `dns`, `tcp`, `http2`\n\n## Operational Problem\n\nMost test captures sitting in team wikis are IPv4-only from 2014—leaving IPv6 RA\nGuard, DHCPv6 Guard, ICMPv6 pseudo-header rules, and IPv6 application firewall\npolicies completely untested until production turn-up.\n\nCrafting valid IPv6 packets by hand means recalculating 40-byte IPv6 pseudo-header\nchecksums across ICMPv6/TCP/UDP, padding RFC 4861 SLLA/TLLA link-layer options to\n8-byte boundaries, and remembering Hop Limit 255 on NDP so switches don’t drop\nframes as off-link spoofs.\n\nIn FrameAssembly, 78 of the 81 protocols morph between IPv4 and IPv6 automatically\nbased solely on the `host` IP literal—so a single parameterized `flow api_probe(c,\ns)` emits both IPv4 (`0x0800`) and IPv6 (`0x86dd`) captures back-to-back.\n\n## Scenario & Topology: Access VLAN 60 IPv6 SLAAC + DHCPv6 Guard Audit + Dual-Stack HTTP/2 Probe\n\n- **Topology:** `Dual-Stack Client (10.60.1.25 / 2001:db8:60::25) <-> Leaf Switch\n  & Gateway (10.60.1.1 / 2001:db8:60::1)`\n\nEighteen frames validate both first-hop IPv6 security and dual-stack parity: (1)\nHop-Limit-255 `ndp` `routersolicit` -> `routeradvert` + `neighborsolicit` ->\n`neighboradvert` with SLLA/TLLA MAC TLVs; (2) 4-packet `dhcp` v6 `solicit ->\nadvertise -> request -> reply` on UDP 546/547 (`flowlabel 0x60200`); and (3) one\n`dual_stack_http2(c, s)` flow invoked first on IPv4 hosts and then on IPv6 hosts.\n\n## FrameAssembly Workflow\n\nEmits 18 frames: 4 RFC 4861 IPv6 NDP frames, 4 RFC 8415 DHCPv6 SARR frames, and a\n5-frame DNS + TCP + HTTP/2 flow replayed across IPv4 and IPv6.\n\n### Adapt It for Your Network\n\n1. Update client_v6 and gw_v6 to your `2001:db8::` or production `/64` prefix and\n  MACs.\n2. To test switch RA Guard drops, emit an unauthorized `ndp routeradvert\n  routerlifetime 1800` from an untrusted host port.\n3. Compile -> verify both `ip` and `ipv6` protocol trees in Wireshark -> run\n  against dual-stack firewall and IDS rules.\n\n## Runnable Capture Specification (`ipv6_ndp_dualstack.frasm`)\n\n```frameassembly\nhost client_v4 { ip 10.60.1.25       mac 00:1b:21:60:00:25 }\nhost gw_v4     { ip 10.60.1.1        mac 00:1c:73:60:00:01 }\nhost client_v6 { ip 2001:db8:60::25  mac 00:1b:21:60:00:25 }\nhost gw_v6     { ip 2001:db8:60::1   mac 00:1c:73:60:00:01 }\n\nflow ipv6_first_hop_onboarding(host6, rtr6) {\n    // 1. RFC 4861 Neighbor Discovery (Hop Limit 255 + SLLA / TLLA options)\n    host6 -> rtr6 vlan 60 ndp routersolicit slla 00:1b:21:60:00:25 wait 2ms\n    host6 <- rtr6 vlan 60 ndp routeradvert routerlifetime 1800 slla 00:1c:73:60:00:01 wait 3ms\n    host6 -> rtr6 vlan 60 ndp neighborsolicit target 2001:db8:60::1 slla 00:1b:21:60:00:25 wait 1ms\n    host6 <- rtr6 vlan 60 ndp neighboradvert target 2001:db8:60::1 tlla 00:1c:73:60:00:01 wait 2ms\n\n    // 2. RFC 8415 Stateful DHCPv6 SARR on UDP 546 <-> 547 with IPv6 ECMP flowlabel\n    host6 -> rtr6 vlan 60 flowlabel 0x60200 dhcp solicit xid 0x006025 dnsserver 2001:db8:60::53 wait 2ms\n    host6 <- rtr6 vlan 60 flowlabel 0x60200 dhcp advertise xid 0x006025 dnsserver 2001:db8:60::53 wait 1ms\n    host6 -> rtr6 vlan 60 flowlabel 0x60200 dhcp request xid 0x006025 wait 1ms\n    host6 <- rtr6 vlan 60 flowlabel 0x60200 dhcp reply xid 0x006025 dnsserver 2001:db8:60::53 wait 4ms\n}\n\nflow dual_stack_http2(c, s) {\n    // 3. Reusable flow: automatically emits IPv4 or IPv6 + pseudo-header checksums\n    c -> s vlan 60 dscp 26 dns query txid 0x6001 qname \"api.dualstack.internal\" qtype \"AAAA\" wait 2ms\n    c -> s vlan 60 dscp 26 tcp syn srcport 52443 dstport 443 win 65535 mss 1440 wait 1ms\n    c <- s vlan 60 dscp 26 tcp syn ack win 65535 mss 1440 wait 1ms\n    c -> s vlan 60 dscp 26 tcp ack wait 1ms\n    c -> s vlan 60 dscp 26 http2 settings wait 2ms\n}\n\ncompile {\n    ipv6_first_hop_onboarding(client_v6, gw_v6)\n    dual_stack_http2(client_v4, gw_v4)\n    dual_stack_http2(client_v6, gw_v6)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Preview all 18 IPv6 NDP, DHCPv6, and dual-stack IPv4/IPv6 packets\nframeassembly show ipv6_ndp_dualstack.frasm\n\n# 2. Compile to nanosecond .pcapng and inspect ICMPv6 NDP + DHCPv6 options in tshark\nframeassembly ipv6_ndp_dualstack.frasm ipv6_ndp_dualstack.pcapng\ntshark -r ipv6_ndp_dualstack.pcapng\n\n# 3. Replay onto an access trunk to verify RA Guard, DHCPv6 Guard, and dual-stack ACLs\nsudo tcpreplay -i eth0 ipv6_ndp_dualstack.pcapng\n```\n\n## Protocol Reference Links\n\n- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p\n  QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))\n- [`ndp` — IPv6 Neighbor Discovery\n  Protocol](https://frameassembly-lang.dev/docs/protocols/ndp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/ndp.md))\n- [`dhcp` — Dynamic Host Configuration Protocol — DHCPv4 &\n  DHCPv6](https://frameassembly-lang.dev/docs/protocols/dhcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/dhcp.md))\n- [`dns` — Domain Name System over UDP or\n  TCP](https://frameassembly-lang.dev/docs/protocols/dns) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/dns.md))\n- [`tcp` — Transmission Control Protocol & RFC 7323\n  Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))\n- [`http2` — Hypertext Transfer Protocol Version 2 Binary\n  Framing](https://frameassembly-lang.dev/docs/protocols/http2) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/http2.md))\n"}
{"id":"pretrain-usecase-dhcp-dns-radius-nac-pcap","kind":"use_case_playbook","title":"Reproduce Full 802.1X NAC, RADIUS, DHCP DORA & DNS Onboarding — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/dhcp-dns-radius-nac-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","eapol","dns","dhcp","ntp","radius"],"text":"# Reproduce Full 802.1X NAC, RADIUS, DHCP DORA & DNS Onboarding\n\n> **FrameAssembly v3.3.0** · Operational Playbook (IPv6, DDI & Campus NAC) ·\n> Canonical URL: https://frameassembly-lang.dev/use-cases/dhcp-dns-radius-nac-pcap\n\nTrace every packet from plug-in to working network—EAPOL 0x888e, RADIUS UDP 1812,\n4-step DHCPv4 DORA, DNS, and Stratum-1 NTP.\n\n- **Category:** IPv6, DDI & Campus NAC\n- **Capture Filename:** `campus_nac_dora.frasm` (12 Ethernet frames)\n- **Protocols Exercised:** `eapol`, `vlan`, `radius`, `dhcp`, `dns`, `ntp`\n\n## Operational Problem\n\n\"Branch laptops take 90 seconds to get on Wi-Fi/wired\" spans four different\nteams—802.1X switch ports, RADIUS NAC servers, DHCP relays, and DNS/NTP—and nobody\nhas a clean baseline capture showing the whole chain end to end.\n\nCapturing a clean plug-in sequence on a live laptop is surprisingly messy: the OS\nblasts mDNS, LLMNR, WPAD, and cached TLS retries before DHCP even finishes,\nburying the 12 packets you actually care about.\n\nWith FrameAssembly, you can model the pre-IP `0.0.0.0` supplicant, the IEEE\n`01:80:c2:00:00:03` PAE multicast EAPOL handshake, the switch-to-ISE/ClearPass\nRADIUS exchange, all four DHCPv4 DORA frames (`68 <-> 67`), DNS resolution, and\nNTP clock sync in one crystal-clear capture.\n\n## Scenario & Topology: Branch Port Gi1/0/8 Plug-In -> 802.1X Auth -> VLAN 30 DHCP Lease -> DNS + NTP\n\n- **Topology:** `Supplicant PC (0.0.0.0 -> 10.30.0.142) <-> Access Switch\n  (10.30.0.2) <-> Core DDI / RADIUS (10.30.0.10)`\n\nTwelve surgical frames capture the textbook campus boot sequence: (1) `eapol\nstart` + EAP-Identity `\"corp\\\\jdoe\"` (`0x888e`); (2) switch-to-AAA `radius\naccessrequest` <-> `accessaccept` on UDP 1812; (3) full 4-packet DHCPv4 `discover\n-> offer -> request -> ack` assigning `10.30.0.142/24` with Option 3 router and\nOption 6 DNS; and (4) internal `dns` A-record lookup + `ntp` Stratum-1 time sync.\n\n## FrameAssembly Workflow\n\nBuilds 12 campus onboarding frames: 802.1X EAPOL Start/Identity, RADIUS\nAccess-Request/Accept, 4-step DHCPv4 DORA, DNS, and NTP.\n\n### Adapt It for Your Network\n\n1. Adjust boot_pc MAC (`chaddr`), offered lease IP (`yiaddr 10.30.0.142`),\n  `router`, and `dnsserver` to match your branch scope.\n2. To test DHCP Snooping untrusted-port drops, replay the `dhcp offer` frame into\n  an access port.\n3. Compile -> inspect BOOTP magic cookie + options 1/3/6/12/51/53 in Wireshark ->\n  use as a training or DDI test fixture.\n\n## Runnable Capture Specification (`campus_nac_dora.frasm`)\n\n```frameassembly\nhost boot_pc     { ip 0.0.0.0     mac 00:1b:21:30:01:42 }\nhost leased_pc   { ip 10.30.0.142 mac 00:1b:21:30:01:42 }\nhost access_sw   { ip 10.30.0.2   mac 00:1c:73:30:00:02 }\nhost ddi_aaa_srv { ip 10.30.0.10  mac 00:50:56:30:00:10 }\n\nflow dot1x_and_radius_auth(supplicant, sw, aaa) {\n    // 1. IEEE 802.1X EAPOL Start + EAP Identity Response on PAE group MAC\n    supplicant -> sw eapol start version 2 wait 2ms\n    supplicant -> sw eapol eappacket version 2 eapcode 2 eapid 1 eapmethod 1 identity \"corp\\\\jdoe\" wait 3ms\n\n    // 2. Switch relays credentials to RADIUS server (UDP 1812)\n    sw -> aaa vlan 30 radius accessrequest id 77 user \"corp\\\\jdoe\" nasip 10.30.0.2 wait 4ms\n    sw <- aaa vlan 30 radius accessaccept id 77 wait 2ms\n}\n\nflow dhcp_dora_dns_and_ntp(unconf_pc, ready_pc, infra) {\n    // 3. Full 4-packet DHCPv4 DORA lease negotiation (UDP 68 <-> 67)\n    unconf_pc -> infra vlan 30 dhcp discover xid 0x30014200 chaddr 00:1b:21:30:01:42 hostname \"branch-lt-42\" wait 2ms\n    unconf_pc <- infra vlan 30 dhcp offer xid 0x30014200 yiaddr 10.30.0.142 siaddr 10.30.0.10 chaddr 00:1b:21:30:01:42 subnetmask 255.255.255.0 router 10.30.0.1 dnsserver 10.30.0.10 leasetime 28800 wait 2ms\n    unconf_pc -> infra vlan 30 dhcp request xid 0x30014200 chaddr 00:1b:21:30:01:42 hostname \"branch-lt-42\" wait 1ms\n    unconf_pc <- infra vlan 30 dhcp ack xid 0x30014200 yiaddr 10.30.0.142 siaddr 10.30.0.10 chaddr 00:1b:21:30:01:42 subnetmask 255.255.255.0 router 10.30.0.1 dnsserver 10.30.0.10 leasetime 28800 wait 5ms\n\n    // 4. Post-lease split-horizon DNS lookup + Stratum-1 NTP clock sync\n    ready_pc -> infra vlan 30 dns query txid 0x8801 qname \"intranet.corp.example\" qtype \"A\" wait 2ms\n    ready_pc <- infra vlan 30 dns response txid 0x8801 qname \"intranet.corp.example\" qtype \"A\" rdata \"10.30.20.80\" wait 3ms\n    ready_pc -> infra vlan 30 ntp vn 4 mode 3 poll 6 wait 2ms\n    ready_pc <- infra vlan 30 ntp li 0 vn 4 mode 4 stratum 1 poll 6 refid \"GPS\" wait 1ms\n}\n\ncompile {\n    dot1x_and_radius_auth(boot_pc, access_sw, ddi_aaa_srv)\n    dhcp_dora_dns_and_ntp(boot_pc, leased_pc, ddi_aaa_srv)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Preview the 12-step 802.1X -> RADIUS -> DHCP DORA -> DNS -> NTP ladder\nframeassembly show campus_nac_dora.frasm\n\n# 2. Compile to .pcap and inspect EAPOL, RADIUS, DHCP options, DNS, and NTP in tshark\nframeassembly campus_nac_dora.frasm campus_nac_dora.pcap\ntshark -r campus_nac_dora.pcap\n\n# 3. Replay into DDI / NAC lab interfaces or Wireshark training sessions\nsudo tcpreplay -i eth0 campus_nac_dora.pcap\n```\n\n## Protocol Reference Links\n\n- [`eapol` — IEEE 802.1X Port-Based Network Access Control (EAP over\n  LAN)](https://frameassembly-lang.dev/docs/protocols/eapol) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/eapol.md))\n- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p\n  QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))\n- [`radius` — Remote Authentication Dial-In User Service (Auth &\n  Accounting)](https://frameassembly-lang.dev/docs/protocols/radius) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/radius.md))\n- [`dhcp` — Dynamic Host Configuration Protocol — DHCPv4 &\n  DHCPv6](https://frameassembly-lang.dev/docs/protocols/dhcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/dhcp.md))\n- [`dns` — Domain Name System over UDP or\n  TCP](https://frameassembly-lang.dev/docs/protocols/dns) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/dns.md))\n- [`ntp` — Network Time Protocol\n  v1–v4](https://frameassembly-lang.dev/docs/protocols/ntp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/ntp.md))\n"}
{"id":"pretrain-usecase-cicd-pcap-regression-testing","kind":"use_case_playbook","title":"Replace Mystery Binary .pcap Fixtures in Git & CI/CD With .frasm — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/cicd-pcap-regression-testing","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp","http2","grpc","postgres","mqtt"],"text":"# Replace Mystery Binary .pcap Fixtures in Git & CI/CD With .frasm\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Sanitize PCAP & CI/CD) ·\n> Canonical URL:\n> https://frameassembly-lang.dev/use-cases/cicd-pcap-regression-testing\n\nBuild deterministic gRPC, PostgreSQL v3.0, and MQTT QoS 1 captures on the fly in\nGitHub Actions, GitLab CI, or Rust integration tests.\n\n- **Category:** Sanitize PCAP & CI/CD\n- **Capture Filename:** `cicd_parser_suite.frasm` (22 Ethernet frames)\n- **Protocols Exercised:** `tcp`, `http2`, `grpc`, `postgres`, `mqtt`\n\n## Operational Problem\n\nEvery DPI, eBPF/XDP, service-mesh, or SIEM repository has a cursed\n`tests/fixtures/` folder stuffed with binary `.pcap` blobs nobody can review in a\npull request or update without breaking TCP sequence numbers.\n\nBinary `.pcap` files are miserable in Git: `git diff` just prints `Binary files\ndiffer`, security scanners flag unknown binary blobs, and changing a gRPC method\nname or SQL query string requires recapturing live microservices in Docker.\n\nChecking in `.frasm` text files (`text/vnd.frameassembly`) gives pull-request\nreviewers line-by-line diffs while the rootless `frameassembly` CLI or Rust\n`frameassembly` crate compiles byte-identical `.pcap` / `.pcapng` fixtures in\nunder 1 millisecond during CI.\n\n## Scenario & Topology: Microservice & Telemetry Parser CI Suite (gRPC + PostgreSQL v3.0 + MQTT QoS 1)\n\n- **Topology:** `App Gateway (10.90.1.10) <-> gRPC Mesh (:50051), PostgreSQL\n  (:5432) & MQTT Broker (:1883)`\n\nTwenty-two deterministic frames exercise three complex binary/framed Layer 7\ndissectors in a single CI fixture: (1) TCP 50051 handshake + `http2 settings` +\n`grpc` `/ledger.Payments/Authorize` (`grpcstatus 0` OK followed by `grpcstatus 14`\nUNAVAILABLE); (2) TCP 5432 handshake + `postgres startup` -> `authok` -> `query`\n-> `errorresponse`; and (3) TCP 1883 handshake + `mqtt connect` -> `connack` ->\n`qos 1` retained `publish` -> `puback`.\n\n## FrameAssembly Workflow\n\nCompiles 22 multi-service frames (HTTP/2 + gRPC status trailers, PostgreSQL v3.0\nwire frames, and OASIS MQTT QoS 1) with deterministic timestamps.\n\n### Adapt It for Your Network\n\n1. Commit `.frasm` specs alongside your Suricata rules, Zeek scripts, eBPF\n  parsers, or Wireshark Lua dissectors in Git.\n2. Compile to `.pcap` or nanosecond `.pcapng` inside CI via the `frameassembly`\n  CLI or `cargo add --dev frameassembly`.\n3. When an existing binary fixture needs updating, run `frameassembly reverse\n  legacy.pcap fixture.frasm` once and delete the opaque blob.\n\n## Runnable Capture Specification (`cicd_parser_suite.frasm`)\n\n```frameassembly\nhost app_gw     { ip 10.90.1.10 }\nhost backend_sv { ip 10.90.2.50 }\n\nflow grpc_mesh_fixture(c, s) {\n    // 1. HTTP/2 + gRPC call succeeding (0) and failing over (14 UNAVAILABLE) on TCP 50051\n    c -> s tcp syn srcport 55051 dstport 50051 win 65535 mss 1460 wait 1ms\n    c <- s tcp syn ack win 65535 mss 1460 wait 1ms\n    c -> s tcp ack wait 1ms\n    c -> s http2 settings wait 1ms\n    c -> s grpc service \"ledger.Payments\" method \"Authorize\" wait 2ms\n    c <- s grpc grpcstatus 0 wait 2ms\n    c -> s grpc service \"ledger.Payments\" method \"Settle\" wait 2ms\n    c <- s grpc grpcstatus 14 wait 3ms\n}\n\nflow postgres_and_mqtt_fixtures(c, s) {\n    // 2. PostgreSQL v3.0 Startup -> AuthOk -> SQL Query -> ErrorResponse on TCP 5432\n    c -> s tcp syn srcport 55432 dstport 5432 win 65535 mss 1460 wait 1ms\n    c <- s tcp syn ack win 65535 mss 1460 wait 1ms\n    c -> s tcp ack wait 1ms\n    c -> s postgres startup user \"ci_runner\" db \"ledger\" wait 1ms\n    c <- s postgres authok wait 1ms\n    c -> s postgres query sql \"SELECT tx_id, amount_cents FROM transfers LIMIT 5;\" wait 2ms\n    c <- s postgres errorresponse wait 3ms\n\n    // 3. OASIS MQTT v3.1.1 Connect -> ConnAck -> QoS 1 Publish -> PubAck on TCP 1883\n    c -> s tcp syn srcport 51883 dstport 1883 win 65535 mss 1460 wait 1ms\n    c <- s tcp syn ack win 65535 mss 1460 wait 1ms\n    c -> s tcp ack wait 1ms\n    c -> s mqtt connect clientid \"ci-sensor-01\" keepalive 30 wait 1ms\n    c <- s mqtt connack returncode 0 wait 1ms\n    c -> s mqtt publish topic \"ci/line1/watts\" qos 1 retain pktid 10 payload \"{\\\"w\\\":412.5}\" wait 1ms\n    c <- s mqtt puback pktid 10 wait 1ms\n}\n\ncompile {\n    grpc_mesh_fixture(app_gw, backend_sv)\n    postgres_and_mqtt_fixtures(app_gw, backend_sv)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Compile deterministic .pcapng in CI/CD (under 1ms, zero root privileges)\nframeassembly cicd_parser_suite.frasm cicd_parser_suite.pcapng\n\n# 2. Assert decoded gRPC, PostgreSQL, and MQTT fields in automated tshark / Zeek checks\ntshark -r cicd_parser_suite.pcapng -Y \"grpc || pgsql || mqtt\"\n\n# 3. Or convert legacy binary Git fixtures into reviewable .frasm source once\nframeassembly reverse legacy_fixture.pcap readable_fixture.frasm\n```\n\n## Protocol Reference Links\n\n- [`tcp` — Transmission Control Protocol & RFC 7323\n  Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))\n- [`http2` — Hypertext Transfer Protocol Version 2 Binary\n  Framing](https://frameassembly-lang.dev/docs/protocols/http2) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/http2.md))\n- [`grpc` — gRPC Remote Procedure Calls over\n  HTTP/2](https://frameassembly-lang.dev/docs/protocols/grpc) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/grpc.md))\n- [`postgres` — PostgreSQL Frontend/Backend Wire Protocol\n  v3.0](https://frameassembly-lang.dev/docs/protocols/postgres) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/postgres.md))\n- [`mqtt` — Message Queuing Telemetry Transport (IoT &\n  IIoT)](https://frameassembly-lang.dev/docs/protocols/mqtt) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/mqtt.md))\n"}
{"id":"pretrain-usecase-tcp-retransmission-zero-window-pcap","kind":"use_case_playbook","title":"Reproduce TCP Retransmissions, Out-of-Order & Zero-Window Stalls — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/tcp-retransmission-zero-window-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tcp"],"text":"# Reproduce TCP Retransmissions, Out-of-Order & Zero-Window Stalls\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Routing, VLANs & Overlays) ·\n> Canonical URL:\n> https://frameassembly-lang.dev/use-cases/tcp-retransmission-zero-window-pcap\n\nTrigger Wireshark tcp.analysis.fast_retransmission, out_of_order, zero_window, and\nwindow_update flags deterministically on demand.\n\n- **Category:** Routing, VLANs & Overlays\n- **Capture Filename:** `tcp_anomalies_stall.frasm` (12 Ethernet frames)\n- **Protocols Exercised:** `tcp`\n\n## Operational Problem\n\nWhen an application team blames \"random network packet loss\" for API timeouts—or\nyou need to test how an L7 proxy, middlebox, or APM agent handles TCP Zero-Window\nstalls and out-of-order segments—your OS kernel flatly refuses to emit broken TCP\nsequences on command.\n\nLinux `tc netem` can drop or reorder a random percentage of live packets, which\nmeans every capture is non-deterministic and impossible to assert against in a\nregression suite. Meanwhile, normal user-space sockets cannot advertise `win 0`\nfollowed 25ms later by a `win 65535` Window Update.\n\nIn FrameAssembly, automatic 4-tuple tracking handles the boring segments while\nexplicit `seq`, `acknum`, and `win` overrides let you inject exact sequence holes,\nduplicate ACKs, fast retransmissions, Zero-Window probes, and `rst ack` aborts on\nspecific lines.\n\n## Scenario & Topology: Microservice TCP 8443 Sequence Hole, Fast Retransmit & Zero-Window Backpressure\n\n- **Topology:** `App Client (10.44.1.15:54120) <-> Load Balancer / WAN <-> API\n  Server (10.44.2.80:8443)`\n\nTwelve surgical TCP segments reproduce every classic Wireshark Expert Info alert\nin one trace: (1) a `sackperm` + `wscale 7` 3-way handshake; (2) `CHUNK_01` at\n`seq 1001` followed immediately by out-of-order `CHUNK_03` at `seq 1033` (skipping\n`1017..1033`); (3) two server Duplicate ACKs (`acknum 1017`) triggering client\nFast Retransmission of `CHUNK_02` at `seq 1017`; and (4) server receive-buffer\nexhaustion (`win 0`), a 1-byte client Zero-Window Probe, a `win 65535` Window\nUpdate, and `rst ack` teardown.\n\n## FrameAssembly Workflow\n\nEmits 12 TCP segments exercising out-of-order delivery, duplicate ACKs, fast\nretransmission, Zero-Window (`win 0`) + probe + Window Update, and RST.\n\n### Adapt It for Your Network\n\n1. Change app_client, api_server, and `dstport 8443` to match the service tuple\n  your APM sensor or middlebox monitors.\n2. Adjust `seq` offsets by exact payload byte lengths (16 bytes per `CHUNK_*` in\n  this template) to move or widen the sequence hole.\n3. Compile -> inspect `tcp.analysis.flags` in Wireshark or `tshark` -> feed into\n  Suricata stream-reassembly or proxy tests.\n\n## Runnable Capture Specification (`tcp_anomalies_stall.frasm`)\n\n```frameassembly\nhost app_client { ip 10.44.1.15 mac 00:1b:21:44:01:15 }\nhost api_server { ip 10.44.2.80 mac 00:1c:73:44:02:80 }\n\nflow tcp_retransmit_and_zerowin(c, s) {\n    // 1. 3-way handshake negotiating MSS 1460, Window Scale 7, and SACK Permitted\n    c -> s tcp syn srcport 54120 dstport 8443 seq 1000 win 64240 mss 1460 wscale 7 sackperm wait 1ms\n    c <- s tcp syn ack seq 5000 acknum 1001 win 65535 mss 1460 wscale 7 sackperm wait 1ms\n    c -> s tcp ack seq 1001 acknum 5001 win 64240 wait 1ms\n\n    // 2. CHUNK_01 (seq 1001..1017), then CHUNK_03 arrives out-of-order at seq 1033\n    c -> s tcp psh ack seq 1001 acknum 5001 win 64240 payload \"CHUNK_01_16BYTES\" wait 2ms\n    c -> s tcp psh ack seq 1033 acknum 5001 win 64240 payload \"CHUNK_03_OUT_ORD\" wait 1ms\n\n    // 3. Server sends 2 Duplicate ACKs for 1017 -> Client fast-retransmits missing CHUNK_02\n    c <- s tcp ack seq 5001 acknum 1017 win 65535 wait 1ms\n    c <- s tcp ack seq 5001 acknum 1017 win 65535 wait 1ms\n    c -> s tcp psh ack seq 1017 acknum 5001 win 64240 payload \"CHUNK_02_RETRANS\" wait 2ms\n\n    // 4. Server buffer fills (ZeroWindow win 0) -> Client 1B probe -> Window Update -> RST\n    c <- s tcp ack seq 5001 acknum 1049 win 0 wait 25ms\n    c -> s tcp ack seq 1049 acknum 5001 win 64240 payload \"Z\" wait 5ms\n    c <- s tcp ack seq 5001 acknum 1050 win 65535 wait 2ms\n    c <- s tcp rst ack seq 5001 acknum 1050 win 0 wait 1ms\n}\n\ncompile {\n    tcp_retransmit_and_zerowin(app_client, api_server)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Preview the 12-frame TCP retransmission & Zero-Window timeline\nframeassembly show tcp_anomalies_stall.frasm\n\n# 2. Compile to .pcap and verify Wireshark tcp.analysis flags in tshark\nframeassembly tcp_anomalies_stall.frasm tcp_anomalies_stall.pcap\ntshark -r tcp_anomalies_stall.pcap -Y \"tcp.analysis.flags\"\n\n# 3. Feed into Suricata stream engine or APM / middlebox parser tests\nsuricata -r tcp_anomalies_stall.pcap -k none -l ./suricata_tcp/\n```\n\n## Protocol Reference Links\n\n- [`tcp` — Transmission Control Protocol & RFC 7323\n  Options](https://frameassembly-lang.dev/docs/protocols/tcp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/tcp.md))\n"}
{"id":"pretrain-usecase-dns-nxdomain-traceroute-igmp-pcap","kind":"use_case_playbook","title":"Simulate DNS NXDOMAIN / SERVFAIL, Traceroute TTL Hops & IGMP Snooping — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/dns-nxdomain-traceroute-igmp-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","icmp","igmp","udp","dns"],"text":"# Simulate DNS NXDOMAIN / SERVFAIL, Traceroute TTL Hops & IGMP Snooping\n\n> **FrameAssembly v3.3.0** · Operational Playbook (IPv6, DDI & Campus NAC) ·\n> Canonical URL:\n> https://frameassembly-lang.dev/use-cases/dns-nxdomain-traceroute-igmp-pcap\n\nTest negative DNS caching, hop-by-hop ICMP Time Exceeded traceroute paths, and\nVLAN 50 IGMPv2/v3 multicast joins and leaves in 11 frames.\n\n- **Category:** IPv6, DDI & Campus NAC\n- **Capture Filename:** `dns_traceroute_igmp.frasm` (11 Ethernet frames)\n- **Protocols Exercised:** `vlan`, `dns`, `udp`, `icmp`, `igmp`\n\n## Operational Problem\n\nReproducing negative DNS responses (`NXDOMAIN` / `SERVFAIL`), multi-hop `ttl 1` ->\n`icmp timeexceeded` traceroute ladders, and switch IGMP Snooping group\njoins/leaves normally takes broken upstream zones, three routed hops, and a live\nmulticast receiver.\n\nDDI monitoring pipelines and SIEM DNS threat-hunting rules often get tested\nexclusively against happy `NOERROR` (`rcode 0`) lookups—missing broken DNSSEC\n`SERVFAIL` (`rcode 2`) storms or DGA `NXDOMAIN` (`rcode 3`) bursts until an outage\nhits.\n\nLikewise, verifying campus switch IGMP Snooping and multicast pruning on VLAN 50\nrequires an RFC 2236 General Query to `224.0.0.1` (`01:00:5e:00:00:01`), an RFC\n3376 IGMPv3 Membership Report (`0x22`), and an IGMPv2 Fast Leave (`0x17`)—all with\nvalid IPv4 Protocol 2 checksums at `ttl 1`.\n\n## Scenario & Topology: Branch VLAN 50 DNS Triage + 2-Hop UDP Traceroute + IPTV Multicast Join/Leave\n\n- **Topology:** `Branch Client (10.50.10.25) -> Hop-1 Router (10.50.10.1) -> Core\n  DNS (10.50.0.53) & Multicast (224.0.0.1 / 239.50.1.100)`\n\nEleven VLAN-50 packets validate three everyday NetOps workflows: (1) DNS `rcode 3`\n(`NXDOMAIN`) for a retired hostname plus `rcode 2` (`SERVFAIL`) for a broken\nupstream zone; (2) classic Unix UDP traceroute probes (`dstport 33434/33435`) at\n`ttl 1` (answered by Hop-1 `icmp timeexceeded`) and `ttl 2` (answered by\ndestination `icmp destunreach code 3` Port Unreachable); and (3) router `igmp v2\nquery` followed by receiver `igmp v3 report` and `igmp v2 leave` for\n`239.50.1.100`.\n\n## FrameAssembly Workflow\n\nCompiles 11 VLAN-50 frames covering DNS NXDOMAIN + SERVFAIL, a 2-hop TTL-expiry\nUDP traceroute, and IGMPv2/v3 Query/Report/Leave.\n\n### Adapt It for Your Network\n\n1. Swap `qname` and `rcode` (`2` SERVFAIL, `3` NXDOMAIN, `5` REFUSED) to match\n  your DNS alerting thresholds.\n2. Add extra hop `host` blocks (`ttl 1`, `ttl 2`, `ttl 3`) to model longer\n  traceroute topologies.\n3. Replay the IGMP frames into a test VLAN to confirm switch IGMP Snooping prunes\n  `239.50.1.100` after `igmp v2 leave`.\n\n## Runnable Capture Specification (`dns_traceroute_igmp.frasm`)\n\n```frameassembly\nhost branch_client { ip 10.50.10.25  mac 00:1b:21:50:10:25 }\nhost hop1_router   { ip 10.50.10.1   mac 00:1c:73:50:10:01 }\nhost core_dns_vip  { ip 10.50.0.53   mac 00:50:56:50:00:53 }\nhost all_hosts_mc  { ip 224.0.0.1 }\nhost iptv_group_mc { ip 239.50.1.100 }\n\nflow dns_failures_and_traceroute(client, hop1, dns_srv) {\n    // 1. Negative DNS responses: RCODE 3 (NXDOMAIN) & RCODE 2 (SERVFAIL)\n    client -> dns_srv vlan 50 dns query txid 0x9101 qname \"retired-db.corp.example\" qtype \"A\" wait 2ms\n    client <- dns_srv vlan 50 dns response txid 0x9101 qname \"retired-db.corp.example\" qtype \"A\" rcode 3 wait 3ms\n    client -> dns_srv vlan 50 dns query txid 0x9102 qname \"broken-dnssec.partner.example\" qtype \"A\" wait 2ms\n    client <- dns_srv vlan 50 dns response txid 0x9102 qname \"broken-dnssec.partner.example\" qtype \"A\" rcode 2 wait 4ms\n\n    // 2. 2-hop UDP traceroute: TTL=1 expires at hop1 -> TTL=2 reaches core_dns_vip\n    client -> dns_srv vlan 50 ttl 1 udp srcport 53100 dstport 33434 payload \"TRACEROUTE_HOP_1\" wait 2ms\n    hop1 -> client vlan 50 ttl 64 icmp timeexceeded code 0 wait 2ms\n    client -> dns_srv vlan 50 ttl 2 udp srcport 53101 dstport 33435 payload \"TRACEROUTE_HOP_2\" wait 2ms\n    client <- dns_srv vlan 50 ttl 63 icmp destunreach code 3 wait 3ms\n}\n\nflow igmp_snooping_lifecycle(client, rtr, all_mc, group_mc) {\n    // 3. Switch IGMP Snooping: v2 General Query -> v3 Join Report -> v2 Fast Leave\n    rtr -> all_mc vlan 50 ttl 1 igmp v2 query group 0.0.0.0 maxresp 100 wait 3ms\n    client -> group_mc vlan 50 ttl 1 igmp v3 report group 239.50.1.100 wait 10ms\n    client -> group_mc vlan 50 ttl 1 igmp v2 leave group 239.50.1.100 wait 2ms\n}\n\ncompile {\n    dns_failures_and_traceroute(branch_client, hop1_router, core_dns_vip)\n    igmp_snooping_lifecycle(branch_client, hop1_router, all_hosts_mc, iptv_group_mc)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Preview all 11 DNS failure, traceroute TTL, and IGMP multicast frames\nframeassembly show dns_traceroute_igmp.frasm\n\n# 2. Compile to .pcap and inspect DNS rcode, ICMP Time Exceeded, and IGMP groups\nframeassembly dns_traceroute_igmp.frasm dns_traceroute_igmp.pcap\ntshark -r dns_traceroute_igmp.pcap -Y \"dns || icmp || igmp\"\n\n# 3. Replay onto a lab trunk to test switch IGMP Snooping & SIEM DNS alerts\nsudo tcpreplay -i eth0 dns_traceroute_igmp.pcap\n```\n\n## Protocol Reference Links\n\n- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p\n  QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))\n- [`dns` — Domain Name System over UDP or\n  TCP](https://frameassembly-lang.dev/docs/protocols/dns) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/dns.md))\n- [`udp` — User Datagram\n  Protocol](https://frameassembly-lang.dev/docs/protocols/udp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/udp.md))\n- [`icmp` — Internet Control Message Protocol v4 & Dual-Stack\n  ICMPv6](https://frameassembly-lang.dev/docs/protocols/icmp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/icmp.md))\n- [`igmp` — Internet Group Management Protocol v1, v2 &\n  v3](https://frameassembly-lang.dev/docs/protocols/igmp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/igmp.md))\n"}
{"id":"pretrain-usecase-netflow-ipfix-sflow-ptp-telemetry-pcap","kind":"use_case_playbook","title":"Validate NetFlow v5, Dual-Stack IPFIX, sFlow & Nanosecond PTPv2 — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/use-cases/netflow-ipfix-sflow-ptp-telemetry-pcap","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["ptp","netflow","ipfix","sflow"],"text":"# Validate NetFlow v5, Dual-Stack IPFIX, sFlow & Nanosecond PTPv2\n\n> **FrameAssembly v3.3.0** · Operational Playbook (Telemetry, VoIP & OT) ·\n> Canonical URL:\n> https://frameassembly-lang.dev/use-cases/netflow-ipfix-sflow-ptp-telemetry-pcap\n\nSelf-templated IPFIX (zero missing-template blind spots), NetFlow v5, sFlow v5,\nand sub-microsecond IEEE 1588v2 PTP ready for .pcapng.\n\n- **Category:** Telemetry, VoIP & OT\n- **Capture Filename:** `telemetry_ptp_suite.frasm` (10 Ethernet frames)\n- **Protocols Exercised:** `netflow`, `ipfix`, `sflow`, `ptp`\n\n## Operational Problem\n\nTesting flow ingestion pipelines (ElastiFlow, Akvorado, pmacct, GoFlow2) and\nprecision timing monitors is notoriously painful: IPFIX collectors drop Data Sets\nuntil a periodic Template Set arrives, and classic `.pcap` files round\nsub-microsecond IEEE 1588v2 PTP hardware timestamps to microseconds.\n\nCapturing live IPFIX (UDP 4739) from a production spine switch often gives you\norphan Data Sets that Wireshark (`cflow`) and CI tests cannot decode because\nTemplate Set 2 was sent 10 minutes earlier. FrameAssembly packs both Template Set\n`2` and Data Set `256` inside every `ipfix` packet—switching automatically between\nIPv4 and 128-bit IPv6 Information Elements.\n\nFor broadcast media (SMPTE ST 2110), 5G fronthaul, and trading fabrics,\nFrameAssembly also pairs Event (`UDP 319`) and General (`UDP 320`) IEEE 1588v2\n`ptp` frames with `ns`/`us` post-packet `wait` intervals—preserving exact `1ns`\n(`IfTsResol = 9`) resolution when exported as `.pcapng`.\n\n## Scenario & Topology: Spine Telemetry Ingest (NetFlow v5 + IPv4/IPv6 IPFIX + sFlow v5) & Two-Step PTPv2 Sync\n\n- **Topology:** `Spine Exporter / Grandmaster (172.20.0.1) <-> Collector &\n  Boundary Clock (172.20.50.10)`\n\nTen packets exercise your entire observability and timing stack: (1) Cisco\n`netflow` v5 (UDP 2055) reporting a 12 MB HTTPS transfer; (2) self-templated\n`ipfix` (UDP 4739) exporting both a VRF-10 IPv4 flow and a VRF-20 IPv6 gRPC flow;\n(3) XDR-aligned `sflow` v5 packet samples (UDP 6343) across two `seq` numbers; and\n(4) a complete 5-packet two-step IEEE 1588v2 `ptp` exchange (`announce -> sync ->\nfollowup -> delayreq -> delayresp`) spaced at `120us`–`500ns` intervals.\n\n## FrameAssembly Workflow\n\nEmits 10 frames: NetFlow v5, dual-stack self-templated IPFIX, sFlow v5, and a\n5-packet sub-microsecond two-step PTPv2 loop (`.pcapng` ready).\n\n### Adapt It for Your Network\n\n1. Point spine_exporter and telemetry_col at your flow collector IPs, and adjust\n  `dstport` if your NetFlow listener uses UDP 9995.\n2. Set `domain 127` (SMPTE ST 2059-2), `24`/`44` (ITU-T G.8275 telecom), or `0`\n  (default IEEE 1588) on the `ptp` lines.\n3. Export as `.pcapng` (`frameassembly telemetry_ptp_suite.frasm\n  telemetry_ptp_suite.pcapng`) to preserve `wait 500ns` / `120us` nanosecond\n  timestamps.\n\n## Runnable Capture Specification (`telemetry_ptp_suite.frasm`)\n\n```frameassembly\nhost spine_exporter { ip 172.20.0.1    mac 00:1c:73:d0:00:01 }\nhost telemetry_col  { ip 172.20.50.10  mac 00:50:56:d0:50:10 }\n\nflow flow_collectors_ingest(exp, col) {\n    // 1. Cisco NetFlow v5 (UDP 2055) + Dual-Stack Self-Templated IPFIX (UDP 4739)\n    exp -> col netflow srcip 10.20.5.14 dstip 203.0.113.80 srcport 54120 dstport 443 proto 6 packets 8500 octets 12240000 wait 2ms\n    exp -> col ipfix domainid 10 srcip 10.100.4.15 dstip 198.51.100.44 srcport 50112 dstport 443 proto 6 packets 420 octets 512000 wait 2ms\n    exp -> col ipfix domainid 20 srcip 2001:db8:20::15 dstip 2001:db8:99::5051 srcport 54200 dstport 50051 proto 6 packets 95 octets 84000 wait 2ms\n\n    // 2. Switch sFlow v5 XDR packet sampling on UDP 6343\n    exp -> col sflow agentip 172.20.0.1 subagentid 1 seq 101 uptime 450000 samples 1 wait 1ms\n    exp -> col sflow agentip 172.20.0.1 subagentid 1 seq 102 uptime 451000 samples 1 wait 2ms\n}\n\nflow ptpv2_twostep_nanosecond_sync(gm, slave) {\n    // 3. IEEE 1588v2 Two-Step PTP (UDP 320 General + UDP 319 Event) with us/ns precision\n    gm -> slave dscp 46 ptp announce domain 127 seqid 500 clockid \"ec4670fffe010203\" wait 250us\n    gm -> slave dscp 46 ptp sync domain 127 seqid 501 clockid \"ec4670fffe010203\" wait 500ns\n    gm -> slave dscp 46 ptp followup domain 127 seqid 501 clockid \"ec4670fffe010203\" wait 180us\n    slave -> gm dscp 46 ptp delayreq domain 127 seqid 88 clockid \"005056fffed05010\" wait 120us\n    gm -> slave dscp 46 ptp delayresp domain 127 seqid 88 clockid \"ec4670fffe010203\" wait 1ms\n}\n\ncompile {\n    flow_collectors_ingest(spine_exporter, telemetry_col)\n    ptpv2_twostep_nanosecond_sync(spine_exporter, telemetry_col)\n}\n```\n\n## Equivalent CLI Commands\n\n```bash\n# 1. Compile to nanosecond-precision .pcapng (preserves wait 500ns / 120us timestamps!)\nframeassembly telemetry_ptp_suite.frasm telemetry_ptp_suite.pcapng\n\n# 2. Verify NetFlow/IPFIX (cflow), sFlow v5, and PTPv2 fields in tshark\ntshark -r telemetry_ptp_suite.pcapng -Y \"cflow || sflow || ptp\"\n\n# 3. Replay toward ElastiFlow, Akvorado, GoFlow2, pmacct, or PTP boundary-clock monitors\nsudo tcpreplay -i eth0 telemetry_ptp_suite.pcapng\n```\n\n## Protocol Reference Links\n\n- [`netflow` — Cisco NetFlow Version 5 Flow\n  Export](https://frameassembly-lang.dev/docs/protocols/netflow) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/netflow.md))\n- [`ipfix` — IP Flow Information Export (NetFlow\n  v10)](https://frameassembly-lang.dev/docs/protocols/ipfix) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/ipfix.md))\n- [`sflow` — sFlow Version 5 Switched & Routed Packet\n  Sampling](https://frameassembly-lang.dev/docs/protocols/sflow) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/sflow.md))\n- [`ptp` — IEEE 1588 Precision Time Protocol\n  v2](https://frameassembly-lang.dev/docs/protocols/ptp) ([Raw\n  .md](https://frameassembly-lang.dev/docs/protocols/ptp.md))\n"}
{"id":"pretrain-lab-chapter-0-intro","kind":"interactive_lab","title":"Lab 0: Chapter 0: Introduction and Use Cases — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/learn","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":[],"text":"# Lab 0: Chapter 0: Introduction and Use Cases\n\n> FrameAssembly v3.3.0 · Interactive Packet Lab · MIT License · Canonical URL:\n> https://frameassembly-lang.dev/learn\n\nWhy FrameAssembly exists for network technicians, four everyday packet jobs it\nsolves without Python or root sockets, and a 30-second live sandbox warm-up.\n\n## Operational Scenario\n\nClick through the four real-world technician captures in the live sandbox on the\nright, then tweak one host IP address before starting Chapter 1.\n\n## Learning Objectives\n\n- Understand why `host` + `compile` with `->` and `<-` arrows replaces raw-socket\n  Python scripts and brittle hex edits.\n- Explore live Firewall VLAN 20, Encrypted SNMPv3 Trap, Basic Port Scan, and TAC\n  `.pcap` scrubbing captures in your browser.\n- Change one host IP address and watch every Ethernet/IP/TCP/UDP header\n  recalculate automatically.\n\n## Why FrameAssembly Exists\n\nOn a real shift, network technicians need test packets fast: verifying that Zabbix\nor PRTG actually pages on an encrypted SNMPv3 linkDown trap, proving a\nFriday-night VLAN 20 firewall ACL passes HTTPS before Monday morning, testing IDS\nscan alerts, or scrubbing private customer subnets before attaching a .pcap to a\nvendor TAC ticket.\n\nTraditional packet tools get in the way. Python + Scapy forces you to wrestle\nimports, sudo raw-socket permissions, and manual TCP sequence math. Meanwhile\ntcprewrite can swap outer Layer 3 IPs, only to break packet lengths and checksums\nthe moment an internal DNS hostname or TLS SNI changes length.\n\nFrameAssembly (.frasm <-> .pcap) treats packet captures like a readable whiteboard\nladder diagram: list your devices in host, draw -> and <- packet lines inside\ncompile, and let the local compiler build every Ethernet tag, IP length, stateful\nTCP counter, and SNMPv3 key—or reverse any existing .pcap back into plain text.\n\n## How to Read Any .frasm File in 5 Seconds\n\nLook at the editor beside this panel. Every `.frasm` file reads just like the\npacket ladder you sketch on a whiteboard during an outage:\n\n- Top (`host`): Lists each device on the wire with its plain IPv4, IPv6, or MAC\n  address.\n- Bottom (`compile`): Sends packets top-to-bottom using `->` and `<-` (`1 line = 1\n  Ethernet frame`).\n- File extension: FrameAssembly files always end in `.frasm`\n  (`text/vnd.frameassembly`).\n\n## Complete Lab Solution (`branch_vlan20_https.frasm`)\n\n```frameassembly\n// 1. Declare the branch workstation (updated IP!) and internal HTTPS portal\nhost branch_pc { ip 10.20.10.50 }\nhost portal_gw { ip 10.20.90.80 }\n\n// 2. Tag every frame on VLAN 20: 3-way TCP handshake + TLS ClientHello\ncompile {\n    branch_pc -> portal_gw vlan 20 tcp syn srcport 51200 dstport 443 win 65535 mss 1460 wait 2ms\n    branch_pc <- portal_gw vlan 20 tcp syn ack win 65535 mss 1460 wait 2ms\n    branch_pc -> portal_gw vlan 20 tcp ack wait 1ms\n    branch_pc -> portal_gw vlan 20 tls clienthello sni \"portal.corp.internal\" alpn \"h2\"\n}\n```\n\n```bash\n# Compile straight to branch_vlan20_https.pcap\nframeassembly branch_vlan20_https.frasm\n\n# Or inspect the packet ladder in your terminal without writing a file\nframeassembly show branch_vlan20_https.frasm\n```\n"}
{"id":"pretrain-lab-chapter-1-first-pcap","kind":"interactive_lab","title":"Lab 1: Chapter 1: Core Syntax & Basic Ping (`host` + `compile`) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/learn","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["icmp"],"text":"# Lab 1: Chapter 1: Core Syntax & Basic Ping (`host` + `compile`)\n\n> FrameAssembly v3.3.0 · Interactive Packet Lab · MIT License · Canonical URL:\n> https://frameassembly-lang.dev/learn\n\nLearn the two-block `.frasm` layout, the lowercase keyword rule, and how to build\na 4-packet LAN ping capture from scratch.\n\n## Operational Scenario\n\nA user ticket claims \"the LAN is down.\" Build a clean 4-packet ping capture\n(`laptop -> gateway` and `laptop -> dns_srv`) to test Wireshark display filters\nand baseline connectivity.\n\n## Learning Objectives\n\n- Declare network devices with `host name { ip ... }` using plain IPv4 or IPv6\n  addresses.\n- Send Ethernet frames top-to-bottom inside `compile { ... }` (`1 line = 1 frame`\n  on the wire).\n- Apply the Golden Keyword Rule: built-in keywords are lowercase letters + digits\n  with zero underscores (`echorequest`, never `echo_request`).\n\n## 1. `host` — Naming the Devices on Your Segment\n\nEvery `.frasm` file opens by listing the devices on the wire with `host`. Give\neach device a clear label (`laptop`, `dns_srv`, `fw-dmz-01`) and put `ip\n<address>` inside curly braces `{ ... }`.\n\nIf you omit `mac`, FrameAssembly assigns clean, repeatable MAC addresses in order\n(`00:00:00:00:00:01`, `00:00:00:00:00:02`, ...) so you only type Layer 2 MACs when\ntesting ARP, STP, or port security.\n\n- Plain host IPs only (`ip 192.168.1.10`) — never include `/24` CIDR masks, `=`\n  signs, or commas.\n- Write notes for teammates using `//` comments (`#` and `;` are rejected).\n- Built-in keywords never contain underscores or hyphens: write `echorequest` and\n  `echoreply`, never `echo_request`.\n\n## 2. `compile` — One Line Equals One Ethernet Frame\n\nPlace `compile { ... }` below your `host` declarations. Each line emits one\ncomplete Ethernet II + IP + ICMP frame into your `.pcap`, calculating total\nlengths and RFC 1071 checksums automatically.\n\n## Complete Lab Solution (`first_ping_check.frasm`)\n\n```frameassembly\n// Step 1: Declare the devices on the LAN (plain IPs, no /24 mask)\nhost laptop  { ip 192.168.1.10 }\nhost gateway { ip 192.168.1.1 }\nhost dns_srv { ip 192.168.1.53 }\n\n// Step 2: Emit packets in order (1 line = 1 Ethernet frame)\ncompile {\n    // Ping the default gateway and receive its reply\n    laptop -> gateway icmp echorequest id 100 seq 1\n    gateway -> laptop icmp echoreply id 100 seq 1\n\n    // Ping the internal DNS server and receive its reply\n    laptop -> dns_srv icmp echorequest id 101 seq 1\n    dns_srv -> laptop icmp echoreply id 101 seq 1\n}\n```\n\n```bash\nframeassembly first_ping_check.frasm\nframeassembly show first_ping_check.frasm\n```\n"}
{"id":"pretrain-lab-chapter-2-arrows-timing","kind":"interactive_lab","title":"Lab 2: Chapter 2: Basic Examples — Reply Arrows (`<-`), Timing (`wait`) & DNS — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/learn","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["dns"],"text":"# Lab 2: Chapter 2: Basic Examples — Reply Arrows (`<-`), Timing (`wait`) & DNS\n\n> FrameAssembly v3.3.0 · Interactive Packet Lab · MIT License · Canonical URL:\n> https://frameassembly-lang.dev/learn\n\nKeep `client <-> server` columns aligned like a network sequence diagram and\nsimulate realistic WAN latency down to the microsecond.\n\n## Operational Scenario\n\nUsers at a remote branch complain logins take forever. Build a capture showing a\nsluggish 250ms WAN DNS lookup followed by a quick ping so junior techs can spot\nDNS lag in Wireshark.\n\n## Learning Objectives\n\n- Use `<-` so client and server stay pinned in consistent left/right columns while\n  MACs, IPs, and UDP/TCP ports flip automatically.\n- Control exact inter-packet delays at the end of any line with `wait` (`ns`,\n  `us`, `ms`, `s`, `m`).\n- Build real UDP port 53 `dns query` and `dns response` packets with matching\n  `txid` values.\n\n## 1. Keep Endpoints in Clean Columns with `<-`\n\nIn Chapter 1 we flipped `gateway -> laptop` for the reply. Across a 20-packet\ntrace, constantly swapping left and right host names makes it hard to tell who\ninitiated the session.\n\nThe reverse arrow `<-` fixes that: writing `branch_pc <- dns_wan dns response ...`\nkeeps `branch_pc` on the left and `dns_wan` on the right while sending the frame\n*from* `dns_wan` *back to* `branch_pc` (flipping MACs, IPs, and ports\nautomatically).\n\n## 2. Controlling Packet Timestamps with `wait`\n\nPacket #1 always starts at `0.000 ms`. When you omit `wait`, FrameAssembly\nadvances the capture clock by `10ms` before the next packet.\n\nAdding `wait 250ms` (or `500us`, `2s`, `0ns`) at the end of Packet #1 makes Packet\n#2 arrive `250.000 ms` later.\n\n- Attach lowercase units directly to the number: `0ns`, `250us`, `250ms`, `2s`,\n  `1m`.\n- `wait` always goes at the end of a packet line — never put `wait 250ms` alone on\n  its own line.\n- Text values like `qname \"erp.corp.local\"` always use double quotes `\"...\"`,\n  never single quotes.\n\n## Complete Lab Solution (`wan_dns_latency.frasm`)\n\n```frameassembly\n// Branch workstation, WAN DNS resolver, and internal ERP server\nhost branch_pc { ip 10.15.1.20 }\nhost dns_wan   { ip 172.16.53.53 }\nhost erp_srv   { ip 10.80.1.20 }\n\ncompile {\n    // 1. DNS lookup over a slow 250ms WAN link\n    branch_pc -> dns_wan dns query txid 0x2a10 qname \"erp.corp.local\" qtype \"A\" wait 250ms\n    branch_pc <- dns_wan dns response txid 0x2a10 qname \"erp.corp.local\" qtype \"A\" rdata \"10.80.1.20\" ansttl 300 wait 5ms\n\n    // 2. Ping the resolved ERP server + aligned <- reply\n    branch_pc -> erp_srv icmp echorequest id 200 seq 1 wait 2ms\n    branch_pc <- erp_srv icmp echoreply id 200 seq 1\n}\n```\n\n```bash\nframeassembly wan_dns_latency.frasm wan_dns_latency.pcapng\nframeassembly show wan_dns_latency.frasm\n```\n"}
{"id":"pretrain-lab-chapter-3-vlan-tcp","kind":"interactive_lab","title":"Lab 3: Chapter 3: Firewall Rule Testing (802.1Q `vlan` & Stateful TCP) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/learn","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["vlan","tcp","http"],"text":"# Lab 3: Chapter 3: Firewall Rule Testing (802.1Q `vlan` & Stateful TCP)\n\n> FrameAssembly v3.3.0 · Interactive Packet Lab · MIT License · Canonical URL:\n> https://frameassembly-lang.dev/learn\n\nGenerate VLAN-tagged, stateful 3-way TCP sessions (`syn` -> `syn ack` -> `ack`) so\nfirewalls and Suricata rules inspect your traffic instead of dropping it.\n\n## Operational Scenario\n\nYou need to validate a firewall ACL permitting VLAN 100 clients to reach an\ninternal API on TCP port 8080—and Windows/macOS NIC drivers keep stripping 802.1Q\ntags from live captures.\n\n## Learning Objectives\n\n- Establish a 3-way TCP handshake (`syn` -> `syn ack` -> `ack`) specifying\n  `srcport` and `dstport` only once.\n- Let Layer 7 protocols (`http`, `tls`, `ssh`, `postgres`) inherit ports and\n  advance 32-bit `seq` / `acknum` counters automatically.\n- Attach IEEE 802.1Q `vlan 100` headers onto every frame to test trunk ACLs and\n  inter-VLAN firewall policies.\n\n## 1. Why Stateful Firewalls Drop Single Spoofed Packets\n\nIf you send a lone HTTP `GET` or TLS `ClientHello` through a FortiGate, Palo Alto,\nCisco ASA, or Suricata (`flow:established,to_server;`), it gets dropped\nimmediately because no TCP session exists in the state table.\n\nIn FrameAssembly, three short lines (`syn`, `syn ack`, `ack`) build a valid\nstateful session. Set `srcport` and `dstport` once on the opening `syn`, and every\n`<-` and `->` line that follows reuses the port pair and counts payload bytes into\n`seq` and `acknum` automatically.\n\n## 2. 802.1Q `vlan` Tagging & Why HTTP Uses `hosthdr`\n\nAdding `vlan 100` inserts a real 4-byte IEEE 802.1Q tag (`0x8100`) between\nEthernet II and IP so switch trunk ports and VLAN-aware firewall interfaces see\nthe exact subinterface tag.\n\nOne helpful naming rule: because `host` is used at the top of `.frasm` files to\ndeclare devices, HTTP and SSDP use `hosthdr \"api.corp.local\"` for the HTTP `Host:`\nheader.\n\n## Complete Lab Solution (`vlan100_http_acl.frasm`)\n\n```frameassembly\n// VLAN 100 client testing firewall policy to internal API server\nhost client  { ip 10.100.5.25 }\nhost api_srv { ip 10.200.5.80 }\n\ncompile {\n    // 1. Stateful 3-way TCP handshake tagged on VLAN 100 -> port 8080\n    client -> api_srv vlan 100 tcp syn srcport 51400 dstport 8080 win 65535 mss 1460 wait 1ms\n    client <- api_srv vlan 100 tcp syn ack win 65535 mss 1460 wait 1ms\n    client -> api_srv vlan 100 tcp ack wait 1ms\n\n    // 2. HTTP health check -> 200 OK reply tagged on VLAN 100\n    client -> api_srv vlan 100 http get uri \"/healthz\" hosthdr \"api.corp.local\" wait 2ms\n    client <- api_srv vlan 100 http status 200 reason \"OK\" contenttype \"application/json\" body \"{\\\"ok\\\":true}\"\n}\n```\n\n```bash\nframeassembly vlan100_http_acl.frasm\nsuricata -r vlan100_http_acl.pcap -l ./logs\n```\n"}
{"id":"pretrain-lab-chapter-4-snmp-syslog","kind":"interactive_lab","title":"Lab 4: Chapter 4: SNMP Trap Simulation & Syslog Alerts (`snmp2`, `snmp3` & `syslog`) — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/learn","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["snmp2","snmp3","syslog"],"text":"# Lab 4: Chapter 4: SNMP Trap Simulation & Syslog Alerts (`snmp2`, `snmp3` & `syslog`)\n\n> FrameAssembly v3.3.0 · Interactive Packet Lab · MIT License · Canonical URL:\n> https://frameassembly-lang.dev/learn\n\nSimulate SNMPv2c and encrypted SNMPv3 `authPriv` traps plus Syslog alerts to\nverify Zabbix, PRTG, LibreNMS, or Splunk alerting without pulling live cables.\n\n## Operational Scenario\n\nVerify your NMS pages the on-call engineer when building uplink `Gi1/0/24` goes\ndown—without unplugging the fiber feeding Building 2.\n\n## Learning Objectives\n\n- Emit RFC 5424 `syslog` alerts on UDP 514 with `facility`, `severity`,\n  `hostname`, `app`, and `msg`.\n- Simulate MIB-free `snmp2 trap` and encrypted `snmp3 trap` (`sha256` + `aes`)\n  packets on UDP 162.\n- Attach numeric OID `varbind` pairs (`oidval`, `string`, `int`, `timeticks`)\n  cleanly.\n\n## 1. Simulating SNMPv2c & Encrypted SNMPv3 Traps Without MIB Files\n\nTesting SNMPv3 traps with CLI tools like `snmptrap` often turns into a fight over\nmissing vendor MIB paths, engine IDs, and key-localization flags.\n\nFrameAssembly builds standard UDP 162 trap packets and runs full SHA-256 HMAC\nauthentication + AES-128 encryption directly from numeric OIDs. For a `linkDown`\ntrap, pair `1.3.6.1.6.3.1.1.4.1.0` (`snmpTrapOID.0`) with `oidval\n1.3.6.1.6.3.1.1.5.3`, then add interface varbinds like `ifDescr`.\n\n- String varbinds use the full word `string \"...\"` (never `str \"...\"`).\n- `snmp3` `engineid` expects an even-length hex string such as\n  `\"80001f888011223344\"`.\n- `trap`, `inform`, and `report` default to UDP `162`; `get`, `getnext`,\n  `getbulk`, and `set` default to UDP `161`.\n\n## Complete Lab Solution (`switch_uplink_alert.frasm`)\n\n```frameassembly\n// Building 2 access switch sending critical uplink alerts to the central NMS\nhost access_sw { ip 10.30.0.12 }\nhost nms_srv   { ip 10.30.0.200 }\n\ncompile {\n    // 1. Critical Syslog (severity 2) for uplink Gi1/0/24 on UDP 514\n    access_sw -> nms_srv syslog facility 16 severity 2 hostname \"sw-bldg2\" app \"IFMGR\" msg \"Uplink Gi1/0/24 link down\" wait 3ms\n\n    // 2. Encrypted SNMPv3 linkDown trap for Gi1/0/24 on UDP 162\n    access_sw -> nms_srv snmp3 trap user \"zabbix-ops\" engineid \"80001f888011223344\" engineboots 2 enginetime 900 auth sha256 \"AuthKey2026!\" priv aes \"PrivKey2026!\" sysuptime 180000 varbind 1.3.6.1.6.3.1.1.4.1.0 oidval 1.3.6.1.6.3.1.1.5.3 varbind 1.3.6.1.2.1.2.2.1.2.24 string \"Gi1/0/24\"\n}\n```\n\n```bash\nframeassembly switch_uplink_alert.frasm\ntshark -r switch_uplink_alert.pcap\n```\n"}
{"id":"pretrain-lab-chapter-5-reusable-flows","kind":"interactive_lab","title":"Lab 5: Chapter 5: Multi-Subnet Policy Checks with Reusable `flow(c, s)` — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/learn","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":["tls"],"text":"# Lab 5: Chapter 5: Multi-Subnet Policy Checks with Reusable `flow(c, s)`\n\n> FrameAssembly v3.3.0 · Interactive Packet Lab · MIT License · Canonical URL:\n> https://frameassembly-lang.dev/learn\n\nWrite a multi-packet firewall check once using placeholder names, then replay it\nacross Floor 1, Floor 2, Guest Wi-Fi, or IPv4 + IPv6.\n\n## Operational Scenario\n\nThree campus user VLANs (`floor1_pc`, `floor2_pc`, `wifi_user`) all need to pass\nthe same 4-packet TCP + TLS handshake to `sso_gw` without copy-pasting 12 lines.\n\n## Learning Objectives\n\n- Define `flow name(c, s) { ... }` between `host` and `compile`.\n- Reference only the placeholder parameter names (`c`, `s`) inside the `flow`\n  body.\n- Call `tls_check(...)` inside `compile` across multiple subnet pairs (including\n  IPv4 and IPv6 pairs).\n\n## 1. `flow(c, s)` — Reusable Packet Stencils Without Loops\n\nCopy-pasting the same 4-packet TCP + TLS handshake across five campus subnets\nmakes captures tedious to read and easy to mistype.\n\nA `flow` block sits between `host` and `compile`. Give it placeholder names in\nparentheses (`flow tls_check(c, s) { ... }`), then call `tls_check(floor1_pc,\nsso_gw)` inside `compile` for each subnet pair you want to test.\n\n- Parentheses with >= 1 parameter are required: `flow tls_check(c, s) { ... }`.\n- Inside the `flow` braces, only use the parameter names (`c`, `s`), never global\n  `host` names.\n- There is no `loop` keyword: each `flow` call inside `compile` expands\n  predictably in order.\n\n## Complete Lab Solution (`campus_sso_matrix.frasm`)\n\n```frameassembly\n// Three campus client subnets + central SSO gateway\nhost floor1_pc { ip 10.10.1.25 }\nhost floor2_pc { ip 10.10.2.25 }\nhost wifi_user { ip 10.10.99.50 }\nhost sso_gw    { ip 10.100.0.10 }\n\n// Reusable 4-packet TCP + TLS handshake stencil\nflow tls_check(c, s) {\n    c -> s tcp syn dstport 443 win 65535 mss 1460 wait 1ms\n    c <- s tcp syn ack win 65535 mss 1460 wait 1ms\n    c -> s tcp ack wait 1ms\n    c -> s tls clienthello sni \"sso.corp.internal\" alpn \"h2\" wait 5ms\n}\n\ncompile {\n    tls_check(floor1_pc, sso_gw)\n    tls_check(floor2_pc, sso_gw)\n    tls_check(wifi_user, sso_gw)\n}\n```\n\n```bash\nframeassembly campus_sso_matrix.frasm\nframeassembly show campus_sso_matrix.frasm\n```\n"}
{"id":"pretrain-lab-chapter-6-reverse-sanitize","kind":"interactive_lab","title":"Lab 6: Chapter 6: Reverse `.pcap` -> Scrub Secrets -> Rebuild `.pcap` — FrameAssembly v3.3.0","url":"https://frameassembly-lang.dev/learn","version":"3.3.0","license":"MIT","media_type":"text/vnd.frameassembly","protocols":[],"text":"# Lab 6: Chapter 6: Reverse `.pcap` -> Scrub Secrets -> Rebuild `.pcap`\n\n> FrameAssembly v3.3.0 · Interactive Packet Lab · MIT License · Canonical URL:\n> https://frameassembly-lang.dev/learn\n\nReverse binary captures into `.frasm` text, redact private subnets & internal\nhostnames, and rebuild valid `.pcap` files for vendor support.\n\n## Operational Scenario\n\nVendor TAC asks for your failing login `.pcap`, except it exposes `10.99.4.x` and\n`\"payroll.secret-corp.internal\"` inside DNS and TLS SNI — scrub both before\nuploading.\n\n## Learning Objectives\n\n- Reverse `.pcap` / `.pcapng` bytes into readable `.frasm` (`host1`, `host2`, ...)\n  locally in the browser or via `frameassembly reverse`.\n- Replace private IPs once in `host` so every packet header and transport checksum\n  updates automatically.\n- Redact Layer 7 strings (`qname`, `sni`, `hosthdr`) without corrupting IP total\n  lengths or TCP `seq` counters.\n\n## 1. Why `.pcap -> .frasm -> .pcap` Beats `tcprewrite`\n\nHex-editing a `.pcap` breaks IP lengths and TCP checksums the instant\n`\"payroll.secret-corp.internal\"` shortens to `\"app.example.test\"`. Meanwhile\n`tcprewrite` swaps outer Layer 3 IPs while leaving internal domain names sitting\nin plaintext inside DNS queries and TLS SNI.\n\nRunning `frameassembly reverse incident.pcap clean.frasm` (or clicking \"Reverse\nSample .pcap\" in the sandbox) converts the capture into readable `host1`, `host2`,\n... lines. Find-and-replace sensitive values, rebuild, and attach a clean `.pcap`\nto your ticket.\n\n- Zero cloud uploads: reversing and rebuilding run locally inside WebAssembly in\n  your browser tab.\n- Custom binary payloads survive round-trips intact via `hexpayload \"...\"`.\n\n## Complete Lab Solution (`tac_ticket_sanitized.frasm`)\n\n```frameassembly\n// Sanitized capture ready to attach to external vendor TAC ticket\nhost host1 { ip 198.51.100.21 mac 02:00:00:00:00:01 }\nhost host2 { ip 198.51.100.53 mac 02:00:00:00:00:02 }\nhost host3 { ip 198.51.100.80 mac 02:00:00:00:00:03 }\n\ncompile {\n    host1 -> host2 dns query txid 0x7712 qname \"app.example.test\" qtype \"A\" wait 2ms\n    host1 <- host2 dns response txid 0x7712 qname \"app.example.test\" qtype \"A\" rdata \"198.51.100.80\" ansttl 60 wait 3ms\n    host1 -> host3 tcp syn srcport 53410 dstport 443 win 65535 mss 1460 wait 1ms\n    host1 <- host3 tcp syn ack win 65535 mss 1460 wait 1ms\n    host1 -> host3 tcp ack wait 1ms\n    host1 -> host3 tls clienthello sni \"app.example.test\" alpn \"h2\"\n}\n```\n\n```bash\nframeassembly reverse customer_incident.pcap tac_ticket_sanitized.frasm\nframeassembly tac_ticket_sanitized.frasm tac_ticket_sanitized.pcap\n```\n"}
