# amqp — Port 5672 RabbitMQ Exchanges, Channels & Deliveries (`amqp`)

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

- **Full Protocol Name:** Advanced Message Queuing Protocol (RabbitMQ)
- **Keyword:** `amqp`
- **OSI Layer & Transport:** Layer 7 · TCP 5672
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** AMQP 0-9-1
- **Wireshark Display Filter:** `amqp`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 5672 -> AMQP 0-9-1`

## Overview

From the 8-byte `"AMQP\x00\x00\x09\x01"` greeting to `basicpublish` and `0xce` frame-end markers on TCP `5672`, `amqp` lets you verify message-bus firewall rules without spinning up RabbitMQ.

Advanced Message Queuing Protocol (`amqp`, AMQP 0-9-1) powers RabbitMQ and enterprise event-driven message queues over **TCP port `5672`**. Connections open with the 8-byte `AMQP  	` `protocolheader`, negotiate channels (`connectionstart`, `channelopen`), route messages via `exchange` and `routingkey` (`basicpublish`, `basicdeliver`), and keep idle sockets open with `heartbeat` frames—each terminated by the `0xce` frame-end byte.

FrameAssembly computes AMQP frame sizes, Class/Method IDs (`10.10` Connection.Start, `20.10` Channel.Open, `60.40` Basic.Publish, `60.60` Basic.Deliver), and the `0xce` frame-end marker automatically.

## Minimal Quickstart (`amqp_quickstart.frasm`)

```frameassembly
host producer { ip 10.65.1.15 }
host rabbitmq { ip 10.65.1.56 }

compile {
    producer -> rabbitmq tcp syn srcport 55672 dstport 5672 wait 1ms
    producer <- rabbitmq tcp syn ack wait 1ms
    producer -> rabbitmq tcp ack wait 1ms
    producer -> rabbitmq amqp protocolheader wait 1ms
    producer <- rabbitmq amqp connectionstart channel 0 wait 2ms
    producer -> rabbitmq amqp basicpublish channel 1 exchange "orders" routingkey "order.created" payload "{\"id\":901}"
}
```

### Automatic Wire Calculations

- Defaults to TCP destination port `5672` (`psh ack`) and appends the mandatory `0xce` frame-end octet to every AMQP 0-9-1 frame.
- Emits the exact 8-byte `AMQP\x00\x00\x09\x01` connection header on `protocolheader` so Wireshark locks onto the AMQP dissector.
- Encodes short-string length prefixes for `exchange` and `routingkey` inside Class `60` (`Basic.Publish` / `Basic.Deliver`) Method frames.

## Practical Lab Example: Full RabbitMQ Connection Startup, Channel Open, Publish, Deliver & Heartbeat (`amqp_rabbitmq_flow.frasm`)

Walks through TCP 5672 connection startup, opening Channel 1, publishing an audit event to `"sec.events"`, delivering to a worker, and sending a Channel 0 heartbeat.

```frameassembly
host auth_svc { ip 172.16.65.10 }
host mq_node  { ip 172.16.65.56 }

compile {
    auth_svc -> mq_node tcp syn srcport 51672 dstport 5672 win 65535 mss 1460 wait 1ms
    auth_svc <- mq_node tcp syn ack win 65535 mss 1460 wait 1ms
    auth_svc -> mq_node tcp ack wait 1ms
    auth_svc -> mq_node amqp protocolheader wait 1ms
    auth_svc <- mq_node amqp connectionstart channel 0 wait 2ms
    auth_svc -> mq_node amqp channelopen channel 1 wait 2ms
    auth_svc -> mq_node amqp basicpublish channel 1 exchange "sec.events" routingkey "login.mfa" payload "{\"user\":\"netadmin\"}" wait 3ms
    auth_svc <- mq_node amqp basicdeliver channel 1 exchange "sec.events" routingkey "login.mfa" payload "{\"user\":\"netadmin\"}" wait 10ms
    auth_svc <- mq_node amqp heartbeat channel 0
}
```

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

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

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

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

## All `amqp` Keywords & Header Options

Packet line pattern: `src_host -> dst_host amqp [protocolheader | connectionstart | channelopen | basicpublish | basicdeliver | heartbeat] [channel <0..65535>] [exchange "<text>"] [routingkey "<text>"]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `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`). |
| `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. |
| `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`. |

## Cross-Layer Options Valid with `amqp`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"` or `"de:ad:be:ef"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType u16 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or 16-bit EtherType for this single packet. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255 | `Unlabeled (at most 1 mpls tag per packet)` | Inserts a 32-bit MPLS label header (`0x8847`) ahead of the Layer 3 header. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>]` | IPv4 ID, DF/MF flags, fragment offset 0..8191 | `ipid 1, flags 0, fragoffset 0` | Sets IPv4 Identification, Do-Not-Fragment (`df`), More-Fragments (`mf`), and fragment offset (ignored over IPv6). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 5672` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `seq <number> \| acknum <number> \| win\|window <0..65535> \| urgent <0..65535> \| syn \| ack \| psh \| fin \| rst \| urg \| ece \| cwr` | TCP sequence/ack numbers, window size, flags & RFC 7323 options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323 options (`mss`, `wscale`, `sackperm`, `tsval`, `tsecr`). |

## Common Mistakes & Quick Fixes

### Heartbeats Always Use Channel 0 Per AMQP 0-9-1

- **Valid v3.2.2 Syntax:** `auth_svc <- mq_node amqp heartbeat channel 0`

AMQP 0-9-1 requires `Type 8` Heartbeat frames to carry `channel 0` (`channel >= 1` is used for `channelopen`, `basicpublish`, and `basicdeliver`).
