Professional Documents
Culture Documents
Edition: 5.3
May 2011
Copyright Notices
©Copyright 2002-2011 Hewlett-Packard Development Company, L.P.
Tcl /Tk and supporting software are copyrighted by the Regents of the University of California, Sun
Microsystems, Inc., Scriptics Corporation, ActiveState Corporation and other parties.
GetLine is Copyright© 1991, 1992, 1993 by Chris Thewalt
TclXML and TclDOM is Copyright© 1998-2004 Zveno Pty Ltd
Tcl SOAP is Copyrigh © 2001 Pat Thoyts
Tcl Thread Extension is Copyright© 2005 Zoran Vasiljevic
Tix is Copyright© Ioi Lam
TclX is Copyright© Karl Lehenbauer and Mark Diekhans
Oratcl is Copyright© 2000-2004 Todd M. Helfter
CGI Tcl is made by Don Libes (libes@nist.gov)
Scotty/Tnm Copyright©1993-1996 Juergen Schoenwaelder, Technical University of Braunschweig
TLS Copyright© Matt Newman @ Novadigm
Sqlite3 Copyright© Hwaci
No part of this document may be copied, reproduced, or translated to another language without the
prior written consent of Hewlett-Packard Company. The information contained in this material is
subject to change without notice.
2
Trademark Notices
Adobe®, Acrobat® and PostScript® are trademarks of Adobe Systems Incorporated.
HP-UX Release 10.20 and later and HP-UX Release 11.00 and later (in both 32 and 64-bit
configurations) on all HP 9000 computers are Open Group UNIX 95 branded products.
Java™ is a U.S. trademark of Sun Microsystems, Inc.
Microsoft® , Windows® and Windows NT® are U.S. registered trademarks of Microsoft Corporation.
Oracle® is a registered U.S. trademark of Oracle Corporation, Redwood City, California.
UNIX® is a registered trademark of The Open Group.
X/Open® is a registered trademark, and the X device is a trademark of X/Open Company Ltd. in the
UK and other countries.
All other product names are the property of their respective trademark or service mark holders and are
hereby acknowledged.
3
Document Information
Preface
The target audience for this User’s Guide comprises system architects who need to evaluate
TeMIP Tcl Scripting for use in a project and system integrators who will use it to build
functionality. It has two parts, a primer and a reference part. For evaluation it will suffice to read
part I or some of it. For a system integrator it is recommended to read the primer to gain an
initial understanding and then use part II for reference.
Part I is structured as follows:
• Chapter 1 contains a brief introduction to the benefits of TeMIP Tcl Scripting.
• Chapter 2 gives a general description to introduce the capabilities of TTS.
• Chapter 3 briefly describes the Tcl commands that are available for a Tcl script to
interwork with the TeMIP framework and TeMIP management modules.
The descriptions given in chapters Chapter 2 and Chapter 3 are at a high level and do not cover
all details. For full details refer to part II.
• Chapter 4 contains brief descriptions of a number of suggested uses of TTS, to convey an
understanding of the range of possible applications.
• Chapter 5 contains a simplified example, with a complete set of sources, of how an access
module can be implemented, and how its information model can be accessed.
Part II is structured as follows:
• Chapter 6 gives a complete description of the TTS commands with miscellaneous related
information needed to use the commands.
• Chapter 7 gives reference information which is specific to TTS PM.
• Chapter 8 gives reference information which is specific to TTS MM.
• Chapter 9 gives reference information which is specific to corrective filters.
• Chapter 10 describes a way to do remote calls of TTS commands in a client-server setup.
• Chapter 11 gives additional reference information which does not belong in any of the
preceding chapters of Part II.
The following information is given in appendices.
• Appendix A describes the high level TTS command temip.
• Appendix B gives an introduction to Tcl as used by TTS.
• Appendix C is a Tcl syntax resume.
Font Conventions
A monospace font is used throughout this guide for code examples, command dialogues and
elements of Tcl syntax which appear within regular body text. Metasymbols representing
variables or formal arguments in Tcl code are rendered in monospace italics. Italics are also used
to indicate variable elements of TeMIP full names in other contexts, and otherwise to highlight
and delimit specific terms that are being introduced or emphasized as well as names of
referenced documents. Bold font is used only for highlighting effect to make it easier to locate
headings for tables and sections of body text.
9.4 Adding user defined fields to the TeMIP Alarm Object ................................................................. 112
Figures
Figure 1, TeMIP Event Processing ..................................................................................................................... 17
Figure 2, Tcl Interpreters in a TTS MM ............................................................................................................. 21
Tables
Table 1, Data Values by Type ............................................................................................................................ 49
Table 2, Data value constants ............................................................................................................................. 53
Table 3, Attribute Reasons ................................................................................................................................. 54
Table 4, OIDs by Dictionary Node Type ........................................................................................................... 62
Table 5, Dictionary Definitions .......................................................................................................................... 64
Table 6, Data Object Convert to Options ........................................................................................................... 69
Table 7, Data Object Convert from Options....................................................................................................... 70
Table 8, Data Object Show Options ................................................................................................................... 70
Table 9, Data Object Set Options ....................................................................................................................... 71
Table 10, Call Command Status ......................................................................................................................... 78
Table 11, Call response options.......................................................................................................................... 79
Table 12, Call “more” options ............................................................................................................................ 80
Table 13, Standard Tcl variables reflecting command line and interactivity ..................................................... 91
Table 14, Interactive Line Edit Keys .................................................................................................................. 94
Table 15, TTS global Tcl variables .................................................................................................................. 121
References
OpenView TeMIP, System Reference Manual, V5 and V6
OpenView Visual TeMIP, Development Guide, V5 and V6
OpenView TeMIP, Customization Guide, V5 and V6
OpenView TeMIP, Event Filtering and Correlation User’s Guide, V5 and V6
OpenView TeMIP, Security Operator’s Guide, V5 and V6
A large number of Internet sites provide useful information on the standard Tcl/Tk software used
in TTS (Tcl/Tk 8.5). The official home of Tcl/Tk is http://www.tcl.tk
The TeMIP Tcl Scripting software is a tool kit dedicated to implementing small amounts of
functionality into a TeMIP solution for integration purposes.
TeMIP is object-oriented, modular and flexible, with support for many types of interfaces. In
general the granularity of TeMIP functionality is the management module, be it presentation
module (PM), functional module (FM) or access module (AM). This allows the system
integrator to put together a solution which precisely meets the customer’s requirement by
combining just the necessary management modules.
However, sometimes a situation occurs where a small amount of functionality is needed in
addition to what an existing management module already does, even when the possibilities for
customization of the management module have been exhausted. It is then often found that
building a dedicated management module or modifying the existing one is not feasible or that
the cost is forbidding, due to the technical and logistical overhead involved.
System integrators typically use scripting languages to implement small amounts of functionality
that do not exist in the applications they integrate.
TeMIP has a native command line language, FCL, which permits any command that can be
performed by a TeMIP management module to be expressed, but FCL is lacking in features to
post process responses from TeMIP and to express control flow. It is mainly suitable for
executing single commands interactively or strictly sequential scripts.
To overcome these limitations the TeMIP Tcl Scripting (TTS) tool kit has been implemented.
This manual describes TTS and the tool kit in details.
TTS incorporates interpreters for the dynamic language Tcl (Tool Command Language) into
three modules: TTS PM (command line, GUI and applications), TTS MM (Access Modules and
Function Modules) and TTS CF (Corrective Filters). All the modules are integrated with the
TeMIP framework and have very generic properties, thus enabling a number of cases of “small
amount of missing functionality” to be solved at the cost of writing a script that does exactly the
required job, but does not include an “integration tax”.
It is easy to start using TTS. It is not necessary to set up a complex environment to build
software before it can be deployed (see Appendix B).
The following are some tasks which can be done easily and therefore quickly with TTS:
• Building and maintaining configuration scripts for a TeMIP solution.
• Extracting, filtering, arranging and formatting information that is held within a TeMIP
management model. Data from a TeMIP model can be combined with data from other
sources, say an Oracle database. Information can be presented graphically, say in a
dedicated pop up window.
• Building a TeMIP GUI application to be launched on a TeMIP director or Windows®
platform.
• Adding scripted corrective filters to TeMIP.
• Building some functions and exposing them as directive calls against a TeMIP
management model.
• Building an access module which interacts by commands and responses with a network
element without C++ programming, GAT customization, etc.
This chapter provides an overview description of the capabilities of TeMIP Tcl Scripting (TTS).
TTS makes Tcl scripting available in the TeMIP environment in three forms:
• TTS PM, launchable Tcl/Tk applications with ability to make TeMIP directive calls and
forward events.
• TTS MM, management modules exposing callable directives against a TeMIP
management model. TTS MM can appear either as an AM or an FM.
• TTS CF, a corrective filter library, which can execute TTS scripts in the context of an
existing management module to modify events forwarded by the module.
The basic component is the same in all the cases: a collection of new Tcl commands which make
it possible to work with TeMIP data and make TeMIP directive calls. These commands are
implemented as an extension to Tcl and integrated into the binary executable files of the
modules together with a number of Tcl language interpreters 1.
Section 2.1 describes the capabilities that are common for TTS PM, TTS MM and TTS CF, i.e.
the context that is provided for Tcl scripting, in particular the TTS Tcl commands.
Section 2.2 describes the capabilities of TTS PM over and above the common capabilities,
section 2.3 does likewise for TTS MM, and section 2.4 for TTS CF.
All TTS modules will run on the same (UNIX) operating system platforms as the TeMIP
Framework. Tcl/Tk itself will run on almost any operation system and using the TTS remote
features, TTS scripts can be executed remotely from all Tcl/Tk enabled systems.
1
The Tcl interpreter, executing the Tcl commands, is actually not an interpreter, but an on-the-fly byte code
compiler and execution engine.
may return:
{{{OPERATION_CONTEXT rose_ns:.demo-oc} {alarm_object 10637}} State
Outstanding} {{{OPERATION_CONTEXT rose_ns:.demo-oc} {alarm_object 10637}}
{Alarm Type} CommunicationsAlarm}
Note
The words oper and alarm which appear in the command line are display names (of a
global and a child entity class, respectively), which are looked up in the TeMIP dictionary.
Actually they are abbreviations of OPERATION_CONTEXT and alarm_object.
Both command arguments and results are in the form of Tcl lists. Tcl include many efficient
commands to handle lists, so extracting and using relevant information returned by TTS
commands is easy and fast.
2.1.3 Low Level Commands
The low level commands are used when there is need for close control of details or if
performance is of the essence.
Six of the low level commands can be used to create and manipulate objects, which are
themselves again dedicated commands in addition to being Tcl variables. The six types of
objects are: dictionary objects, data objects, call objects, event objects, MIR objects and ACLOC
objects. A command that creates a TTS object returns the reference name of the object.
In the manner which is common with Tcl each of the main TTS commands is in fact a command
collection, with the first argument (“subcommand”) defining the actual function to be
performed, for example the command temip::data with subcommand type:
temip::data type type-spec
returns a TTS data object which can hold a value of the TeMIP data type specified by type-
spec, whereas:
temip::data info types
2
Not to be confused with the Tcl command “dict”
Event Requester
Service Provider
(generic) event pool
Event Manager
applies filtering
Event Sink
forward event
incoming message
from network
• The access module (could also be an FM) which receives and replies to the GetEvent
directive (referred to in the referenced description as the service provider). A generic
implementation of this function is included in all access modules that deliver events. It is
also included as part of a TTS MM.
• TeMIP’s event manager, a central function within the TeMIP framework which on each
TeMIP director maintains an event pool. TeMIP has a set of general “low level” filtering
mechanisms that can be applied to events as they are processed by the event manager.
• The originator of the event, known as an event sink, which posts (“forwards”) the event to
the event manager to be put into the event pool, allowing it to be matched to a call of
GetEvent requesting events from the entity specified for the event report.
The TTS event command temip::event and event object can be used to build an event sink
function and have the capability to generate any type of TeMIP event and forward it to the event
manager. According to strict TeMIP modular architecture the event sink is a part of the service
provider management module which services the GetEvent directive, but the coupling is not
enforced, and the TTS event command is available with TTS MM as well as with TTS PM. With
TTS MM it can be used to build an event sink as an integrated part of a management module.
With TTS PM it can be used to generate events on behalf of any TeMIP entity regardless of
which management module implements other functions of the entity.
Each entity data set can hold attributes lists for all attributes in all partitions of the entity class
plus a user defined string. The partition data is compatible with the data layout used by e.g.
visual TeMIP written management modules.
The subcommands of the MIR object allows insert, alias, lookup and delete of entities in the
MIR, and read, write and merge of associated data.
Note
TTS also includes additional Tcl packages that allow access to both Oracle and SQLite
databases. These could also be used as local repositories in a management module.
3
A Tcl interpreter executes the Tcl/TTS commands and has a variable and command context that is
independent of all other Tcl interpreters. Multiple interpreters can be created in the same process and in the
same process thread. See http://www.tcl.tk/man/tcl8.5/TclCmd/interp.htm for details.
Script files
A Tcl script for a TTS PM can be read and executed from a file. The file may be specified on the
UNIX command line as filename (see above for command line syntax), or a UNIX
executable file may be created.
Example (TTS executable file “helloworld”):
#!/bin/sh
# the next line restarts using tts_pm \
exec /usr/opt/temip/bin/tts_pm "$0" "$@"
# This is a TTS script file
puts {Hello World}
Interactive example
The following example shows TTS PM being invoked from a UNIX command line ($) 4 without
arguments, followed by alternating Tcl command input (TTS>) and response output lines (with
no prompt). The example uses the low level temip::call command to prepare and make a
call of a Show directive, and then to examine the response.
Example (Interactive TTS commands):
$ tts_pm
TTS> set mycall [temip::call setup show {{oper demo-oc}} char]
::_Call_00000015
TTS> $mycall call
Response
TTS> $mycall response text
{Show Success} {}
Note that all interactive examples in this guide will use this form.
TeMIP security
When a TTS PM is started a security session is created. This is done by using the same wrapper
that is also used for the standard TeMIP command line application mcc_fcl_pm. The wrapper
will set the active access control view for the session, normally the default access control view
defined for the user.
4
The PATH environment variable must include the path /usr/opt/temip/bin. This is normally the case for
TeMIP users.
5
The GetEvent directive must be included in the configuration if events are emitted on the class.
directive Directive
module
call interpreter start
Master
Directive interpreter eval
interpreter eval
Module
interpreter
.... callback
Directive
interpreter
module
stop
Initializations needed to define a common environment for all interpreters belonging to a TTS
MM module can be placed in a common script which is sourced (executed) by all the
interpreters.
Each directive interpreter knows only the dedicated script for its particular directive. These
interpreters are initialized on the first call of each directive after the management module is
started. As the last initialization step the interpreter executes its directive script, thus learning the
specific procedures (OnExecute etc.) for the directive in question. If a directive is called while
its interpreter is still busy with a previous call, the interpreter may be cloned. The calls made to
retrieve a sequence of replies whose availability is indicated by the “more” flag will, however,
all go to the same interpreter, i.e. the Tcl interpreter context will remain unaltered between these
calls.
This chapter gives a brief description of all the TTS commands and objects with subcommands,
starting with the high level, and then proceeding to the low level commands which are the most
numerous. The commands at the high levels are themselves implemented as Tcl procedures
using the low level commands.
The low level commands will be needed to build management modules (TTS MM applications),
to extract dictionary information, or if detailed control is required of how TeMIP calls are made.
For applications which can be built by making wholesale TeMIP directive calls the information
in section 3.2 will not be needed.
This chapter is intended to provide an overview. Therefore it does not describe the arguments
that each command takes, nor does it describe the results returned by all commands. For this
level of detail refer to Chapter 6.
Two techniques can be used for further manipulation of the object name: either 1) hold its name
as the value of a Tcl variable or 2) move/rename the object.
Here is an example of the first technique:
set MyNumber [temip::data type Unsigned32]
This command creates a data object and saves its name in the Tcl variable MyNumber, so the
subsequent command to set the data value to 123 will be:
$MyNumber encode 123
or
set $MyNumber 123
This command creates a data object and renames it to MyNumber, so the subsequent command
to set the data value to 123 will be:
MyNumber encode 123
or
set MyNumber 123
This chapter gives brief descriptions of a number of suggested uses of TTS with small figures
illustrating how the scripted function is positioned relative to and inter-works with other solution
components, notably the TeMIP Framework. The first six suggestions can be built with TTS PM
as indicated by blue circles; the remaining ones will require TTS MM indicated by blue
rectangles.
4.8 Simple AM
For simple management interfaces where no network element state information or
only a very small amount needs to be stored by the AM a complete AM can be
constructed using TTS MM. If the network element or element management
system to which the AM must interface provides fast responses, command
dialogues can be implemented in directive scripts for Set and action directives as
well as the Show directive. Event processing can be done in callbacks executed in
the Master interpreter.
Section 5.1 contains a complete example of a TeMIP access module, called person_am, built
using the TTS MM application. Section 5.2 shows how to install the example in the TeMIP
environment and section 5.3 includes some scripts that can be run using a TTS PM to retrieve
dictionary information about person_am and the data it makes showable.
File /var/opt/temip/person_am/data
Peter,30,M,1,Happy
Miranda,8,F,0,Thrilled
Arthur,65,M,5,Depressed
The first task in the customization process is to decide the TeMIP management model. The
model chosen in this example has only a single class, which is therefore a global class, where
each person described in the data file is represented as an entity. The name of the person is the
identifier attribute (making it impossible to distinguish between multiple persons with the same
name, but that is not important for the example). The other four attributes are all implemented in
the characteristic partition. The only directive supported in this example is Show.
The model must be specified in MSL as shown below 6.
Note that a globally unique code must be assigned to the global class. In this example the code is
180651.
File person_am_srvc_if.ms
IDENTIFIER ATTRIBUTES
6
A template is available in /usr/opt/temip/tts/mm/models/tts_mm_srvc_if_template.ms
CHARACTERISTIC ATTRIBUTES
It is also necessary to describe the self-management model for the module. TTS includes a
template file for this 7. The module name (person_am) and module id must be edited into the
template. The beginning of the self-management MSL file for person_am is shown below with
module name and id appearing in the CHILD ENTITY line. Note that the code for the global
class is reused as module id. This is customary for management modules which support a single
global class.
File person_am_mgmt_if.ms
The next is the configuration file which binds the person_am module to the class group
implementation in TTS MM. It has two lines, one that establishes the attribute partition binding
for class Person (IDENTIFIER and CHARACTERISTIC), and one subordinate line that does the
same for the verb SHOW.
File /var/opt/temip/conf/person_am.cfg
7
/usr/opt/temip/tts/mm/models/tts_mm_mgmt_if_template.ms
File /usr/opt/temip/tts/mm/scripts/person_am/Module.tts
proc OnInit {} {
temip::trace trace 0 "Initializing module person_am"
temip::module debug on
The core functionality is that of the Show directive on entity class Person, implemented in the
directive script file TTSCG/Show.tts. It reads the person data file from the location shown in the
example at the beginning of this section. The file location is “hard coded” into the script.
Due to the simple nature of the task at hand the only TTS command which is needed is
temip::context. It is used to retrieve the in-entity and partition that the directive call
concerns and to pass out-entity, attribute values and exceptions as replies. The script is
commented to be self-explanatory.
It should be noted that to keep the example simple there is no checking that the data file is
present and correctly formatted, and no handling of partial wildcarding and no handling of
instance value upper/lower case conversion.
In a real implementation some error handling, etc. would most likely be needed.
File /usr/opt/temip/tts/mm/scripts/person_am/TTSCG/Show.tts
As no global entities are registered for the class Person, the FCL/manage utility are not able to
show wild carded instances. We can use the TTS examine command to show them anyway.
$ tts_pm
TTS> temip::examine show {{person *}} char
{{{{Person Peter}} Response {SHOW_SUCCESS {Examination of attributes
shows}} 2009-04-02-10:19:58} {{Age 30} {Gender M} {Children 1} {Mood
Happy}}} {{{{Person Miranda}} Response {SHOW_SUCCESS {Examination of
attributes shows}} 2009-04-02-10:19:58} {{Age 8} {Gender F} {Children 0}
{Mood Thrilled}}} {{{{Person Arthur}} Response {SHOW_SUCCESS {Examination
of attributes shows}} 2009-04-02-10:19:58} {{Age 65} {Gender M} {Children
5} {Mood Depressed}}}
Or
TTS> temip show {{person *}} {expand no}
Show Identifiers @ 2009-04-03-10:22:22.686 on rap_ns:.temip.rap_director
Response @ 2009-04-03-10:22:23.714 from {{Person rap_ns:.Miranda}}
SHOW_SUCCESS :: Examination of attributes shows
Name = rap_ns:.Miranda
Response @ 2009-04-03-10:22:23.715 from {{Person rap_ns:.Peter}}
SHOW_SUCCESS :: Examination of attributes shows
Name = rap_ns:.Peter
Response @ 2009-04-03-10:22:23.716 from {{Person rap_ns:.Arthur}}
SHOW_SUCCESS :: Examination of attributes shows
Name = rap_ns:.Arthur
The example AM can be un-installed again using the following UNIX shell commands.
$ su – root
$ manage stop MCC 0 application person_am
$ manage delete MCC 0 application person_am
$ temip_enroll -r person_am
$ /usr/opt/temip/mmtoolkit/bin/mcc_msl -r1.3.12.2.1011.2.22.1.180651
$ /usr/opt/temip/mmtoolkit/bin/mcc_msl -r1.3.12.2.1011.2.22.1.7.180651
$ /usr/opt/temip/mmtoolkit/bin/mcc_ptb
$ reloaddictionary mcc 0
$ rm person_am_mgmt_if.ms person_am_srvc_if.ms
/usr/opt/temip/tts/mm/scripts/person_am/ Module.tts
/usr/opt/temip/tts/mm/scripts/person_am/TTSCG/Show.tts
/var/opt/temip/conf/person_am.cfg /var/opt/temip/person_am/data
These commands (not specifically related to person_am) show how to create and encode a value
for a data object of a simple type:
TTS> [temip::data type Latin1String] move s
::s
TTS> s encode Hello
::s
TTS> set s
Hello
The following low level commands make a Show call to retrieve the data for Miranda, get the
entire attribute list from the call as a single data object and inspect the association of this object
to the dictionary:
TTS> [temip::call setup Show {{Person Miranda}} char] move c
::c
TTS> c call
Response
TTS> [c get reply 1 -object] move attrs
::attrs
TTS> attrs decode
{Age 8 Available} {Gender F Available} {Children 0 Available} {Mood
Thrilled Available}
TTS> attrs show association
1.3.12.2.1011.2.22.6.180651.126.1.1.1 0
TTS> c get attribute Age -object
::_Data_00000007
TTS> c get attribute Age
8
TTS> c more
0
Finally a procedure to rebuild the comma separated file from the result of a wild-carded call:
proc writeData {res} {
foreach entRes $res {
set outEntity [lindex $entRes 0 0]
set line [lindex [split [lindex $outEntity 0 1] .] 1]
foreach attr [lindex $entRes 1] {
append line , [lindex $attr 1]
}
puts $line
}
}
and a call of the procedure using a high level TTS call to do the wild-carded show:
TTS> writeData [temip::examine Show {{Person *}} char]
Peter,30,M,1,Happy
Miranda,8,F,0,Thrilled
Arthur,65,M,5,Depressed
startFileMonitor /var/opt/temip/person_am/data
Note that the files mcc_getevent_directive.ms, osi_types.ms and osi_alarms.ms must be included
in the person_am self management model (person_am_mgmt_if.ms), if the event is emitted on
that class, as in this example.
INCLUDE osi_types.ms;
INCLUDE osi_alarms.ms;
INCLUDE mcc_getevent_directive.ms;
In general; the used event model definitions and the GetEvent directive must be defined for the
class that an event is submitted on.
This chapter is the core of the present manual in that it provides the detailed descriptions of all
of the commands that are available in TTS together with associated reference documentation.
Section 6.1describes how TTS applications, whether MM or PM, are described and controlled in
TeMIP using application and application process entities on the TeMIP self-management
interface. One function that can be controlled through the application process entity is tracing.
With TTS this is done by means of the trace command which is described in section 6.6.
Section 6.2 describes properties which are common to all TTS objects (dictionary, data, call,
mir, event and acloc).
An important issue that cuts across all TTS commands is how to represent TeMIP data values in
Tcl, i.e. how to specify values for data that must be encoded for use within TeMIP. The subject
of representation of data values is covered in section 6.3, and section 6.4 then briefly
summarizes how TeMIP data values can be specified in TTS commands.
Descriptions of the TTS high level commands are given in section 6.4.2.
Section 6.7 contains background information on the structure and codes used in the TeMIP
dictionary. Section 6.8 then describes the TTS dictionary command and dictionary object which
can be used to inspect the contents of the dictionary.
The last five sections (6.9, 6.10, 6.11, 6.12 and 6.13) describe, respectively, the TTS data, call,
event, acloc and mir commands and the corresponding TTS objects.
Here the command temip::data creates a new TeMIP data object with the name
::_Data_00000001
The name that is given to a TTS object is auto-generated within the current namespace when the
object is created. To enable the code which creates the object to control the naming, the move
command (described below) is supported for all TTS objects. The standard Tcl rename
command can also be used for a simple control of the name of an object.
An object is visible in a Tcl script according to the following rules:
Variable As a Tcl variables (using Tcl command upvar etc,)
Command In the Tcl namespace where the object is created or moved to.
Reference Same as a command.
If an object is global (in any namespace), then it is always available using fully qualified name.
Important
The lifetime of a TTS object is determined by its scope according to the same rules that apply
for Tcl variables, unless it is explicitly deleted.
6.2.2 Deletion
TTSObj delete
TTSObj deleteall
All TTS objects support the delete subcommand, which will delete the object it is called on.
For each kind of TTS object the deleteall subcommand of the main TTS commands dict,
data, call, event, mir and acloc can be used to delete all objects of that kind in all namespaces
within a the Tcl interpreter. This may be useful in a situation where a general cleanup is needed,
for example when an error situation occurs during the processing of a directive call in a TTS
MM application.
TTSCommand info object
Each of the six TTS low-level commands also supports a subcommand info object which
returns a list of the names of all the current TTS objects of the kind in question.
6.2.3 Renaming
TTSObj move newname ?level?
The move sub-command changes the name of an object TTSObj to newname and returns the
new name including the complete namespace path. The specified new name may optionally
include a namespace; if it does not, the current namespace is used. If newname is empty or only
a namespace ("" or "MySpace:: ") the object name is auto generated to be unique within the
specified namespace.
When the namespace of an object is changed then its scope changes accordingly.
A Tcl array element can also be given as newname, allowing arrays of TTS objects.
If newname is the name of an existing Tcl variable that variable is overwritten. It is not possible
to overwrite a Tcl command in this way.
The scope of the object can be controlled by the optional level argument (interpreted in the
same way as with the standard Tcl commands upvar and uplevel), e.g. a value of 1 will
move the object to the scope of the caller of the procedure in which move is called.
When TTS objects are created their names are auto-generated. These names will be
unpredictable and cumbersome. It will often be convenient to use move to control the name of a
TTS object, as in this example:
[temip::data type Unsigned32] move MyNumber
The following TTS PM command-response dialog show a number of examples of the use of the
move subcommand :
Create the data object in the Tcl namespace NS.
TTS> [temip::data type Unsigned32] move NS::
::NS::_Data_00000001
Define procedure that creates a data object in the scope of the caller.
TTS> proc GetIntObj {name} {
[temip::data type Unsigned32] move $name 1
}
And this continued TTS PM command-response dialog shows further use of the object
subcommands and the object used as a variable:
Create data object and assign its name to variable “int32”
TTS> set int32 [temip::data type Unsigned32]
::_Data_00000004
Assign variable the value of data object using double reference (variable holds the name of data
object variable):
5. Infinity (literally).
8
Unicode character are also supported by TTS, using the \u construct.
Note that a constant value used as a command argument must be enclosed in “” or {} to separate
if from other arguments. The value itself is the string within the delimiters.
Value: {company {my small business}}
Argument: "{company {my small business}}"
or {{company {my small business}}}
Table 2, Data value constants
Type Example of constant value
BinAbsTime 2004-09-14-16:55
BinRelTime +13-19:24:52.333
Range -5 27
A TTS record data value (r) may be converted to or from a Tcl array (a) where array index is the
field name:
array set a [tts::recordToArray $r];
set r [tts::recordFromArray [array get a]]
Or it may be used directly with a Tcl dictionary variable (d) where the key is the field name:
set d [tts::recordToDict $r]
set r [tts::recordFromDict $d]
A TTS event report data value may be converted similar to a record using the commands:
tts::eventReportToArray,
9
A common mistake is to forget the “list” command and just write:
set Entity "{$GlobalClass $GlobalInstance}"
This would result in the invalid entity value:
{company my small business}
Example: &myDataObject
• As the decoded value of a data object, denoted in the standard Tcl manner by the name of
the object (considered as a variable) prepended by the $ (dollar) character.
Example: $myDataObject
For complex objects the use of the second form represents an optimization over the third form
when used as arguments to TTS commands.
response status
This result contains at the outer level of a list of a single element, as there is only one entity. To
pick out the list of attribute values, use the standard Tcl lindex command to extract first this
single element (index 0), then its second element (index 1) to skip the response status:
TTS> lindex $r 0 1
{{Application Id} {-- AttributeUnused}} {{Application Name} tts_pm}
Here the trace line shows the timestamp, the process id (5821) and the thread name
(Master), followed by the trace text “test of trace”
Example (Check that trace is on):
If [temip::trace trace 0x5] {
# Bit 1 or 3 (or both) is set in trace mask
…
}
The names of dictionary node types as shown in the left hand column are those used with the
TTS dictionary command (see next section).
temip::dict deleteall
See section 6.2.
temip::dict oid ?oidVal?
creates a dictionary object associated with the dictionary node identified by oidVal interpreted
as an OID (see section 6.7). If no value is present, the object is associated with the root node of
the dictionary as if the value had been the OID of this node: 1.3.12.2.1011.2.1.
It is not checked if the specified OID is valid. That can be done using the check subcommand
of the dictionary object.
The name of the new dictionary object is returned as result.
Example (Create dict object referencing a specific oid):
TTS> temip::dict oid 1.3.12.2.1011.2.22.1.7
::_Dict_00000000
dictObj delete
See section 6.2.
dictObj children type
retrieves a list of the nodes which are children of the node associated with the dictionary object
and whose type agrees with the value of type (see Table 4).
Each element in the returned list is itself a list of three elements: the code, the display name and
the OID of the child node.
Example (Get list of child classes):
TTS> ::_Dict_00000001 children Class
{202 APPLICATION 1.3.12.2.1011.2.22.1.7.202} ……
dictObj up
moves the association of the dictionary object up one level in the dictionary tree.
dictObj check
checks that the dictionary object has a valid association to a dictionary node as defined by its
OID and returns 1 (true) if this is the case, otherwise 0 (false).
dictObj type
returns as result the type of the dictionary node associated with the dictionary object (see Table
4).
dictObj oid ?oidVal?
returns as result the OID value of the dictionary object (same as the value of the object
considered as a Tcl variable), and, if oidVal is present, sets it as the new value. Setting the
OID redefines the association of the object with a dictionary node. It is not checked that the OID
is valid.
Example (Get referenced oid):
TTS> ::_Dict_00000001 oid
1.3.12.2.1011.2.22.1.7.202
If index is specified, it must be the name of one of the definition items as mentioned in Table
5. In this case only the indicated item is returned.
Example (Get definitions for referenced object):
TTS> ::_Dict_00000001 definitions
202 APPLICATION CLASS_APPLICATION Dynamic Required
TTS> ::_Dict_00000001 def Symbol
CLASS_APPLICATION
dictObj private
returns as value the “private” text from the dictionary entry.
dictObj snmp
returns the SNMP OID, if defined, from the dictionary entry.
dictObj cmip
returns the CMIP OID, if defined, from the dictionary entry.
dictObj sql
returns a list with two elements, if they are defined, from the dictionary entry: the SQL column
size and storage mask.
dictObj dependson
returns a list with three elements, if Depends On is defined, from the dictionary entry:
characteristic attribute name, operator and values. Values are again a list of enumeration values.
Similarly, myObj may be used as a command argument wherever a variable name is accepted,
for example as the first argument of the Tcl set command. Such use will typically imply both
encoding and decoding of the data value to take place, for example evaluation of:
set myObj dataVal
causes dataVal to be encoded according to the type of myObj, whose newly assigned value is
then again decoded to yield the result of the set command. Unless the latter result is actually
used for a purpose, this is less efficient than:
myObj encode dataVal
When the decoded value of an object is a Tcl list it is also possible to use Tcl commands that
insert, modify or append elements to a list, as in the following examples:
TTS> [[temip::data type FullEntity] move entity] encode {{mcc 0} {appl *}}
TTS> set entity
{MCC mermaid_ns:.temip.mermaid_director} {APPLICATION *}
TTS> lset entity 1 1 tts_pm
{MCC mermaid_ns:.temip.mermaid_director} {APPLICATION tts_pm}
TTS> lset entity 1 0 NewClass
can't set "entity": unknown class NewClass
TTS> lindex $entity 0 1
mermaid_ns:.temip.mermaid_director
as the later will just set the name of the data object into another variable.
dataObj encode dataVal
sets the value of the data object to dataVal which must be a data value (see section 6.4.1) of
the same type as the object.
Example (Set data value):
TTS> $dataObjVar encode "{MCC $temip_director}"
::_Data_00000005
except that the first form returns the name of the data object and the second form returns the
(decoded) value assigned.
dataObj decode ?form?
returns as result the decoded value (see section 6.3) of the data object. Dictionary information is
represented as codes (if form is -codes) or as display names (if form is -names or omitted).
Example (Get data value):
set value [$dataObjVar decode]
dataObj clear
resets the data value of the data object to default value whilst other information items such as
dictionary node association are retained.
dataObj compare value
compares value of dataObj with value and returns one of the following:
0 the values are equal.
1 the value of dataObj is greater than the value specified (or different from if
greater/less than does not make sense).
10
This can be used check if instance matches wild-carding.
DC filters can be hard to encode, so using the TeMIP client DC editor to initialize a CMISFilter
attribute and then copy its value to the TTS script, is recommended. Use e.g. the tts_mb
application to get the instance DC attribute value in TTS format.
For further description of DC filters, refer to “TeMIP Fault Management Reference Guide”,
Chapter 3.1.
Example (Wait for asynchronous show call response for max. 10 seconds):
TTS> proc callback {resp} {puts {Got Response}}
TTS> [temip::call setup show {{mcc 0}} ident] call access callback
Asynchronous
TTS> temip::call wait 10000
Got Response
callObj delete
See section 6.2 and the remark on call object deletion at the beginning of this section.
callObj type
returns the verb type of the call object. It will be one of the following: Examine, Modify,
Action, Event, Presentation.
Example (Inspect type of directive “Show”):
TTS> set cl [temip::call setup Show {{mcc 0} {appl tts_pm}} ident]
TTS> $cl type
Examine
callObj dump
returns a ILV dump of the call object for debugging.
Example (Debug show directive):
TTS> [temip::call setup Show {{mcc 0} {appl tts_pm}} ident] dump
Note
The total length of all data set in a call object cannot exceed ~ 60 Kbytes
After a synchronous call the response, timestamp, entity, director, get and more
subcommands on the same call object that was used to make the call may be used to extract
result information. If there are multiple replies, as indicated by the “more” flag, the call
command may be called again to retrieve the next one.
In the asynchronous form of the command the parameter callback is a Tcl command which is
called by the interpreter’s event handler when the response is received. It is called in the global
namespace. In this case the call reply information is not placed in the call object that was used to
make the call, but on another object, the reply object, which is created as a copy of the original
call object, before the reply information is placed in it. The name of the reply object is appended
to the callback command passed by the call command. For this reason the callback command
will typically take the form of a procedure call which is one parameter short of matching the
proc command that defines the procedure. The same subcommands as in the synchronous case
(response, timestamp, entity, get and more) can be used to extract information from
the reply call object.
When an asynchronous call returns multiple responses - typically if it is wild carded, the
responses are fetched automatically and the callback called for each one, i.e. the call
subcommand shall not (and cannot) be called repeatedly. The callControl parameter of the
initial call determines the flow control policy: if it has the value -single each new response is
retrieved when the previous one has been processed by the callback; if it has the value -all all
responses are retrieved to the TTS process as fast as they are produced by the called
management module and queued by the interpreter. This may require extended memory use for
the TTS process.
Example (Synchronous Show directive call):
TTS> set cl [temip::call setup Show {{mcc 0} {appl tts_pm}} ident]
TTS> $cl call function
TTS> $cl get attribute "Application Name"
tts_pm
TTS> c call
Response
Example (Print all registered TeMIP application names and break when no more):
[temip::call setup show {{mcc 0} {appl *}} ident] move c
while {[c call function] eq "Response"} {
puts "Application name is [c get attribute "Application Name"]"
if ![c more] break
}
eventObj delete
See section 6.2.
eventObj entity value
re-specifies the out-entity of the event according to the entity argument, which must be a data
value (see section 6.4.1) of type FullEntity.
eventObj set id value
sets the value of the event report argument identified by id, which can be its name or code, to
the value specified by value, which must be a data value (see section 6.4.1) of the type of the
argument. Values for event record arguments already set by the setup subcommand can be
redefined.
This subcommand returns 1 (true), if a value had previously been set for the event argument,
otherwise 0 (false).
Example (Add arguments to an event object):
[temip::event setup {{OSI_SYSTEM test}} 16 1708 5 1 3] move eventObj
eventObj set "Additional Text" "Bad password"
Note
The total length of all data set in an event object should not exceed ~ 30 Kbytes
This subcommand will return a Tcl error if the operation fails for any reason.
Example (Put event into event poll using low level filters):
set event [temip::event setup {{OSI_SYSTEM test}} 16 1708 5 1 3]
$event forward
Example (Put event with modified out-entity into event poll with no low level filtering):
set event [temip::event nofiltersetup {{OSI_SYSTEM test}} 16 1708 5 1 3]
$event entity {{OSI_SYSTEM moretests}}
$event forward
Note
If the event is not an OSI event (no event type specified) or if it was created using the
nofiltersetup sub-command, no low-level filtering will take place on forwarding.
temip::acloc deleteall
See section 6.2 and also the remark in the beginning of this section about deleting an acloc
object.
temip::acloc session ?user?
creates a security acloc object and returns its name as result; this uses functions of the TeMIP
ACLOC API to create a security session for a specified user. ACLOC retrieves the name of the
user profile which applies to the user and the default AC view from the profile.
The user specified towards ACLOC can be given explicitly as the value of the user argument.
If this argument is omitted the user is specified as follows:
TTS PM The user of the TTS PM session as established when TTS PM was called;
see section 7.1 under the heading Security Setup.
TTS MM The owner of the process which called the directive in the management
module (the client of the management module).
Example (Create an acloc session for user temip):
temip::acloc session temip
11
The user is checked against NIS, /etc/shadow and /etc/passwd depending on configuration and permissions.
aclocObj info
retrieves the information contents of the acloc object and returns a list of 8 elements: host name,
user name, process name, session name, active AC view filename, user profile filename, central
LOC status, user session LOC status.
Example (Get acloc attributes for the temip user):
TTS> set user temip
TTS> set al [temip::acloc session $user]
TTS> $al info
rap.dnk.hp.com temip tts_pm temip.hgo@rap.dnk.hp.com@tts_pm@2009-MAR-31-
15:48:20:008067
/var/opt/temip/acloc/user_profiles/temip_root_default_ac_view.v
/var/opt/temip/acloc/user_profiles/user_temip.profile OFF {}
To manage the MIR files, use the TeMIP utilities temip_mir_backup, temip_mir_recover, etc.
A new MIR object is created by the temip::mir open command.
A MIR object acts as a reference to a specific entity in the MIR (the current entity). This
reference may be changed by the subcommands of the MIR object.
Any number of MIR objects, open on the same MIR, may be used simultaneously; referencing
the same or different entities. There are no transaction locks or synchronization between access
to the same MIR, but each MIR object subcommand do read/write on the MIR as an atomic
operation.
The MIR is indexed by TeMIP entities (managed objects) with valid class ids and identifier
attribute values according to the TeMIP dictionary. For multi level entities, the parent entity
must exist in the MIR before a child entity can be inserted.
12
Other data-base interfaces are also available in TTS. See the Sqlite and Oratcl packages in chapter 11.2.
mirObj delete
See section 6.2. Deleting the MIR object does not affect the data base.
mirObj insert entity
inserts entity (FullEntity) in the MIR. Returns 1 (true) if a new entity was inserted and returns 0
(false) if the entity did already exist. The entity referenced by the MIR object is changed to the
inserted entity. The data associated with a new entity is empty.
Example (Add parent and child entity to MIR):
$mymir insert {{mcc 0}}
$mymir insert {{mcc 0} {appl tts_pm}}
Example (Open second MIR object and point it to same entity as first MIR object):
[temip::mir open MyMIR] move mymirobj1
mymirobj1 lookup {{mcc 0} {appl tts_pm}}
[temip::mir open MyMIR] move mymirobj2
mymirobj2 key [mymirobj1 key]
Example (Get all Characteristics attribute values from Show call and set in MIR):
Example (Get all Characteristics attribute values from MIR and use in Set directive call):
[temip::call setup Set {{mcc 0} {appl tts_pm}} Characteristics] move c
c set request "Attribute Values" [$mymir show Characteristics]
c call
Example (Efficient assignment using -object and TTS object reference “&”, see section 6.4.1):
c set request "Attribute Values" &[$mymir show Characteristics -object]
Example (Get attributes from MIR and use in reply in Show directive script in a MM):
temip::context set reply "Attribute Values" [$mymir show Characteristics]
Initialization
If there exists a file named .ttsrc in the home directory of the user, TTS PM evaluates its
contents as a Tcl script just before reading the first command from standard input (in interactive
mode).
For example, if ~/.ttsrc contains the command:
puts "$tts_version $temip_version"
then the TTS and TeMIP versions will be output before the first prompt.
Executable script file
A TTS script file can be made executable in the standard UNIX way, i.e. by including:
#!/bin/sh
# the next line restarts using tts_pm \
exec /usr/opt/temip/bin/tts_pm "$0" "$@"
as the first 3 lines of the file 13. Shell command line arguments given to an executable script will
be available in the scripts as described in Table 13.
Alternative application names
An alternative name for the TTS PM application can be created by making a link from the new
application name (e.g. NAN) to the security wrapper:
ln –s /usr/opt/temip/acloc/bin/temip_up_pm NAN
All commands and packages that are not directly related to TeMIP are still available in the
standard Tcl shell.
13
The tts_pm can not be called directly on Solaris, as it does not allow SUID programs as shell in executable
scripts.
By adding these two environment settings to the .ttsrc file, this option can be set for all
interactive uses of TTS PM.
This interactive single Tcl event handling is very useful for debugging code that uses Tcl events
and call-backs, e.g. the tts::remote or asynchronous TeMIP call commands, as you can monitor
each event separately.
Note
Output from the temip::trace or puts commands in the background code will be
displayed just before the next prompt.
Command history
The line editor maintains a command line history, up to 500 lines, that can be accessed by edit
key functions. If TTS PM is exited by CTRL-D the command history is saved in the file
.ttspmhist in the user’s home directory ($HOME). If this file exists when a TTS PM starts,
it is reloaded as the active history.
Table 14, Interactive Line Edit Keys
Key Description
CTRL-A Move cursor to beginning of line.
CTRL-B Move cursor left (back) 1 column. (left-arrow)
CTRL-C Skip the current line, but save in history list.
See also INTR below.
ESC-B Move cursor back one word.
CTRL-D Delete the character under the cursor or exit from TTS PM if empty line (saving the history).
CTRL-E Move cursor to end of line.
Note
If a command entered in interactive mode is not recognized as Tcl/TTS command it is
executed as a Unix shell command if possible.
A general description of the capabilities of a TTS Access or Function module (TTS MM) is
given in section 2.3. This chapter supplements that description with specific reference
information. Chapter 5 shows an example of how to implement a TeMIP AM using TTS.
where class-path is a comma-separated list of the class names encountered in the class
containment tree on the path from the global entity class to the target class, and partitions is
a comma-separated list of codes of attribute partitions supported by the module (i.e. by the
customization of TTS MM). The X can be leaved out or replaced by a digit between 0 and 9,
defining up to 11 different groups.
The VerbGroup line has the syntax:
where verb-group is one of (X is the same as used for the associated class group):
TTSXEG for verbs of type Examine, e.g. Show.
TTSXMG for verbs of type Modify, e.g. Set.
TTSXAG for verbs of type Action, e.g. Create.
TTSXGG for the verb GetEvent. If events are emitted from the configured
class, this must be defined.
and verbs is a comma-separated list of directive codes in the verb group.
Note
The verbs defined using the verb groups are associated with all classes defined by the
associated class group. To be able to define other sets of verbs associated with different
classes, another set of verb classes and verb groups must be selected.
At enrollment and run-time the configuration file for a TTS MM must be present as:
/var/opt/temip/conf/module-name.cfg
The configuration can be checked as describe in 8.7.
Example:
ClassGroup= TTS0CG, Class=(company), ClassPartitionIds=(1, 4)
VerbGroup = TTS0EG, verbIds = (1)
VerbGroup = TTS0MG, verbIds = (2)
VerbGroup = TTS0AG, verbIds = (12, 13)
VerbGroup = TTS0GG, verbIds = (65)
Development
To accelerate the development cycle, it is recommended that you create a developer's dictionary
and use it until the management and service interfaces for your management module stabilize.
To do this, perform the following steps:
1. Establish a conf directory and define the TEMIP_CONF_LOCATION environment
variable to point to this location, as shown below.
% mkdir conf
% cd conf
% export TEMIP_CONF_LOCATION=`pwd`
% export MCC_DICT_NAME=mcc_fdictionary.dat
3. Copy the developer's parse tables and dictionary tree extract as shown below.
% cp /usr/opt/temip/conf/%L/mcc_fdictionary.bpt mcc_fdictionary.bpt
4. Copy the contents of the initial TEMIP_CONF_LOCATION directory into your conf
directory as follows:
% cp /var/opt/temip/conf/%L/* .
5. Invoke the Management Specification Language (MSL) Translator (mcc_msl) and load
your new management and service interfaces for your entity as follows. Be sure you
have write access to the dictionary files and to the directory.
% mcc_msl -I/usr/opt/temip/mmtoolkit/msl mcc_entity_am_srvc_if.ms
% mcc_msl -I/usr/opt/temip/mmtoolkit/msl mcc_entity_am_mgmt_if.ms
In addition to the scripts listed above a common initialization script for all the interpreters can be
located in the file Common.tts (within the module’s script directory). It can be used to
perform initialization actions that are needed in all the interpreters such as defining common
procedures.
The Master and Module interpreters are created and initialized when the TTS MM module is
started, and the OnInit procedures are called in the scripts if defined.
Initialization of the directive interpreters is deferred until the first time each one is needed to
process a directive call. A new directive interpreter will be initialized for each client (thread)
calling the management module. Whenever a client is terminated or times out
(MCC_RPC_TIMEOUT), the associated directive interpreter will be deleted. This means a
directive interpreter is not necessarily unique to the directive; therefore there should be no
dependence on Tcl variables surviving between calls (except in case of “more” handling).
Initialization of an interpreter is done in 4 steps:
1. The standard Tcl commands are created and Tcl libraries are loaded from:
/usr/opt/temip/tts/lib/tcl8.5/*.
2. The Common.tts initialization script is executed. It does not have access to TTS
commands.
3. The TTS commands, including the module and context commands are created.
4. The script which is specific to the interpreter is executed. The procedures which it defines
(OnExecute, etc.) are not called at this time.
If debugging is turned on for the module (see section 8.5), then step 4 is repeated each time a
directive or filter is called, allowing the script file to be modified between calls.
8.4.1 Directive scripts
The behavior of TeMIP directives is implemented by Tcl procedures defined in dedicated script
files, one per (class group, directive) combination.
Note
This implies that a directive script is common for all classes of the same class group as
defined in the module configuration file.
Note
The module and directive names used to name these directories and files must match exactly
(case sensitive) the display names defined for the management module in MSL. The class
group name must be one of the fixed names defined by TTS (see section 8.2).
A directive script shall contain between one and six Tcl procedures with predefined names to
implement the behavior of the directive. The procedures are all parameter-less. They can all use
the TTS module and context commands to access module-specific information and the call-
context, i.e. call and reply parameters, etc. The example in chapter 5.1 illustrates the use of these
procedures.
The six TTS framework procedures are.
OnInit This optional procedure, if it is present, is called once before any
of the other procedures during the processing of each TeMIP
directive call, i.e. when the handle is “first”. It can be used to
perform initialization which applies to wild-carded calls as well
as calls with a uniquely specified in-entity.
OnExecute This procedure must implement the directive behavior for a call
with uniquely specified in-entity. If the “more” flag is set on a
reply, this procedure may be called multiple times as part of a
single TeMIP directive call, all calls having the same call-
context.
Example:
temip::module id
returns the module-id defined when the module was enrolled.
Example (Check the module id):
if {[temip::module id] == 12345} {…}
will produce
{Person {Identifiers Characteristics} {Show}}
returns:
V1.0.3
Note that this is the default form of decoding (-names); list form could have been specified by
appending –codes to the command.
temip::module debug ?debugVal?
turns debug mode on or off for the module according to the value of argument debugVal,
which may be any boolean value valid in Tcl. If the argument is not present the command just
returns the current debug mode.
When debug mode is on, directive scripts and corrective filter scripts are sourced at each call,
before their TTS framework procedures are called (see section 8.4).
Example (Turn on TTS debugging in module):
temip::module debug on
logs
If not set by this command the returned out-entity will equal the in-entity of the directive call. It
must be set to a specific value if the in-entity is wild-carded. Otherwise it is normally not
necessary to set the out-entity.
temip::context inentity ?returnDataSpec?
returns the value of the in-entity of the call context - a data value of type FullEntity - in the
form specified by returnDataSpec (see section 6.4.2). It may be wild-carded, i.e. the entity
name may include wildcard characters.
Example (Check wild-carding type of entity in directive call):
[temip::context inentity -object] show wildtype
Note
The default reply of type Response with code 1 is (re)set automatically on entering the
OnExecute or OnExecuteWild procedures. This implies that the replycode
subcommand is only useful within these procedures.
temip::context more
sets the handle (more flag) of the call to be conveyed in the reply to indicate that more data is
available. This may be more data from the same out-entity or, for a wild-carded call, data from
additional entities.
temip::context instance ?-all | -last? ?-nonamespace?
returns the identifier value(s) (as string) of the instance(s) in the current entity of the context (in-
entity or out-entity as for entity subcommand). If -all is present a list of all instance
identifiers in the current entity is returned. If –last is present (default) then only the last
instance value is returned. If –nonamespace is present, instance identifiers of type FullName
are returned without prefixed namespace.
Example (Get value of last instance identifier without namespace prefix):
set inName [temip::context instance -last -nonamespace]
MSL compilation
The following UNIX command will compile the management model and self management
model into the TeMIP dictionary, assuming the current directory is the directory where the MSL
files are located. There is no standard location for this, and the files are not needed again after
compilation.
$ /usr/opt/temip/mmtoolkit/bin/mcc_msl -I/usr/opt/temip/mmtoolkit/msl *.ms
Note
The shell command mcc_msl_extract or the tts_mb demo application may be used to
extract existing model information from the dictionary for edit and compile.
The output from this command should be inspected for error messages.
The TTS temip::module own command (see 8.5) can also be used later on to check if the
configuration matches the needed class, verb, and partition combinations.
Create application entity
The TeMIP command to create the application entity for the customized module is:
$ manage create MCC 0 application module-name application type = MM, \
filename = /usr/opt/temip/bin/tts_mm
Uninstallation
The TeMIP command to stop the management module is:
$ manage stop MCC 0 application module-name
The UNIX shell command to remove the management model from the TeMIP dictionary is:
$ /usr/opt/temip/mmtoolkit/bin/mcc_msl –rclass-OID
where class-OID is the OID of the global class of the management model.
A general description of the TTS corrective filter capabilities is given in section 2.4. This
chapter supplements that description with specific reference information.
A corrective filter has two parts:
• A corrective filter entity, e.g. MCC 0 CORRECTIVE_FILTER MyFilter. This
entity defines the events to which the corrective process is applied. One attribute of the
entity specifies the management module which emits the event (by forwarding it to the
event manager) by its application name. Another attribute specifies a discriminator
construct which is applied to the entity against which the event is reported (its out-
entity).
• A corrective process which is applied to the events that passes the constrains, set by the
corrective filter entity.
The TeMIP Event Filtering and Correlation Software Reference Manual describes how to
implement the corrective process by C++ programming. The TTS CF module allows this same
corrective process to be implemented as a TTS/Tcl script.
The script for each corrective filter type must be in a separate file in:
/usr/opt/temip/tts/cf
The file is only sourced the first time the filter is activated and the OnEvent procedure is
thereafter repeatedly called each time the filter is activated.
If debug mode is on - it can be set by calling the debug subcommand of the TTS module
command - the script file is re-sourced each time the filter is activated. See also section 11.5.
The filter TTS code can use all the general low level TTS commands including the module
command (see section 8.5) plus the special event filter command which makes it possible to
manipulate the filtered event, as described in section 9.2.
The event report being filtered is also available as a global TTS data object - of data type
EventReport - called ::event.
All changes made to the current event using the temip::event filter command or by
modifying the ::event object, are applied to the event when the OnEvent procedure
returns. The event is then cascaded to the next low level filter.
If OnEvent returns with a Tcl error, this will be reported in the Additional Text argument of the
event report.
The OnEvent procedure must be defined with arguments if additional argument values are given
in the corrective filter attribute “Parameters”, as described below.
The above filter code changes all new-lines in the “additional text” attribute of an alarm event to
“+” characters.
with:
TEMIP_EF_USER_LIB=/usr/opt/temip/mmtoolkit/lib/libtemip_ef_user_library.so
TEMIP_EFUL_DIR=/var/opt/temip/conf/eful
/usr/opt/temip/tts/bin/libtemip_ef_tts_library.so 15
to the file(s):
/var/opt/temip/conf/eful/MM
where MM is the application name of the Management Module which is the source of the
events to be filtered.
It is important to note that the filter libraries are loaded into each of the management modules
specified and that the TTS scripts are initialized and executed in each management module
processes.
The management module(s) must be restarted for the addition of the filters to take effect.
Note
14
As the scripts are shared, checking for e.g. module name can be included for module specific code.
15
On PA-RISC the library files ends in .sl
16
On PA-RISC the library files ends in .sl
It may be necessary to increase the thread count and stack size for the
management module where the filter is enabled, if the TTS filter code uses many
resources (e.g. using the Oracle Tcl package).
Example (Get additional text argument value from event only if it is set):
set addtxtObj [temip::event filter get {additional text} -object]
if {[$addtxtObj show reason] eq Available} {
set addtxt [$addtxtObj decode]
…
}
Note
The total length of all data set in the event should not exceed ~ 30 Kbytes
may produce 17
2009-04-04-10:17:11[25271] 1806 1.3.12.2.1011.2.22.9.7.202.126.1806 {
Object Creation} {OSI Event : Object Created}
Note
At least one event parameter must be modified (using the set subcommand of the event
object) for the associated event to be forwarded.
17
If this trace is included in a CF, it will be logged to the file belonging to the management module that
forwarded the event.
A tts_pm interpreter or the Master interpreter in a tts_mm may be configured to act as a remote
TTS server.
The server allows execution of Tcl/TTS scripts from any remote Tcl interpreter client, including
Tcl/Tk (version 8.5 or later) scripts running on Windows®, Linux, Mac or Windows Mobile®.
10.1 Server
The server TTS side interpreter is initialized by the command:
The connection to the TTS server can then be established using the command:
18
If you install the package anywhere else, then you must ensure that the directory containing the package is in
the auto_path global variable or an immediate subdirectory of one of the directories in auto_path
19
See http://www.tcl.tk/man/tcl8.5/TclCmd/interp.htm for a description of the “interp” Tcl command and the
concept of slave interpreters.
20
In the same thread as the tts::remote server command was executed
tts:remote disconnect
The server can close a connection to the client by executing the exit command in the client
specific interpreter.
All variables, commands, TTS objects, etc. created by the command, will be stored in the
dedicated interpreter on the server side and can not be accessed locally on the client, only via
new call of the tts::remote eval command from the same client.
Example (Set the variable a in the Tcl interpreter on the server side and return 27 as the result):
tts::remote eval set a 27
10.5 Callbacks
Many times, when working with TeMIP, there is a need for asynchronous event handling (e.g.
alarm handling). In a traditional client-server setup, this is implemented by having the client
waiting for the events in a separate thread. In TTS this is instead implemented as a standard Tcl
callback, allowing the server to push events (commands) to the client.
The code running in the slave interpreter on the server side of a remote connection can execute
commands in the associated client as call backs, using the following command:
tts::notify <arg> ?<arg> …?
The command specified by <arg> … is evaluated as a callback command on the client. Note that
no result from the command is returned to the server interpreter, as the command is executed
asynchronously on the client.
A server side interpreter can only execute commands in its associated client side interpreter
using this command. Not in any other interpreters or clients.
The tts::notify command returns 1 if the command was send to the client and 0 if it was
ignored (callback is off on the client).
tts::notify set a 27
This will set the global variable “a” in the associated client side interpreter. No result is returned
from the command.
Example:
On the server side a TeMIP directive call is executed as:
This will call the directive specified in the callObject (already defined) and when the result is
returned later (asynchronous) it will notify the client side by calling the procedure “callreturn” in
the client interpreter (with call result argument appended).
Note
This command is only available in a slave interpreter that runs as remote interpreter of a
client connection made by tts::remote connect. Both client and server (Master
interpreter) must handle events (using commands like: update or vwait).
Errors from tts::notify are reported on the client side as background errors.
No errors are returned by this command in the case that the client has set the callback to off.
$ tclsh
% source TTS.tcl
% tts::remote connect MyHost 12345
%
% # Execute a remote TTS command
% tts::remote send {temip show {{mcc 0}}}
This string is handed over to the server side as an argument to the servers <connect command>,
if any.
The server may be started with an additional specification of a <connect command> and a <close
command>:
The <connect command> will be called with the following arguments each time a client
connects:
The <close command> will be called when the client exits again with the following argument:
<interp>
The <slave interp> is the name of the dedicated slave interpreter that executes the client
commands (via tts::remote eval). The interpreter is a slave of the Master interpreter that executes
the <connect command> and the Tcl command interp and its slave commands may be used to
do further initialization of the slave interpreter.
The <client host> is the IP address of the connecting client and <port> is the port it connects
from.
The <client string> is the string specified by the client in it’s connect command. This string
may be used to e.g. identify the client (user, password, etc).
If the <connect command> returns a non-empty string, this is taken as an error message returned
to the connecting client. The connection will in that case be closed (rejected).
# Start server
puts "Start server on port 12345"
tts::remote server 12345 OnConnect
vwait forever
$ tclsh
% package require Tts
%
% # Connect
% tts::remote connect MyHost 12345
%
% # Define an alias “remote” for the
% # “tts::remote eval” command
% interp alias {} remote {} tts::remote eval
%
% # Source local file in remote slave interpreter (if needed)
% tts::remote source C:/InitMyServer.tcl
%
% # Define new procedure in remote slave interpreter (server)
% tts::remote send {
proc slaveProcedure {a} {
puts "Client called me"
return "Slave procedure called with $a"
}
}
%
% # Call it
% remote slaveProcedure Test
Slave procedure called with Test
%
% # Call procedure in remote Master interpreter
% # via alias in slave
% remote masterAlias
Master procedure called
%
% # Define local procedure
% proc clientCallback {} {
puts {Server called me}
}
%
% # Enable callbacks from server
% tts::remote callback on
%
% # Call procedure serverCallback on server side
% # This will in turn call clientCallback defined above
Then the needed SSL parameters must be set using the command:
tls::init ?options?
The OpenSSL command line utilities (like openssl) and libraries are not part of the TTS
TLS package. These must be available on the TeMIP platform before the SSL connections
can be made.
Example:
On the server side the initialization could be:
package require tls
tls::init -certfile server-pub.pem -keyfile server-priv.key –cafile ca.pem
11.1 Files
This section gives an overview of the files that are installed as part of TTS.
/usr/opt/temip/bin location for TeMIP commands
tts_pm symbolic link to security wrapper
tts_mm indirect symbolic link to TTS MM executable
/usr/opt/temip/mmexe contains links used by wrappers
tts_pm.exe symbolic link to actual TTS PM executable
tts_mm.exe symbolic link to actual TTS MM executable
/usr/opt/temip/tts/bin actual TTS executables
tts_pm actual TTS PM executable
tts_mm actual TTS MM executable
libtemip_ef_tts_library.so TTS corrective filter library
/usr/opt/temip/tts/lib/* Packages installed with TTS
/usr/opt/temip/tts/lib/tts TTS as package
libtts.so TTS low level commands
TeMIP.tcl TTS high level commands
TTS.tcl TTS support procedures and tts::remote command
pkgIndex.tcl TTS package description (for external install)
/usr/opt/temip/tts/mm/models MSL template files
/usr/opt/temip/tts/mm/scripts TTS AM or FM directive scripts
/usr/opt/temip/tts/cf/ Corrective filter scripts
21
The links and references given in this document may not be the official home pages of the Tcl packages.
Important Note
The environment variable ORACLE_HOME must be specified correctly before the package
is loaded. The environment variable ORACLE_LIBRARY may also need to be set if the
standard Oracle library “libclntsh” is not available.
Values for TeMIP Oracle could be (Check your local Oracle setup):
Example (Use the SQlite package to create a database with a table and insert rows into it):
package require sqlite3
sqlite3 db ./testdb
db eval {create table tbl1 (i int, s string)}
db eval {insert into tbl1 (i,s) values (42,'test text')}
db eval {insert into tbl1 (i,s) values (55,'hej')}
lassign [db eval {select i,s from tbl1 where i == 42}] i s
puts "Result: $i - $s"
db close
Tracing
The standard TeMIP trace environment is modified as follows:
TFC_DEFAULT_EXCEPTION_TRACE=OFF
MCC_K_TRACE_NO_FORMATTED_HEADER=TRUE
The tracing from TTS includes its own header with timestamp controlled by
MCC_TIME_OUT_MODE and with thread names and ids following the Thread extension
package format.
TTS
The following environment variables are specific to TTS:
TTS_SCRIPTS Root location for TTS MM script files, default value:
/usr/opt/temip/tts/mm/scripts
This may be changed before staring a module, to use scripts from
another location.
TTS_FCL When this environment variable is present, data values of types
FullEntity and LocalEntity are accepted in FCL format. This is not
recommended for scripts, but may be useful for online use. For
scripts, the convert sub-command of data objects should be used
instead.
TTS_MASTER A timestamp set when the TTS Master interpreter thread is started.
TTSCHANNEL Output channel for the temip high level command standard
formatter. Defaults to stdout.
TTSFORMATTER Output formatter used for the temip high level command.
TTS_EVENTHANDLING
Enable interactive event handling in TTS PM (see section 7.4).
TTS_SHOWEVENTHANDLING
Enable display of interactive event handling PM (see section 7.4).
.
Within each Tcl interpreter the current set of environment variables (shared by all Tcl
interpreters and threads in the process) can be read and written through the global Tcl array
variable ::env.
Example (Set environment variable; Allow “manage” formatted entities):
set ::env(TTS_FCL) {}
A UNIX shell telnet connection to the Master interpreter 22 in the test_am could look like this.
$ telnet -8 –e c localhost 12345
Trying...
Connected to localhost.dnk.hp.com.
Escape character is '^C'.
test_pm Master> array get env TTS*
TTS_MASTER 2007-08-23-09:28:49 TTS_SCRIPTS /usr/opt/temip/tts/mm
The puts Tcl command writes per default to stdout of the module, not to the telnet consol. So
to write to the telnet connection, use the open Tcl channel saved in the TTSCHANNEL
environment variable.
test_pm Master> puts Hello
test_pm Master> puts $::env(TTSCHANNEL) Hello
Hello
test_pm Master> exit
Connection closed by foreign host.
22
The Master interpreter will run both in MMs created using TTS and in MMs where a TTS CF has been
loaded.
23
Not to be confused with the temip::trace command
Tcl exceptions
Errors in Tcl scripts will result in Tcl exceptions, i.e. violations of Tcl rules or syntax which are
detected at runtime.
Tcl exceptions can be caught, using the Tcl catch command, and handled by outer level code.
If not caught within user the code, a Tcl exception will propagate to where the user code was
executed from: e.g. a command running from a script file, interactively or event driven in TTS
PM, or a call from TTS MM into one of the procedures in a directive script. When a command in
a script produces an unhandled Tcl exception, the script terminates.
All Tcl exceptions which are not caught by user code will print a Tcl error text. Tcl exception
texts are normally printed on stderr of the process where they occur. With a TTS PM
Application started from a command line on a terminal this normally means the exception text
will be visible in the terminal window.
Exceptions occurring in Tcl code evaluated as callbacks triggered by events are called
background errors. Tk includes its own handling of background errors: a special window with
information about the exception is launched. To handle background errors in other contexts such
as a TTS PM not running as GUI or a TTS MM Master interpreter, will require an explicit
background error handler. For this topic, consult a Tcl documentation source.
Example (Catch error):
set errorState [catch {command arg1 arg2} errorText]
if {$errorState != 0} {
# Handle error
……
}
Example (Catch error):
if ![catch {command arg1 arg2} errorText] {
# Command OK
…
} else {
# Handle error
……
}
TTS MM considerations
When an unhandled Tcl exception occurs in a TTS MM during the evaluation of a procedure in a
directive script, the directive call will return the common exception “The requested operation
cannot be completed.”, and a Tcl exception trace is provided in the reply argument
Additional Text.
Management modules built with TTS MM may be started implicitly in which case stdout and
stderr may not be visible, as they are inherited from the process that started the TeMIP
Framework. To make them visible, the TSM MM process can be started from a UNIX shell
prompt in a terminal window (which could be dedicated to this purpose). The UNIX command
for this is:
/usr/opt/temip/bin/tts_mm –i module-id
Using the TTS module command (see section 8.5) a TTS MM can be placed in the debug mode.
In this mode directive scripts are reloaded each time the MM receives a directive call. Also the
Tcl Error Trace bit (see next paragraph) is automatically set in the debug mode.
The temip command is intended for interactive use, for example for testing of functionality
implemented with TTS or existing TeMIP modules.
Tcl errors found while executing the command will terminate the execution and return a Tcl
error. Exceptions found as results of the directive call are reported as part of the result and
command execution is done as normal.
The temip command is at same functional level as the directive commands of TeMIP’s FCL
command line utility (“manage”). The basic syntax is however different.
As the temip command does not enforce as many restrictions on calls as FCL, this is not an
operator command, but a command useful for testing.
Important: The temip command should not be used in scripts except in simple cases, as the
performance is not as good as the low level commands.
The temip command has the following syntax:
temip directive entity ?arg ...?
Where:
directive is the id (code or name) of the directive to use in the call.
entity is the entity to call. The entity may be wild-carded. The format of
the entity is the TTS format (see section 6.3).
arg is a list with two elements: key and info, which supplies
arguments, etc. for the call. The argument may be repeated.
The value that can be used for info depends on key as shown in the table below.
The key may be abbreviated.
key info
attribute List of pairs of attribute id and value.
For examine directives (E.g. Show) the value shall be omitted.
event List of event ids.
argument List of pairs of argument id and value.
partition List of attribute partition ids.
all List of attribute partition ids. If omitted, specifies all available partitions (with
all attributes).
any List of event partition ids.
duration Specifies end time as absolute value (BinAbsTime) or relative value
(BinRelTime).
qualifier List of qualifier name and value pairs
formatter Name of result formatter. Defaults to “stdout”, writing directly to tty.
expand Boolean. If false, don't expand global wild-carded entities using the entities
registered with the registration FM. The global level wild-carded entity is given
to the local MM directly.
The contents of this table can be displayed on-line by means of the command:
tts::help temip
Note
If an attribute or argument name contains spaces they must be escaped ( using {}, "" or \ ).
Example (Wait for all notification events from a class (stop using CTRL-C)):
TTS> temip getevent {{company *}} {any notif} {duration infinity}
All the normal Tcl syntax, variable and command substitution handling also applies to the temip
command arguments.
Example (All call info in variables):
TTS> temip $directive &entity [list attr [list $attrName $attrValue]]
Formatter
The formatter controls how the result from a call of command temip is returned.
There are 3 build-in formatters, but the user can write his/her own for special purposes.
The default formatter in interactive mode is called “stdout” and writes the result and errors on
the standard output (the terminal) in an FCL like format. The temip command does in this case
not return any Tcl result.
The standard out channel used by the “stdout” formatter can be changed to any other open Tcl
channel by setting the channel name in the environment TTSCHANNEL.
Example (Redirect output from temip command):
TTS> set ::env(TTSCHANNEL) [open "MyFile" w]
TTS> temip show {{mcc 0}} all
TTS> close $::env(TTSCHANNEL)
All output from the temip call is now in the file MyFile.
The next build-in formatter is called “list” and it returns the result as a return value of the
temip command. Errors are returned as Tcl errors. The list format is the default in non-
interactive mode. The result is a list of entity-values pairs that can be used to assign to an array.
The list is the “raw” result of the temip call and is not processed and formatted as in the “stdout”
formatter.
Example (Get result from temip command into Tcl array):
TTS> array set showResult [temip show {{mcc 0}} all "format list"]
The showResult array index is then a pair of entity and partition values and the array entry value
is the reply values from the entity on the partition.
Example (Show the result from the entity " MCC x_ns:.temip.x_director" in partition Counters
from the call above):
TTS> puts $showResult({{MCC x_ns:.temip.x_director}} Counters)
Response {{Show Success} {Examination of Attributes Shows:}} 2003-06-30-
11:09:50 {{Arg Show Values} {{{Last zeroed} 2003-01-28-09:48:24 Available}
{{Number of remote directors} 1 Available} {{Number of inbound connections}
0 Available} {{Number of outbound connections} 3 Available} {{Number of
inbound messages} 0 Available} {{Number of outbound messages} 59
Available}}}
The default formatter can be changed by setting the environment variable TTSFORMATTER to
the name of the requested default formatter.
set ::env(TTSFORMATTER) list
Asynchronous calls
The asynchronous call allows for the call of any number of directives before the responses are
handled.
E.g. call the GetEvent directive asynchronous on a number of different unrelated entities and
then wait for a response from any of the calls.
Note that each pair of entity, partition in the result will be returned as a single response.
The wait can be done using, e.g. the, update, vwait or temip::poll commands.
Example (Asynchronous temip command call):
TTS> temip show {{mcc 0} {appl *}} all {async yes} {var res} {format list}
Asynchronous
TTS> vwait res
TTS> puts $res
{{{MCC x_ns:.x.peony_director} {APPLICATION iconicmap_pm}} Characteristics}
{Response {{Show Success} {Examination of Attributes Shows:}} 2004-09-21-
10:39:43 {{Arg Show Values} {{{Application Type} MM Available} {{Module
Type} Standalone_PM Available} ...
The TTS temip:poll command is just a wrapper around the temip::call wait command,
like this:
namespace eval temip {
proc poll {{timeout 0}} {
while {[call wait $timeout]} {}
}
}
The dynamic scripting language Tcl (Tool Command Language) used by TTS is a very simple
programming language. If you have programmed before, you can learn enough to write
interesting Tcl programs within a few hours. This chapter provides a quick overview of the main
features of Tcl. After reading this you'll probably be able to start writing simple TTS scripts on
your own; however, we recommend that you consult one of the many available Tcl books for
more complete information.
For online information and documentation you may also visit:
http://tcl.activestate.com/doc/ or http://tcl.tk
Basic syntax
TTS and Tcl scripts are made up of commands separated by newlines or semicolons. Commands
all have the same basic form illustrated by the following example:
expr 20 + 10
This command computes the sum of 20 and 10 and returns the result, 30. You can try out this
example and all the others in this page by typing them to a Tcl application such as tts_pm;
after a command completes, tts_pm prints its result on the terminal.
Each Tcl command consists of one or more words separated by spaces. In this example there are
four words: expr, 20, +, and 10. The first word is the name of a command and the other
words are arguments to that command. All Tcl commands consist of words, but different
commands treat their arguments differently. The expr command treats all of its arguments
together as an arithmetic expression, computes the result of that expression, and returns the
result as a string. In the expr command the division into words isn't significant: you could just
as easily have invoked the same command as
expr 20+10
However, for most commands the word structure is important, with each word used for a distinct
purpose.
All Tcl commands return results! If a command has no meaningful result then it returns an
empty string as its result.
All Tcl commands also returns an exception code, if this is 0 the command executed without
error.
Variables
Tcl allows you to store values in variables and use the values later in commands. The set
command can be used to write and read variables. For example, the following command
modifies the variable x to hold the value 32:
set x 32
The command returns the new value of the variable. You can read the value of a variable by
invoking set with only a single argument:
set x
You don't need to declare variables in Tcl: a variable is created automatically the first time it is
set. Tcl variables don't have types: any variable can hold any value.
When a $ appears in a command, Tcl treats the letters and digits following it as a variable name,
and substitutes the value of the variable in place of the name. In this example, the actual
argument received by the expr command will be 32*3 (assuming that variable x was set as in
the previous example). You can use variable substitution in any word of any command, or even
multiple times within a word:
set cmd expr
set x 11
$cmd $x*$x
Command substitution
You can also use the result of one command in an argument to another command. This is called
command substitution:
set a 44
set b [expr $a*4]
When a [ appears in a command, Tcl treats everything between it and the matching ] as a
nested Tcl command. Tcl evaluates the nested command and substitutes its result into the
enclosing command in place of the bracketed text. In the example above the second argument of
the second set command will be 176.
Quotes and braces
Double-quotes allow you to specify words that contain spaces. For example, consider the
following script:
set x 24
set y 18
set z "$x + $y is [expr $x + $y]"
After these three commands are evaluated variable z will have the value 24 + 18 is 42.
Everything between the quotes is passed to the set command as a single word. Note that (a)
command and variable substitutions are performed on the text between the quotes, and (b) the
quotes themselves are not passed to the command. If the quotes were not present, the set
command would have received 6 arguments, which would have caused an error.
Curly braces provide another way of grouping information into words. They are different from
quotes in that no substitutions are performed on the text between the curly braces:
set z {$x + $y is [expr $x + $y]}
This script consists of a single command, proc. The proc command takes three arguments: the
name of a procedure, a list of argument names, and the body of the procedure, which is a Tcl
script. Note that everything between the curly brace at the end of the first line and the curly
brace on the last line is passed verbatim to proc as a single argument. The proc command
creates a new Tcl command named power that takes two arguments. You can then invoke
power with commands like the following:
When power is invoked, the procedure body is evaluated. While the body is executing it can
access its arguments as variables: base will hold the first argument and p will hold the second.
The body of the power procedure contains three Tcl commands: set, while, and return.
The while command does most of the work of the procedure. It takes two arguments, an
expression ($p > 0) and a body, which is another Tcl script. The while command evaluates its
expression argument using rules similar to those of the C programming language and if the result
is true (nonzero) then it evaluates the body as a Tcl script. It repeats this process over and over
until eventually the expression evaluates to false (zero). In this case the body of the while
command multiplied the result value by base and then decrements p. When p reaches zero the
result contains the desired power of base. The return command causes the procedure to exit
with the value of variable result as the procedure's result.
Where do commands come from?
As you have seen, all of the interesting features in Tcl are represented by commands. Statements
are commands, expressions are evaluated by executing commands, control structures are
commands, and procedures are commands.
Tcl commands are created in three ways. One group of commands is provided by the Tcl
interpreter itself. These commands are called built-in commands. They include all of the
commands you have seen so far and many more (see below). The built-in commands are present
in all Tcl applications.
The second group of commands is created using the Tcl extension mechanism. Tcl provides
APIs that allow you to create a new command by writing a command procedure in C or C++ that
implements the command. You then register the command procedure with the Tcl interpreter by
telling Tcl the name of the command that the procedure implements. In the future, whenever that
particular name is used for a Tcl command, Tcl will call your command procedure to execute the
command. The built-in commands are also implemented using this same extension mechanism;
their command procedures are simply part of the Tcl library.
When Tcl is used inside an application, the application incorporates its key features into Tcl
using the extension mechanism. Thus the set of available Tcl commands varies from application
to application. There are also numerous extension packages that can be incorporated into any Tcl
application. One of the best known extensions is Tk, which provides powerful facilities for
building graphical user interfaces. Other extensions provide object-oriented programming,
database access, more graphical capabilities, and a variety of other features. One of Tcl's greatest
advantages for building integration applications is the ease with which it can be extended to
incorporate new features or communicate with other resources.
The third group of commands consists of procedures created with the proc command, such as
the power command created above. Typically, extensions are used for lower-level functions
where C programming is convenient, and procedures are used for higher-level functions where it
is easier to write in Tcl.
Strings and Lists
Under Tcl, the value of each variable is stored as a string. Even if you want to save a number in
a variable, this number is transformed into a string.
As a special type of string, the list deserves a special attention in data representation in Tcl. The
list is nothing more than a string with, as elements separator, the white-space. A list may contain
sublists.
Example
TTS> set list {12 {78 5} 45 "I am not a number"}
12 {78 5} 45 "I am not a number"
TTS> set sublist1 [lindex $list 1]
78 5
TTS> set sublist2 [lindex $list 3]
I am not a number
TTS> lindex $sublist2 2
not
TTS> lindex $list 1 1
5
Other features
Tcl contains many other commands besides the ones used in the preceding examples. Here is a
sampler of some of the features provided by the built-in Tcl commands:
• More control structures, such as if, for, foreach, and switch.
• String manipulation, including a powerful regular expression matching facility. Arbitrary-
length strings can be passed around and manipulated just as easily as numbers.
• I/O, including files on disk, network sockets, and devices such as serial ports. Tcl provides
particularly simple facilities for socket communication over the Internet.
• File management: Tcl provides several commands for manipulating file names, reading
and writing file attributes, copying files, deleting files, creating directories, and so on.
• Subprocess invocation: you can run other applications with the exec command and
communicate with them while they run.
• Lists: Tcl makes it easy to create collections of values (lists) and manipulate them in a
variety of ways.
• Arrays and Dicts: you can create structured values consisting of name-value pairs with
arbitrary string values for the names and values.
• Time and date manipulation.
• Events: Tcl allows scripts to wait for certain events to occur, such as an elapsed time or the
availability of input data on a network socket.
The following 12 rules define the syntax and semantics of the Tcl language:
[1] Commands.
A Tcl script is a string containing one or more commands. Semi-colons and newlines are
command separators unless quoted as described below. Close brackets are command terminators
during command substitution (see below) unless quoted.
[2] Evaluation.
A command is evaluated in two steps. First, the Tcl interpreter breaks the command into words
and performs substitutions as described below. These substitutions are performed in the same
way for all commands. The first word is used to locate a command procedure to carry out the
command, and then all of the words of the command are passed to the command procedure. The
command procedure is free to interpret each of its words in any way it likes, such as an integer,
variable name, list, or Tcl script. Different commands interpret their words differently.
[3] Words.
Words of a command are separated by white space (except for newlines, which are command
separators).
[6] Braces.
If the first character of a word is an open brace (“{”) and rule [5] does not apply, then the word
is terminated by the matching close brace (“}”). Braces nest within the word: for each additional
open brace there must be an additional close brace (however, if an open brace or close brace
within the word is quoted with a backslash then it is not counted in locating the matching close
brace). No substitutions are performed on the characters between the braces except for
backslash-newline substitutions described below, nor do semi-colons, newlines, close brackets,
or white space receive any special interpretation. The word will consist of exactly the characters
between the outer braces, not including the braces themselves.