introduction to ns-2venky/acn/handouts/ns2-sara.pdfwhat is the core of ns-2 discrete-event driven...
TRANSCRIPT
![Page 1: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/1.jpg)
Introduction to NS-2
Noun Choi + Hai Vu + Ryan Burchfield + Sara Arbab Yazd
February 2012
![Page 2: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/2.jpg)
Outline
NS-2 Internals
Installation + Usage
Troubleshooting
Resources
Q & A
![Page 3: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/3.jpg)
What is the core of NS-2
Discrete-event driven network simulation
Object Oriented
NS-2 is an extended Tcl (OTcl) interpreter
NS-2 is written in C++ and OTcl
OTcl = Tcl + OO
C++ implements the code that executed frequently
OTcl configures the system
![Page 4: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/4.jpg)
Platforms
Most UNIX and UNIX-like systems
- FreeBSD or *BSD
- Linux
- Sun Solaris
- HP, SGI
WINDOWS
Under Cygwin
![Page 5: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/5.jpg)
Components of NS-2 package
Tcl/TK: ns-2 is an extended Tcl interpreter
OTcl: Object Tcl
TclCL: Tcl with classes library
NS-2
nam-1: Network Animator
xgraph: Plotting and Graphing
And more….
![Page 6: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/6.jpg)
NS-2 architecture
(picture from www.wikipedia.org)
![Page 7: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/7.jpg)
Pros & Cons
Free
Almost all network components are implemented
Active contributions from researchers
Easy to modify and/or add new functions
Unreliable
No technical support
Hard to troubleshoot
Unrealistic
abstraction/model
Contains bugs
![Page 8: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/8.jpg)
LINKING OTCL AND C++
![Page 9: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/9.jpg)
OTcl and C++: The Duality
(picture from www.wikipedia.org)
![Page 10: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/10.jpg)
OTcl Linkage
set tcp [new Agent/TCP]
init
Agent/TCP
init
Agent
Create Otcl
shadow object
TclObject
Create C++
object
constructor
TclObject
(C++)
constructor
parent
constructor
TcpAgent
OTcl
C++
static class TcpClass : public TclClass {
public:
TcpClass() : TclClass("Agent/TCP") {}
TclObject* create(int, const char*const*) {
return (new TcpAgent);}
} class_tcp;
![Page 11: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/11.jpg)
OTcl Linkage (III)
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 You must set the initial
values of variants in
~ns-2.34/tcl/lib/ns-
default.tcl
![Page 12: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/12.jpg)
OTcl Linkage (II)
Command() Otcl $tcp advance 10
C++ int Agent::command(int argc, const char*const* argv)
{
if (argc == 3) { if (strcmp(argv[1], “advance") == 0) {
int newswq = atoi(argv[2]);
return (TCL_OK);
}
}
return (Agent::command(argc, argv);
}
![Page 13: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/13.jpg)
How ns-2 works
Scheduler
Event Queue Target object
Event (Packet)
Time
Object B Object A
Deque
Dispatch Dispatch
Register Event
![Page 14: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/14.jpg)
An Example A B
CBR
Transport
Network
LL
IFQ
MAC
NetIF
CBR Sink
Transport
Network
LL
IFQ
MAC
NetIF
Scheduler
Wireless Channel
![Page 15: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/15.jpg)
Download Ns-Allinone
Latest stable version: 2.34 (June 17, (2009
Download ns-allinone http://www.utdallas.edu/~sara.arbabyazd/ns2
http://sourceforge.net/projects/nsnam/
Faster
download on
campus!
![Page 16: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/16.jpg)
Installation ssh cs1.utdallas.edu
wget http://www.utdallas.edu/
~sara.arbabyazd/ns2/ns-allinone-2.34.tar.gz
tar -zxf ns-allinone-2.34.tar.gz
cd ns-allinone-2.34
./install
![Page 17: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/17.jpg)
Please put /home/ryan/ns2/ns-allinone-2.34/bin:/home/ryan/ns2/ns-allinone-2.34/tcl8.4.18/unix:/home/ryan/ns2/ns-allinone-2.34/tk8.4.18/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph. IMPORTANT NOTICES: (1) You MUST put /home/ryan/ns2/ns-allinone-2.34/otcl-1.13, /home/ryan/ns2/ns-
allinone-2.34/lib, into your LD_LIBRARY_PATH environment variable. If it complains about X libraries, add path to your X libraries into LD_LIBRARY_PATH. If you are using csh, you can set it like: setenv LD_LIBRARY_PATH <paths> If you are using sh, you can set it like: export LD_LIBRARY_PATH=<paths> (2) You MUST put /home/ryan/ns2/ns-allinone-2.34/tcl8.4.18/library into your
TCL_LIBRARY environmental variable. Otherwise ns/nam will complain during startup. After these steps, you can now run the ns validation suite with cd ns-2.34; ./validate For trouble shooting, please first read ns problems page http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list
archive for related posts.
![Page 18: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/18.jpg)
Environment Configuration Add environment variables
nano ~/.bash_profile export PATH=$PATH:/home/ryan/ns2/ns-allinone-2.34/bin:/home/ryan/ns2/ns-
allinone-2.34/tcl8.4.18/unix:/home/ryan/ns2/ns-allinone-2.34/tk8.4.18/unix
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ryan/ns2/ns-allinone-2.34/otcl-1.13: /home/ryan/ns2/ns-allinone-2.34/lib
export TCL_LIBRARY=$TCL_LIBRARY: /home/ryan/ns2/ns-allinone-2.34/tcl8.4.18/library
• source ~/.bash_profile
![Page 19: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/19.jpg)
Usage NS-2 Source code: ns-allinone-2.34/ns-2.34
C++ portion of NS-2
To rebuild NS-2 after modifying
cd ns-allinone-2.34/ns-2.34
make all
Create an experiments directory
mkdir ~/ns2_experiments
cd ~/ns2_experiments wget http://www.utdallas.edu/~sara.arbabyazd/ns2/example2.tcl
ns example2.tcl
If you change a
header file (.h) run
“make clean” first.
![Page 20: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/20.jpg)
Demonstration
N1
N2
N3
Destination
N0
N5
N4
Source 2
Source 1
![Page 21: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/21.jpg)
Demonstration (Contd.)
Scenarios: n0 sends packets to n5 at 0.5 second
n1 sends packets to n5 at 2.5 second
Link (n0,n4) is down at 3.0 second
n0 redirects packets through n2
Which cause congestion, some packets are dropped
At 4.0 second, n1 stops
Things get back to normal after that
![Page 22: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/22.jpg)
Trace File Format
Event Abbreviation Type Value
Normal Event
r: Receive
d: Drop
e: Error
+: Enque
-: Deque
%g %d %d %s %d %s %d %d.%d %d.%d %d %d
double Time
Int Source Node
int Destination Node
string Packet Name
int Packet Size
string Flags
Int Flow ID
Int Source Address
Int Destination Address
Int Sequence Number
Int Unique Packet ID
Ex: r 0.026198 0 4 rtProtoDV 6 ------- 0 0.2 4.1 -1 11
d 3.00771 0 4 cbr 500 ------- 1 0.0 5.0 54 95
![Page 23: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/23.jpg)
Troubleshooting
Problem while installing Check known errors
Program crashes/Tcl complains Check tcl files for errors
Unexpected results Use gdb or any debug tool
Hidden problem Slice & dice the trace log
TA does not fix your problems
![Page 24: Introduction to NS-2venky/acn/Handouts/ns2-sara.pdfWhat is the core of NS-2 Discrete-event driven network simulation Object Oriented NS-2 is an extended Tcl (OTcl) interpreter NS-2](https://reader034.vdocuments.us/reader034/viewer/2022051406/5aa492be7f8b9ac8748c1e92/html5/thumbnails/24.jpg)
Resource http://www.isi.edu/nsnam/ns/ Manual & Tutorial
http://nsnam.isi.edu/nsnam/index.php/NS_manual http://www.isi.edu/nsnam/ns/ns-documentation.html http://www.isi.edu/nsnam/ns/tutorial/index.html http://www-
sop.inria.fr/maestro/personnel/Eitan.Altman/COURS-NS/n3.pdf Mailing List
http://www.isi.edu/nsnam/ns/ns-lists.html Tcl
http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html OTcl
http://bmrc.berkeley.edu/research/cmt/cmtdoc/otcl/tutorial.html
tclCL http://www.openmash.org/lxr/source/tclcl/tclcl.tcl?c=tutorials
Slides: http://www.utdallas.edu/~sara.arbabyazd/ns2