TCL Ios
TCL Ios
Petr Grygrek
prototyping, embedding into applications, creation of GUIs (TCL/Tk toolkit) Runtime engine available for many platforms
2009 Petr Grygarek, Advanced Computer Networks Technologies 4
and overriden Object-oriented extensions are available Many extension libraries were developed
2009 Petr Grygarek, Advanced Computer Networks Technologies 5
IOS Policies
Applets
TCL Scripts
sequences of IOS commands Stored in device's running config Programs in TCL Stored on FLASH or external storage
Event Detectors
CLI, Timer Syslog Object Tracking interface state change detector insertion/removal of module detector ...
2009 Petr Grygarek, Advanced Computer Networks Technologies
10
info commands info exists <varName> info args <procName> info body <procName> info globals info vars
Getting Help
Command typed with wrong argument(s) make tclsh to display usage help # this is a comment
2009 Petr Grygarek, Advanced Computer Networks Technologies 11
12
13
Expr command
Examples:
14
Arrays
Array Functions
set a(1) 10 set a(2) 20 array get a -> 1 10 2 20 array get a 1 -> 1 10 array size a -> 2 array names a -> 1 2
16
Strings
17
Lists
Conditional Execution
set x 1 if {$x < 10} { puts LESS } else { puts GREATER } -> LESS
20
Procedures
proc myproc {p1 p2} { set res [expr $p1+$p2] return $res } set sum [myproc 10 20]
21
Files
set fd [open flash:f.txt w] puts $fd kocour puts $fd mour close $fd Router# more flash:f.txt set fd [open flash:f.txt r] while { [gets $fd line] > 0 } { puts $line } close $fd tell $fd, seek $fd <pos> file <operation> <argument(s)> e.g. file delete flash:f.txt
2009 Petr Grygarek, Advanced Computer Networks Technologies
22
puts "Argument count: $argc" puts "Argv0: $argv0" puts "Argv: $argv" puts "Individual arguments:" foreach {iterVar} $argv { puts $iterVar } router #tclsh http://10.0.0.2/sample.tcl aaa bbb ccc -> Argument count: 3 Argv0: http://10.0.0.2/kocour.tcl Argv: aaa bbb ccc Individual arguments: aaa bbb ccc
2009 Petr Grygarek, Advanced Computer Networks Technologies 23
24
26
It is
recommended to exit from TCL shell for the configuration changes to take effect Always end the configuration commands with end to avoid locking
2009 Petr Grygarek, Advanced Computer Networks Technologies 27
interactive TCL shell. On the other hand, ios_config does NOT work in TCL scripts (?)
28
29
30
EEM policies have to be stored on some local filesystem to ensure their availability regardless of the current state of the connectivity to any external storage server.
31
32
Router(config)#event manager
environment myVariable myValue Router(config)#event manager session cli username kocour sh event manager session cli username
33
EEM Applets
Definition consists of
applet
EEM versions
35
Most Interesting Supported Features (1) Reaction to composite events Reacting to interface status change Processing of RIB change events Reacting to IOS object status change Enhanced Object Tracking Reacting to Syslog messages Reacting to increased resource utilization (CPU,
memory, ...) Integration with SLA monitoring Timers & Counters events
2009 Petr Grygarek, Advanced Computer Networks Technologies
36
Most Interesting Supported Features (2) Sockets Library SNMP Library (outgoing/incoming messages) SMTP Library Integration with Netflow CLI library & events issuing IOS exec and config commands interception of command handling process creation of user commands and/or extending
command parameters
37
Most Interesting Supported Features (3) Messaging between policies running in parallel,
policy synchronization Policy priorization
38
References
Summarized at
http://wh.cs.vsb.cz/sps/index.php/TCL _scripting_on_Cisco_IOS
39