






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







hqhrIr xvtB hqhrIr xvt
!Xvr !
Dmitrii ZagorodnovDmitrii Zagorodnov
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 2
vr Pr vr
Introduction to Tcl Introduction to OTcl Introduction to ns ns installation Midterm project
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 3
UpyCv
Tcl = Tool Command Language Simple, extendible, interpreted language Tk is an extension for building GUI applications Invented by John Ousterhout 1988 : first version of Tcl and Tk 1990 : presented at USENIX 1993 : first workshop at Berkeley 1994 - 1997 : Ousterhout at Sun 1997 - present : Ousterhout at Scriptics Can be given a script or used interactively (tclsh)
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 4
Scripts are commands separated by newlines or ; cmd arg arg ... Variables are referenced using $ $var Commands are nested using [ ] cmd [cmd arg ...] arg Words are grouped into single argument using “” or { } puts “Hello, $name” while {$i < 10} { incr i } Backslash is used to quote special characters (e.g. \n ) Pound character # is used for comments (note ;# )
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 7
yT p r 8 yT p r
if { ... } { ...} elseif { ... } else { ... }
while { $x > 0 } { ... }
foreach x { a b c d } { ... }
for {set i 0} {$i < 10} {incr i 1} { ... }
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 8
prq r Q prq r
Procedures: proc name arglist body proc add {a b} {return [expr $a + $b]} Envoke just like a command add 4 5 Single, global scope for procedure names Global variables must be brought into procedures proc foo { ... } { global ns ... } “Qualified names” can be used to reference a variable in any scope ::x
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 9
Create a class with Class command Class Bagel Bagel abagel or set abagel [new Bagel] Methods are defined using instproc , instance variables using set or instvar. Use $self to refer to the object inside its methods. Bagel instproc toast { } { $self instvar toasted ... } Constructors/destructors are called init and destroy
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 10
vhprvPUpy Dur vhprvPUpy
Classes can be extended using -superclass Class SpreadableBagel -superclass Bagel One can trace the hierarchy using info **SpreadableBagel info heritage
Bagel Object** Command next arranges for the next method with the same name up the inheritance tree to be invoked SpreadableBagel instproc init {args} { eval $self next $args ... }
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 13
set ns [new Simulator]
set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node]
$ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns duplex-link $n3 $n2 1Mb 10ms DropTail
xUyt) Ir xUyt)
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 14
xUyt) Ir xUyt)
set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp
set cbr0 [new Application/Traffic/CBR] $cbr0 set interval_ 0. $cbr0 attach-agent $udp
set null0 [new Agent/Null] $ns attach-agent $n3 $null
$ns connect $udp0 $null
cbr0 / udp
null
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 15
Traffic flows can be started/stopped using at : $ns at 0.5 “$cbr0 start” $ns at 1.0 “$cbr0 stop” The script is typically terminated by a finish() proc $ns at 5.0 “finish” proc finish { } { global ns fd $ns flush-trace; close $fd exec nam out.nam & exit 0 }
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 16
Class Agent/Message/Receiver -superclass Agent/Message
Agent/Message/Receiver instproc handle msg {
$self instvar congested_ if $congested_ { set congested_ 0 } else { $self send "uncongested [lindex $msg 1]" }
}
February 9, 2001 CSE 222 -- Lecture 9 – ns tutorial 19
IrUvr, A IrUvr,
Domain Name System Read and review Mockapetris and Dunlap paper from SIGCOMM ‘ 88 Read section 9.1 in the textbook