# sip — VoIP INVITE, SDP & Call-ID Ladders Over UDP/TCP 5060 (`sip`)

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

- **Full Protocol Name:** Session Initiation Protocol VoIP Signaling
- **Keyword:** `sip`
- **OSI Layer & Transport:** Layer 7 · UDP 5060 (or TCP 5060 via transport tcp)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 3261
- **Wireshark Display Filter:** `sip`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 5060 (or TCP 5060 via transport tcp) (transport tcp|udp) -> SIP (VoIP)`

## Overview

Debugging why desk phones ring once and drop at the Session Border Controller? `sip` builds full RFC 3261 `Via`, `From`, `To`, `Call-ID`, and `CSeq` headers over UDP `5060` or `transport tcp`.

Session Initiation Protocol (`sip`, RFC 3261) sets up, modifies, and tears down VoIP phone calls and SIP trunks across IP PBXs (Asterisk, FreeSWITCH, Cisco CUCM) and Session Border Controllers (SBCs) on **port `5060`**. `sip` defaults to **UDP port `5060`**, and adding `transport tcp` switches to **TCP port `5060`**.

Writing valid SIP messages by hand is tedious because strict parsers reject packets missing RFC 3261 headers or the `z9hG4bK` branch magic cookie. FrameAssembly automatically builds `Via` (with `z9hG4bK` branch cookie), `From`, `To`, `Call-ID`, `CSeq`, `Max-Forwards: 70`, `Contact`, and `Content-Length`—so Wireshark’s **Telephony -> VoIP Calls** ladder diagram renders your call flow immediately.

## Minimal Quickstart (`sip_quickstart.frasm`)

```frameassembly
host desk_phone { ip 10.30.20.101 }
host corp_pbx   { ip 10.30.20.10 }

compile {
    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
    desk_phone <- corp_pbx sip status 180 reason "Ringing" callid "call-401" cseq 1 wait 10ms
    desk_phone <- corp_pbx sip status 200 reason "OK" callid "call-401" cseq 1 wait 2ms
    desk_phone -> corp_pbx sip ack uri "sip:1002@pbx.internal" callid "call-401" cseq 1
}
```

### Automatic Wire Calculations

- Defaults to UDP `5060` (`SIP/2.0/UDP`) or switches `Via` and Layer 4 to TCP `5060` (`SIP/2.0/TCP`) when `transport tcp` is added.
- Generates mandatory RFC 3261 headers (`Via` with `branch=z9hG4bK...`, `From`, `To`, `Call-ID`, `CSeq`, `Max-Forwards: 70`, `Contact`, and exact `Content-Length`).
- Treats `ack` on a `sip` line as the SIP `ACK` request method (even when `transport tcp` is used).

## Practical Lab Example: Complete VoIP Call Setup (`INVITE` + SDP), `RTP` Audio & `BYE` Hangup (`sip_rtp_voip_call.frasm`)

Establishes a SIP call with an `application/sdp` offer on VLAN 30, streams G.711 `rtp` voice packets with `dscp 46` (EF), and hangs up cleanly via `bye` + `200 OK`.

```frameassembly
host phone_a { ip 172.16.30.101 }
host sbc_01  { ip 172.16.30.10 }

compile {
    // 1. SIP INVITE with SDP offer + 180 Ringing + 200 OK + SIP ACK
    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
    phone_a <- sbc_01 sip status 180 reason "Ringing" callid "voip-8801" cseq 1 vlan 30 dscp 24 wait 20ms
    phone_a <- sbc_01 sip status 200 reason "OK" callid "voip-8801" cseq 1 vlan 30 dscp 24 wait 2ms
    phone_a -> sbc_01 sip ack uri "sip:2050@voice.internal" callid "voip-8801" cseq 1 vlan 30 dscp 24 wait 5ms
    // 2. Bidirectional G.711 PCMU RTP audio (DSCP 46 Expedited Forwarding)
    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
    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
    // 3. Call hangup (BYE -> 200 OK)
    phone_a -> sbc_01 sip bye uri "sip:2050@voice.internal" callid "voip-8801" cseq 2 vlan 30 dscp 24 wait 2ms
    phone_a <- sbc_01 sip status 200 reason "OK" callid "voip-8801" cseq 2 vlan 30 dscp 24
}
```

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

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

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

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

## All `sip` Keywords & Header Options

Packet line pattern: `src_host -> dst_host sip [invite | ack | bye | cancel | register | options | method "<text>"] [uri "<text>"] [status <100..699>] [reason "<text>"] [from "<text>"] [to "<text>"] [callid "<text>"] [cseq <number>] [via "<text>"] [contact "<text>"] [contenttype "<text>"] [body "<text>"] [transport <udp|tcp>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `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. |
| `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. |
| `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. |
| `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:`). |
| `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. |
| `transport <udp\|tcp>` | `udp` or `tcp` | `udp` | Switches SIP transport between UDP `5060` and TCP `5060`. |

## Cross-Layer Options Valid with `sip`

| 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), UDP 5060 (or TCP 5060 via transport tcp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `transport <tcp\|udp>` | `tcp` or `udp` (supported on 9 dual-L4 protocols) | `transport udp` | Switches Layer 4 transport between TCP (`psh ack` + length framing where required) and UDP. |
| `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` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`tsval`/`tsecr`. |

## Common Mistakes & Quick Fixes

### Keep callid Identical Across INVITE, 200 OK, ACK & BYE

- **Valid v3.2.2 Syntax:** `Use callid "voip-8801" on every packet in the same call`

Wireshark and SBCs group VoIP dialogs by `Call-ID`. Matching `callid` lets Wireshark render the entire call in Telephony -> VoIP Calls.

### No Hyphens in callid or contenttype Keyword Names

- **Avoid:** `phone_a -> sbc_01 sip invite call_id "123" content_type "application/sdp"`
- **Valid v3.2.2 Syntax:** `phone_a -> sbc_01 sip invite callid "123" contenttype "application/sdp"`

Spell SIP modifiers without hyphens or underscores: `callid` and `contenttype`.
