RTP Endpoint Setup

Introduction

These methods in the TestRtpLuaAgent Lua API are used as part of the negotiation process to agree which RTP endpoints will be used during a test.

The endpoints are established in two steps:

  1. The register method requests the TestRtpApp to assign a local UDP port number.
  2. 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.

This method takes two arguments.

The first is a SIP context object created by the TestSipLuaAgent Lua API’s invite_context or non_invite_context method. The object will be updated with the local RTP endpoint details.

The second 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
context Object [Required] The SIP context object created by the TestSipLuaAgent.
This will be updated with the local RTP endpoint details.
timeout_secs Integer Optional override for the inactivity guard timer.
(Default = use configured value for the TestRtpApp).

The method returns true.

Example registering an RTP local port:

-- Create a new outcall SIP INVITE Context for our calling/called parties.
local context = tsuo.invite_context (nil, "7000", "048989777")
...

-- Ask the TestRtpApp to assign us an RTP port.
truo.register (context)

.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 ()

-- Static for our call.
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 (nil, calling_party, called_party)

-- Attempt to establish a RTP listener that we can direct RTP packets at and store for comparison.
truo.register (context)

-- 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 " .. context.endpoints.local_rtp_ip .. "\
s=-\
c=IN IP4 " .. context.endpoints.local_rtp_ip .. "\
t=0 0\
m=audio " .. context.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)
...