title = “RTP Endpoint Setup” weight = 2 +++
Introduction
These methods in from TestRtpLuaAgent Lua API are used as part of the negotiation process to agree which RTP endpoints will be used during the RTP stream within this test.
The endpoints are established in two steps:
- The
register
method requests the TestRtpApp to assign a local UDP port number. - The
connect
method specifies the far-end IP address and UDP port number.
Setup API
.register [Asynchronous]
The register
method requests the TestRtpApp
to assign for us a local port from its reserved UDP port
range, and we wait for the application to create the UDP socket and then return the selected port number
to us so that it can be used in the construction of the SDP Offer/Answer that we send via SIP.
The method takes only a single parameter which is an optional override for the inactivity timeout period, which is a guard timer against death of the testing LogicApp. If there is no packet exchange on the RTP stream for this many seconds, then the RTP socket will be torn down and made available to future tests.
Note that there is no matching deregister
method. The RTP port deregistration is performed automatically
by the TestRtpLuaAgent when the Lua test script execution is over.
Argument | Type | Description |
---|---|---|
timeout_secs
|
Integer |
Optional override for the inactivity guard timer. (Default = use configured value for the TestRtpApp ).
|
The method returns a result object.
Argument | Type | Description |
---|---|---|
result
|
Object | Container for returned result attributes. |
.local_port
|
Object | The assigned local UDP port number for our test RTP stream endpoint. |
Note that the IP address for the bound UDP socket is not provided as a result from this method,
your test script should get this value from separate configuration, e.g. from a global
variable
definition in the LogicApp
configuration.
Example registering an RTP local port:
-- Ask the TestRtpApp to assign us an RTP port.
local result = truo.register ()
local rtp_listener_port = result.local_port
...
-- Initialise endpoints from global variables, but with our private RTP port.
local endpoints = tsuo.default_endpoints ({ local_rtp_port = rtp_listener_port })
...
-- Create a new outcall SIP INVITE Context for our endpoints and calling/called parties.
local context = tsuo.invite_context (endpoints, "7000", "048989777")
...
.connect [Synchronous]
The connect
method informs the TestRtpApp
what the destination address will be for any packets
which we are going to send for this RTP stream. If your test does not send RTP packets, then this
step in the process is not necessary.
This method is synchronous. The remote endpoint information is sent to the TestRtpApp
but we
do not wait for any acknowlegement, we return immediately to Lua script control.
This method takes three arguments.
Argument | Type | Description |
---|---|---|
remote_ip
|
IPv4 Address | [Required] The IPv4 dot-notation remote endpoint address. |
remote_port
|
Integer | [Required] The remote endpoint UDP port number. |
clock_rate
|
Integer |
The clock rate, which is used to determine the correct timing intervals for sending
RTP packets, including telephone-event and payloads. (Default = 8000 ).
|
The method returns true
.
Example registering an RTP local port and defining the remote ip/port address:
-- Start timer for elapsed checking.
local tv = match.elapsed ()
-- Attempt to establish a RTP listener that we can direct RTP packets at and store for comparison.
local register_result = truo.register ()
-- Static for our call.
local endpoints = tsuo.default_endpoints ({ local_rtp_port = register_result.local_port })
local calling_party = '665566'
local called_party = '4000'
local encoding = 'AMR-WB/16000'
-- Get a SIP outcall context from our helper library.
local context = tsuo.invite_context (endpoints, calling_party, called_party)
-- Construct the SDP.
local sdp_session_id = os.time () % 10000
local sdp_session_version = math.random (1000) - 1
local sdp_offer =
"v=0\
o=" .. calling_party .. " " .. sdp_session_id .. " " .. sdp_session_version .. " IN IP4 " .. endpoints.local_rtp_ip .. "\
s=-\
c=IN IP4 " .. endpoints.local_rtp_ip .. "\
t=0 0\
m=audio " .. endpoints.local_rtp_port .. " RTP/AVP 98 103\
a=rtpmap:98 AMR-WB/16000\
a=fmtp:98 octet-align=1\
a=rtpmap:103 telephone-event/16000"
-- Construct and Send INVITE Request.
tsuo.invite_send_request (context, sdp_offer)
-- Expect Trying & Ringing.
tsuo.invite_expect_response (context, 100, "Trying")
tsuo.invite_expect_response (context, 180, "Ringing")
tv = match.elapsed ("Ring Notification (immediate)", tv, 0.0)
-- Expect INVITE Answer Response (200 OK) after 2 seconds.
local invite_response = tsuo.invite_expect_response (context, 200, "OK", nil, { sdp_media = tsuo.SDP_MEDIA_N2_AMRWB_OA })
tv = match.elapsed ("Call Answered (2.0s)", tv, 1.99)
-- Request our RTP tester to connect to the far-end IP/port. Now we can send RTP as well as receive it.
truo.connect (invite_response.sdp.connection.ip4.address, invite_response.sdp.media.audio.port, 16000)
-- Send an AMR CMR before we ACK to ensure streaming uses the desired mode.
truo.send_amr_cmr (98, 2)
...