Complete reference for the rtpengine-compatible NG (Next Generation) protocol implemented by Karl.
The NG protocol is a UDP-based protocol using bencode encoding for communication between SIP proxies and media servers.
- Default Port: UDP 22222
- Encoding: Bencode
- Request/Response: Synchronous
SIP Proxy Karl
│ │
│ ping │
│─────────────────────────►│
│ │
│ pong │
│◄─────────────────────────│
│ │
<cookie> <bencoded-dictionary>
- cookie: Unique identifier to match responses (string)
- bencoded-dictionary: Command and parameters
abc123 d7:command5:offer7:call-id10:call-567898:from-tag9:tag-12345 3:sdp...e
| Type | Format | Example |
|---|---|---|
| String | <length>:<data> |
4:ping |
| Integer | i<number>e |
i42e |
| List | l<items>e |
l4:spam4:eggse |
| Dictionary | d<key><value>...e |
d3:cow3:mooe |
Health check command.
Request:
d7:command4:pinge
Response:
d6:result4:ponge
Use: Keepalive, health monitoring
Process SDP offer for new or existing call.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | offer |
call-id |
string | Unique call identifier |
from-tag |
string | SIP From-tag |
sdp |
string | SDP offer body |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
to-tag |
string | SIP To-tag (for re-INVITE) |
flags |
list | Processing flags |
replace |
list | SDP elements to replace |
direction |
list | Media direction hints |
ICE |
string | ICE handling mode |
DTLS |
string | DTLS handling mode |
SDES |
string | SDES handling mode |
transport-protocol |
string | Force transport protocol |
media-address |
string | Override media address |
Example Request:
d7:command5:offer7:call-id10:call-567898:from-tag9:tag-123453:sdpX:v=0...e
Response:
d6:result2:ok3:sdpX:v=0...e
Process SDP answer for existing call.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | answer |
call-id |
string | Call identifier |
from-tag |
string | SIP From-tag |
to-tag |
string | SIP To-tag |
sdp |
string | SDP answer body |
Optional Parameters:
Same as offer.
Example Request:
d7:command6:answer7:call-id10:call-567898:from-tag9:tag-123456:to-tag9:tag-678903:sdpX:v=0...e
Response:
d6:result2:ok3:sdpX:v=0...e
Terminate call and release resources.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | delete |
call-id |
string | Call identifier |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
from-tag |
string | Delete specific leg |
to-tag |
string | Delete specific leg |
flags |
list | Processing flags |
Example Request:
d7:command6:delete7:call-id10:call-56789e
Response:
d6:result2:oke
Get real-time statistics for a call.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | query |
call-id |
string | Call identifier |
Response Fields:
| Field | Type | Description |
|---|---|---|
result |
string | ok or error |
totals |
dict | Aggregate statistics |
tags |
dict | Per-tag statistics |
created |
int | Creation timestamp |
last-signal |
int | Last signaling timestamp |
Example Response:
d6:result2:ok6:totalsd12:packets-sent i1000e16:packets-receivedi950e...ee
List all active calls.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | list |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
limit |
int | Max results |
Response:
d6:result2:ok5:callsl d7:call-id10:call-12345 8:from-tag9:tag-11111 6:to-tag9:tag-22222 5:state6:active e ...ee
Begin call recording.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | start recording |
call-id |
string | Call identifier |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
from-tag |
string | Record specific leg |
to-tag |
string | Record specific leg |
Response:
d6:result2:oke
End call recording.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | stop recording |
call-id |
string | Call identifier |
Mute media in one or both directions.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | block media |
call-id |
string | Call identifier |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
from-tag |
string | Specific leg |
direction |
list | from-tag, to-tag, or both |
Unmute media.
Parameters: Same as block media.
Inject DTMF tones.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | play DTMF |
call-id |
string | Call identifier |
dtmf |
string | DTMF digits (0-9, *, #) |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
from-tag |
string | Inject toward this leg |
duration |
int | Tone duration (ms) |
pause |
int | Inter-digit pause (ms) |
Get server-wide statistics.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | statistics |
Response Fields:
| Field | Description |
|---|---|
currentstatistics |
Current counters |
totalstatistics |
Lifetime counters |
sessions |
Active session count |
uptime |
Server uptime (seconds) |
| Flag | Description |
|---|---|
RTP/AVP |
Plain RTP (Audio/Video Profile) |
RTP/AVPF |
RTP with feedback |
RTP/SAVP |
SRTP (Secure AVP) |
RTP/SAVPF |
SRTP with feedback |
UDP/TLS/RTP/SAVP |
DTLS-SRTP |
UDP/TLS/RTP/SAVPF |
DTLS-SRTP with feedback |
| Flag | Description |
|---|---|
replace-origin |
Replace SDP origin line |
replace-session-connection |
Replace session-level connection |
trust-address |
Trust SDP addresses |
SIP-source-address |
Use SIP source as media address |
symmetric |
Force symmetric RTP |
asymmetric |
Allow asymmetric RTP |
| Flag | Description |
|---|---|
ICE=remove |
Remove all ICE attributes |
ICE=force |
Force ICE negotiation |
ICE=force-relay |
Force TURN relay |
| Flag | Description |
|---|---|
DTLS=off |
Disable DTLS |
DTLS=passive |
DTLS passive role |
DTLS=active |
DTLS active role |
| Flag | Description |
|---|---|
SDES-off |
Disable SDES |
SDES-on |
Enable SDES |
SDES-unencrypted_srtp |
Allow unencrypted SRTP |
SDES-unencrypted_srtcp |
Allow unencrypted SRTCP |
| Flag | Description |
|---|---|
codec-strip-all |
Remove all codecs |
codec-offer-XXXX |
Add codec XXXX to offer |
codec-mask-XXXX |
Remove codec XXXX |
transcode-XXXX |
Transcode to codec XXXX |
| Flag | Description |
|---|---|
record-call |
Enable call recording |
| Flag | Description |
|---|---|
media-timeout=N |
Media timeout in seconds |
receive-only |
Receive-only mode |
send-only |
Send-only mode |
d6:result2:ok...e
d6:result5:error12:error-reason18:Invalid parameterse
| Error | Description |
|---|---|
Unknown call-id |
Session not found |
Invalid SDP |
Malformed SDP |
Port allocation failed |
No available ports |
Codec negotiation failed |
No common codecs |
Session limit reached |
Max sessions exceeded |
If no response within timeout:
- Retry the request (up to configured retries)
- Mark instance as failed
- Failover to backup instance
Invalid bencode results in:
d6:result5:error12:error-reason14:Parse error: ...e
Attempting operations on invalid session state:
d6:result5:error12:error-reason20:Invalid session statee
# Ping test
echo -n "test123 d7:command4:pinge" | nc -u localhost 22222
# Expected response contains "pong"# In SIP proxy config, enable debug logging for rtpengine module
# Then make a test call and check logs