XFL and Python API

get_absolute_time

get_absolute_time ()

Returns time in milliseconds elapsed since 00:00:00 UTC 1 January 1970. Differs from “gettime” API and “gettime” function in XFL Formulas in the following points:

Callable from:

Arguments

Return Value

encode

encode (data1 [, data2[, …]] [, mode])

Encodes data element–usually a whole message–into a bit string

Callable from:

Arguments

Argument Name M/O Value Type Description
data M PDU Data to encode
mode O Integer OR of binary flags. If omitted, the value is 0

mode flags

Value Description
256 Return encoded data as charStr instead of bitStr

Return Value

Return Type

Python Example:

# Encoding 4 layers together into a binary

isup, sigtr, sctp, ipv4 = Build_ISUP_IAM(), Build_M3UA_DATA(), Build_SCTP_Packet(), Build_IPv4_Frame()

binaryData = sk.encode(isup, sigtr, sctp, ipv4)

seedrandom

seedrandom ([seed])

Restarts the pseudo-random sequence generated by rand(). The sequence is also implicitly restarted when Packet Studio starts, and in the beginning of XFL execution.
Affects receive() in random mode (see ‘Settings.ReceiveSide.Random mode’ on ‘Vars’ page). This call doesn’t affect language-specific random generation.

Callable from:

Arguments

Argument Name Type Value Description
seed O Int Seed value. Omit this argument to make a really random seed. Pass 1 to reproduce the sequence that occured before any call to seedrandom.

Return Value

getdir

getdir ()

Returns the script directory

Callable from:

Arguments

Return Value

Return Type

getexamplesdir

getexamplesdir ()

Returns the absolute path to ‘Examples’ folder

Callable from:

Arguments

Return Value

Return Type

getworkspacedir

getworkspacedir ()

Returns the script directory

Callable from:

Arguments

Return Value

Return Type

getcommondir

getcommondir ()

Returns the script directory

Callable from:

Arguments

Return Value

Return Type

rtp_create_session

rtp_create_session (local-host, local-port [, remote-host] [, remote-port] [, flags])

Creates an RTP session

Callable from:

Arguments

Argument Name Type Value Description
local_host M String Local IP Address
local_port M Integer Local Port numbe r
remote_host O String Remote IP Address
remote_port O Integer Remote Port number
flags O integer OR of binary flags. If omitted, the value is 0

flags values

Value Description
1 Allow receiving RTP packets with frames per packet ratio greater than the codec’s default

Return Value

Return Type

Python Example:

rtpSessionId = sk.rtp_create_session(SourceIPAddress, SourceRTPPort, remoteIPPort, remoteRTPPort)

rtp_set_session_remote_addr

rtp_set_session_remote_addr (session-id, remote-host, remote-port)

Sets remote address and port for an RTP session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session identifier, returned from a ‘rtp_create_session’ call
remote-host M String Remote IP Address
remote-port M Integer Remote Port number

Return Value

rtp_tx_init_srtp

rtp_tx_init_srtp (session-id, cipher-type, cipher-key-len, auth-type, auth-key-len, auth-tag-len, key)

Initialize SRTP in the outgoing direction

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session identifier
cypher-type M Integer Cypher type
cypher-key-len M Integer Cypher key length
auth-type M Integer Authentification type
auth-key-len M Integer Authentification key length
auth-tag-len M Integer Authentification tag length
key M Integer Security key

cypher_type values

Value Description
0 NULL_CIPHER
1 AES_128_ICM
2 SEAL
3 AES_128_CBC

auth_type values

Value Description
0 NULL_AUTH
1 UST_TMMHv2
2 UST_AES_128_XMAC
3 HMAC_SHA1

Return Value

Python Example:

sk.srtp_tx_init_srtp(rtpSessionId, 1, 30, 3, 20, 10, secret)

rtp_rx_init_srtp

rtp_rx_init_srtp (session-id, cipher-type, cipher-key-len, auth-type, auth-key-len, auth-tag-len, key)

Initialize SRTP in the incoming direction

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session identifier
cypher-type M Integer Cypher type
cypher-key_len M Integer Cypher key length
auth-type M Integer Authentification type
auth-key-len M Integer Authentification key length
auth-tag-len M Integer Authentification tag length
key M Integer Security key

cypher_type values

Value Description
0 NULL_CIPHER
1 AES_128_ICM
2 SEAL
3 AES_128_CBC

auth_type values

Value Description
0 NULL_AUTH
1 UST_TMMHv2
2 UST_AES_128_XMAC
3 HMAC_SHA1

Return Value

Python Example:

sk.srtp_rx_init_srtp(rtpSessionId, 1, 30, 3, 20, 10, secret)

rtp_terminate_session

rtp_terminate_session (session-id)

Terminates an RTP session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

Python Example:

rtp_terminate_session rtpSessionId

rtp_tx_set_dscp

rtp_tx_set_dscp (session-id, dscp)

Sets DSCP field in outgoing IP frames

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
dscp M Integer DSCP field value for outgoing IP frames

dscp values

Value Description
0 Best effort
10 AF11
12 AF12
14 AF13
18 AF21
20 AF22
22 AF23
26 AF31
28 AF32
30 AF33
34 AF41
36 AF42
38 AF43
46 Expedited forwarding

Return Value

rtp_tx_setup_iuup

rtp_tx_setup_iuup (session-id [, IuUP-mode-version ], RFCI [, CRC])

Configures IuUP parameters for a transmitting session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
IuUP-mode-version O Integer IuUP mode version to be used in IuUP signalling. Valid range is 0..15 (versions 1..16 respectively). Default value: 0.
RFCI M Integer RFCI (RAB sub-Flow Combination Indicator) to be used in outgoing IuUP signalling. Valid range is 0..63.
CRC O Boolean Whether to use Payload CRC in outgoing IuUP signalling. Default value: true.

Return Value

rtp_tx_tone

rtp_tx_tone (session-id, encoding, freq, power [, pt ] [, frames-per-packet])

Commences transmission of a tone consisting of one harmonic as an RTP stream

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
encoding M Integer RTP payload encoding
freq M Integer Frequenct, Hz
power M Integer Power, dB
pt O Integer Payload type, in range 0..127. Value used for PT field in RTP packet header. Specify this argument only for dynamic payloads (AMR and AMR-WB). See RFC 3550, 3551 for details. If omitted, static payload type for the encoding is used (or 96 if no static mapping is present).
frames-per-packet O Integer Frames per packet, in range 1..100. Defines how many speech frames of the codec (specified by ‘encoding’ argument) is placed in a single RTP packet. Default value depends on the codec, see ‘encoding’ description.

Return Value

Python Example

sk.rtp_tx_tone(rtpSessionId, 1, 440)

rtp_tx_dtmf

rtp_tx_dtmf (session-id, encoding, digits [, power] [, pt] [, frames-per-packet] [, digit-duration] [, repeats] [, blocking])

Sends DTMF digits over a given RTP session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
encoding M Integer RTP payload encoding
digits M String String of DTMF digits. Valid characters are 0..9, * and #.
power M Integer Power, dB
pt O Integer Payload type, in range 0..127. Value used for PT field in RTP packet header. Specify this argument only for dynamic payloads (AMR and AMR-WB). See RFC 3550, 3551 for details. If omitted, static payload type for the encoding is used (or 96 if no static mapping is present).
frames-per-packet O Integer Frames per packet, in range 1..100. Defines how many speech frames of the codec (specified by ‘encoding’ argument) is placed in a single RTP packet. Default value depends on the codec, see ‘encoding’ description.
digit_duration O Integer Duration of each DTMF digit except last, in milliseconds, if more than one digit specified. 550 milliseconds if omitted.
repeats O Integer Number of repeats. Repeat once if omitted.
blocking O Boolean True - wait until all DTMF digits except last are transmitted for ‘digit_duration’ each, then call returns, and the last digit starts and lasts indefinitely until explicitly stopped by another API call. False - call returns immediately and after that all DTMF digits are transmitted for ‘digit_duration’ each. True if omitted.

Return Value

rtp_tx_silence

rtp_tx_silence (session-id, encoding [, pt ] [, frames-per-packet])

Sends silence over a given session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
encoding M Integer RTP payload encoding
pt O Integer Payload type, in range 0..127. Value used for PT field in RTP packet header. Specify this argument only for dynamic payloads (AMR and AMR-WB). See RFC 3550, 3551 for details. If omitted, static payload type for the encoding is used (or 96 if no static mapping is present).
frames-per-packet O Integer Frames per packet, in range 1..100. Defines how many speech frames of the codec (specified by ‘encoding’ argument) is placed in a single RTP packet. Default value depends on the codec, see ‘encoding’ description.

Return Value

rtp_tx_wav

rtp_tx_wav (session-id, encoding, file-path [, repeats] [, pt] [, frames-per-packet])

Commences transmission of a waveform from a .wav file as an RTP stream

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
encoding M Integer RTP payload encoding
file-path M String Absolute path to the .wav file to be transmitted
repeats O Integer Number of repeats. Play forever if omitted
pt O Integer Payload type, in range 0..127. Value used for PT field in RTP packet header. Specify this argument only for dynamic payloads (AMR and AMR-WB). See RFC 3550, 3551 for details. If omitted, static payload type for the encoding is used (or 96 if no static mapping is present).
frames-per-packet O Integer Frames per packet, in range 1..100. Defines how many speech frames of the codec (specified by ‘encoding’ argument) is placed in a single RTP packet. Default value depends on the codec, see ‘encoding’ description.

Return Value

Python Example

sk.rtp_tx_wav(rtpSessionId, 1, "Examples\\Voice\\digits.wav", 1)

rtp_tx_encoded

rtp_tx_encoded (session-id, encoding, file-path [, repeats] [, pt] [, frames-per-packet])

Commences transmission of a preencoded file as an RTP stream

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
encoding M Integer RTP payload encoding
file_path M String Absolute path to the .wav file to be transmitted
repeats O Integer Number of repeats. Play forever if omitted
pt O Integer Payload type, in range 0..127. Value used for PT field in RTP packet header. Specify this argument only for dynamic payloads (AMR and AMR-WB). See RFC 3550, 3551 for details. If omitted, static payload type for the encoding is used (or 96 if no static mapping is present).
frames-per-packet O Integer Frames per packet, in range 1..100. Defines how many speech frames of the codec (specified by ‘encoding’ argument) is placed in a single RTP packet. Default value depends on the codec, see ‘encoding’ description.

Return Value

Python Example

originalWavPath = sk.getrootdir() + "\\Examples\\Voice\\female.wav"
encodedWavPath = sk.getdir() + "\\voice-preencoded-rtp.wav"
recordedWavPath = sk.getdir() + "\\recorded-voice-rtp.wav"

sk.rtp_preencode(originalWavPath, encodedWavPath, 2)

rtpSessionID1 = sk.rtp_create_session("127.0.0.1", 2000, "127.0.0.1", 3000)
rtpSessionID2 = sk.rtp_create_session("127.0.0.1", 3000, "127.0.0.1", 2000)

sk.rtp_rx_wav(rtpSessionID1, recordedWavPath) # start saving incoming RTP stream to the .wav file
sk.rtp_tx_encoded(rtpSessionID2, 2, encodedWavPath, 1) # start sending encoded file

sk.sleep(5000)

sk.rtp_tx_off(rtpSessionID2)
sk.rtp_rx_off(rtpSessionID1)

rtp_tx_audio

rtp_tx_audio (session-id, encoding [, pt] [, frames-per-packet])

Commences transmission of the PC’s audio input (e.g., microphone)

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
encoding M Integer RTP payload encoding
pt O Integer Payload type, in range 0..127. Value used for PT field in RTP packet header. Specify this argument only for dynamic payloads (AMR and AMR-WB). See RFC 3550, 3551 for details. If omitted, static payload type for the encoding is used (or 96 if no static mapping is present).
frames-per-packet O Integer Frames per packet, in range 1..100. Defines how many speech frames of the codec (specified by ‘encoding’ argument) is placed in a single RTP packet. Default value depends on the codec, see ‘encoding’ description.

Return Value

rtp_tx_get_status

rtp_tx_get_status (session-id)

Retrieves RTP generation process status

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

Value Meaning
-2 no process started
-1 in progress
0 error occured
1 successfully finished

Return Type

rtp_rx_setup_payload

rtp_rx_setup_payload (session-id, pt, mime [, mode])

Configures encoding to be used to handle incoming RTP packets with the specified dynamic payload type. See RFC 3550, 3551 on payload types.

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
pt M Integer Payload type. Range 0..127. Value used for PT field in RTP packet header. See RFC 3550, 3551 for details.
mime M String MIME name of the encoding
mode O Integer Valid only for AMR and AMR-WB

mime values

Value Meaning
“AMR” AMR Codec
“AMR-WB” AMR-WB Codec

mode values

Value Meaning
0 bandwidth-efficient mode
1 octet-aligned mode
2 IuUP mode

Return Value

rtp_rx_wav

rtp_rx_wav (session-id, file-path [, sampling-frequency])

Commences reception of the waveform from an RTP stream and recording it to a .wav file

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
file-path M String Path to a file to save to
sampling-frequency O Integer .wav sampling frequency, in kHz. Default value: 8000.

Return Value

Python Example

originalWavPath = sk.getrootdir() + "\\Examples\\Voice\\female.wav"
encodedWavPath = sk.getdir() + "\\voice-preencoded-rtp.wav"
recordedWavPath = sk.getdir() + "\\recorded-voice-rtp.wav"

sk.rtp_preencode(originalWavPath, encodedWavPath, 2)

rtpSessionID1 = sk.rtp_create_session("127.0.0.1", 2000, "127.0.0.1", 3000)
rtpSessionID2 = sk.rtp_create_session("127.0.0.1", 3000, "127.0.0.1", 2000)

sk.rtp_rx_wav(rtpSessionID1, recordedWavPath) # start saving incoming RTP stream to the .wav file
sk.rtp_tx_encoded(rtpSessionID2, 2, encodedWavPath, 1) # start sending
encoded file

sk.sleep(5000)

sk.rtp_tx_off(rtpSessionID2)
sk.rtp_rx_off(rtpSessionID1)

rtp_rx_audio

rtp_rx_audio (session-id)

Commences reception of the waveform and redirecting it to PC’s audio output

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

rtp_rx_detect_dtmf

rtp_rx_detect_dtmf (session-id)

Starts DTMF detection on a given RTP session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

rtp_rx_dtmf

rtp_rx_dtmf (session-id)

Receives DTMF digits from given RTP session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

Return Type

rtp_rx_detect_tone

rtp_rx_detect_tone (session-id, freq [, power])

Starts tone detection on a given RTP session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
freq M Integer Frequency, Hz
power O Integer Power threshold, dB. (Not yet supported).

Return Value

rtp_rx_tone

rtp_rx_tone (session-id, freq)

Checks whether a tone was detected on an RTP session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
freq M Integer Frequency, Hz

Return Value

Return Type

rtp_rx_off

rtp_rx_off (session-id)

Ceases reception on a given rtp session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

Python Example

originalWavPath = sk.getrootdir() + "\\Examples\\Voice\\female.wav"
encodedWavPath = sk.getdir() + "\\voice-preencoded-rtp.wav"
recordedWavPath = sk.getdir() + "\\recorded-voice-rtp.wav"

sk.rtp_preencode(originalWavPath, encodedWavPath, 2)

rtpSessionID1 = sk.rtp_create_session("127.0.0.1", 2000, "127.0.0.1", 3000)
rtpSessionID2 = sk.rtp_create_session("127.0.0.1", 3000, "127.0.0.1", 2000)

sk.rtp_rx_wav(rtpSessionID1, recordedWavPath) # start saving incoming RTP
stream to the .wav file
sk.rtp_tx_encoded(rtpSessionID2, 2, encodedWavPath, 1) # start sending encoded file

sk.sleep(5000)

sk.rtp_tx_off(rtpSessionID2)
sk.rtp_rx_off(rtpSessionID1)

rtp_rx_get_jitter

rtp_rx_get_jitter (session-id)

Retrieves the current jitter

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

Return Type

rtp_rx_get_loss

rtp_rx_get_loss (session-id)

Retrieves the current jitter

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

Return Type

rtp_rx_get_comulative_loss

rtp_rx_get_comulative_loss (session-id)

Retrieves the cumulative packet loss ratio

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

Return Value

rtp_tx_data

rtp_tx_data (session-id, pt, data)

Transmits data block within RTP session, e.g. for DTMF or tone events

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
pt M Integer Payload type, in range 0..127. Set a PT field in RTP packet header (RFC 3550-3551).
data M Octet String Data to send

Return Value

rtp_tx_off

rtp_tx_off (session-id)

Ceases transmission on a given RTP session

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id

Return Value

Python Example

originalWavPath = sk.getrootdir() + "\\Examples\\Voice\\female.wav"
encodedWavPath = sk.getdir() + "\\voice-preencoded-rtp.wav"
recordedWavPath = sk.getdir() + "\\recorded-voice-rtp.wav"

sk.rtp_preencode(originalWavPath, encodedWavPath, 2)

rtpSessionID1 = sk.rtp_create_session("127.0.0.1", 2000, "127.0.0.1", 3000)
rtpSessionID2 = sk.rtp_create_session("127.0.0.1", 3000, "127.0.0.1", 2000)

sk.rtp_rx_wav(rtpSessionID1, recordedWavPath) # start saving incoming RTP stream to the .wav file
sk.rtp_tx_encoded(rtpSessionID2, 2, encodedWavPath, 1) # start sending encoded file

sk.sleep(5000)

sk.rtp_tx_off(rtpSessionID2)
sk.rtp_rx_off(rtpSessionID1)

rtp_set_mirroring_mode

rtp_set_mirroring_mode (session-id, mirroring-mode)

Controls RTP session mirroring mode

Callable from:

Arguments

Argument Name Type Value Description
session-id M Integer RTP session id
mirriring-mode M Boolean True - set mirroring mode, False - clear mirroring mode.

Return Value

rtp_preencode

rtp_preencode (src-file-path, dst-file-path, encoding [, frames-per-packet])

Encodes .wav with the specified audio codec and saves the result to the other file.

Callable from:

Arguments

Argument Name Type Value Description
_src-file-path M String Path to the file to be encoded
dst-file-path M String Path to the file to be saved
encoding M Integer RTP payload encoding
frames-per-packet O Integer Frames per packet, in range 1..100. Defines how many speech frames of the codec are placed in a single RTP packet. Default value depends on the codec selected.

Return Value

Python Example

originalWavPath = sk.getrootdir() + "\\Examples\\Voice\\female.wav"
encodedWavPath = sk.getdir() + "\\voice-preencoded-rtp.wav"
recordedWavPath = sk.getdir() + "\\recorded-voice-rtp.wav"

sk.rtp_preencode(originalWavPath, encodedWavPath, 2)

rtpSessionID1 = sk.rtp_create_session("127.0.0.1", 2000, "127.0.0.1", 3000)
rtpSessionID2 = sk.rtp_create_session("127.0.0.1", 3000, "127.0.0.1", 2000)

sk.rtp_rx_wav(rtpSessionID1, recordedWavPath) # start saving incoming RTP stream to the .wav file
sk.rtp_tx_encoded(rtpSessionID2, 2, encodedWavPath, 1) # start sending encoded file

sk.sleep(5000)

sk.rtp_tx_off(rtpSessionID2)
sk.rtp_rx_off(rtpSessionID1)

mos_calc

mos_calc (rxWav, txWav)

Calculates MOS

Callable from:

Arguments

Argument Name Type Value Description
rxWav M String Path to received the.wav file
txWav M String Path to the transmitted.wav file

Return Value

1 - sucess, 0 - failure.

Return Type

Python Example

txWav = "examples\\Audio\\Voice\\male.wav" # original
rxWav = sk.getdir() + "\\rec\\male-rx.wav" # degradated

if sk.mos_calc(rxWav, txWav):
sk.print_("mos_val=", sk.mos_get_val_int, ", mos_delay=", sk.mos_get_delay, " sec")

mos_get_val_int

mos_get_val_int ()

Retrieves the calculated MOS value

Callable from:

Arguments

Return Value

Return Type

Python Example

txWav = "examples\\Audio\\Voice\\male.wav" # original
rxWav = sk.getdir() + "\\rec\\male-rx.wav" # degradated

if sk.mos_calc(rxWav, txWav):
sk.print_("mos_val=", sk.mos_get_val_int, ", mos_delay=", sk.mos_get_delay_ms, " ms")

mos_get_delay_ms

mos_get_delay_ms ()

Retrieves the calculated MOS value

Callable from:

Arguments

Return Value

Return Type

Python Example

txWav = "examples\\Audio\\Voice\\male.wav" # original
rxWav = sk.getdir() + "\\rec\\male-rx.wav" # degradated

if sk.mos_calc(rxWav, txWav):
sk.print_("mos_val=", sk.mos_get_val_int, ", mos_delay=", sk.mos_get_delay_ms, " ms")

definevariable

definevariable (id, type [, defVal] [, flags] [, description])

Define a variable

Callable from:

Arguments

Argument Name Type Value Description
id M String Identifier
type M PDU/field type Type. Must be one of types in “common” PCO
defVal O String Digital (Initial) value. String formatted appropriately for .
flags O Integer Bit combination (OR) of flags
description O String Arbitrary description

flags values

Value Description
2 global (define a global variable)
16 overwrite on id clash (if identifier already used, overwrite it with the new Definition)
32 fail on id clash (if identifier already used, skip this new definition and return false)

If omitted the value is 2.

Return Value

Return Type

Boolen

MD4

MD4 (data)

Calculates MD4 of an octet string

Callable from:

Arguments

Argument Name Type Value Description
data M Octet String Data to calculate MD4 on

Return Value

Return Type

Python Example

data = "Data"
MD4hash = sk.MD4(str2hex(data))

MD5

MD5 (data)

Calculates MD5 of an octet string

Callable from:

Arguments

Argument Name Type Value Description
data M Octet String Data to calculate MD5 on

Return Value

Return Type

Python Example

data = "Data"
MD5hash = sk.MD5(str2hex(data))

DES_Encrypt

DES_Encrypt (key, data)

Encrypts data using DES

Callable from:

Arguments

Argument Name Type Data Type Description
key M Octet String 7 Octets
data M Octet String 8 Octets

Return Value

Return Type

Python Example

raw_data = "94 74 B8 E8 C7 3B CA 7D"
key = "A1 B2 C3 D4 E5 F6 57"
encrypted_data = sk.DES_Encrypt(key, data)

DES_Decrypt

DES_Decrypt (key, data)

Decrypt data using DES

Callable from:

Arguments

Argument Name Type Data Type Description
key M Octet String 7 Octets
data M Octet String 8 Octets

Return Value

Return Type

Python Example

key = "A1 B2 C3 D4 E5 F6 57"
raw_data = sk.DES_Decrypt(key, encrypted_data)

MD5DigestResponse

MD5DigestResponse (alg, nonce, nc, cnonce, user, password, realm, qop, method, uri)

Calculates MD5 Digest Response when SIP called party requires authentication

Callable from:

Arguments

Argument Name Type Data Type Description
alg M String Algorithm. Possible values are “MD5” and “MD5-sess”
nonce M String A value of Nonce parameter from a server response
nc M String A value of nc (NonceCount) parameter from a server response
cnonce M String A value of CNonce parameter from a server response
user M String User Name
password M String Password
realm M String A value of Realm parameter from a server response
qip M String A string of tokens indicating “quality of protection” values supported by the a server
method M String SIP method from the original request
uri M String A URI from the original response

Return Value

Return Type

Python Example

nonce="46f9646f0794e0796d3874ff1a38c497f5200785"
SIPUserName="12345"
SIPUserPassword="54321"
realm="sip.example.com"
method="REGISTER"
uri="sip:sip.example.com"
md5response = sk.MD5DigestResponse("MD5", nonce, "", "", SIPUserName, SIPUserPassword, realm, "", method, uri)

ModPow

ModPow (base, exp, mod)

Computes (base ^ exp) % mod

Callable from:

Arguments

Argument Name Type Data Type Description
base M Octet String Base. Octet string representing a big integer, first octet is the most significant.
exp M Octet String Exponent. Octet string representing a big integer, first octet is the most significant.
mod M Octet String Modulus. Octet string representing a big integer, first octet is the most significant.

Return Value

Return Type

Python Example

g = "02" # MSB first
x = "09 a3 78 f9 b2 e3 32 a7 09 a3 78 f9 b2 e3 32 57" # MSB first
p = "21 68 C2" # MSB first
# e = g^x mod p:
e = sk.ModPow(g, x, p)

SHA1

SHA1 (data)

Calculates SHA1 of data

Callable from:

Arguments

Argument Name Type Data Type Description
data M Octet String Data for SHA1 hash function

Return Value

Return Type

Python Example

sha1Param = "A1 B2 C3 D4 E5 F6 57 A1 B2 C3 D4 E5 F6 57 A1 B2 C3 D4 E5 F6"
H = sk.SHA1(sha1Param)

HMAC

HMAC (algorithm, key, data)

Calculates a hash-based message authentication code (HMAC)

Callable from:

Arguments

Argument Name Type Value Description
algorithm M String HMAC algorithm
key M Octet String Key for HMAC algorithm
data M Octet String Data for HMAC algorithm

algorithm values

Value
“hmac-md5”
“hmac-sha1”
“hmac-sha1-96”
“hmac-sha-256”
“hmac-sha-256-96”

Return Value

Return Type

MILENAGE_f1

MILENAGE_f1 (k, rand, sqn, amf, op)

Calculates f1 function from the MILENAGE algorithm set (3GPP TS 35.205-208)

Callable from:

Arguments

Argument Name Type Value Type Description
k M Octet String Subscriber key, 16 octets
rand M Octet String Random challenge, 16 octets
sqn M Octet String Sequence number, 6 octets
amf M Octet String Authentication management field, 2 octets
op M Octet String Operator Variant Algorithm Configuration Field, 16 octets

Return Value

Return Type

MILENAGE_f2345

MILENAGE_f2345 (k, rand, op)

Calculates f2345 function from the MILENAGE algorithm set (3GPP TS 35.205-208)

Callable from:

Arguments

Argument Name Type Value Type Description
k M Octet String Subscriber key, 16 octets
rand M Octet String Random challenge, 16 octets
op M Octet String Operator Variant Algorithm Configuration Field, 16 octets

Return Value

Return Type

Python Example

k    = "01 25 45 74 58 35 43 65 14 21 33 12 54 77 92 ff"
rand = "a1 b2 c3 57 89 78 85 32 14 56 85 56 62 14 47 32"
res_ck_ik_ak = sk.MILENAGE_f2345(k, rand, "63 54 56 54 56 43 65 46 35 45 64 56 45 64 56 55")
res = res_ck_ik_ak(0)
ck = res_ck_ik_ak(1)
ik = res_ck_ik_ak(2)
ak = res_ck_ik_ak(3)

MILENAGE_f1star

MILENAGE_f1star (k, rand, sqn, amf, op)

Calculates f1* function from the MILENAGE algorithm set (3GPP TS 35.205-208)

Callable from:

Arguments

Argument Name Type Value Type Description
k M Octet String Subscriber key, 16 octets
rand M Octet String Random challenge, 16 octets
sqn M Octet String Sequence number, 6 octets
amf M Octet String Authentication management field, 2 octets
op M Octet String Operator Variant Algorithm Configuration Field, 16 octets

Return Value

Return Type

MILENAGE_f5star

MILENAGE_f5star (k, rand, op)

Calculates f5* function from the MILENAGE algorithm set (3GPP TS 35.205-208)

Callable from:

Arguments

Argument Name Type Value Type Description
k M Octet String Subscriber key, 16 octets
rand M Octet String Random challenge, 16 octets
op M Octet String Operator Variant Algorithm Configuration Field, 16 octets

Return Value

Return Type

TLS_AddTrustFile

TLS_AddTrustFile (src-file-path)

Adds the trusted CAs in order to verify client or server certificates

Callable from:

Arguments

Argument Name Type Value Type Description
src-file-path M String Absolute path to the X.509 Certificate file

Return Value

Return Type

TLS_SetupCredentials

TLS_SetupCredentials (cert-file-path, key-file-path)

Sets a certificate/private key pair

Callable from:

Arguments

Argument Name Type Value Type Description
cert-file-path M String Absolute path to the X.509 Certificate file
key-file-path M String Absolute path to the X.509 private key file

Return Value

Return Type

Python API

send

send (pdu [, pdu [, …]])

Send a packet. The arguments are comma separated PDU data structures. The first one is a PDU of the top stack layer, the next one of the layer immedialtely below, etc. Each consecutive PDU is encoded and placed into a payload field of the follow-up PDU. The last argument is either an IP layer PDU or a data harness structure for passing the scripted part of the packet to an independently running transport stack (TCP for example) for further processing.

Callable from: from

Arguments

Argument Name Type Value Description
pdu M PDU PDU to be sent

Return Value

Example:

sk.send(pdu_ISUP, pdu_MTP2, pdu_MTP2_HAL)

receive

receive ([var-pdu] [, timeout], pdu-type1 [, pdu-type2 [, …]] [, var-extra-pdu1, extra-pco1 [, var-extra-pdu2, extra-pco2 [, …]]])

Receives a packet. Checks every incoming packet for any of the specified PDU types listed (pdu-type1, pdu-type2, …), left to right. For the first PDU type match, stores the corresponding packet data to a variable specified in “var-pdu” argument. If more than one of the listed PDU types is present in the packet, the leftmost one takes priority. If no match is found, the packet is ignored.

To intercept lower layers of the captured packet, one or more pairs of “var-extra-pdu, extra-pco” arguments may be specified. If a PDU of “extra-pco” layer is present in the packet, the PDU data is stored to “var-extra-pdu”. There is no exact PDU type check for “extra-pdu”.

Callable from:

Arguments

Argument Name Type Value Description
var-pdu O PDU/field Variable to store the received PDU. This parameter must be initialized using create() API call without arguments.
timeout O Integer Maximum time to wait for an incoming packet, in milliseconds; infinite if omitted.
pdu-type M PDU/field type Type of PDU to receive
var-extra-pdu O PDU/field Variable to store a PDU captured at ‘extra-pco’, if present in the packet. This parameter must be initialized using create() API call without arguments.
extra-pco O PCO Additional PCO to intercept

Return Value

Return Type

Example:

var_SDPorINVITE = sk.create()  # var_PDU
var_SIP = sk.create() # extra PDU var, here SIP will go, if present in the packet at all
var_TCPIP = sk.create() # extra_PDU var, here TCP/IP Control will go

success = sk.receive (
var_SDPorINVITE, # will capture SDP or SIP.INVITE PDU data present in the incoming packet, can't predict which
10000, # optional timeout
sk.SDP, # expected PDU type to fill inSDPorINVITE variable
sk.SIP.INVITE, # another expected PDU type to fill inSDPorINVITE variable
var_SIP, # optional var to capture SIP, if present in the packet received
sk.SIP, # PDU type to fill var_SIP variable above
var_TCPIP, # optional var to capture TCP/IP Control, if any
sk.TCP_IP_Control) # PDU type to fill var_TCPIP variable above

sleep

sleep (timeout)

Delays script execution

Callable from:

Arguments

Argument Name Type Value Description
timeout M Integer Time to sleep

Return Value

Example:

sk.sleep(3000)

gettime

gettime ()

Time in milliseconds elapsed from the script start

Callable from:

Arguments

Return Value

Return Type

Example:

tStart = sk.gettime()
# do something
sk.print ("Duration: " + str(sk.gettime() - tStart) + " ms.")

run

run (path, [mode] [, arg1 [, arg2 [, …]]])

Start a child script

Callable from:

Arguments

Argument Name Type Value Description
path M String Path to the script to run
mode O Integer Bit combination (OR) of the following flags. If omitted, the mode is equal to 0.
arg O Any Argument Name to pass to the script. Accessible in the child via ‘Settings.Arguments’ array.

arg values

Value Meaning
1 Asynchronous mode (run() returns immediately and the started child script continues to run; otherwise, run() returns after child script returns; note that parent won’t stop until all asynchronous children are completed, even if the parent’s code is already executed completely)
2 Inherit globals (global variables and functions of this script are visible in the child script)
4 Separate socket set (send() and receive() in the child script use only IP sockets opened by the child itself, sockets opened in the parent script are not visible; for transceivers other than IP sockets, all incoming packets from emulator(s) are routed to each child separately)
8 Don’t preprocess (don’t preprocess (handle #includes etc) non-XFL script and don’t compile XFL scripts; variable values from text includes in XFL script are still updated)
16 Don’t update variable values (don’t update variable values from text includes in XFL script)

Return Value

Return Type

Example:

ch = [None] * 3                   # array to store children ids
for i in range(3):
ch[i] = sk.run("child.ats", 1) # run another child asynchronously and store its id

waitchild

waitchild (child [, timeout] [, mode])

Waits for child script to complete. The child script must be previously run() in asynchronous mode.

Callable from:

Arguments

Argument Name Type Value Description
child M Integer Identifier of the child script, returned by asynchronous run()
timeout O Integer Timeout, in milliseconds; infinite wait if omitted
mode O Integer Reserved for the future, use 0

Return Value

Return Type

Example

child = sk.run("Demo", 1, "child")  # '1' => asynch. mode
result = sk.waitchild(child) # wait until the child completes

decode

decode (data, raw, type [, method])

Stops script execution

Callable from:

Arguments

Argument Name Type Value Description
data M PDU/field Variable to store the decoded data
raw M Octet string Octet or bit string representing data encoding
type M PDU/field type Type of data to decode
method O Integer Decoding method

Return Value

Return Type

Example:

inSIP = sk.create(sk.SIP.REGISTER)
ok = sk.decode(inSIP, inUDP.Data, sk.SIP.REGISTER)

decodeex

decodeex (data, lowerPCO, upperPCO, mode [, pco1 [, pco2 [, …]]])

Decodes multiple PDUs from a string of octets or bits or from a lower PDU.

Callable from:

Arguments

Argument Name Type Value Description
data M Octet string Octet or bit string representing data encoding, or the lowest PDU to start decode from
lowerPCO M PCO Lower PCO of the transformer applicable to ‘data’. Omitted (with no placeholder actual argument) if ‘data’ is a PDU instead of octet/bit string.
upperPCO M PCO Upper PCO of the transformer applicable to ‘data’. Omitted (with no placeholder actual argument) if ‘data’ is a PDU instead of octet/bit string.
mode M Integer Bit combination (OR) of flags
pco O PCO PCOs for decode process directing and ambiguity resolution

mode values

Value Meaning
1 to the top (‘pcos’ argument is used only for ambiguity resolution; decode climbs up as much as possible, independent on ‘pcos’)
2 explicit suppresses implicit (if the transformer’s upper PCO is listed in ‘pcos’ explicitly, it leaves no chance for other non-mutex transformers to be applied)

Return Value

Return Type

Example:

# Decoding multiple layers from raw binary, which must result in 4 decoded PDUs (layers)
tree = sk.decodeex(binaryData, sk.Ethernet_L2, sk.IPv4, 1, sk.UDP)

create

create (type)

Creates a variable of a given type, typically a packet

Callable from:

Arguments

Argument Name Type Value Description
type M PDU/field type Type of data to create. Typically a PDU type.

Return Value

Return Type

gettype

gettype (data)

Returns type of a PDU or another data element

Callable from:

Arguments

Argument Name Type Value Description
data M PDU/field type Packet or any other data element created by create(), receive() or decode()/decodeex().

Return Value

Return Type

getpco

getpco (data)

Determines PCO of the data type. Yields run-time error if the type is not a packet at any PCO.

Callable from:

Arguments

Argument Name Type Value Description
data M PDU/field type PDU type. If a ‘type’ is not a type of a whole PDU, run-time error occurs.

Return Value

Return Type

copy

copy (dst, src)

Creates a copy of a PDU (or any data element - e.g., PDU’s field).

Callable from:

Arguments

Argument Name Type Value Description
dst M PDU/field Destination data element. If omitted function returns created element.
src M PDU/field Source data element

Return Value

Return Type

equal

equal (data1, data2)

Compares data elements - PDUs or their fields. Data elements can be of any complexity. They must be of the same type or, at least, compatible types - e.g., both integers - otherwise run-time error occurs. If you want to compare safely being not sure about type compatibility, first compare types of the data using gettype().

Callable from:

Arguments

Argument Name Type Value Description
data1 M PDU/field First data element to compare
data2 M PDU/field Second data element to compare

Return Value

Return Type

spoil

spoil (data)

Overwrites the data element passed as the argument with a value of ASN.1 ‘ANY’ type. You can then modify that ‘ANY’ and thus substitute any possible encoding for the ‘spoiled’ element. This is useful in negative testing, when invalid from the point of view of the protocol specification packet has to be sent.

Callable from:

Arguments

Argument Name Type Value Description
data M PDU/field Data element to overwrite

Return Value

random

random ()

Pseudo-random number in range 0..1. Independent from language-specific random generation. Pseudo-random sequence can be restarted by seedrandom.

Callable from:

Arguments

Return Value

print

print (value1 [, value2 [, …]])

Outputs one or more values to the Output pane

Callable from:

Arguments

Argument Name Type Value Description
value M Any Value to output. Can be anything at all, not necessarily protocol data.

Return Value

sprint

sprint (value1 [, value2 [, …]])

Formats one or more values as a string, identically to print().

Callable from:

Arguments

Argument Name Type Value Description
value M Any Value to format. Can be anything at all, not necessarily protocol data.

Return Value

Return Type

keypressed

keypressed ()

Checks for keyboard input.

Callable from:

Arguments

Return Value

Return Type

getchar

getchar ()

Gets a character from the keyboard.

Callable from:

Arguments

Return Value

Return Type

getchars

getchars ()

Gets all available character from the keyboard.

Callable from:

Arguments

Return Value

Return Type

bindevent

bindevent (functionName)

Creates a handler for the event from a HTML control. Assign it to a HTML event handler.

Callable from:

Arguments

Argument Name Type Value Description
functionName M String Name of the function to be used as an event handler

Return Value

Example:

ie.Document.getElementById("MyButton").onclick = sk.bindevent("OnMyButtonClick")

createwindow

createwindow (utl, options [, arguments])

Waits for child script to complete. The child script must be previously run() in asynchronous mode.

Callable from:

Arguments

Argument Name Type Value Description
url M String URL of the HTML resource to load. Typically “about:blank” or a file path.
options M String Window ornaments for the dialog box. This parameter can be a string that contains a combination of values, each separated by a semicolon (;). See the description of the features parameter of the IHTMLWindow2::showModalDialog method of the Window object for detailed information.
arguments O Any Arbitrary object to access from the HTML script code.

Return Value

helper

helper (class)

Creates a Packet Studio-defined helper object.

Callable from:

Arguments

Argument Name Type Value Description
class M String Class name of helper object.

Return Value

getcorecount

getcorecount ()

Get number of CPU cores available.

Callable from:

Arguments

Return Value

Return Value

mos_get_val

mos_get_val ()

Returns the calculated MOS value.

Callable from:

Arguments

Return Value

Return Value

Example:

txWav = "examples\\Audio\\Voice\\male.wav" # original
rxWav = sk.getdir() + "\\rec\\male-rx.wav" # degradated

if sk.mos_calc(rxWav, txWav):
sk.print_("mos_val=", sk.mos_get_val, ", mos_delay=", sk.mos_get_delay, " sec")

mos_get_delay

mos_get_delay ()

Returns the calculated MOS delay.

Callable from:

Arguments

Return Value

Return Value

Python Example:

txWav = "examples\\Audio\\Voice\\male.wav" # original
rxWav = sk.getdir() + "\\rec\\male-rx.wav" # degradated

if sk.mos_calc(rxWav, txWav):
sk.print_("mos_val=", sk.mos_get_val, ", mos_delay=", sk.mos_get_delay, " sec")

presskey

presskey (char)

Simulates a key pressed.

Callable from:

Arguments

Argument Name Type Value Description
char M String Character to simulate

Return Value

Python Example:

sk.presskey(ch);