# rtsp — Port 554 Camera Stream Control & transporthdr Rules (`rtsp`)

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

- **Full Protocol Name:** Real Time Streaming Protocol IP Camera & Media Control
- **Keyword:** `rtsp`
- **OSI Layer & Transport:** Layer 7 · TCP 554
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 2326, RFC 7826
- **Wireshark Display Filter:** `rtsp`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 554 -> RTSP`

## Overview

Controlling CCTV cameras and media relays on TCP `554` — remember to spell the RTSP `Transport:` header `transporthdr` so it never collides with FrameAssembly’s Layer 4 `transport` keyword!

Real Time Streaming Protocol (`rtsp`, RFC 2326 / RFC 7826) controls IP security cameras, NVRs, and live video servers over **TCP port `554`**. An NVR typically sends `OPTIONS`, `DESCRIBE`, `SETUP` (negotiating client RTP/RTCP UDP ports inside the `Transport:` header), `PLAY`, and `TEARDOWN`.

FrameAssembly formats RTSP/1.0 requests and `status` responses (`RTSP/1.0 200 OK`) with `CSeq`, `Transport` (`transporthdr`), and `Session` headers while tracking TCP sequence numbers automatically.

## Minimal Quickstart (`rtsp_quickstart.frasm`)

```frameassembly
host nvr_srv { ip 10.50.10.10 }
host ip_cam  { ip 10.50.20.45 }

compile {
    nvr_srv -> ip_cam rtsp options uri "rtsp://10.50.20.45:554/stream1" cseq 1 wait 2ms
    nvr_srv <- ip_cam rtsp status 200 cseq 1 wait 2ms
    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"
}
```

### Automatic Wire Calculations

- Defaults to TCP destination port `554` (`psh ack`) and writes `
`-terminated `RTSP/1.0` lines with `CSeq`.
- Switches from an RTSP client request to an `RTSP/1.0 <status> OK` server reply whenever `status` is set.
- Writes `Transport:` (`transporthdr`) and `Session:` (`session`) headers cleanly for Wireshark RTSP/RTP conversation tracking.

## Practical Lab Example: Full IP Camera RTSP Setup, PLAY, RTP Video Frame & TEARDOWN (`rtsp_camera_session.frasm`)

Walks through TCP 554 connection setup, `DESCRIBE`, `SETUP` (`client_port=5004-5005`), `PLAY`, an H.264 `rtp pt 96` packet from the camera, and `TEARDOWN`.

```frameassembly
host vms_nvr  { ip 192.168.60.10 }
host gate_cam { ip 192.168.60.105 }

compile {
    vms_nvr -> gate_cam tcp syn srcport 51554 dstport 554 win 65535 mss 1460 wait 1ms
    vms_nvr <- gate_cam tcp syn ack win 65535 mss 1460 wait 1ms
    vms_nvr -> gate_cam tcp ack wait 1ms
    vms_nvr -> gate_cam rtsp describe uri "rtsp://192.168.60.105/h264" cseq 1 wait 2ms
    vms_nvr <- gate_cam rtsp status 200 cseq 1 wait 2ms
    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
    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
    vms_nvr -> gate_cam rtsp play uri "rtsp://192.168.60.105/h264" cseq 3 session "98112233" wait 2ms
    vms_nvr <- gate_cam rtsp status 200 cseq 3 session "98112233" wait 5ms
    // Camera sends H.264 RTP packet (pt 96) to client port 5004
    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
    vms_nvr -> gate_cam rtsp teardown uri "rtsp://192.168.60.105/h264" cseq 4 session "98112233"
}
```

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

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

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

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

## All `rtsp` Keywords & Header Options

Packet line pattern: `src_host -> dst_host rtsp [options | describe | setup | play | teardown | method "<text>"] [uri "<text>"] [status <100..599>] [cseq <number>] [transporthdr "<text>"] [session "<text>"]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `options \| describe \| setup \| play \| teardown \| method "<text>"` | RTSP request verb | `options` | Sets the RTSP command method on the request line. |
| `uri "<text>"` | Quoted `rtsp://...` stream URL | `"rtsp://camera.local/stream"` | Sets the target stream URL in the RTSP request line. |
| `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. |
| `cseq <number>` | Command sequence counter | `1` | Writes the mandatory `CSeq:` header matching requests to responses. |
| `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`). |
| `session "<text>"` | Quoted RTSP Session ID | `Omitted unless set` | Writes the `Session:` header linking `SETUP`, `PLAY`, and `TEARDOWN`. |

## Cross-Layer Options Valid with `rtsp`

| 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 554` | 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

### Always Use transporthdr (Never transport) for the RTSP Transport Header

- **Avoid:** `nvr_srv -> ip_cam rtsp setup transport "RTP/AVP;unicast;client_port=5004-5005"`
- **Valid v3.2.2 Syntax:** `nvr_srv -> ip_cam rtsp setup transporthdr "RTP/AVP;unicast;client_port=5004-5005"`

In FrameAssembly, `transport` is reserved for switching Layer 4 TCP/UDP on dual-transport protocols. RTSP runs over TCP `554` and uses `transporthdr` for the `Transport:` header.
