15-744: computer networking l-3 the network simulator ns-2 slides loosely based on a tutorial by...
Post on 15-Jan-2016
216 views
TRANSCRIPT
![Page 1: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/1.jpg)
15-744: Computer Networking
L-3 The network simulator ns-2Slides loosely based on a tutorial by Polly Huang, ETH Zurich.
![Page 2: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/2.jpg)
What is ns?
• Network simulator• VINT Project -- Virtual Internet Testbed
• Collaboration of many institutes• AT&T• UC Berkeley• XEROX PARC• ETH
• Goals
![Page 3: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/3.jpg)
ns --- what is it good for?
• Evaluate performance of existing network protocols.• Prototyping and evaluation of new protocols.• Large-scale simulations not possible in real experiments.
Used to:
![Page 4: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/4.jpg)
ns
• Event-driven simulator• Packet level• Link layer and up
How does it work:
![Page 5: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/5.jpg)
Development Status
• 100K lines of C++ code• 70K lines of otcl code• 20K lines of documentation
Otcl / Tcl
tclcl
C++
Current status:
![Page 6: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/6.jpg)
otcl and C++: The Duality
OTcl C++
Pure OTclobjects
Pure C++objects
C++/OTcl split objects
ns
Your ns-script
![Page 7: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/7.jpg)
Basic otcl
Class mom
mom instproc init {age} {$self instvar age_set age_ $age
}
mom instproc greet {} {$self instvar age_puts “$age_ years old mom: How are you doing?”
}
set a [new mom 45]$a greet
• instead of single class declaration multiple definitions
• instproc adds method
• instvar adds instance variable
• methods are always called through object ( $self)
• init instproc instead of constructor
![Page 8: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/8.jpg)
Basic otcl - inheritance
Class kid -superclass mom
kid instproc greet {} {
$self instvar age_
puts “$age_ years old kid: What’s up, dude?”
}
set b [new kid 15]
$b greet
![Page 9: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/9.jpg)
Basic structure of ns-scripts
• Creating the event scheduler• [Tracing]• Creating network topology• Creating Transport Layer - Agents• Creating Applications - Applications• Events!
![Page 10: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/10.jpg)
Creating Event Scheduler
• Create scheduler• set ns [new Simulator]
• Schedule event• $ns at <time> <event>• <event>: any legitimate ns/tcl commands
• Start scheduler• $ns run
![Page 11: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/11.jpg)
“Hello World” in ns
simple.tclset ns [new Simulator]
$ns at 1 “puts \“Hello World!\””
$ns at 1.5 “exit”
$ns run
gs116% ns simple.tcl
Hello World!
gs116%
![Page 12: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/12.jpg)
Creating Network
• Nodes• set n0 [$ns node]• set n1 [$ns node]
• Links & Queuing• $ns duplex-link $n0 $n1 <bandwidth> <delay>
<queue_type>
![Page 13: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/13.jpg)
Transport Layer
Class Agent
Agent/UDP Agent/TCP (=Tahoe)
…
Other TCP flavors
![Page 14: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/14.jpg)
The transport layer: UDP
• UDP
• set udp [new Agent/UDP]• set null [new Agent/NULL]
• $ns attach-agent $n0 $udp• $ns attach-agent $n1 $null
• $ns connect $udp $null
![Page 15: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/15.jpg)
The transport layer: TCP
• TCP• set tcp [new Agent/TCP]• set tcpsink [new Agent/TCPSink]
• $ns attach-agent $n0 $tcp• $ns attach-agent $n1 $tcpsink
• $ns connect $tcp $tcpsink
![Page 16: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/16.jpg)
Transport Layer
Class Agent
Agent/UDP Agent/TCP (=Tahoe)
…
Other TCP flavors Agent/TCP/FullTCP
![Page 17: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/17.jpg)
Two-way TCP
• FullTcp connection
• set tcp1 [new Agent/TCP/FullTcp]• set tcp2 [new Agent/TCP/FullTcp]• $ns attach-agent $n1 $tcp1• $ns attach-agent $n2 $tcp2• $ns connect $tcp1 $tcp2• $tcp2 listen
![Page 18: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/18.jpg)
Application Layer
Class Application
{Simulated Applications} (on top of TCP)
{Traffic generators}(on top of UDP)
![Page 19: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/19.jpg)
Creating Traffic: On Top of TCP
FTP• set ftp [new Application/FTP]• $ftp attach-agent $tcp• $ns at <time> “$ftp start”
Telnet• set telnet [new Application/Telnet]• $telnet attach-agent $tcp
![Page 20: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/20.jpg)
Creating Traffic: On Top of UDP
• CBR• set src [new Application/Traffic/CBR]
• Exponential or Pareto on-off• set src [new Application/Traffic/Exponential]• set src [new Application/Traffic/Pareto]
![Page 21: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/21.jpg)
Attaching a traffic source
• set cbr [new Application/Traffic/CBR]
• $cbr attach-agent $udp
• $ns at <time> “$cbr start”
![Page 22: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/22.jpg)
Tracing
Trace packets on all links:
• set f[open out.tr w]• $ns trace-all $f
• $ns flush-trace• close $f
<event> <time> <from> <to> <pkt> <size>--<flowid> <src> <dst> <seqno> <aseqno>+ 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0- 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0
Is tracing all links allways the best thing to do?
![Page 23: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/23.jpg)
More Tracing
• Tracing specific links• $ns trace-queue $n0 $n1 $f
• Tracing variables • set cwnd_chan_ [open all.cwnd w]• $tcp trace cwnd_• $tcp attach $cwnd_chan
![Page 24: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/24.jpg)
Putting it all togetherset ns [new Simulator]
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 1.5Mb 10ms DropTail Creating Topology
set tcp [$ns create-connection TCP $n0 TCPSink $n1 0]
Creating Transport layer
set ftp [new Application/FTP]
$ftp attach-agent $tcpCreating Applications
$ns trace-queue $n0 $n1 $f
Schedule Events$ns at 0.2 "$ftp start“
$ns at 1.2 ”exit“
$ns run
![Page 25: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/25.jpg)
nam – the network animator
n0 n1
set nf [open out.nam w]
$ns namtrace-all $nf
exec nam out.nam &…
![Page 26: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/26.jpg)
Computing routes
• Unicast• $ns rtproto <type>• <type>: Static, Session, DV.
![Page 27: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/27.jpg)
Network Dynamics: Link failures
• $ns rtmodel-at <time> <up|down> $n0 $n1
• $ns rtmodel Trace <config_file> $n0 $n1
• $ns rtmodel <model> <params> $n0 $n1
<model>: Deterministic, Exponential
![Page 28: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/28.jpg)
Issues in Simulations
• Suppose you want to study the way TCP sources share a bottleneck link…
Agent/FTP
Agent/FTP
Agent/FTP
Agent/FTP
Which topology?
When to start sources?
What else affects results?
Which traffic sources? Background Traffic?
![Page 29: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/29.jpg)
Another practical issue: Memory
• Avoid trace-alltrace-all
• Use arrays for a sequence of variables• Instead of n$in$i, say n($i)n($i)
~ns/tcl/ex/cmcast-150.tcl:
150 nodes, 2200 links => 53MB2420 nodes, 2465 linkd => 800MB
![Page 30: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/30.jpg)
Basic ns-2: Not Covered
• mobile IP• multicasting• satellite• emulation
![Page 31: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/31.jpg)
Making changes to ns – where???
OTcl C++
Pure OTclobjects
Pure C++objects
C++/OTcl split objects
ns
Where would you implement• one-time configuration variables• complex procedures• per packet action
![Page 32: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/32.jpg)
ns directory structure
TK8.0 OTcl tclclTcl8.0 ns-2 nam-1
ns-allinone
tcl
ex test lib
...
...
examplesvalidation tests
C++ code
OTcl code
mcast
Makefile.in
![Page 33: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/33.jpg)
New component purely in Otcl
examples
TK8.0 OTcl tclclTcl8.0 ns-2 nam-1
ns-allinone
tcl
ex test lib
...
...
validation tests
C++ code
OTcl code
mcastmysrc
msg.tcl
Makefile.in
source msg.tcl
![Page 34: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/34.jpg)
New component in C++
• Create C++ class, fill in methods• Define otcl linkage• Write otcl code (if any)
• Build (and debug)
![Page 35: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/35.jpg)
How does linkage work?
C++ OTcl
Pure C++objects
Pure OTclobjects
C++/OTcl split objects
ns
• how to access Tcl variables from C++• how is C++ object created from interpreter• ……
![Page 36: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/36.jpg)
TclObject: Hierarchy and Shadowing
TclObject
Agent
Agent/TCP
Agent/TCP otcl shadow object
_o123Agent/TCP C++
object
*tcp
TclObject
Agent
TcpAgent
otcl classhierarchy
C++ classhierarchy
![Page 37: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/37.jpg)
TclObject
• Example
set tcp [new Agent/TCP]set tcp [new Agent/TCP] => how is corresponding C++ object created?=> how is corresponding C++ object created?
$tcp set window_ 500$tcp set window_ 500 => how is corresponding C++ variable set?=> how is corresponding C++ variable set?
$tcp advance 5000$tcp advance 5000 => how is C++ procedure called?=> how is C++ procedure called?
![Page 38: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/38.jpg)
TclObject: Hierarchy and Shadowing
TclObject
Agent
Agent/TCP
Agent/TCP otcl shadow object
_o123Agent/TCP C++
object
*tcp
TclObject
Agent
TcpAgent
otcl classhierarchy
C++ classhierarchy
![Page 39: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/39.jpg)
TclObject::bind()
• Link C++ member variables to otcl object variables
• C++TcpAgent::TcpAgent() {
bind(“window_”, &wnd_);
… …
}
• bind_time(), bind_bool(), bind_bw()
• otcl$tcp set window_ 200$tcp set window_ 200
![Page 40: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/40.jpg)
TclObject::command()
• Implement otcl methods in C++• Trap point: otcl method cmd{}• Send all arguments after cmd{} call to
TclObject::command()
![Page 41: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/41.jpg)
TclObject::command()
$tcp advance TclObject::unknown{} $tcp cmd advanceno suchprocedure
TcpAgent::command()
match “advance”?
Invoke parent: return Agent::command()
process and return
Yes No
OTcl space
C++ space
![Page 42: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/42.jpg)
TclObject::command()
• otclset tcp [new Agent/TCP]
$tcp advance 10
• C++int TcpAgent::command(int argc,
const char*const* argv) {
if (argc == 3) { if (strcmp(argv[1], “advance”) == 0) { int newseq = atoi(argv[2]);
…… return(TCL_OK);
} }
return (Agent::command(argc, argv);}
![Page 43: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/43.jpg)
TclObject
• Example
set tcp [new Agent/TCP]set tcp [new Agent/TCP] => how is corresponding C++ object created?=> how is corresponding C++ object created?
$tcp set window_ 500$tcp set window_ 500 => how is corresponding C++ variable set?=> how is corresponding C++ variable set?
$tcp advance 5000$tcp advance 5000 => how is C++ procedure called?=> how is C++ procedure called?
?
![Page 44: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/44.jpg)
C++
OTcl
TclObject: Creation and Deletion
invoke parentconstructor
Agent/TCPconstructor
parentconstructor
invoke parentconstructor
TclObjectconstructor
create C++object
AgentTCPconstructor
invoke parentconstructor
invoke parentconstructor
parent (Agent)constructor
do nothing,return
TclObject (C++)constructor
bind variablesand return
bind variablesand return
create OTclshadow object
complete initialization
complete initialization
which C++ object to create? – TclClass
![Page 45: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/45.jpg)
TclClass
Static class TcpClass : public TclClass {public:
TcpClass() : TclClass(“Agent/TCP”) {}TclObject* create(int, const char*const*) {
return (new TcpAgent());}
} class_tcp;
Static class TcpClass : public TclClass {public:
TcpClass() : TclClass(“Agent/TCP”) {}TclObject* create(int, const char*const*) {
return (new TcpAgent());}
} class_tcp;
![Page 46: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/46.jpg)
Class Tcl
• Singleton class with a handle to Tcl interpreter
• Usage• Invoke otcl procedure• Obtain otcl evaluation results• Pass a result string to otcl• Return success/failure code to otcl
![Page 47: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/47.jpg)
Class Tcl
Tcl& tcl = Tcl::instance();
if (strcmp(argv[1], “now”) == 0) {tcl.resultf(“%g”, clock());
return TCL_OK;
}
if (strcmp(argv[1], “helloworld”) {
tcl.evalc(“puts stdout Hello World”);
return TCL_OK;
}
Passing resultsto the interpreter:
Executing Otclcommands fromC++
![Page 48: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/48.jpg)
Class TclCommand
• C++ implementation of global otcl commands
class RandomCommand : public TclCommand {public: RandomCommand() : TclCommand("ns-random") {} virtual int command(int argc, const char*const* argv);};
int RandomCommand::command(int argc, const char*const* argv){ Tcl& tcl = Tcl::instance(); if (argc == 1) { sprintf(tcl.buffer(), "%u", Random::random()); tcl.result(tcl.buffer()); }
![Page 49: 15-744: Computer Networking L-3 The network simulator ns-2 Slides loosely based on a tutorial by Polly Huang, ETH Zurich](https://reader036.vdocuments.mx/reader036/viewer/2022062518/56649d5a5503460f94a3a854/html5/thumbnails/49.jpg)
Summary
Root of ns-2 object hierarchy
bind(): link variable values between C++ and OTcl TclObject
command(): link OTcl methods to C++ implementations
TclClass Create and initialize TclObject’s
Tcl C++ methods to access Tcl interpreter
TclCommand Standalone global commands
EmbeddedTcl ns script initialization