# Diagnose One-Way VoIP Audio, SIP ALGs & WAN DSCP Stripping

> **FrameAssembly v3.2.2** · Operational Playbook (Telemetry, VoIP & OT) · Canonical URL: https://frameassembly-lang.dev/use-cases/voip-sip-rtp-qos-pcap

Build a complete STUN + SIP INVITE/SDP + bidirectional G.711 RTP (DSCP 46 EF) call ladder that opens straight in Wireshark Telephony -> VoIP Calls.

- **Category:** Telemetry, VoIP & OT
- **Capture Filename:** `voip_sip_rtp_qos.frasm` (10 Ethernet frames)
- **Protocols Exercised:** `vlan`, `stun`, `sip`, `rtp`

## Operational Problem

Phones ring fine on UDP 5060, somebody picks up, and only one side hears audio—usually because a firewall SIP ALG mangled the SDP media IP, UDP 16384+ RTP is Asymmetric-NAT blocked, or the WAN carrier bleached DSCP 46 back to 0.

Testing VoIP trunks and SBC policies by placing 30 live test calls annoys everyone in earshot, and hand-crafting SIP messages fails fast if you miss the RFC 3261 `z9hG4bK` Via branch magic cookie or miscalculate SDP `Content-Length`.

FrameAssembly builds valid RFC 5389 XOR-masked STUN bindings, complete RFC 3261 SIP dialogs with matching `callid` headers, and VLAN-tagged `dscp 46` G.711 RTP media streams in ten readable lines.

## Scenario & Topology: Voice VLAN 110 Desk Phone <-> NAT Firewall / SBC Call Lifecycle

- **Topology:** `Desk Phone (10.110.20.45, VLAN 110) -> Firewall / WAN -> Cloud SBC & STUN (198.51.100.60)`

Ten packets reproduce a full enterprise voice call: (1) RFC 5389 `stun bindingrequest` <-> `bindingresponse` discovering public NAT IP `203.0.113.45`; (2) CS3-marked (`dscp 24`) `sip invite` with SDP audio offer -> `180 Ringing` -> `200 OK` -> `sip ack` sharing `callid "voip-call-901"`; (3) bidirectional EF-marked (`vlan 110 pcp 5 dscp 46`) G.711 PCMU `rtp` voice frames; and (4) clean `sip bye` -> `200 OK` teardown.

## FrameAssembly Workflow

Generates 10 Voice-VLAN frames covering STUN XOR-MAPPED-ADDRESS discovery, a matched-Call-ID SIP + SDP dialog, bidirectional DSCP-EF RTP, and BYE.

### Adapt It for Your Network

1. Set desk_phone and cloud_sbc to your voice subnet and SBC trunk IPs, and adjust vlan 110 to your Voice VLAN.
2. Keep callid identical across invite, status, ack, and bye so Wireshark groups the call into one VoIP ladder.
3. Compile -> open in Wireshark (Telephony -> VoIP Calls) -> replay across your firewall to check SIP ALG and DSCP 46 preservation.

## Runnable Capture Specification (`voip_sip_rtp_qos.frasm`)

```frameassembly
host desk_phone { ip 10.110.20.45  mac 00:04:f2:aa:20:45 }
host cloud_sbc  { ip 198.51.100.60 mac 00:1c:73:60:00:01 }

flow nat_stun_discovery(phone, sbc) {
    // 1. RFC 5389 STUN NAT discovery returning XOR-masked public IP 203.0.113.45
    phone -> sbc vlan 110 stun bindingrequest txid 0x20459001 software "PolyEdge-B" wait 2ms
    phone <- sbc vlan 110 stun bindingresponse txid 0x20459001 xormappedaddr 203.0.113.45 wait 3ms
}

flow sip_call_and_ef_rtp(phone, sbc) {
    // 2. SIP call setup (CS3 dscp 24) with SDP offer sharing callid "voip-call-901"
    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
    phone <- sbc vlan 110 pcp 3 dscp 24 sip status 180 reason "Ringing" callid "voip-call-901" cseq 1 wait 20ms
    phone <- sbc vlan 110 pcp 3 dscp 24 sip status 200 reason "OK" callid "voip-call-901" cseq 1 wait 2ms
    phone -> sbc vlan 110 pcp 3 dscp 24 sip ack uri "sip:18005550199@sbc.example.net" callid "voip-call-901" cseq 1 wait 5ms

    // 3. Bidirectional G.711 PCMU RTP audio stamped with 802.1p PCP 5 + DSCP 46 (EF)
    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
    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

    // 4. Clean call hangup (BYE -> 200 OK)
    phone -> sbc vlan 110 pcp 3 dscp 24 sip bye uri "sip:18005550199@sbc.example.net" callid "voip-call-901" cseq 2 wait 2ms
    phone <- sbc vlan 110 pcp 3 dscp 24 sip status 200 reason "OK" callid "voip-call-901" cseq 2 wait 1ms
}

compile {
    nat_stun_discovery(desk_phone, cloud_sbc)
    sip_call_and_ef_rtp(desk_phone, cloud_sbc)
}
```

## Equivalent CLI Commands

```bash
# 1. Compile the STUN + SIP + DSCP-EF RTP call capture
frameassembly voip_sip_rtp_qos.frasm voip_sip_rtp_qos.pcap

# 2. Verify STUN XOR-MAPPED-ADDRESS, SIP Call-ID, and RTP DSCP 46 markings in tshark
tshark -r voip_sip_rtp_qos.pcap -Y "stun || sip || rtp"

# 3. Replay across your WAN edge or firewall to verify SIP ALG & QoS queue mapping
sudo tcpreplay -i eth0 voip_sip_rtp_qos.pcap
```

## Protocol Reference Links

- [`vlan` — IEEE 802.1Q Virtual LAN Tagging & 802.1p QoS](https://frameassembly-lang.dev/docs/protocols/vlan) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/vlan.md))
- [`stun` — Session Traversal Utilities for NAT](https://frameassembly-lang.dev/docs/protocols/stun) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/stun.md))
- [`sip` — Session Initiation Protocol VoIP Signaling](https://frameassembly-lang.dev/docs/protocols/sip) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/sip.md))
- [`rtp` — Real-time Transport Protocol Audio & Video Streams](https://frameassembly-lang.dev/docs/protocols/rtp) ([Raw .md](https://frameassembly-lang.dev/docs/protocols/rtp.md))
