Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Interacting with the operating system from Titan(Issuing system commands from TTCN-3)
Interacting with the operating system from Titan [message #1729921] Wed, 20 April 2016 09:32
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 754
Registered: January 2015
Senior Member
The TTCN-3 universe described in the language standard consists of an abstract space , populated by components that can share information only through connected test ports.
(They don't and can't share any variables, as the concept of global variables does not exist; this would be the equivalent of information being able to propagate with infinite speed,
hence in the universe that allows global variables the speed of light would be unlimited. They can and do share constants and templates though, their approximate counterpart-
if we stick to the analogy- being the cosmological constants..... Smile )

This abstract space connects to the external world through test ports and sometimes via external functions (which commonly address an environment close to this abstract space ,
while test ports can reach as far as the... well, SUT; as far as needed)

All this intro was necessary to explain why there is no "system" or system-like command in TTCN-3: the language prefers to stay within the abstract boundaries described above;
talking to the operating system is not something that is within the scope of the language.


However , as hinted, the existing APIs can be used for this purpose; we can communicate with the underlying OS via test ports or via external functions.
Examples for both will be offered.

Needless to say, these solutions refer to a specific implementation so the resulting code wil be non-standard, hence less portable.


When it comes to ports, of course Titan can connect to a host with TELNET or SSH, including the host it runs on, but this is rather tedious.
Instead , I would offer the PIPE test port which can be used to execute shell commands ( see https://github.com/eclipse/titan.TestPorts.PIPEasp)


For example the following code:

template ASP_PExecute t_PExecute(
    template charstring p_command, template charstring p_stdin)  := {
    command := p_command,
    stdin := p_stdin
}


PIPE_PCO.send(t_PExecute("/bin/ls -l PipeTest.ttcn", ""));
PIPE_PCO.receive(t_PResult(?,?,?));



will result in a simple shell command execution:

2016/Apr/20 09:56:33.508057 PipeTest.ttcn:145 Sent on PIPE_PCO to system @PIPEasp_Types.ASP_PExecute : {
    command := "/bin/ls -l PipeTest.ttcn",
    stdin := ""
}
2016/Apr/20 09:56:33.518065 PipeTest.ttcn:146 Message enqueued on PIPE_PCO from system @PIPEasp_Types.ASP_PResult : {
    stdout := "-rw-r--r-- 1 ethlel rnd 4832 Apr 19 15:34 PipeTest.ttcn",
    stderr := "",
    code := 0
} id 2




Similarly, a new shell can be started and a command executed in it, see /demo for more examples.
As discussed in https://www.eclipse.org/forums/index.php/t/1075617/,
the PIPE test port can also be used to pop up a window with warning when manual interaction from user is required.


A number of external function are offered in https://github.com/eclipse/titan.Libraries.TCCUsefulFunctions;
some of them can be used for system commands, some offer other utilities, like mathematical functions, text manipulation etc.

Below you can find a comprehensive list of files and covered functions by name; as names are quite suggestive, this should ease your search for a particular functionality.



TCCAssertion_Functions.ttcn:	f_assert
TCCConversion_Functions.ttcn:	f_putInLowercase
TCCConversion_Functions.ttcn:	f_putInUppercase
TCCConversion_Functions.ttcn:	f_unichar2charstr
TCCConversion_Functions.ttcn:	f_charstr2unichar
TCCConversion_Functions.ttcn:	f_replaceFirstOccurenceOfSubstring
TCCConversion_Functions.ttcn:	f_replaceEveryOccurenceOfSubstring
TCCConversion_Functions.ttcn:	f_replaceFirstOccurenceOfPattern
TCCConversion_Functions.ttcn:	f_replaceEveryOccurenceOfPattern
TCCConversion_Functions.ttcn:	f_addOctetstring
TCCConversion_Functions.ttcn:	f_subOctetstring
TCCConversion_Functions.ttcn:	f_compOctetstring
TCCConversion_Functions.ttcn:	f_substr_token
TCCConversion_Functions.ttcn:	f_substr_token_oct
TCCConversion_Functions.ttcn:	f_substr_all_token
TCCConversion_Functions.ttcn:	f_substr_all_token
TCCConversion_Functions.ttcn:	f_strstr
TCCConversion_Functions.ttcn:	f_strstr_oct
TCCConversion_Functions.ttcn:	f_OctetIpv4
TCCConversion_Functions.ttcn:	f_convertIPAddrToBinary
TCCConversion_Functions.ttcn:	f_convertBinaryToIPAddr
TCCConversion_Functions.ttcn:	f_oct2char_safe
TCCConversion_Functions.ttcn:	f_IPv6_literal
TCCConversion_Functions.ttcn:	f_isNumber
TCCConversion_Functions.ttcn:	f_isWhiteSpace
TCCConversion_Functions.ttcn:	f_stripWhitespaces
TCCConversion_Functions.ttcn:	f_isInteger
TCCConversion_Functions.ttcn:	f_str2int
TCCDateTime_Functions.ttcn:	f_time
TCCDateTime_Functions.ttcn:	f_ctime
TCCDateTime_Functions.ttcn:	f_ctime_UTC
TCCDateTime_Functions.ttcn:	f_getTimeFormatted
TCCDateTime_Functions.ttcn:	f_time2sec
TCCDateTime_Functions.ttcn:	f_time2sec_UTC
TCCDateTime_Functions.ttcn:	f_getCurrentDateWithOffset
TCCDateTime_Functions.ttcn:	f_getCurrentGMTDate
TCCDateTime_Functions.ttcn:	f_tic
TCCDateTime_Functions.ttcn:	f_toc
TCCDateTime_Functions.ttcn:	f_timeDiff
TCCEncoding_Functions.ttcn:	f_encode_ISUP_Called_Party_Number
TCCEncoding_Functions.ttcn:	f_encode_ISUP_Calling_Party_Number
TCCEncoding_Functions.ttcn:	f_encode_MobileL3_CalledPartyBCDNumber
TCCEncoding_Functions.ttcn:	f_encGSM7bit
TCCEncoding_Functions.ttcn:	f_decGSM7bit
TCCEncoding_Functions.ttcn:	f_is_TBCD
TCCEncoding_Functions.ttcn:	f_enc_TBCD
TCCEncoding_Functions.ttcn:	f_dec_TBCD
TCCEncoding_Functions.ttcn:	f_enc_TBCD_hex
TCCEnv_Functions.ttcn:	f_GetEnv
TCCEnv_Functions.ttcn:	f_PutEnv
TCCFileIO_Functions.ttcn:	f_FIO_open_rdonly
TCCFileIO_Functions.ttcn:	f_FIO_open_append_wronly
TCCFileIO_Functions.ttcn:	f_FIO_open_append_rdwr
TCCFileIO_Functions.ttcn:	f_FIO_open_trunc_wronly
TCCFileIO_Functions.ttcn:	f_FIO_open_trunc_rdwr
TCCFileIO_Functions.ttcn:	f_FIO_open_append_wronly_excl
TCCFileIO_Functions.ttcn:	f_FIO_open_append_rdwr_excl
TCCFileIO_Functions.ttcn:	f_FIO_open_trunc_wronly_excl
TCCFileIO_Functions.ttcn:	f_FIO_open_trunc_rdwr_excl
TCCFileIO_Functions.ttcn:	f_FIO_close
TCCFileIO_Functions.ttcn:	f_FIO_seek_end
TCCFileIO_Functions.ttcn:	f_FIO_seek_forward
TCCFileIO_Functions.ttcn:	f_FIO_seek_backward
TCCFileIO_Functions.ttcn:	f_FIO_write_data
TCCFileIO_Functions.ttcn:	f_FIO_write_text
TCCFileIO_Functions.ttcn:	f_FIO_write_data_flush
TCCFileIO_Functions.ttcn:	f_FIO_write_text_flush
TCCFileIO_Functions.ttcn:	f_FIO_flush
TCCFileIO_Functions.ttcn:	f_FIO_read_data
TCCFileIO_Functions.ttcn:	f_FIO_read_text
TCCFileIO_Functions.ttcn:	f_FIO_read_text_until
TCCFileIO_Functions.ttcn:	f_FIO_read_data_until
TCCFileIO_Functions.ttcn:	f_FIO_read_data_TLV
TCCFileIO_Functions.ttcn:	f_FIO_get_error_string
TCCFileIO_Functions.ttcn:	f_FIO_get_error_code
TCCFileIO_Functions.ttcn:	f_FIO_set_filedescriptor_previousline
TCCFileIO_Functions.ttcn:	f_FIO_chdir
TCCFileIO_Functions.ttcn:	f_FIO_mkdir
TCCFileIO_Functions.ttcn:	f_FIO_rmdir
TCCFileIO_Functions.ttcn:	f_FIO_fileOrDirExists
TCCFileIO_Functions.ttcn:	f_FIO_stat
TCCFileIO_Functions.ttcn:	f_FIO_chmod
TCCFileSystem_Functions.ttcn:	f_FS_bsize
TCCFileSystem_Functions.ttcn:	f_FS_blocks
TCCFileSystem_Functions.ttcn:	f_FS_bfree
TCCFileSystem_Functions.ttcn:	f_FS_dspacerate
TCCIPsec_Functions.ttcn:	f_IPsec_SADB_add
TCCIPsec_Functions.ttcn:	f_IPsec_SADB_delete
TCCIPsec_Functions.ttcn:	f_IPsec_SADB_flush
TCCIPsec_Functions.ttcn:	f_IPsec_SPDB_add
TCCIPsec_Functions.ttcn:	f_IPsec_SPDB_delete
TCCIPsec_Functions.ttcn:	f_IPsec_SPDB_flush
TCCInterface_Functions.ttcn:	f_getPortAvailabilityStatus
TCCInterface_Functions.ttcn:	f_setIP
TCCInterface_Functions.ttcn:	f_setIP_ip
TCCInterface_Functions.ttcn:	f_delIP_ip
TCCInterface_Functions.ttcn:	f_deleteIP
TCCInterface_Functions.ttcn:	f_getIP
TCCInterface_Functions.ttcn:	f_setInterfaceUp
TCCInterface_Functions.ttcn:	f_setInterfaceDown
TCCInterface_Functions.ttcn:	f_getHostName
TCCInterface_Functions.ttcn:	f_getIpAddr
TCCInterface_Functions.ttcn:	f_getIpAddresses
TCCMaths_Functions.ttcn:	f_maxIL
TCCMaths_Functions.ttcn:	f_maxFL
TCCMaths_Functions.ttcn:	f_minIL
TCCMaths_Functions.ttcn:	f_minFL
TCCMaths_Functions.ttcn:	f_averageFL
TCCMaths_Functions.ttcn:	f_averageIL
TCCMaths_Functions.ttcn:	f_updateFL
TCCMaths_Functions.ttcn:	f_updateIL
TCCMaths_Functions.ttcn:	f_stdFL
TCCMaths_Functions.ttcn:	f_stdFLL
TCCMaths_Functions.ttcn:	f_stdIL
TCCMaths_Functions.ttcn:	f_stdILL
TCCMaths_Functions.ttcn:	f_sinVL
TCCMaths_Functions.ttcn:	f_cosVL
TCCMaths_Functions.ttcn:	f_sin
TCCMaths_Functions.ttcn:	f_cos
TCCMaths_Functions.ttcn:	f_asin
TCCMaths_Functions.ttcn:	f_acos
TCCMaths_Functions.ttcn:	f_powFF
TCCMaths_Functions.ttcn:	f_powII
TCCMaths_Functions.ttcn:	f_powIF
TCCMaths_Functions.ttcn:	f_powFI
TCCMaths_Functions.ttcn:	f_sqrF
TCCMaths_Functions.ttcn:	f_sqrI
TCCMaths_Functions.ttcn:	f_sqrtF
TCCMaths_Functions.ttcn:	f_sqrtI
TCCMaths_Functions.ttcn:	f_ceil
TCCMaths_Functions.ttcn:	f_floor
TCCMaths_Functions.ttcn:	f_exp
TCCMaths_Functions.ttcn:	f_log
TCCMaths_Functions.ttcn:	f_generate_poissonTable
TCCMaths_Functions.ttcn:	f_getNext_poissonValue
TCCMaths_Functions.ttcn:	f_gen_Exponential_Distribution 
TCCMessageHandling_Functions.ttcn:	f_TCCMessageHandling_getMessageLength
TCCMessageHandling_Functions.ttcn:	f_TCCMessageHandling_getMessageLength4Diameter
TCCMessageHandling_Functions.ttcn:	f_TCCMessageHandling_getMessageLength4Radius
TCCMessageHandling_Functions.ttcn:	f_TCCMessageHandling_getMessageLength4BER
TCCPermutatedParameters_Functions.ttcn:	f_PP_getPermutatedParams
TCCPermutatedParameters_Functions.ttcn:	f_PP_getInRangeValue
TCCPermutatedParameters_Functions.ttcn:	f_PP_getPermutationIndexList
TCCPermutatedParameters_Functions.ttcn:	f_PP_countPermutations
TCCPermutatedParameters_Functions.ttcn:	f_PP_charListContains
TCCPermutatedParameters_Functions.ttcn:	f_PP_countRange
TCCPermutatedParameters_Functions.ttcn:	f_PP_calculateTypeCounts
TCCPermutatedParameters_Functions.ttcn:	f_PP_divideValuesOfTypes
TCCPermutatedParameters_Functions.ttcn:	f_PP_mergeValuesToParamSet
TCCPermutatedParameters_Functions.ttcn:	f_PP_countValuesOfTypes
TCCPermutatedParameters_Functions.ttcn:	f_PP_mergeValuesFromRanges
TCCPermutatedParameters_Functions.ttcn:	f_PP_getValueFromRange
TCCPermutatedParameters_Functions.ttcn:	f_PP_normalizeParams
TCCPermutatedParameters_Functions.ttcn:	f_PP_convertToRangeList
TCCPermutatedParameters_Functions.ttcn:	f_PP_getParamValueFromSet()
TCCRegexp_Functions.ttcn:	f_pcre_regexp
TCCRegexp_Functions.ttcn:	f_pcre_regexp
TCCSystem_Functions.ttcn:	f_SYS_getpid
TCCTemplate_Functions.ttcn:	f_Template_substitutetemplate
TCCTemplate_Functions.ttcn:	f_Template_subsfiletemplate
TCCTitanMetadata_Functions.ttcn:	f_compilationTime











Best regards
Elemer

[Updated on: Wed, 20 April 2016 12:39]

Report message to a moderator

Previous Topic:Problem titan HelloWorld example in eclipse
Goto Forum:
  


Current Time: Tue Jun 19 05:10:57 GMT 2018

Powered by FUDForum. Page generated in 0.01294 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top