0% found this document useful (0 votes)
2 views49 pages

W03 OTcl

Uploaded by

dnamanh4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views49 pages

W03 OTcl

Uploaded by

dnamanh4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

ul

ak
iy
ar
I ss
at
Linkage Between
n OTcl
OT
OTc and C++ in

w
NS2
NS 2

er
Te
by
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 1
Pr
ul
ak
iy
Outline

ar
ss
• NS2 C++/OTcl Architecture
e

I
• Environment binding:

at
– Class Tcl

w
er
– Class TclCommand

Te
• Component binding:
ding:
– Cl
Class TclClass,
T lClass,
by
– Class TclObject,
Obbject and
ed

– Class
Cl InstVar
InstV
V
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 2
Pr
ul
ak
NS2 C++ and OTcl Composition
ositi
itio

iy
ar
• Two language architecture

ss
• C++ Q: What
What is the NS2 component

I
which link C++ and OTcl ?

at
– Compiler
C il
hange
– Fast to run; Slow to change

w
er
• OTcl

Te
– Interpreter
– Slow to run; Fast
Fas
a to change
by
• Hierarchy
y
– C++ = Compiled
Compi
mpi Hierarchy
ed

– OTcl
cl = In
Interpreted Hierarchy
ar

• Why
hy tw languages? Î C++ coding styles
y two
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 3
Pr
ul
Three C++ Coding
g Styles
y

ak
iy
1. Basic C++

ar
– Compile and create “prog
prog.exe
exe”

ss
– Recompile for every minor changess (e.g., number of nodes,
link speed)

I
at
2. C++ coding with input arguments
gumen

w
er
– Use parameters input argum
argument
gume (argv,argc)
(argv argc)
– E.g., “prog <num_node>
ode> <link
<link_speed>”

– What
h if f there
h Te
Invocation “prog 100 3”
are too many parameters?
by

3 C++ coding
3. g wit
with input files Í NS
NS2
ed

– Put input
nput pa
parameters in a configuration file
ar

– Noo need to change C++ code


– One iinput argument—the filename.
ep

4
– E.G., “prog config.txt”
Pr
ul
ak
NS2 and C++ Coding Styles
yles
es

iy
ar
ss
• C++ coding with input files

I
• E.G., “ns
ns myfirst
myf rst_ns.tc
ns.tcl“

at
• C++ codes: Located under
nder ~
~/ns/*

w
• C++ executable file: ns

er
• The input argument=?:
ment= (myfirst_ns.tcl )
• A configuration
ation Te
n file=?: (myfirst_ns.tcl
(myfirst ns tcl )
by
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 5
Pr
ul
Why
y Tcl/OTcl?

ak
iy
ar
• Problem 1:

ss
– Reading Tcl files from C++ is hard!

I
– Use Tcl

at
w
• Problem 2:

er
sses Î Tcl is not OOP
– C++ contains classes
– Use OTcl
Te
by
• Problem 3::
ed

– Some e comp
components are easy to implement
– C+++ mak
make things complicated
ar

– De
Define
fi them
h in OTcll
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 6
Pr
ul
ak
C++/OTcl Architecture
ure
e

iy
ar
• C++: Internal
nternal mechanism
mechan sm

ss
• OTcl: User interface Files:

I
p (input);
Tcl script p
– Monitor

at
Output file

w
– Keyboard

er
– Tcl
T l Si
Simulation
l ti S Script/Output
Scrip
i tt/O t t fil
file

Te
by
User
Interface
ed
ar
ep

Keyboard Screen
7
(input) (output)
Pr
ul
ak
C /OT l C
C++/OTcl Components:
mp n nts: C
C++ Cl
Classes
asses
sss s

iy
ar
ss
• Provide an access to OTcl from C
C++

I
• 6 main classes:

at
– Class Tcl: Access to Tcl/OTcl
cl/OTc interpreter

w
– Class InstVar: Define e C++ class variables which is

er
b
boundd to OTcll class
lass variables
var bl

Te
– Class TclObject:t: C++ object + OTcl interface
– Class
Cl T lCl s: Bind
TclClass: Bi
B dC C++ and
d OT
OTcll Cl
Classes
by
Comman Global command
– Class TclCommand:
– Class Embed
EmbeddedTcl:
bed Translate OTcl to C++
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 8
Pr
ul
ak
C++/OTcl Component Functionality
nality
ity

iy
ar
- Tcl:
T l Invoke
I k Tcl
T l from
f C++
C

ss
om OTc
- TclCommand: Invoke C++ from OTcl

I
- EmbeddedTcl: Translate OT
OTcl to C++

at
C++ OTcl

w
er
-TclObject:
TclObject: C+++ & Tcl
Tc
T interfaces
-TclClass:: Bind c
classnames
C++ Class
Te OTcl Class
by
InstVar: Bind variables
In
ed

C variable
C++ i bl OT l variable
OTcl i bl
ar
ep

9
Pr
ul
ak
C++/OTcl Components and
d

iy
NS2 Directories

ar
ss
~tclcl
~ns

I
at
w
er
Te
by
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 10
Pr
ul
ak
iy
Outline

ar
ss
• NS2 C++/OTcl Architecture
e

I
• Environment binding:

at
– Class Tcl

w
er
– Class TclCommand

Te
• Component binding:
ding:
– Cl
Class TclClass,
T lClass,
by
– Class TclObject,
Obbject and
ed

– Class
Cl InstVar
InstV
V
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 11
Pr
ul
ak
Cl ss Tcl
Class T l

iy
ar
ss
• Access OTcl from C++

I
• 5 Main Functionalities

at
– Obtain the Tcl instancee

w
– Invoke OTcl statement
ment
ent from
f C++

er
– Pass/Receive results
esults to/from the OTcl
– Report error Te
by
– Retrieve tthe
he ref
reference to TclObjects
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 12
Pr
ul
ak
Class
a Tcl: Ma
Main
n Functionalities
Fun na s

iy
• Obtain the Tcl instance W
What is the

ar
difference

ss
between?
• Invoke OTcl procedures

I
– Tcl::eval(char* str)

at
w
– Tcl::evalc(const
onst char*
ch str)T
by
ed

– Tcl::evalf(const
valf(c char* format,…)
ar

13
e

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Pr
ul
ak
Class
a Tcl: Ma
Main
n Functionalities
Fun na s

iy
• Pass results to the OTcl

ar
– Tcl::result(const
cl result(const char
char* str):
str)

ss
tI
Suppose $d =10.

w
What would

er
– Tcl::result(const char*
har* fmt
fmt) appear

Te
on the screen as
a result of ?
by
• Receive results
sult ffrom the OTcl
ed

– Tcl::result()
esult()
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariy 14
Pr
ul
ak
iy
Outline

ar
ss
• NS2 C++/OTcl Architecture
e

I
• Environment binding:

at
– Class Tcl

w
er
– Class TclCommand

Te
• Component binding:
ding:
– Cl
Class TclClass,
T lClass,
by
– Class TclObject,
Obbject and
ed

– Class
Cl InstVar
InstV
V
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 15
Pr
ul
ak
Class TclCommand

iy
ar
• Invoke C++ from the OTcl cl (r
(reverse
(rev

ss
of Class Tcl)

I
• Available globally.
globally

at
w
• Not recommended (non OOP).
ed (no

er
• Use command in Tc TclObject
(discussed later)
atter) Te
by
• Exampless
– ns-version
ns version
rsion
ion
ed

– ns-random
rando
ar

• See
ee fi
fil ~/ns/common/misc.cc
file / / / i
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 16
Pr
ul
ak
iy
Outline

ar
ss
• NS2 C++/OTcl Architecture
e

I
• Environment binding:

at
– Class Tcl

w
er
– Class TclCommand

Te
• Component binding:
ding:
– Cl
Class TclClass,
T lClass,
by
– Class TclObject,
Obbject and
ed

– Class
Cl InstVar
InstV
V
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 17
Pr
ul
ak
C mp n nt Binding
Component Bindin

iy
ar
• Applicable only to bounded hierarchy
iera
erarc

I ss
at
w
er
Te
by
• Three major
jor com
components
ame Î TclClass
– Class name
ed

– Object (o instance) Î TclObject


ject (or
ar

– Class
lass
ass variable
v Î InstVar
ep

18
Pr
ul
ak
C mp n nt Binding
Component Bindin

iy
ar
• Every C++
C bounded class has a corresponding
correspond
resp
espon ng OOTcl
cl

ss
class
• What happen when the following
ing OT
OTcl statement

I
is executed?

at
w
er
• C++ counterpart is created
created!! (shadowing process)

Te
Î How? Î TclCL
• Main binding components:
ompo
p
by
– Located in ~tclcl
tclcl
– TclClass: Bind cl
classname
ed

– TclObject:
ect: Bin
Bind the instance (or object)
– InstVar: Bind class variables
Var: Bi
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 19
Pr
ul
ak
iy
Outline

ar
ss
• NS2 C++/OTcl Architecture
e

I
• Environment binding:

at
– Class Tcl

w
er
– Class TclCommand

Te
• Component binding:
ding:
– Cl
Class TclClass,
T lCl ss,
by
– Class TclObject,
Obbject and
ed

– Class
Cl InstVar
InstV
V
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 20
Pr
ul
I. Class TclClass

ak
riy
• Bind Classname (e.g., Agent/TCP Ù
TcpAgent)

sa
Is
?

• Mappingg clas
class
las name = TcpClass
ed

• Static
ic =( static mapping variable )=( class_tcp )
ar

• TcpCla
TcpClass derived from (TclClass)
ep

Textbook:
k: T. Iss
Issariy
Issariyakul 21
i k and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Pr
ul
Class TclClass

ak
riy
• Bind Classname (e.g., Agent/TCP Ù
TcpAgent)

sa
Is
b

• TclClass tak takes


ake an OTcl class name as an
ed

input argum argument.


ar

• Fn F crea create(.) ( ) returns the h created d TcpAgent


T A
ep

Textbook:
k: T. I i k and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
Issariy
Issariyakul 22
pointer
poi
Pr
ul
To Bind C++ and OTcl class
ss

ak
iy
1. Define a mapping class as a derived
erived class

ar
of TclClass

ss
2. Declare a static mappingg varia
variable right at

I
the declaration

at
3. Feed the OTcl classname
sname as an input

w
argument to classs Tcl
TclClass
Tc

er
4. Define function
on create(.),
cre returning the
created C++ ob
object.
o
object Te
by
Q: Whatt iis the pu
purpose of having class TcpClass ?
Whatt is nnot p
possible to do without TcpClass?
p
ed

new Agent/TCP
Agen Î create a TcpAgent object
ar

Q: Why do we declare TcpClass as static ?


Q
ep

Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 23
We need unique class mapping objects
W
Pr
ul
ak
iy
Outline

ar
ss
• NS2 C++/OTcl Architecture
e

I
• Environment binding:

at
– Class Tcl

w
er
– Class TclCommand

Te
• Component binding:
ding:
– Cl
Class TclClass,
T lClass,
by
– Class TclObject,
Obbject and
ed

– Class
Cl InstVar
InstV
V
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 24
Pr
ul
ak
II Class TclObject
II.

iy
• TclClass:

ar
– C
Create
t a “hook”
“h k” between
b t OTcl
OT l andd C++
C + clas
class
l name

ss
– When creating an OTcl object, NSNS22 cre
creates a C++

I
object
j with the class name defined
ined in TclClass

at
– How to construct such the C++ object ? Î TclObject !!
++ obj

w
• TclObject

er
– C++ object & OTcl functionalities
unctiona

Te
archies
– In the bound hierarchies
• C++: Based class
asss = TclObject; see ~/tclcl/tclcl.h
/tclcl/tclcl h
by
• OTcl: Based
ed class = SplitObject see ~/tclcl/tcl-object.tcl
ed

– A userr createscreate a TclObject from the OTcl


– NS2 auto automatically creates a “shadow” C++ object
ar

– Shado
Shadow
h d Î The
Th same object bj residing
idi iin diff
different class l
ep

Textbook:
k: T. Ishiera
hierarchy
Issariyakul
ssariyaku and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 25
Pr
ul
ak
Class TclObject: Outline
tline

iy
ar
• Object construction: Whatt happ
happen when

ss
“new” is executed.

I
at
• OTcl commands: Invoking
king C
C++ from the

w
OTcl.

er
• C++ and OTcl class
ass var
variable binding
• Others Te
by
– Reference
ce to TclObjects
Tc
– Objectt destruction
dest (similar to the
ed

construction)
struct
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 26
Pr
ul
TclObject Constructionn

ak
iy
• NS2 creates object using a global
bal OT
OTcl

ar
procedure

ss
new <className> [[<args>]
args

I
• E.g.,
E g “new
new Agent/TCP”

at
rw
TclClass

alloc + init

Te
y
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issar 27
Pr
ul
TclObject Constructionn

ak
iy
• Procedure “create” invokes

ar
– alloc{…}:
alloc{ }: Allocate memory

ss
ction
– init{…}: OTcl object construction

I
• Example:

at
rw
Invoke the same
instproc of

ee
the parent class

Belong to TclClass:
Invoke C++ function
“crate(
crate(…))”
a
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 28
Pr
ul
TclObject Constructionn

ak
iy
• Example: TCP

ar
OTcl

ss
C++

I
( SplitObject
p j ) ( Tc
TclObject
j )

at
w
er


Te
by
Agent/TCP
t/TCP
TCP TCPAgent
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 29
Pr
ul
TclObject Constructionn

ak
iy
• Example: Create a TCP object

ar
Q: OTcl command = ( new Agent/TCP
Q g )
)?

ss
Q: What does it do ? 1. ( alloc ), and 2. ( init )

I
at
Constructor of TcpAgent
C

w
Agent/TCP::init

er
$self init

Te
<other stuff>
TcpClass::create shadow
TcpClass::create_shadow
by
new TcpAgent();
d

S litObjject::i
SplitObject::init
t i it
re

TcpClass::create-shadow
ass::cre TclClass::create_shadow
a
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulatorclass_tcp.create(…);


k: T. Issariyaku NS2, Springer 2008. 30
Pr
ul
OTcl Commands

ak
iy
• Example: $ns connect $tcp $sink

ar
• The syntax is

ss
<object> <command_name>
d_naam [<args>]

I
at
• <command_name> can
an be

w
er
11. An instproc of <obj
<object>
<ob

Te
2. OTcl command
mand associated
a with the
<object>
bj t
by
Q: From the e above
ab
bov example
ed

-<object>
bj t = ( $ $ns )
-<command_name>
mand_n = ( connect )
ar

-<args>
gs>
s> = ( $tcp $sink )
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 31
Pr
ul
ak
OTcl Commands

iy
ar
• The detail of Tcl command is defined
efine in C++
f
function
i

ss
c,arg
gv)
command(argc,argv)

I
at
– argc = no. of argumentss

w
– argv = an argument vecto
vector

er
• argv [0] = cmd,
d,

Te
• argv[1] = <command_name>,
comman
• argv[n]
g [n] = <a
<args>,
g >, n > 1
by
• Return either er Tcl
Tc codes (e.g., TCL_OK,
TCL_ERROR)
_ OR))
ed

• Invoke e the same function of the parent


ar

class..
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 32
Pr
ul
OTcl Commands

ak
• Q: Which hierarchy do we define ( C++ ) an
and

iy
invoke (OTcl ) an OTcl command ?

ar
• Example:

ss
tI
<command_name>

ee
Returning
g
TCL_OK
by
I vo
Invoking the same function Q: Why?
of
o f the
th parentt class
l What’s the benefit?
Is it still return
ar

a Tcl code?
33
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku
Pr
ul
ak
OTcl Commands

iy
ar
To define an OTcl command:
omm
mman

ss
1. Define function “command(argc,argv)”
nd
d(arg

I
at
2. Use “if”
“ f” statement too match
mat h

w
<command_name> with a argv[1]

er
3. Return a Tcl code
ode
4. Invoke function
tio
io ““command(…)” Te
command(…) of the
by
parent class
ass if the <command_name> is
not found.
und.
nd.
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 34
Pr
ul
ak
OTcl Commands

r iy
Q How do we invoke the command
Q: omm
mman

sa
“eventtrace” from the OTcl?

Is
at
ed

$tcp eventtrace <EVENT>


ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 35
Pr
ul
ak
Component Binding
ng

iy
ar
ss
• Tclclass Î Bind
nd
d classnames
c

I
at
• TclObject Î Bin
Bind objects

w
(shadowing)

er
• OTcl command d Î Bind functions
binding Î Bind variables
• Variable bindin
Te
by
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 36
Pr
ul
ak
Variable Binding
g

iy
ar
ss
• 2 Tasks

I
1 Binding variables:
1.

at
• ariab Î Auto.
A change in one variable

w
er
change in another
her
er variable
v
• Class InstVar
2. Setting the
he d
Var
Te
default values: The value
by

assigned
nedd tto instvars upon object
ed

struc
construction
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 37
Pr
ul
ak
Binding Variables

iy
ar
• Syntax
y

ss
bind(“<ovar>”,&<cvar>);
c
cvar>

I
– <ovar> = OTcl class variable
ariab
riabl name

at
– <cvar> = C++ class varia
variable name

w
er
– <ovar> and
d <cvar>
a > need
need nott be
b th
the same
• Other types
– Regular:
Te
b
bind(“<ovar>”,&<cvar>);
i
by
– dth
Bandwidth: bind_bw(“<ovar>”,&<cvar>);
_ ( , );
ed

– Time:
e: bind_time(“<ovar>”,&<cvar>);
ar

– Boolean:
Boole
oolea bind bool(“<ovar>”
bind_bool( <ovar> ,&<cvar>);
&<cvar>);
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 38
Pr
ul
ak
Binding Variables

iy
• E.G.,

ar
OTcl C++
C+

I ss
Class Agent/TCP
g CP TcpAgent
p g

at
Object name otcp ctcp

w
er
Class variable t seqno
t_seqno_
seqn
eqno t seq no
t_seq_no_

Te
a
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 39
Pr
ul
ak
Setting the Default Values
alue
ues

iy
ar
• File ~/ns/tcl/lib/ns-default.tcl
/ns/tcl/lib/ns default.tcl
lt.t
lt.tc

ss
• Not doing so Î warning ng me
message

I
at
• Syntax:

w
<Class Name> set
<Class_Name> et <instvar>
<<in <value>

er
Te
• E.G., y
a
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 40
Pr
ul
ak
Reference to TclObjects
ject

iy
ar
I ss
C++ O
OTcl

at
Base class TclObjectt SplitObject

w
Variable name g (e.g.
String (e.g.,
( g , tcp)
p) Stringg (e.g.,
( g , tcp)
p)

er
Reference value Hexadecimal:
exadecim Decimal string:
x al
au
0x<value> _oTe
o<value>
au
by
Example 0xd6f9c0
0xd _o10
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 41
Pr
ul
ak
iy
Outline

ar
ss
• NS2 C++/OTcl Architecture
e

I
• Environment binding:

at
– Class Tcl

w
er
– Class TclCommand

Te
• Component binding:
ding:
– Cl
Class TclClass,
T lClass,
by
– Class TclObject,
Obbject and
ed

– Class
Cl InstVar
InstV
V
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 42
Pr
ul
ak
iy
III. Class InstVarr

ar
ss
• Recall: Variable binding
– bind (“<ovar>”,&<cvar>); ty
typee=( regular,integer,real )

I
– _
bind_bw ((“<ovar>”,&<cvar>);
, ) type
yp = ( bandwidth )

at
– bind_time (“<ovar>”,&<cvar>); typ
type = ( time )
– bind_bool (“<ovar>”,&<cvar>); type = ( )

w
boolean
• What are the difference? Î Make
Mak it easier for

er
manipulation
l in the
h OTcll

Te
• Derived class
– Real C
Classs InstVarReal
I
– Integer Cla
Class InstVarInt
by
– Boolean Cla
Class InstVarBool
– Bandwidth Class InstVarBandwidth
ed

– Ti
Time Cl
Class I
InstVarTime
V Ti
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 43
Pr
ul
ak
iy
Class InstVar

ar
ss
• Real and Integer

I
– e<x> Ùx 10<x>

at
rw
– E.G.,

ee
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 44
Pr
ul
ak
Class InstVar

iy
ar
• Bandwidth = Integer + Unit

ss
• Unit:

I
at
– “k” or “K” = 103

w
– “m” or “M” = 106

er
– b = bi
bits; B = B
Bytes
es
• E.G.,
Te
e
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 45
Pr
ul
ak
iy
Class InstVar

ar
ss
• Time = Real + Unit

I
• Unit:

at
– “m” = 10-3

w
er
n = 10-99
– “n”

Te
– “p” = 10-12
• E.G.,
EG
by
e
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 46
Pr
ul
ak
Class InstVar

iy
ar
• Boolean = {True or False}

ss
• See the first Letter only

I
• True (nonzero or T)/ False(0
alse(0
se(0 or F)

at
w
er
Te
a
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 47
Pr
ul
ak
Summary
y

iy
• NS2 = C++ with input file

ar
• Execute statements and/orr receive/pass
rece

ss
results

I
at
– From
F C++:
C Invoke
k [TTcl::eval(…)
l l( ) ],
]
Pass/Receive
eceive [ Tcl::result(…) ]

w
er
– From OTcl: [ TclCommand
Comm
omm ]
],
[ TclObject::command(…)
TclObj ]
• Binding/Shadowing
ow
w ng Te
by
– Class name:e: ( Tc
TclClass )
– Objects:
j (TTclObject
j )
ed

– Class vari
variables: ( InstVar )
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 48
Pr
ul
ak
iy
Related files

ar
• ~/ns/common/misc.cc
/ s/ mm /mis

ss
• ~/tclcl/tcl-object.tcl

I
at
• ~/ns/tcl/lib/ns-default.tcl
.tcl

w
er
Te
by
ed
ar
ep

Textbook: Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
k: T. Issariyaku 49
Pr

You might also like