(Network Simulator 2
'%
$% #
mehdi_vojdani@yahoo.com
)' " *
+ !,
-.
/0 12 3
7-8
&456
4;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ns
35;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1=
:9
3 *> :<
% C
(D 6 + :B
GE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ns ) 3
J9;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;I!
3
!> ) (.!D
H!6 # L M.
) F$% :E
1)
1 "
H . 1 :G
(D 6
-.
:K
NJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;I!
9PK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;I!
9<P;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;I!
9?E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;I!
I!
O >#) + :J
Q1"1R# H ) MobileIP + :N
9?<;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;I!
*>
31 )
31 )
9?N;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;I!
1 " 4 6 + :99
1 )) .
("' :9<
9BJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ns ) S )
>!. = :9?
L 456
ns
WinXP
;' $ % 1D
2 '! 0 1D
)6
;' ) ) Cygwin W5
(D 6 4>
$ 0 1
2 '! 0 W5 )
) cygwin.exe
1D
ns
'
'.
X ' ) '5 2
-. Z1$Y 1 ! 2 ;'! 0 U V. )
;'! 0 -.
6 [!=
;' $
4*
' $ !(# 1D
) ns-allinone-2.29.2.tar.gz ' L
0 % ) Cygwin
;' 0 _) C )10` \ (6 )
Ha ) install W5
(D 6 1% ls )1.
'
/]R
6\ 6
)4 6
) ns-allinone-2.29 \ (6 ns W5
;'! 0 ) ) ./install )1.
bR
;'! 0
)0
& 1 '3 1C
;'! 0 U V. ) Advanced 2
.6) My Computer
+ = 61 W5
properties \$]
W5
'Y
'Y
10
;'! 0 U V.
'!
$.]!
%1# ;'! 0 ) ) 0 @ $3 ) )
3 !!d. I!e #
3
) Environment Varible $0 bR
2 ;'!3 ) 6 ) Edit $0
0 U V. ) path L
'3
) 4$^
4* )
11
;'! 0 ) )
)1.
'Y 2 )
Export LD_LIBRARY_PATH=/usr/local/ns-allinone-2.29/otcl-1.11
Export LD_LIBRARY_PATH=/usr/local/ns-allinone-2.29/lib
Export TCL_LIBRARY_PATH=/usr/local/ns-allinone-2.29/tcl8.4.11/library
12
;\ ns-simple.tcl 4 6
I $ % %
) $
'
h) )
) 1$
;'! 0 L > )
;'
@1a
'3 1V @
!> H 0 I ) '5
/usr/local \ (6
(. ) L f
3 '0
!Cg /usr/local ) )
( 2 '0
Lf L
L ;:'! 0
0 % ) Cygwin '.
%
)
13
4 6 \ (6
) ;'
C:\cygwin\usr\X11R6\bin C
; 0 '!3 1C '3
+=
$ '
.6) My Computer
'! 0 \6 ) ! )
)' 3
3 d!= ) 0 \
*$ .>"
14
) C:\cygwin\bin \ (6
(D 6 '
$ ;'
.6 ) 0
(. 1R 0 0 \ 4!"
d!=
;'! 0 R0 C:\cygwin\usr\X11R6\bin
) $ 4*$ ' 1#
@ 6 / # ;'! 0
'Y I3 '
;' 0 4
export DISPLAY=:0.0
;'! 0 % ) ns ns-simple.tcl )
15
'3 1C @
>! L i
)18
16
&ns ) 0 c
0 \ tcl 4 6
'!"1# ) 3 % C
0 \ tcl \R *
.]
;'
!a $3 ;' 0
nam
!>
kV
' c
) $
!>
trace 4 6 H \
1)
*$ 0 ' 0
&(network animiator)nam c
0 \ nam trace 4 6 H
L i
@
)18 '! 1#
)
nam-file
$ 0 \ tcl
% ) nam<nam-file> )1.
!> H % C 48
'3
$!M.]
) nam + =
) nam '! 1#
\
'
+ ns T 1#
4* ) ;' $ '3
;' '3 1C
17
&Tcl \R *
3 ) \ 6
'! 1#
$ ;I! 0
;I ) `2
nam
1C !"
(.R *
example1.tcl ) @ 1C L f
% C . 1
;'!3 ) '
% C 4 6 H bR
)$
!"
I! 0
template H
$#
;'!] 1 ) 1C
+ )
(m )
!> c 1
trace
!"
'. )
).
H
'. )
;I! 0
trace 4 6 .]
finish L ) @ 0 6 A 'Y 2
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
+
. ;'! > Z
3'0 n)
13'
$
;' 3
;' 0 %
!>
'Y TC
!>
at )1.
18
$ns run
4 6 H % C ;'! 0 %
ns example1.tcl )1.
0' $
'3
) 4 0 '0
19
&
p!
q Otcl ]- H
V .0 q 3 ' ) ' @
+
)0 0 )
')
1%
!>
V .0 ) 0
) 3 .] L M.
+ 0 a
h)
(.R *
!>
*("1" F 1#
%
*> !
a 0 ' 1 H!6 # F
! )0
H 2 )
) ns '
*>
3 ) 'M
ns
;\
-.
) *>
' )'>
"
-.
*> !
!>
4* ) 0 1 $3
*>
D.V
*>
Yr
CZ
) $Y
' $ +
a ' 0c
3 !]
*("1" q *> H
s >! W
& '3
+ ))0
' 1.!
X
X
1C
ns
("1%
) 0 0 !!Y#
@1a ' 0
+
!]
))0
2 'C) )18
*("1"
$^
H '3 1V ) 0 0 .
! t V .0
*("1"
>! @ 1#
*>
'
ns
' '%
H . 1. 9
-.
'!u!= \
3 ' )
-.
;'.6
-# a
+ .<
*$ ) 0
;' 0
!>
-.
@
'0
20
') )
@ =
!>
' )
8) 0 )
;' 0
L Y6 W
(*>
!>
+!. @'
H 3 0 1
1C 6
!> @
' ) '>
q' '
'>
1 a q 1$
*>
1C 6
Yr p !
V .0 q 3 ' ) ' @
0 + L ) H @ 1.!
!> ) 3 2 n 7# @'
&
) 0 @ @ 1 ^ OTcl
q Otcl ]- H
) ns I!.-2 )1r $3
1 a '3'! @
; 0 + MD @ 1.!
)%@
;\
*>
ns )
0\
1 a CZ
1$ H
4* L f ;\
'!D0 $D0 ; !2
) >^ ]- # 1
) L )
'Y
v^ expr Q ; 1
-. L ) H c
-. @
@ 0 kV
Y# @ ' !!d.
proc $D0
) 'M H k!5V#
;' 0 %
set
!]-# ) 4 M
21
) 1C '
. 1 L ) '! 1#
1C 4 6 ) ; 1
& 1 '3 1C
4*
;\C = I!3 1C
h 0H 1 ^F # 0 +
instvar Q
0 1
-.
)1.
F #H
; 0 I!3 1C
% C)
% CLf
1C 6 $3
! u$3 ;\ 1 I!3 1C h 0 4C ) ) F #
v^ '
'
Y# 4> )
1$ !!d.
;'! 0
-. @
F # 2 \
. 1
1C 6 @
w)
$3
-. instproc Q
!=
1$ !!d.
;1
H +
Class $D0
Y#
TM6 2
Y%
)
+
$3 h 0
instproc ' $3
@
)'= h 0 )
-. )'= h 0 @ 0 kV
22
e )1 F #
1$
1D%
1 ^ F 1#
1C 6
; 1 '3 1C
-.
% C I! 0 % ) Z \R *
&H !" H
_ ) $ns at 5.0 finish 4> \
.(
Y# (
! new
1$ +
) \$]
! H !" H
2 L ;I] 1
$3
Y#
3'0 0 '
) 2
2
.
%1#
+ ) ;'! 0
23
45. I3
) 2
+ ) n0 n1 2
Z )1.
0'0
;' . 1
45. I3
) 1Megabit '
) 4 0 '0 ;'! 0 %
(=
6X
H !"
!Cg example1a.tcl
2 Z TC )
)4 6
;' 0
24
4*
nam )
% C % b=
&
ns ) ;I
H
0L )
n0 2
n1 2
n0 2
0 0 I!3 1C + agent
L ) I!3 1C
H
'Y 2 ) ;' 1
;' 0
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
\6 ) )
;' .]3
L )
n1 )
L )
(" f .>"
agent
agent H
25
constant ) \ o \! x
;1
kV
: ! o ) \0 = \]
'
;' 0
L )
+ n1 2
0' 0
NULL agent H
TC
45. I3
) 2
kV
1# c
'3
) ) 4 0 '0 L
26
) H!6 #
3 ) 1$ C + ) @ 1#
) % C nam )
1$
b=
; 0 '3
27
:Topology Q1"1=1#
L ;'!
Q1"1R#
$ 3
!> ) ' 0 + )
;I!
!>
1)
H $
2 B I!3 1C
D> L f )
'Y L f )
+ 3 2 ! 6 X H !" ?
'0
'! 0 6 A )
3'0 b= ;'! 0 kV
\R * ) '! 1#
!Cg ) 3'0
'!
2L
[ $ 1!
;'! 0 %
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
28
&:Events 3 'C)
l 5.C n1 n0
3 2
) (
I!3 1C
\$]
29
;I! 0
) CBR agent
1.
ByE ! o )
'0L )
c
;' 0
1. ByP ! o )
agent
c ) 9yP ! o )
n2 2 bR
\0 = <PP H !"
n2
n1 n2
H!6 # n0,n1
3 ! o 3 ) \-2 @ 1#
n0
' n3 n2 ! '
)1.!
1% n2 2 \$
H !"
' # > 7
! o ) \!
@ %
% \R * H!6 #
; 0 '3 1C L
PyJ '
\ {) *
3 2
n3 2 \$
2
) H!6 #
(= b= ; 0 ' 3 1C L ) \ EPP
'
(= b= ;' '3 1C
! o
\!
;'! 0 H!D0 ) ( @ 0
; 0 I!3 1C @ ! (
( @ 0 $.
) )0 )
30
& ( % ) `2 @
;'! 0 6 A 3 CBR agent
Y#
TC
;\
;'! 0 6 A :
!>
class_ fid_ . ) =
'Y )
3'0 *# L
) % 1$
;\
4* ) ; !2
e ) flow 3
!!d. n3 n2 ! '
) '%
(= F 1# '! 0
'3
( ) 3'0
0 )1X @ $3
& 8 H @ 0 )1.!
;'! 0 6 A n2 , n3 H !" !
$ns duplex-link-op $n2 $n3 queuePos 0.5
8 H @ 0 )1.!
31
; 1 '3 1C
(.0 = TM6 0 \ s )
(stochastic fair
% 4* ) 0
s)
;'!3 !!d# )
#
1
TC ) 0
3
;'! 0
!>
(.0 =
@ %
3 .] z`
;:' 0
-. n2 ,n3 ! H !"
z`
) ) [V
$
)18
) L
queuing)SFQ
; 1 '3 1C
&I . 1
4*
4 0 '0 L
32
33
34
35
456
1=
|)
3 *> ) ; 0 I!3 1C ) 0 3 2
3 *>
C )18 )
;)
!]
1% !
1=
C@*
3 *>
'0 ;
Q1"1=1# H +
) *3 ) H
I ] 2
;' 0
\ Z 3 2 'Y# Y
&|)
) ) [V
$0 .>" ;' 0
Y#
45. I3
! Tcl ) @ !e
!a
Q1"1=1# )18
) |)
3 Q1"1=1#
!Cg n() ) ) ) (
3 ) 0 '!
) 2 \-3 @ $3
%1#
'0 L
$# for MD
36
*$ '! 0
;' '3 1C
% ) \R *
0 .
&H !"
;' 0 L ) )
'Y 2 )
37
+ ) 0
? P 2
-#
Y !]
-. 4>
( $3
0 < 9 2 ! H !" @ ) 0 I! 0
)0
!> Z
2;1
L ;' 0
down ! o H
3 '0
-.
)1>^ < 9
:'
-. H!6 #
L Y6 !, ) < 9 ! TC
;\6) ' 3 1C !
!> 9yP ! o )
' )
;\]! D*
? P 2
;'! 0
'3
) 0 TC
(.0 = ! o H
nam ) ) } -#
n)
) b= ;I! 0
4* )
38
'.
TC L
; 0 '3 1C 4
) 4*
1=
!]
1 a 0
;'! 0 6 A
$ns rtproto DV
3 2 !]
-.
? P
'3
) % 1$
!>
'Y 1C \R *
!> ! o ) '! 0 % ) \R *
I!3 1C
L f 4 0 '0
39
$ns rtproto DV
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
40
41
42
1 456
@ 1#
)0
;' 2 F
) @ I3 ' !2 @
456
' 0 L ) \0 = H 3 2
; 0 > 7 ) round-trip
;\6 2
@ 1#
\]!
!=
.( ' ~ ) 0 '0 0 \ kV
&:header '
) T>#
0 I! 0
kV
) .C
.>"
4 6H +
4 6
;
'3 1C L M.
struct hdr_ping {
char ret;
double send_time;
};
1 '
ping = 2
> 7 ) 'Y
0 '
.]
)L )
'. 6 z X
3) 0\
Y#Agent h 0
@1^
) PingAgent h 0
\6) @
'0 *#
43
) recv() command()
\o )
'
\ ;' '3 1C
3'.
'0
Y# ) '
-. ping \0 = H '
;\
off_ping_
' 3 1C _ @
&'
C ) Z1$Y
e
/*
* File: Header File for a new 'Ping' Agent Class for the ns
*
network simulator
*
*/
#ifndef ns_ping_h
#define ns_ping_h
#include "agent.h"
#include "tclcl.h"
#include "packet.h"
#include "address.h"
#include "ip.h"
struct hdr_ping {
char ret;
PingAgent() F #
;' '
D7 !
) ping.h 4 0 '0
'7
)
44
double send_time;
};
#endif
&C++
3'0
) ;' !
) ( 4 0 )1r 0 \]!
Z '
;'! 0
'
'3
Y# C++ tcl
) ping '
h 0
3'0
3'0 ! O >#)
C++ O >#)
45
Tcl ) I3 0 ' 0
h.
PingAgent::PingAgent() : Agent(PT_PING)
{
bind("packetSize_", &size_);
bind("off_ping_", &off_ping_);
}
) ;1
% PingAgent h 0
:\ Agent/Ping h 0
) )1.
'!=
r F # 2
H 0 1
1C 6
command() F #
1$ H pa 0 I! 0 S 6 \ $pa send F #
)1r ;I! 0 L )
) ( $2)
Tcl )1.
) ping
(.0 = 0 I ) '5
0\
\"
XC
$
= h 0 ) command F #
Z1X command()
46
return (TCL_OK);
}
}
// If the command hasn't been processed by PingAgent()::command,
// call the command() function for the base class
return (Agent::command(argc, argv));
}
'
' ' )
\0 = H .
0 ' *! kV
0 '
\ 2
\6) @
) ;' '3 1C s
W]a @ $3 \0 =
!!Y# tcl )
;'3
;'
1C 6 tcl F # H : 1
) D$^ recv() #
) '
) 0 T 1#
)0
/*
* File: Code for a new 'Ping' Agent Class for the ns
*
network simulator
* Author: Marc Greis (greis@cs.uni-bonn.de), May 1998
*
*/
#include "ping.h"
47
PingClass() : TclClass("Agent/Ping") {}
TclObject* create(int, const char*const*) {
return (new PingAgent());
}
} class_ping;
PingAgent::PingAgent() : Agent(PT_PING)
{
bind("packetSize_", &size_);
bind("off_ping_", &off_ping_);
}
48
49
' ping 2 ) $
. 1 F #
0 \ tcl.eval()
'0 1 a 0 I! !
;' ' 3 1C [
1C 6 \$]
( V ) ;1
L R 0 ns *
1 )
1C 6recv F # 0
.$( 1
1C 6 . ) = @ 1 ^ \ 2
[!= (D 6
1 a 0 I! !> '
\6) @
4> ; 1
& Z
\ 6
2 i
;' )
. `2 '! 0 L $^
H ) ) (
) 1C
7!A1#
) 1C
!!d# '! 1#
. )
ns F>
!!d# 0 I! 0
(D 6
( != ;'! 0
;: !, #ifdef
!!d# C $
-. I3 ' '% \0 =
comment
-.
;' ) ` ns
$ + ) ;\ packet.h 4 6 [
! ping agent
2I)
\0 = c1 H
;: 1 L $^ @ )
(*# = ID
D.V
1
3'0
!!d#
0L
- Y# '! 1#
) ' '%
- Y#
!> packet_t{}
enum packet_t {
PT_TCP,
PT_UDP,
......
// insert new packet types here
PT_TFRC,
PT_TFRC_ACK,
PT_PING, // packet protocol ID for our ping-agent
PT_NTYPE // This MUST be the LAST one
};
;'! 0 [
class p_info {
public:
p_info() {
) \ Ping 4
0 D 6 @ $3 ) ) p_info() '
! u$3
50
name_[PT_TCP]= "tcp";
name_[PT_UDP]= "udp";
...........
name_[PT_TFRC]= "tcpFriend";
name_[PT_TFRC_ACK]= "tcpFriendCtl";
name_[PT_PING]="Ping";
name_[PT_NTYPE]= "undefined";
}
.....
}
!, ) 0 '!3
'
make )1.
;' 1
!
6 [!=
;'! 0 _) 4 6
3 ) 'M
$# 4 6
) ; 0[
) ) Asent/Ping
4> 0 '!
4 R 04 6
0\
*$
)15
! ) tcl/lib/ns-default.tcl 4 6 '
TC ;\
! u$3
Y# Tcl
'
(.0 =
) H '
; 1 '3 1C
! u$3
{ SRMEXT off_srm_ext_}
{ Ping off_ping_ }} {
set cl PacketHeader/[lindex $pair 0]
(D 6 \]!"
) ping.o 4 6 $ ;
'!3 1C + Makefile 4 6 ) 0 \
;'! 0
;'
!!d# !!d#
6 A ) ns
!> '
$ \]!"
51
$(LIB_DIR)dmalloc_support.o \
ns )1.0
;'!
) make / # ns )
4 R 0 )
'
&Tcl '0
0
'3 1C
I!3 1C @
I!3 1C @
) Ping agent
Tcl L f H
4 0 '0 L
0 ping @
!.
0\
0\
2 @ :node id
2 )$
.6 2
Agent = h 0
&' . 1 $
#Create a simulator object
set ns [new Simulator]
#Open a trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
Z ) '
.-2 '0
node_
ping.tcl 4 0 '0
52
}
#Create three nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
#Connect the nodes with two links
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
#Define a 'recv' function for the class 'Agent/Ping'
Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts "node [$node_ id] received ping answer from \
$from with round-trip-time $rtt ms."
}
#Create two ping agents and attach them to the nodes n0 and n2
set p0 [new Agent/Ping]
$ns attach-agent $n0 $p0
set p1 [new Agent/Ping]
$ns attach-agent $n2 $p1
#Connect the two agents
$ns connect $p0 $p1
#Schedule events
$ns at 0.2 "$p0 send"
$ns at 0.4 "$p1 send"
$ns at 0.6 "$p0 send"
$ns at 0.6 "$p1 send"
$ns at 1.0 "finish"
#Run the simulation
$ns run
53
-# a I! * 1 \6 )
+# ) 0
' # $
0 L ;
.6 '3 1C
) %1. I! * 9 ) \!
pa
1# @ ' ) (.0 = $~
!$3 \ 2 \6) @
L 5# @ ' :\
;' )
'!u!= ) 0
*6 & ' ] 1
' '3 1V @ L )
) 3 '0 C '! 1#
2 H node
e
0I0
\6
! u$3
1 ping agent H pa
'. ) .>" ; '. ) node
54
55
) (a 456
Xgraph
48
(.R *
-.
+
3z 2 +
output
17 I!3 1C
-D.V
' 0 I! #
(D 6 I! 1#
L f ) ;I! 0
( ) 0\
% C
(D 6 +
I!3 1C @
[V
-. Xgraph
) (
0 %1# '
.* ;I!3 @
;)
) ;1
-.
^1$+ bR
I! 0 + tcl
! ) H!6 #
3 '0 +
1% Xgraph
& H!6 #
;I! 0 + '
(.$]
!>
% C
(D 6
3 F>
Q1"1=1#
Q1"1=1#
$3 4>
56
;I
) ) ( 4>
3'0 @ $3
!>
3'0
6 A # I] 1 ' L ) H
'
'.
I! 0 T>A ) n2 n0,n1
;' 0 #
3 F>
) 3 F>
(*!6 # 0 I ) '5
3 ' 0 + H!6 # @ 0
57
idle burst
!$A 2 H
[!=
L )
H!6 # F>
*!=
2 'a
0 :H!6 # F> H
3 peak x
L ) n4 2
\0 = '
) ( T 1# '
'
# '!u!= L )
3j
+ Traffic/Expoo
3 . ) = I !0
H!6 # F>
;I! 0
:' 0 )
handler
H!6 # @ 0 !$A 4f \
H!6 # ' 0 +
;\ @ X
'Y I !0
0 I!e # ) ) '
. )=GL )
3 -!j )
3 F> k!5V#
L )
+ H!6 # bR
I! 0
;:I
H bR ;I! 0
' 1 45. I3
! .
H L ) C )
+ 17
1C L f H
L ;\ ' 0 ! .
-. n3 n1 n0
' 1#
3 2
0
+
sink I! 0
0 + '. ) 0 I! 0
;I
0
;' 1
-. H!6 #
-. '
3 sink @ 1 ^
(= >]7
Agent/LossMonitor !
' 1#
0' 0
!Cg ) '! )
Lf
(.
)
) 'M
58
: % C
;I
)0
D>
(.R * ) )
O1rC ;I !0
(D 6 ) 3
) % C4 6
T>A
@1 0 I3
!> finish L ) )
+ ))0
;' 1
.] rM H ) (D 6
proc finish {} {
global f0 f1 f2
#Close the output files
close $f0
close $f1
close $f2
#Call xgraph to display the results
exec xgraph out0.tr out1.tr out2.tr -geometry 800x400 &
exit 0
}
0\
*$ ;I
1C 6 . [ $
;'
;'] 1
800*400 '
% C
(D 6
0 I!] 1 ) " ) I! 1#
proc record {} {
global sink0 sink1 sink2 f0 f1 f2
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.5
#How many bytes have been received by the traffic sinks?
set bw0 [$sink0 set bytes_]
'5 $
L
59
(= bR ;' 1C
3 sink ) bytes_
;' 0
) H!6 # sink
3) 'M *
' @
' \6 )
'Y# L )
:MBit/s
[!= % C 4 6
) ( bR ;\ 1 '3 1C (
10
&
!>
(.
3 'C) I! 1#
(
%
L
60
'>
) 1C ! o PyE 3
L ) GP ! o ) ;' 1
)15 ) 1C @ q@
1. EPyP )
0c
b=
'
1C 6 record L ) '. )
9PyP ! o ) H!6 #
3 F> bR ; 0 '3 1C
;1
&\
'
) example4.tcl
1C 6 finish
)Lf ' 4 0
61
62
63
!> @
3 ) 1$
% )
!> $
0 .
; 1 '3 1C
@ %)
.* ;\ I(
)
;'
D!C time
H gnuplot
2 L
W
! u$3 ' 1#
3 burst '
0.3Mbit/s )
0 )1X @ $3
1 ) 0.2Mbit/s
) 'M @ 0 '!=
'1
!>
31 )
+ record L )
) 0 '! 0 %1#
0 % C
;' 1
(D 6
-. :) 1$
64
65
I+ = 456
ns ) 3
F$% '
!>
!>
*> s
! ) ) 3
= )1e
) F$%
) % C
0\
@ 1#
;)
1% 3 % C ) F$%
;)
. !
)0
3 .] z`
! ;' 1
'
)18
.] 3
(.!D
-D.V
s ) .>" ; 1 s
&1
*!= *>
!> H
.$(
( ) ;' 0 )
= 'Y # \V ) D 6 ) 'Y
>!. = tracing s )
^ X & trace !
ns )
D! 1 9
): 8)
;' 0
;' 0
trace ) : 8 Z1$Y 3 .] _ C
&Trace/Deque
trace 3 .] z`
&Trace/Drop
trace ) 'Y 2 ) 3 .] \6 )
&Trace/Recv
;' 0
;' 0
;' 0
;' 0
@
' zg .]
&Trace/Enque
!Cg ) ) @
) .]
'
.]>3 '
.] _ C @
&SnoopQueue/In
&SnoopQueue/Out
&SnoopQueue/EDrop
;' 0
!Cg ) z`
66
!,
!
'
. 6
;' 3
.6 )
+ ) s) $ 4$^ ( %
-D.V
) I3
&Monitoring !
(.!$0 !
3 .]
) I3 ' 1#
3)1.!
D!
;' 0
<
trace ! \$] ) 0
.] z` k!V #
(.!D
QueueMonitor
(.!D
&QueueMonitor
3 1$
'
2 \6 ) ) :' )
&QueueMonitorED
^
;)
' 1#
QueueMonitor/ED
(.!D
&QueueMonitorED/Flowmon
^
;' 0 '
T 1#
3 @ %
O1
^ X
2 2 '% )1r q @ % 3 h
^ X
&QueueMonitorED/Flow
1.7
\ ' QueueMonitorED/Flowmon
;1
&Trace !
trace
;\ ) )
!815C 0 )
1% .] 3 ) n .
>!. =
!!Y# ' 0
'!"1# ) .] 0
(" ^ T 1# \!815C
) $Y
H trace
'
.'3
.] '
.]
' 0
>!. =
.* 5V
H 9
) .] c1 <
kV
.1
.\
! )1 .] L M. @
;1
!!Y#
\!$0
. '0
kV
) .]
:T
!. =
' ?
W]a B
(* !" ) $Y
67
;\
'Y#
Y# (* !" )
Trace + )1e
3 2 )
; DropHead,Ttl,Link,Queue,Head ;' 0
;\ Simple-Link H !" D8 h 0 ; 1 L Y6 ((* !"
h 0
-.
Y# ) H !"
) !!d. =
)@ '
) 0 \ trace init-monitor L )
)
;1
4 6
) (
Dequeue ;' 0
!Cg ) 3 .] @'
) 3 .] .C ' )
;' 0
q'
% C
.-2 trace !
O1
^ X Drop q' 0
'Y ;\
;'3
) "]
'0
4* ;' 0
O1
'0
;' *
;' 0
)
)
trace ) 8
'
!!Y#
^ X
) '(
S 6 Trace L ) ! u$3
6 A H !" ) queue
-.
O1
^ X Receive ;' 0
8H '0
6 A H !" O1
&'
;' 0
) 3 .] @' _) C
6 A queue b= ) Dequeue
'0
^ X ( # Enquque c1 ;'. 6
O1
!Cg ) 'Y 2 T 1# 3 .] \6 )
+
trace ! trace L )
queue target
)1 trace L $^
4> ) Enqueue
8 ! ) Drop
H !" )
8^
3 .] 0
5 ^ &Enqt_
' *! trace ) % C
3 .] 0
5 ^ &Dept_
trace ) ' I2
3 .] 0
5 ^ &Drpt_
'0
68
;' 0
;' 0
trace ) 'Y
'0
)
5^
2 T 1# ' \6 )
3 !!d.
3 .] 0
5 ^ &Rcvt_
) ) ' a ) tracing ) 0 2
' 0 L Y6 H !"
&trace 4 6 \ 6
;' 3
) 1
+ trace-all )1.
0 trace 4 6 \ 6
D!
tracing !
)0
H$0 F 1# @
)0
3)1.
-. @ ' @ 1#
)'
L '%
*$0 F 1#
;' 0
4 6 )
) trace !
trace
c1 ;' 2
trace- L ) T 1#
0 '
$3 O1
^ XF #
&flush-trace{}
'0
) Recv,Drop,Dequeue, Enqueue
69
) '
1 trace \ )
!!Y# )1.
callback{ns command}
;1
create-trace F # T 1# > 0 trace
n2 n1 2 ! ' .C ' )
;1
3 .] '5M \
' .C
&trace !
-.
)* ]13
]1
3 \R * ) @ 1#
(* !" ) trace@ 1$ L Y6
(r
) 3)1.
]1
(r
trace % C ; )
.C nam c1
nam animator )
) L 5# :' 0
trace 4 6 H
L Y6
) nam ) 'M op 2 ; 1
) trace
H !"
!>
. 1 '
-# @ 1#
)1.
!!Y# 4 6 ) H !"
nam 4 6
-.
;
. 1 4 6)
% C '0
!!Y#
;\
'0
'
*!
) :H !" @' U C *!
-#
O1
trace \ 6 ;' 0
op
70
. 1 '
!!Y# 4 6 ) @ % C ' 0
L Y6 (* !" $3
) ) trace )1.
. 1 '
!!Y# 4 6 ) @ % C ' 0
L Y6 (* !" $3
) ) nam c1
Trace
;' 0
M#
.6 2 log )1e
trace
H @ 6
L Y6 ) nma tracing *
% \ 4> 4f @ 6
Monitoring !
-.
)
)1
^ X
!>
% C
!2 ) \!D !
^ X
. '1
) F$% )1e
6 A *>
0 ' .]3 !
Q1"1=1#
^1$+ 3)1!.
'Y ! !
' !2
71
'
. 6
3 .]
$#
(3 \] 'Y# q '
.C ' )
*$ monitoring '
)\
3 \] 'Y# q ' \6 )
(3 \] 'Y#
! !
;l C
[t0,t1]
intergrator
D8 6 H ) ' 1#
-.
)1.!
( %
H (
O1
! W]
1 L $^
3 .] 'Y#
1" ^
^ X
Queue Monitoring
; ) Init-monitor
L )
trace ! '
s) 2 Queue monitor
;'3
(
' .]3 h .
2' 2
) ( Queue monitor 0
T 1# 0
3 !!d. ;'
)1.!
) 0'0
;' .]3 O1
Queue
-. Monitor Snoop !
'0
!> @
+ H !"
(.
)
!Cg
Y" X
3 !!d. ) )
-.
!>
b
'Y# ' 1 c
'1
1
% Cs
*$
3 ) 'M monitor
' '2
' _) C
'
.C ' )
' :Pkts_
(.
'Y#:barrival_
(3 \] 'Y#:pdeparture_
' _) C
.C ' )
' &Size
(3 \] 'Y#:parrival_
8 .6 )
'
@ 1#
8 .6 )
.]
8H
Queue monitor
45.
3 .] 'Y# ' 1 c
Queue Monitor H
;' .]3
Queue Monitoring
) 3 .] _ C
3 !!d. ; 1$
) ) 8 { )1.!
'Y#:bdeparture_
(.
(3 \] 'Y# :pdrops_
(.
'Y# :bdrops_
72
3 !!d.
.1
> 7 \
' L
T 1#:bytesInt_
. 1
> 7 .]
' L
T 1#: PktsInt_
# 8 ) Monitoring @' L Y6 @
1C 6 @
3 !!d.
T 1# ' '
2 ) 'M
;'
&QueueMonitoring/ED
6 @'
& \
= XC
3 .] .C ' )
) >^
! \ )
8 5C
3 !!d. ; 1 4~
\ QueueMonitor '
3 .] 'Y# &Epdrops_
3\
'Y# &Ebdrops_
QueueMonitor/ED/FlowMon
'. (
' '
L ) ( % ' 0 )1.!
!= 31D6 O1
.] @
'Y
'0
) F$%
% a
H!6 # !
) F$% 1D6 W]
n3 n0 2 TCP *!6 # \
;I! 0 trace ) n3 n2 2
'
DY. .] 0 ' 0
)
lC
0
!!Y#
^ X 0 1
-.
(" f
.C
Q1"1=1# '! 0 S 6
! H!6 # I!3 C
;\ L ) L
73
;1
W]. (
2 )
:w
'1
()
. 1 )1e
4 6
)1.
!!Y# 4 6 ) \
(* !" $3 ) 3 ' ) $# 4
; )
4 6
0@ % C
'
'
% C
. 1 ' .-2 \ 6
'1
.] (D 6 bR
'
. 1 (D 6 4C
3 trace
;1
^ X finish L ) )
% out.nam 4 6
proc finish {} {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam out.nam&
exit 0
}
H !" f H !" H
-.
)1.!
trace-queue )1.
I! 0 )1.!
) n2 n1 2
74
-. monitoring
0 I! 0
; ) \ ' ) !,
I! 0 )1.!
' _) C
' I2
-# $3 I!3 1V 2 '
3 .]
'Y# L f 3 .]
&L f @ 1 ^ ; 0
-. l C
-.
O1
3 )1e
^ X
@ 1#
^ X
( !M ) 3 .] @' I2 x
D.V
;; !,
.-2 0 )1X @ $3
D.V
( !M )
( !M ) 3 .]
3 )`2 x
)
'Y#
& 1$ L f
;'! 0
'
(=
-.
. `2 4 6 H ) '
-. @ ! n3 n2 ! H !"
7!A1# z`
) monitoring @ 1$ L Y6
;1
.6 2 ' W
)1.
-.
0 '!
'0 )
%1#
1$ @ 1 ^
3' = ) 3 .] @' I2 x
H !"
2 )
'0
L Y6 n3 n2 H !"
) ) monitor-queue
75
proc record {} {
global n1 n2 aggr_thr_file aggr_drops_file
global ns t_u_time_ sent_bytes_ throughput_samples_ drops_samples_
global dropped_bytes_
#get an instance of the simulator
set ns [Simulator instance]
#set time after which this proc should be called again
set time 0.1
#byts no go through the queue
;' 2
H !"
)1.
) '
!!Y# H qMonitor
2 )
)1.
(.
'Y#
)1.
(.
'Y#
)1.
U ]. transf_byte !!d.
' 2
) H !"
' _) C
U ]. new_drops !!d.
' 2
) H !"
' .C ' )
reset 3 !!d.
) 2 )
!"
76
3 ) 'M '3
) D>
!2 1$ @
0p_simtime !!d.
)1.
; 2
)1.
-. @ ! )1.
> 7
!2 1$
!'
(=
> 7
!2 1$
! 3 .] @' I2 x
)1.
!C '
!!Y#
3 ) ) drop_rate used_bw
)1.
77
;' 1
1C 6 )
'Y
D8 6 )
^ X )
$%
Z L )
)1.
) \ ()
D 6 ) ) ( % O1
^ X
'0 ; ) \ ' ( % W]
Lf
^ X @ 1#
)1.
) flowmon1
)1.
flowmon1 W!# #
;' 0
\ 1!= n3 n2 ! H !"
;' 0
) F$% @ % c1 W]
.-2 > 0 . 6
% C W!# #
'0
45. 4 6
) flowmon1
;1
);\
. 14 6
78
) I!3 1V 2 ; 1
) *# e )1
. 1 4 6 4C
flowmon1
3' = ) ) )1.
I! 1#
I !
% C '
!!Y# @
^ X flowmon1
)1.
kC
31 =
;I! 0
'. )1e
; 1$
; 0
-.
Flow Monitoring
^ X ) F$%
@ 1#
'1
!Cg @
O1
3 !!d.
-. @
-.
@ 1#
! u+$3
3 . ) = bR
3 !!d. @ % 3
1
MD
!!Y#
)
-. @
^ X
bR
1$ 1+.]% classifier T 1# ) e )1 @ % @ 1#
! u$3
&L f
&Loss Monitor L f
0
) F$%
0 )
^ X
;1
@#
z !Y#
Y# LossMonitor c1
1
)18
' !2 agent 2
' !2 '! 0 S 6 L f @ 1 ^ ; 1$
-.
79
' '
(.
'Y#
L ) )18
proc record {} {
global sink0 f1
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.5
; !2
(.
'Y#
)1. )
'
!!Y# 4 6 ) ' 0
)'
(=
)1.
)1.
!2 1$ @
-8 ) '3
!2 1$ @
# DY6 @
) ' !2 .6 )
' \6 )
(.
(.
'Y# !d.
'Y
.'3 @
$sink0 set bytes_ 0
#Re-schedule the procedure
;1
1C 6
!2 1$
L )
time @
'
'Y 1
v^
)1.
80
; 1$
-. W!# # !$3 @ 1#
! ) LossMonitor
3 !!d.
81
I!
; node_(1) node_(0)
\0
'7
3 >" \$
456
1)
3 2 Y \ n 7.
'7 ) I3 " V z X
I3 " V
$! )
0 I ) I!
0 \0
! (.0 = 0 I
I3 \$
3 2
5V
Q1"1R#
)
2
-. TCP O >#)
I!3 1C !A1# ns ) I!
. 500*500 '7 )
0 \0
'7
0 #)18 )
!a *
3 1 )
H . 1
! ;' 0
) 2 ;' 1
L ># '
F>% )
7-8 ' a I! 0
\0
!
@ )
!>
&(link layer)LL
0\
6X
) '(
L )
(recvtarget()) 3'5M
;' .]3 ' L )
;'
.6 2 linkDely h 0
\6 )
'! )
0 \ C++ h 0 H H !" Z
:sendtarget() 3 '5M
(.0 = @ 0 )
L )
sendto() recnfrom()
'% 2 )
3'. ;' 0
82
'3
) H !" Z
1$
'
*!= H
ARP L' @
L ) LL
'
1% I!
I!
3 2 !
~ ) #Z
-# H TM6 I!
3 2)
'3 1C node_enter_point
) @ MAC Z bR ;'3
(.0 =
MAC Z
83
0' 2
) * !6 h)
ARP ; )
\0 = h)
'0
\6 ) h) 4 '>#
>
\ '
) '(
) \0 = H h)
2 ;:\
1%1 \0 = '
0 '0
-. Ha10 \0 = 6
% ) ' '%
;'
&Interface Queue
8 '. ) ) Z \ 1"
;'! 0 '3
(.0 =
'
!= (. 1"
) ~ns/priqueue . !
^ X
;' *!
PriQueue
!] 4*# =
! u$3 ;'3
&MAC Layer
T 1# 0 \ (distributed coordination function)DCF 1 "
1 "
V= H#
@ 0 s12 s )
RTS/CTS/DATA/ACK
(" )
3
4*# =
MAC 4*# = F
1 "
Z
!=CMU
@ ;'
-. broadcast
!= ) ;' 0
(" )
DATA
* !6 L 0
-.
&Tap Agent
'3
+ (
) ) { .D!6 4$^ *
Tap h 0
3Agent
) T ) ;'3
\6 )
I!
L 0
) .
5# L'
n 7.
T)
s12 s )
) 3
L ) ' I!
;'
^ X '
3 2
) 6 \V T ) H 0 *>
!= Phy/wirelessPhy h 0
3 4C
(>]a ;' 0
;: !, _1 L1X L ! L M.
3 *> ) ; 1
-. L ) '
-.
)' 4f ' 1
!!Y# )1e
I!
(.0 = L )
-.
' !2 *> T ) )
84
direct-sequence
DSSS 1 ) T ) L'
;\
6 5 @ 1# - '
L )
!Cg qL 0 @ 0
!$V# ) spread-spectrum
;'
'
1/(r*r) L1 6 Free-space H
)1C
! zX
L'
-. 1/(r*r*r*r)
2 (] 0 6 \ (6 ) 0 )1X @ $3 ;' 0
;1
48 16
! 1%
)1C
o) L !
&Antenna
;' 0
-. n 7.
3 2
)L 0 (
gain
'
;'! 0 Y%
n 7.
TDMA
802.11 * 0 '
!= n 7.
H omni-directional . H
~ns/antenna
3 *>
. !
^ X
+ MAC
3 Z
NS ) MAC Z
3 2
4*# =
;\
~ns/mac_802.11
. !
&
.* ;' 0
-.
2'a
\
!"
^ X @'
!A1# $0 4*# =
F>% ) 4> )
0\
'!
-V
.
0 )1X @ $3
e) %
; ' .6
) '
e) @
85
-.
(.0 = \6 )
L ) \ )c
D.V
;'! 0
&n 7
(D*# =
;I
-. ns ) n 7.
0 @! ) '1
'0 3 ;' 0
3'0 '! 1#
3 *> )
!]
3 *> ) 0
I!
(D*# = D.V c 1
+ 4*# = c1 ) (a
) 0
3 ]$3 1
\0 = ; .6 '3 1C } -# 1
3 !]
!] s )
e )1 !]
2 'Y# 0
0 '0
!] @ '
+ *>
kV
) 4*# =
!!d# 0 .
!]
'5M H
)1= 1
)$
( d!= 4*# =
!] L '%
.$0
)
]$3
. ! W!# # ) $
0
C
0 2 2 ;' '3 1C U V. )
.$0
0 '3 1C )
\6 )
\0 = L '%
;\
) )
.(
:' 6
)
) ) ;:' .]3
# L '%
-. ' )
2 ;\
!] 0 ' 0
-.
)L )
!]
3 !] ) 'M
3 32 !
@ ]* '5M H
;'5M @
) dmux
3 !] )
) ;' ' 3 1C
L ># ]$3 n 7.
) @ W!# # ) $
L )
<EE
'Y #Z
0
)1=
Z ) ;:C++
!= ~ns/tcl/mobility/dsdv.tcl
'
&DSR
\ o n 7.
3 2 0 '!
!]
$#
4*# =
^ X
\0 = 2 1 Ha ' F>
'! )
(.0 = $# ' n 7.
!]
^ X
-V 4*# =
3 2)
1 @ -.
\0 = 3 DSR agent )
\0 = 2 ; 0 '3 1C L ) 1D%
) ) \0 =
86
^ X
2 ' 0 \ 1C)
:routing agent
!]
!]
(.0 = s
^ X
3 ]$3
= \6 )
(D 6 ) DSR ) ) . !
^ X ;' 0
-.
& TORA
tora
R0 H
h1*Y H !"
'5M h) 4
2H
2 3 ) ;\
'5M \
# \0 =
;)
%1# ; 0 ' 3 1C )
)
) '5M h)
2;1
!]
.]
! '5M h)
) '( \ '5M
!]
3 2 !
% '5M
broadcast )
'0 @ ^ 0 '0
'
) '5M h)
) ; 0 '3 1C L ) ' . 6
.$0 L1X @ $3 0 @
) CLEAR \0 = '5M h)
1.7 @ 0 n =
L1*# =
2H . ; 1
) 1C L '% !
>X ( ) L '%
' 0 \ 1C)
2 1 \6
; 0 '3 1C L ) L '%
(.0 = m$r 4 17#
))
0 '
-.
4*# =
:ad hoc ) \ o kV
3 2
) ;1
@*
"
-.
3 2
]$3 L 5#
( d!=
; ) ) ~ns/tcl/mobility/tora.tcl ~ns/tora ) . !
)15
!!d#
!]
'3
[3 0
HELLO W]a
^ X ;'3
&AODV
$3 .>" 0 ' )
;' 0 $
) '5M
)
!] 3 2 0 \]!
( d!= c1
0 '0
( d!=
Z 0\
D8 6 )
3 !] 0 L 5# H
-.
(* !" ) '(
c1
!] c1
(. O M ) ;: 1
0
'%
$
( d!=
-.
4*# =
@ $3 (
87
U 1% ) '5M T 1# W!# # ) $
'0
kV
-.
3 !]
C a H ) W!# # ) $ ; 1
.] H ) )
H
;' 0
1%1
!] H .] '5
( )
! F
) '0
) 3
L ) ' 0 \ 1C)
2 0
;' .]3 #
L ) 1%1 '5M
3 h)
!]
^ X \ 1C)
D.V '8 M
$#
( )
.2) W!# # ) $
3 !]
#
( d!=
) L 5#
^ X
)18
.6) !
'0
L 5# @ 0 1
z` )
U V.
2 ' 1 \6 )
$ ) I!M.] !,
(.!D
sequence number
' 3 1C )
.$] 0
. @
]$3 H
H )
!] 1
3 2
)15 Hello
Hello
]$3 H
%1.
2H 0
L Y6 ) !] @ 0
]$3
'0
route discovery
beacon
' 1#
'5M
s) 2 ) !] 0
*$ ' .]3 L Y6 !] H
;' 0
;'3
route
%1.
!] L '%
# ' '3 1C ) *# L )
0\
'0 0
) RREQ
0 1
;'3
D7
Aodv
'5M W!# # ) $ H
) 1C L '%
% AODV s ) ;' 0 L ) )
(* !" @ 0 )
0 ' 3 1C \0
+ )
(.!D
>!0 # F
) 4*# =
3 2 $# ; 0
-. DSDV 4*# =
;' )
n 7.
2H ; 1
\6 '
^ X
) ) simple-wirless.tcl 4 6 L f
) 0)
0 I!3 1C
L M.
*> p % 4
I!
L 0
88
) . L' q . c1 4f
'! 0 \
3 . )=
3'0
;I! 0 kV
7!A1# ) ; 0 kV
'
) *> % c 1 '
) !, ad hoc
!>
'. )
!] 4*# = c1 q1 )
(.R *
TM6
)1>
0 \ val() '
-.
3 !!d.
Y#
5.V
0
#
============================================================
==========
# Define options
#
============================================================
==========
set val(chan)
Channel/WirelessChannel ;# channel type
set val(prop)
Propagation/TwoRayGround ;# radio-propagation model
set val(ant)
Antenna/OmniAntenna
;# Antenna type
set val(ll)
LL
;# Link layer type
set val(ifq)
Queue/DropTail/PriQueue ;# Interface queue type
set val(ifqlen)
50
;# max packet in ifq
set val(netif)
Phy/WirelessPhy
;# network interface type
set val(mac)
Mac/802_11
;# MAC type
set val(rp)
DSDV
;# ad-hoc routing protocol
set val(nn)
2
;# number of mobilenodes
;I! 0
set ns_
;I! 0
.
+ ) simulator
1$ H main )
D8 \$] ) L
[new Simulator]
1C 6 ) trace-all() L )
) (
3) 'M I ) '5 0
0
3 . )=
>!. = )1e
3 !!d. @ 4C ) NS ) 0 \
I! 0 @ ! '
D 64 6
;I! 0
kV
I!
89
x,y
kV
kV
) 1C *>
Q1"1R#
' I3 L
; (x=500,y=500) 1
set topo [new Topography]
$topo load_flatgrid 500 500
1
. ) = @ 1 ^ H!*-#
Q1DR#
; 0 L ) Z ) load_flatgrid
) ) god
; 0 I!3 1C +
create-god $val(nn)
^ X
!Cg
) ) 0
-#
L '% n 7.
hop
'Y
!a $3
2 ;' 0
) '(
X) ; 1
'Y 2
;1
@1 0 I3 ; ) ' ^ X
2 3
-. L M.
1 "
'Y [V
!@
)
-.
^ X b= '
)
1C 6 MAC ! T 1# n 7.
0 '!= !!d# %
!> c
( # 1$ H TM6 0 \
;I )
-.
) `2)
;' '
X ) god
'
god
3 2 'Y#
!>
~)
0\
"1$Y
13
1 "
(D 6
Lf ) 'a 3 ; 1
'Y 2 L M.
1 "
3 2 ) ' 1#
)1C $ )
-. 'Y
ns2.1b6 @Q)
-.
(D 6
Lf
(.!D
-. ; 1
^ ;\
) ) God
'Y
31 "
$
'
!>
0 I! 0 *6
; 0
Z1$Y
.$0
Y# ~ns/tcl/mobility/com.tcl) create-god L )
'
3 2 +
!> ) (.0)
! )1 hop 'Y#
@'! )
[!= L -.
) )
-.
3 2
3 API
3API & .*
90
Y# 4
API
;I! 0 '
*!= ) ( ' I! 0 + ) ( *
[!= ) 3 2 0 \
!] 4*# = c1 q : !,
; 0
Y#
>#
]D \V# f
'. )
3 h) c1
*!= API @ 1#
' $3 ) '
;\
; addressingType: flat %
0 on ) routerTtrace agentTrace
! u$3 ;I
kV
; ' kV
3 'D!6
!$+ = )
M 'D!6 !
MAC
@
) !.C
3) 'M
0 on ) ( $3 '! 1#
macTrace
RTR
3 2 L M. 1 on
) n 7.
&\
# Configure nodes
$ns_ node-config -adhocRouting $val(rp) \
4*
$#
3 2
+#
$ ;I
routerTrace ) 'M
movementTrace
'
*!= L f )
91
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-topoInstance $topo \
-channelType $val(chan) \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF
!!d# ) 'Y# 2
@ 1#
) )
+ ) n 7.
\ 1 I!3 1C
;I!3
) ) 3 2 \!Y 1
L M.
\!Y 1 H (
b= I
)0 c
' L Y6 !, + ) 3 2
0 + n 7.
3 2
6 5# \0
0 L ;:\0
#
# Provide initial (X,Y, for now Z=0) co-ordinates for node_(0) and node_(1)
#
$node_(0) set X_ 5.0
$node_(0) set Y_ 2.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 390.0
$node_(1) set Y_ 385.0
!]
92
3 2 L M. >" ;(390,385) ) 1 2
#
# Node_(1) starts to move towards node_(0)
#
$ns_ at 50.0 "$node_(1) setdest 25.0 20.0 15.0"
$ns_ at 10.0 "$node_(0) setdest 20.0 18.0 1.0"
# Node_(1) then starts to move away from node_(0)
$ns_ at 100.0 "$node_(1) setdest 490.0 480.0 15.0"
!> 50 ! o ) 0 \
\^
!] !!d#
# )1.
15m/s \^
&I! 0
x=25,y=20 '5M
;' .]3 n 7.
3 2 L M.
! ) *!6 # L
) n 7.
3 2 *> % @ 0 reset
>!
2
1# @
! TCP L 5# H ) 0
31)
' $3 L
; 0
93
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at 150.0 "$node_($i) reset";
}
$ns_ at 150.0001 "stop"
$ns_ at 150.0002 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
global ns_ tracefd
close $tracefd
}
$ns_ halt" is called at
) @ 3 2 ' '3 1C 1.
;' '3 1C
1C 6 trace 4 6 .] @ 0 " C
!> 150 ! o )
!>
&\ 1 I!3 1C 1 )
4 6 C ) )
!> c
)1.
I3 C )
'Y
6 H ) 3 2 .>" ' ) [ $
) 1)
' 4 04 6L
simple-wireless.tcl
# A simple example for wireless simulation
#
===========================================================
===========
# Define options
#
===========================================================
===========
set val(chan)
Channel/WirelessChannel ;# channel type
set val(prop)
Propagation/TwoRayGround ;# radio-propagation model
set val(netif)
Phy/WirelessPhy
;# network interface type
set val(mac)
Mac/802_11
;# MAC type
set val(ifq)
Queue/DropTail/PriQueue ;# interface queue type
94
set val(ll)
set val(ant)
set val(ifqlen)
set val(nn)
set val(rp)
LL
;# link layer type
Antenna/OmniAntenna
;# antenna model
50
;# max packet in ifq
2
;# number of mobilenodes
DSDV
;# routing protocol
#
===========================================================
===========
# Main Program
#
===========================================================
===========
#
# Initialize Global Variables
#
set ns_
[new Simulator]
set tracefd [open simple.tr w]
$ns_ trace-all $tracefd
# set up topography object
set topo
[new Topography]
$topo load_flatgrid 500 500
#
# Create God
#
create-god $val(nn)
#
# Create the specified number of mobilenodes [$val(nn)] and "attach" them
# to the channel.
# Here two nodes are created : node(0) and node(1)
# configure node
$ns_ node-config -adhocRouting $val(rp) \
95
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0
}
#
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
#
$node_(0) set X_ 5.0
$node_(0) set Y_ 2.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 390.0
$node_(1) set Y_ 385.0
$node_(1) set Z_ 0.0
#
# Now produce some simple node movements
# Node_(1) starts to move towards node_(0)
#
$ns_ at 50.0 "$node_(1) setdest 25.0 20.0 15.0"
$ns_ at 10.0 "$node_(0) setdest 20.0 18.0 1.0"
# Node_(1) then starts to move away from node_(0)
$ns_ at 100.0 "$node_(1) setdest 490.0 480.0 15.0"
96
97
98
I.-3 456
!> ) (.!D
H!6 # L M.
I!
kV
1)
) 0
scen-3-test
'7 H 4C
L M. 4 6 H
Z M. 0 I 0 % ) I!
(D 6 +
*>
1)
2 ? Z M. 0 0 I!3 1C Y L f
!~ %;' 1
-.
D> [V )
) ' a 3 ;'
+ 1 '
6 5# L M. scen-3-test 4 6 ;'
(D 6 ! a;\ ~ns/tcl/mobility/scene h) ) L M.
G [V ) L M.
(D 6
;\ 670m*670m Q1"1R# H 4C )
@1^ 4 6
1 "
(D 6 ) h .
\ ns F 1#
-.
@ 1#
; 0 I!3 1C
H!6 # 1 " 4 6 H
1%1
W5
1 )
'!3 1C
\R *
' 1#
! ( 0'1
+ n 7.
H!6 # F>% )
(.0 = 0 0 + n 7.
. !
3 !a '! 0 '3
;\ cbr-3-test @
2 ? ! TCP CBR
)4 6
)
)
3 2 ! ! 3 H!6 # 3 2 L M.
~ns/tcl/mobility/scene h) ) ! 4 6
.$]
( % @ 1#
2 ;' 1 L ) 1D%
-.
' 1#
; 0 I!3 1C
0'1
4 6
^
' 1C
;\
) \6 ) qL ) ' 1#
*!6 #
31 " ! a ;\6 2
) ) ( E [V ) 0 ' 1
99
wireless1.tcl ) @
C \R * c
@
: !,
6 5# '^ ' 0 +
Y# 0 D>
3 !!d.
'7 q 2 L M. 4 6 q O >#)
) 0I
0 6A
^ ;I ) `
1 "'
!> @ 0
3 . )=
1.
set val(chan)
Channel/WirelessChannel
set val(prop)
Propagation/TwoRayGround
set val(netif)
Phy/WirelessPhy
set val(mac)
Mac/802_11
set val(ifq)
Queue/DropTail/PriQueue
set val(ll)
LL
set val(ant)
Antenna/OmniAntenna
set val(x)
670 ;# X dimension of the topography
set val(y)
670 ;# Y dimension of the topography
set val(ifqlen)
50
;# max packet in ifq
set val(seed)
0.0
set val(adhocRouting) DSR
set val(nn)
3
;# how many nodes are simulated
set val(cp)
"../mobility/scene/cbr-3-test"
set val(sc)
"../mobility/scene/scen-3-test"
set val(stop)
2000.0
;# simulation time
!] 4*# = @ 1 ^ (dynamic source routing)DSR
;I! 0
! u$3 ; 1
I
0 + 0 )
.6 !!d# ? n 7.
3 2 'Y#
@ 0 trace
*>
! u$3
wireless1-out.tr 4 6 simulator 1$
*!6 2
)18
#I
)0
'Y
) ! ) (network animator)nam
;'3 @
L i
)18
100
) val(cp) val(sc)
> 0 O >#)
1 "
(D 6
3 2 L -. :n 7.
3 2 +
;' ' 3 1C
-.
F>
'Y 'Y 2 )
)15 ' '
Y#
#
# Define node movement model
#
puts "Loading connection pattern..."
source $val(cp)
#
# Define traffic model
#
puts "Loading scenario file..."
source $val(sc)
& 1 '3 1C
!>
2 L M. )1.
) scen-3-test 4 6 2
!> 50 ! o ) 0 \
< 2
;' I!3 1C
TC
!>
rC 4 6
! u$3 ; 0 '3 1C \0
$god_ set-dist 1 2 2
#10 0 \
god
'
3 2 ! !]
# #10 > 7
6 5# waypoint I. )1 "
8 5.C @
8 5.C
-. hop
;1
-.
) L M.
^ X
) god
# #10 god
^ X
^ X
1 "
' 1#
~)
; ) _ !.
;'
) @
) `2 )
2
@ 1#
)1.
TC
< 9 2 ! !]
0 '
!>
#
X)
) G E [V ) 0 setdest
(D 6 : 1
! u$3 scen-3-test 4f (D 6
;' 0
;' 0 ) `2
' 1#
(~ns/indep-utilities/cmu-scen-gen/setdest/calcdest) ' 12
S 6 ' a calcdest
;1
-. god
^ X
'
+ L M.
calcdest @
1 "
(D 6 !]-#
101
2 ; 0 '3 1C 4$^ \ )
@
' > W
) `2) 4 6 3 4*
. )
\ 6
.( ' 0 ) '
) 4 6 ad-hockey
) $
\ 6 2 @1a )
2 ;\
) L M.
0 + $ 0 ) L M.
1 " 4 6H
@ ! ) @
ad-hockey
!Cg bR
!]
0' 0
> 7
1 )
;'! 0 L $^ !
)18 )
'
1C b= ; '
@ 1#
0\
1%1 L M.
(*# = )
!!d#
!( !] L1X 4!D7#
\ ) \ 6
) 3 2 ! hop 'Y#
e6 8 Y
1 "
% C 4 6 ' 1V
!> ) ) . L' X C
) I3
) I3 1 )
'7
monarch Q = T 1# '
god
0 !] L1X
^ X
&4
L M.
'3
% C)
)
1 "H )
^ X q'0
-.
!]
-. ad-hoc *>
'
CMU 0 # ^ X
-. @ *
Q1"1R# !!d# x @ 0 kV
( V
(*# = : ^ X
'
b 06
">
;1
' a 3 ;I! 0
)
6A )
.!] @' I2
(D 6 '
; ' a CMUTrace \0 = 3
]$3 ) ) 4 0 god
1 " 4 6 O1rC ) )
'3
-. ' 1#
wireless1.tcl 4 6
>!. = 1 3 I!
)
%1#
31 )
6 A ) CMUTrace 4 6
^ X
3'
102
1 "
(D 6 0 ' 1
) \R *
)1.
0 !Cg ) wireless1.tcl 4 6 L
m$r
/ # L ;'
1%1 Z ) '
.-2 6 [!=
;'
!!d# \R *
3 )1.* ) L M.
' $!
1 "
O >#)
;'! 0 %
ns wireless1.tcl
4 6 nam % C 4 6
!!d# X C
wireless1-out.tr
; 0 '!3 1C '3
) 2
CMUTrace % C 4 6 % @' 4 0
\0
nam 4 6
'7 _) C < P 2 4 6
! u$3 ; 0 '3 1C 1
3 \ < P
'Y
on/off
3 ) 'M
trace
% Cq
) ; 0 '3 1C L $^ ) \R * 4C movementTrace
3 1 )
'7 ) 9 2 ; 0 ' 1V 1
; 0 '3 1C
&'! 0
I3
!] ) < P !
(.0 =
) wireless1.tcl 4 0 4 6
) L
wireless1.tcl
# A simple example for wireless simulation
#
===========================================================
===========
103
# Define options
#
===========================================================
===========
set val(chan)
Channel/WirelessChannel
set val(prop)
Propagation/TwoRayGround
set val(netif)
Phy/WirelessPhy
set val(mac)
Mac/802_11
set val(ifq)
Queue/DropTail/PriQueue
set val(ll)
LL
set val(ant)
Antenna/OmniAntenna
set val(x)
670 ;# X dimension of the topography
set val(y)
670 ;# Y dimension of the topography
set val(ifqlen)
50
;# max packet in ifq
set val(seed)
0.0
set val(adhocRouting) DSR
set val(nn)
3
;# how many nodes are simulated
set val(cp)
"../mobility/scene/cbr-3-test"
set val(sc)
"../mobility/scene/scen-3-test"
set val(stop)
400.0
;# simulation time
#
===========================================================
==========
# Main Program
#
===========================================================
===========
#
# Initialize Global Variables
#
# create simulator instance
set ns_
[new Simulator]
104
105
# to the channel.
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0
}
#
# Define node movement model
#
puts "Loading connection pattern..."
source $val(cp)
#
# Define traffic model
#
puts "Loading scenario file..."
source $val(sc)
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} {incr i} {
# 20 defines the node size in nam, must adjust it according to your scenario
# The function must be called after mobility model is defined
$ns_ initial_node_pos $node_($i) 20
}
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).0 "$node_($i) reset";
}
$ns_ at $val(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
106
107
I. 3 456
I!
;' 0
*>
*>
I!
O >#) +
I!3 1C W!0 # I!
-.
3 LAN
*> H
wireless1.tcl 4 6 %
>!0 #
!>
( V )
0 + I!
) 4>
) b= ;' 0
;\ `2 I!3 1Cwireless2.tcl I!
3 *>
Q1"1R# 0 '
L ) .] n 7. !,
I
4>
L 5# 1 )
( V ) '
ZF 1
*>
[V
3 2 n 7.
4 6
)@
C ) \
31)
*$
108
I!
getaway ' $3 =
) Lf
Q1"1R#
0\
.]
4* ;' 3
2 c1 ! \0 = L >#
I!
>!0 # 1 )
.]
2H
node0,1,2 I!
I!
% '0
4$^ I!
@
3 1
;'3
'. ;I! 0
) , ) 1C ) 0 wireless1.tcl 4 6 c
@ ' I!
I!
!!d# )
!>
3 2 ! CBR TCP
1# @
) 0 0 I!3 1C
0 I!3 1V
-. opt() )
) 3 !!d. \]!"
X >#)
-.
val() )
1 " 4 6
-.
;\
!!d# DSDV
.6
D> O >#)
!!d# @ 0 Ha L
ad-hoc
!] 4*# =
+ ) 0 '!
\]# \R * ) TM6 @
.
'7
\ ;
1>
!!d#
I!3 1C
Z1X !!d.
Y# 1
) TCP
( %c
! u$3
160.0
170.0
;' 1
-.
.]
I!
3 2 'Y#
Y#
O1rC
set num_wired_nodes
2
set num_bs_nodes
1
1
! (.0 = W!# # )
Q1"1R# )
1D%
Z 5#
>#
=
]D
I!
3 2
) L ) L '%
!]
)18
0I)
Z 3
ns ) U
!]
Z 5#
;3 2
!] 3 ]$3 ! ad-hoc
!> W!0 #
D8 [V ) L
^ X ;I! 0
!6 d% L 5#
-. I!
1 ah
3 2 ) 0 'a 3 ; 1
!]
(*# = 1D%
I!
3
Y ;' .]3
-. I!
) L ) L '%
23
-.
109
L 5# 1
! 0 0 I!3 1C
) 0 >#
]D ) .C
-.
.]
I!
I!
@ ! + ) 0 cluster
1(- ) : 1
3 2 ! (.0 = L >#
3 1
3 1 ;' 0
;'! 0 6 A )
b=
)
Y# ' ) [ $
]D
Q1"1R# bR
H 3) 3 .
1 )
)
0 'Y# ;:I!
3.
1 4C
.
;:'! 0
3 trace
!>
0)
2 ) (a
Z 4*
0 '!
I!
) 3 1
1 ) L
]D
3 '1
+ I!
) '
I!
) trace )
I!e # *> 4* @'
'Y# ; 1
Y# 2 1
0' '
\ ; 0 I!3 1C I!e # )
;I! 0
'. ) Z O1rC )
H 3 ) 3 2 'Y# 'Y TC ; )
1% :I!
( 0\
) 2
Q1"1R#
1 ) 0 ) )
0
]D h) c1
3 2
\ W#
.
*!= >#
I!
Y# ) 3 .
Y# % C 4 6 @ $3
WL '
'
# 2 :I!
1 1 4 0 ' 0
I!
'
I! 0
1% .
H 3)
3 1
0 9 :I!
2H 0 )
Y# Q1"1R#
;' )
) tracing
!>
3 1
-# ;' 1
) nam
1%
'Y 2 )
\
*$
. 1 wireless2-out.tr
! u$3 ;' 1
110
$ 3 2
+
$# +
'!
\ ;I! 0 + )
.]
I!
qI!
3 2'
) 2 3 >#
]D h)
;'! 0 6 A I!
3 2
@
.]
) 0 I! 0 '
3 2 )
;\
.]
!"
'
!* \
3 2
*>
'! )
-. I!
'! )
(.0 =
n 7.
=
;'
domain0
b= :9 P ' .6 2 )
)
1%
@ !
1
'% .
1 H TM6 I!
I!
%
0
I!
!
) ;I! 0
) I!
' )
=
.]
@ ! ) W#
;I ) I!]!
.]
I!
$!e # 0 \
!] @ 0 ON
3 1 +
.]
2 ' I!
+ 17 L f
2 .
)
Z'0
D.V
3 *>
_) C
*>
]D
3 2
2 0 \ I( ) !]
]D
) =
3 2 ) ;' '3 1C @ !
!] ad-hoc )15 I!
3 2
O >#)
0 I!3 1C '
1 ) n 7.
.]
3 2 1 @ $3 )
!> H b= ;' 0
!>
.$]
! gateway
3 2
$# 0 )1r 1 ' 3 1C I!
>#
3 *>
'Y ; !2
I!
.]
*!= 4
&' 0 L $^ )
; 2'a
I!
Z ( ) 0 ' .]3 1
;' ' 3 1C L )
I!
.] @ 1 ^
0 n 7.
!]
2 +
3 node-config
=
0I)
3 2 + bR
; 1 4 '>#
3 2
-.
*!= ) 2 ) .C
domain1 I!
0 1
@!
2L
*>
( )
111
h)
) ;\
* ( h)
'.
' .]3 1 H ) 3 2 $3 b= .
;'! 0
'% 1
;I!
) 2
) ) I!
1
Y (>#
2
]D
I! 1#
Z
'3
) (
0 H ! u$3
=
.]
0).0(first node in
node
in
1.0.2(third
I!3 ) P 1 @ $3 ) ) I!
I! 0 W!0 # I3 ) 3 .
0 I! 1#
I!
cluster)
cluster)
node)
I! 1#
Q1"1R#
112
3 2
I!
113
n 7.
\ ns
1$^
3 2
^ X .!
1# cp , sc F>
0'
'
) %
3 2 ! H!6 # '! 0 % ) 1 )
3 2 ! H!6 # I 0 @ !
2 ; 0
3'0
C '
) ) ( '
> 0 )1X @ $3 ) I!
.>" ;:ns
"+ )
3 2 n 7#
" V \(% )
) wireless2.tcl 4 0 '0
wireless2.tcl
# simulation of a wired-cum-wireless scenario consisting of 2 wired nodes
# connected to a wireless domain through a base-station node.
#
===========================================================
===========
# Define options
#
===========================================================
===========
set opt(chan)
Channel/WirelessChannel ;# channel type
set opt(prop)
Propagation/TwoRayGround ;# radio-propagation model
set opt(netif)
Phy/WirelessPhy
;# network interface type
set opt(mac)
Mac/802_11
;# MAC type
set opt(ifq)
Queue/DropTail/PriQueue ;# interface queue type
114
set opt(ll)
LL
;# link layer type
set opt(ant)
Antenna/OmniAntenna
;# antenna model
set opt(ifqlen)
50
;# max packet in ifq
set opt(nn)
3
;# number of mobilenodes
set opt(adhocRouting) DSDV
;# routing protocol
set opt(cp)
set opt(sc)
""
;# connection pattern file
"../mobility/scene/scen-3-test" ;# node movement file.
;# x coordinate of topology
;# y coordinate of topology
;# seed for random number gen.
;# time to stop simulation
160.0
170.0
set num_wired_nodes
2
set num_bs_nodes
1
#
===========================================================
=================
# check for boundary parameters and random seed
if { $opt(x) == 0 || $opt(y) == 0 } {
puts "No X-Y boundary values given for wireless topology\n"
}
if {$opt(seed) > 0} {
puts "Seeding Random number generator with $opt(seed)\n"
ns-random $opt(seed)
}
# create simulator instance
set ns_ [new Simulator]
# set up for hierarchical routing
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 2
;# number of domains
lappend cluster_num 2 1
;# number of clusters in each domain
AddrParams set cluster_num_ $cluster_num
115
lappend eilastlevel 1 1 4
;# number of nodes in each cluster
AddrParams set nodes_num_ $eilastlevel ;# of each domain
set tracefd [open wireless2-out.tr w]
set namtrace [open wireless2-out.nam w]
$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
# Create topography object
set topo [new Topography]
# define topology
$topo load_flatgrid $opt(x) $opt(y)
# create God
create-god [expr $opt(nn) + $num_bs_nodes]
#create wired nodes
set temp {0.0.0 0.1.0}
;# hierarchical addresses for wired domain
for {set i 0} {$i < $num_wired_nodes} {incr i} {
set W($i) [$ns_ node [lindex $temp $i]]
}
# configure for base-station node
$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channelType $opt(chan) \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace OFF \
-macTrace OFF
#create base-station node
116
set temp {1.0.0 1.0.1 1.0.2 1.0.3} ;# hier address to be used for wireless
;# domain
set BS(0) [$ns_ node [lindex $temp 0]]
$BS(0) random-motion 0
;# disable random motion
#provide some co-ord (fixed) to base station node
$BS(0) set X_ 1.0
$BS(0) set Y_ 2.0
$BS(0) set Z_ 0.0
# create mobilenodes in the same domain as BS(0)
# note the position and movement of mobilenodes is as defined
# in $opt(sc)
#configure for mobilenodes
$ns_ node-config -wiredRouting OFF
for {set j 0} {$j < $opt(nn)} {incr j} {
set node_($j) [ $ns_ node [lindex $temp \
[expr $j+1]] ]
$node_($j) base-station [AddrParams addr2id \
[$BS(0) node-addr]]
}
#create links between wired and BS nodes
$ns_ duplex-link $W(0) $W(1) 5Mb 2ms DropTail
$ns_ duplex-link $W(1) $BS(0) 5Mb 2ms DropTail
$ns_ duplex-link-op $W(0) $W(1) orient down
$ns_ duplex-link-op $W(1) $BS(0) orient left-down
# setup TCP connections
set tcp1 [new Agent/TCP]
$tcp1 set class_ 2
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp1
$ns_ attach-agent $W(0) $sink1
$ns_ connect $tcp1 $sink1
set ftp1 [new Application/FTP]
117
118
}
# Tell all nodes when the simulation ends
for {set i } {$i < $opt(nn) } {incr i} {
$ns_ at $opt(stop).0 "$node_($i) reset";
}
$ns_ at $opt(stop).0 "$BS(0) reset";
$ns_ at $opt(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
$ns_ at $opt(stop).0001 "stop"
proc stop {} {
global ns_ tracefd namtrace
# $ns_ flush-trace
close $tracefd
close $namtrace
}
# informative headers for CMUTracefile
puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp \
$opt(adhocRouting)"
puts $tracefd "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"
puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"
puts "Starting Simulation..."
$ns_ run
119
120
I( 456
I!
@ $3 I ) '5
) I!
Q1"1R# H ) MobileIP +
I
L ;I 0 + ) =
1 @ $3 1 )
! ForeginAgent(FA)
.]
-.
) I!
) ) MobileIP
I!
.]
>!. = D>
! u$3 I ) W1
1)
W0 2
;I )
121
' ) [ $
4 ^
1
#Z 5# ! a ;\ 45. FA HA Y %) C
4* )
1% MobileHost(MH) 2
C4 ^ ! 0 )
MH 0 . ;I!
) HA
;:' $
+ MH
'3
(.0 = L ) I!3 1C
FA 1
!!d#
set opt(nn)
set opt(stop)
sc cp
(D 6
!!d# )
1
250
3 2 ! TCP CBR
sc 4 6 ) ;' 1 L ) 1D%
) ' 1% 4 6
!> @ = @
n 7.
\0
%) C
_) C HA 1
Y 1C
3'0 $# )
3 2 'Y#
FA
)0
@*
"M
! ) TCP L 5# 0 I ) '5
( % cp 4 6 0 )
1C @1a L f
;I! 0 $
-.
I 0
-. 4> ) 0
1 )
(.0 = 0
0 + n 7.
Q1"1R# H 4C ) 3 2
6 5# L M.
) \6 ) qL ) ' 1#
""
""
;I! 0
set opt(ftp1-start)
;' 0
;# just one MH
;\
set opt(cp)
set opt(sc)
2 { ;\
) wireless2.tcl
0 I!3 1C [
I! 0 + MH L M.
4* ) 0 )1X @ $3 1
1C ) 0 ) !A1# )18
;I!3
roaming n 7.
MH W0 ! TCP @ % H 0 I ) '5
C 4 ^ W1 I!
100.0
kV
) TCP@ % c
)1.
122
.]
32
-. 1 )
I!3
Y
!!d#
)1.
) I!
' '3 1C
)15 HA,FA
>!. = 4$^ +
;' '3 1V
set num_wired_nodes
]D
1
Y#
1 H 0
I! 0
;I!3
D]D
h) \ 6 '
3 . )=@
+ ns
1$ 0 TC < 'Y
) ;'! 0 6 A ) H Q1"1R# W#
r
I! 0
FA
kV
(D 6 'Y \$] )
) `2
1 ) ;' '3 1C
(
3 h)
:< 9
Py9yP 0.0.0 @ $3 I!
0 1 ' 3 1C .
:P 1
I!
) FA =
1 H
Q1"1R#
0 H# @ $3 ) 0 I ) ) MH n 7.
0 I!
.] H
I!
2 HA =
.]
9 I!
1 ) ;\ 1.0.1 1.0.0
0 '3 1C \0
FA 1
MH
123
.* ; 0 I!3 1C + ) FA HA
>X
3 2 ) .C
# I! 0 on ) MobileIP
.]
(# 2H
O1
flag '
0\
' '
> I!
3 2
0
-.
124
' I 0 )
) HA ' L
C 4 ^ @1^
;I! 0 OFF n 7.
COA care-of-address @
;' 12
I3 MH 0
h)
1
!> ) ; 1
!!d# FA
'0
'!= !!d#
.]
MH 2 ; '
Y# n 7.
) L
0 ) h) H MH 2 ;I! 0
k!5V# MH
2 +
:MH n 7. @ !
( !
" 0
.] h) :\ @ 4C ) @1 0
MH 4C COA
. !
^ X
!"
)18
HA
; 0 '3 1C '!=
) mip.tcl, ns-wireless-mip.tcl}
0 I!3 1C + ) FA/HA I!
3 2 ! 3link
125
'
.]
0 1
0\
*$ '! 0
;\ wireless2.tcl ' $3 1 )
' $!
;'! 0 '3
1 \ 1 )1r \
$ kV
% )1)
MH
*$ 0 .6)
' L )
3 1
(.0 = )18
) 0'
.]
1 H
MH 2 0 \
' \>o @ 1 2
"
1 @
trace 4 6 ) ; 1
@ $ !
) n 7. @ ! L M. nam
; 0 '3 1C !!d# MH 1
;' $
wireless3.tcl
'3
!!d# )
+0
% C ;'
) wireless3.tcl 4 0 1 )
126
""
""
;# x coordinate of topology
;# y coordinate of topology
;# random seed
;# time to stop simulation
100.0
set num_wired_nodes
2
#set num_bs_nodes
2 ; this is not really used here.
#
===========================================================
===========
# check for boundary parameters and random seed
if { $opt(x) == 0 || $opt(y) == 0 } {
127
128
129
# movement of the MH
$MH set Z_ 0.000000000000
$MH set Y_ 2.000000000000
$MH set X_ 2.000000000000
# MH starts to move towards FA
$ns_ at 100.000000000000 "$MH setdest 640.000000000000 610.000000000000
20.000000000000"
# goes back to HA
$ns_ at 200.000000000000 "$MH setdest 2.000000000000 2.000000000000
20.000000000000"
# create links between wired and BaseStation nodes
$ns_ duplex-link $W(0) $W(1) 5Mb 2ms DropTail
$ns_ duplex-link $W(1) $HA 5Mb 2ms DropTail
$ns_ duplex-link $W(1) $FA 5Mb 2ms DropTail
$ns_ duplex-link-op $W(0) $W(1) orient down
$ns_ duplex-link-op $W(1) $HA orient left-down
$ns_ duplex-link-op $W(1) $FA orient right-down
# setup TCP connections between a wired node and the MobileHost
set tcp1 [new Agent/TCP]
$tcp1 set class_ 2
set sink1 [new Agent/TCPSink]
$ns_ attach-agent $W(0) $tcp1
$ns_ attach-agent $MH $sink1
$ns_ connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns_ at $opt(ftp1-start) "$ftp1 start"
# source connection-pattern and node-movement scripts
if { $opt(cp) == "" } {
puts "*** NOTE: no connection pattern specified."
set opt(cp) "none"
} else {
puts "Loading connection pattern..."
130
source $opt(cp)
}
if { $opt(sc) == "" } {
puts "*** NOTE: no scenario file specified."
set opt(sc) "none"
} else {
puts "Loading scenario file..."
source $opt(sc)
puts "Load complete..."
}
# Define initial node position in nam
for {set i 0} {$i < $opt(nn)} {incr i} {
# 20 defines the node size in nam, must adjust it according to your
# scenario
# The function must be called after mobility model is defined
$ns_ initial_node_pos $node_($i) 20
}
# Tell all nodes when the siulation ends
for {set i 0} {$i < $opt(nn) } {incr i} {
$ns_ at $opt(stop).0 "$node_($i) reset";
}
$ns_ at $opt(stop).0 "$HA reset";
$ns_ at $opt(stop).0 "$FA reset";
$ns_ at $opt(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
$ns_ at $opt(stop).0001 "stop"
proc stop {} {
global ns_ tracefd namtrace
close $tracefd
close $namtrace
}
# some useful headers for tracefile
puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp \
$opt(adhocRouting)"
131
132
I3 456
I!
2 ! H!6 # 1 )
31 )
H!6 # 1 " 4 6 +
' 0 + \R *
-.
CBR TCP Z 5# )
' 1#
h.
n 7. I!
3 2 ! L 5#
(*!6 # +
@ 1#
4*
)1.
CBR L 5# \"
b= ;I! 0 kV
) 1
.C
n 7.
cbrgen.tcl @
;' 12
Z H!6 # 4 6 H
) q 0 + (
-. CBR
6 5# H!6 #
1 '3 1C
+ ) ; 0
! @ 1#
3
-.
0 #Z 5# 'Y#
(.0 = !
> 7
;1
! o 180 ) 'M
;' $ Y%
f0 '
6 5#
cbrgen.tcl \R *
)15 TCP/CBR
H!6 # ' 0 +
Z 5#
!= ) ) . !
(
^ X
133
seed ) 'M
! u$3 9yP
L 5# J f0 '
2 9P ! CBR L 5# 4 6 H
;'! 0 / # )
Lf
)1.
ByP x
ns cbrgen.tcl -type cbr -nn 10 -seed 1.0 -mc 8 -rate 4.0 > cbr-10-test
; 1 '3 1C
!> CBR Z 5#
* :CBR ' 0 +
% C cbr-10-test 4 6 )
b=
#
# 2 connecting to 3 at time 82.557023746220864
#
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(2) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $node_(3) $null_(0)
set cbr_(0) [new Application/Traffic/CBR]
$cbr_(0) set packetSize_ 512
$cbr_(0) set interval_ 0.25
$cbr_(0) set random_ 1
$cbr_(0) set maxpkts_ 10000
$cbr_(0) attach-agent $udp_(0)
$ns_ connect $udp_(0) $null_(0)
$ns_ at 82.557023746220864 "$cbr_(0) start"
F! cbr-10-test 4 6
)
E J 2
'
(. ) ; 1
+
+ <
Z 5# 'Y# c1$+
?
'1
2 ! UDP L 5# H Z ) W!# #
'
U V. P9P
3 2 !
: 3' . 6
;' )
'3 1C
!> L f H ;I !2
e ) tcp ) type %
) TCP Z 5# +
4>
1 " ' $3
;1
134
;' '3 1C
!> tcp-15-test 4 6
1$ L 5# H
#
# 5 connecting to 7 at time 163.0399642433226
#
set tcp_(1) [$ns_ create-connection TCP $node_(5) TCPSink $node_(7) 0]
$tcp_(1) set window_ 32
$tcp_(1) set packetSize_ 512
set ftp_(1) [$tcp_(1) attach-source FTP]
$ns_ at 163.0399642433226 "$ftp_(1) start"
135
I3
I!
) ) ns W5
31 )
3 2 L M.
1 "4 6 +
~ns/indep-utils/cmu-scen-gen/setdest h) ) 3 2 L M.
-. dev/random C
0 RNG h 0 F 1#
4 R 0 )1e
456
;: )
setdest
;' 0
1C 6 6 5# '^ +
. ! 4$ \!D
.>" 0 \
'
% '
-.
;'! 0 L > )
)0
ns @ 0 build )
4 6 H )0
bR
+ ) setdest
;'! 0 % ) make
: 0 '3 1V -. Tclcl
1 " '0 +
3 V .0
makefile H ) 0
V .0 F 1#
6 5# '^ +
( 2 setdest.cc @ 0
.6) ns \ (6
;: 1
.6) indep-utils/cmu-scen-gen/setdest
( # Q) ' '3 1C + ~ns/rng.cc
4M.]
; 0 '3 1C + ) % 4 setdest
;'! 0 %
( $2)
) setdest 4 6
136
! !
10.0m/s \^
0 \0
Q1"1R#
'7
I! 0
f0 '
1. ! o <PP
0 2 <P
'Y )
3 2 L M.
!>
1)
;\ 2s
0 I ) '5
; 1 '3 1C
H I!3 1C
+ )1.
Z M.
L
! b*
500*500
b= ;'
unix
' c
3 2 !" \!Y 1
% C
)1.
4 6
;' 0
% C
) % C
Y# ) 3 2 Z M.
node_(0) 2
'1
-.
!] !!d#
' 1#
)1.
O1rC
scen-20-test ) Z TC
kV
1.37m/s \^
;' 0 \0
; 1 kV
(General
;'
'
~)
) ) '
>
2 L M. 4 6 ) GOD
)1r 3
'3
D0
;\]! ' .C
3 2
;\
2 H @'! )
@
0 )
^ X
&
# #10
!>
TC 4f ' 1
n 7.
3 2
:Directives 3 $ 3 )
Operations Director)GOD
!> ) ' 0 \0
! )1 hop '^
'0 $ > 7
!Cg
44.89)
) H
(.$]
$#
!Cg
TM6 god
3 ) ) '^
god
\
;1
3 2
@1 0 I3
-.
) `2 ) god
L -.
) BG <? 2
! !] ) hop 'Y# Z )
1 "4 6
^ X
137
! u$3 (D 6
;' 0
6 5# waypoint I. )1 "
\ 6 +
+ god
^ X
' > W
\ 6 2 0 )
2 ;\ c1
@ ! ) @
!]
ad-
0' 0
> 7
\ ) \ 6
1 )
) L M.
@ 1#
0\
1%1 L M.
e6 8 Y
1 "
) 4 6 calcdest 2 ; 1
) @
) `2)
.( W
) 4 6 hockey
) $
!> ) ) . L' X C
) I3 1 )
'7
monarch Q = T 1# '
god
0 !] L1X
^ X
L M.
'3
% C)
)
1 "H )
-.
!]
-. ad-hoc *>
'
CMU 0 # ^ X
-. @ *
Q1"1R# !!d# x @ 0 kV
( V
(*# = : ^ X
'
b 06
">
(
1
!!d# q 3 !] c1$+ q h .
) I3
&4
^ X q'0
(D 6 !]-#
(D 6 '
; ' a CMUTrace \0 = 3
]$3 ) ) 4 0 god
1 "
1 " 4 6 O1rC \ 6 ) ) S 6
1 "
) 3 2 ! hop 'Y#
1C b= ; '
Z 5#
X1rC
Z M.
% C 4 6 ' 1V . )
'
!( !] L1X 4!D7#
-.
ad-hockey
!Cg bR
)18 )
(*# = )
) `2 )
0 1
' 0 ) ) L M.
;'! 0 L $^ !
!!d#
^ X god
8 5.C
(D 6 setdest
) 2 L M.
4 ~ns/indep-utils/cmu-scen-gen/setdest ) 0calcdest Y
-.
4
;1
!,
3'5M
2 3
-. ' 1#
'Y# ' $3 # ^ X 2 L M.
) '( n 7.
(D 6
^ X n 7.
(. )
3 2
138
139
I3
I!
! [!=
. H I!
.]= @
'
*> )
; 0 I!3 1C ) 0 ns )
("'
2 3 * !6 Z ) ; 1
\6 )
456
1 ) ) . L'
'
-.
!=
("'
456
.6 ) L ! :power @ 1#
'! ) \0 = 3
\6 ) L ! @ 1# 2 1
;1
1 )
\6 ) \0 = 0 .
z` MAC Z T 1#
&)
1%
'
1% \6 )
) rC .] @
1 ) ) . L'
ns )
~ns/tworayground.{cc,h}
("'
;\
!=
1%1 ~ns/shadowing
I!M.]
!] H
" Y ; )' )
;1
) )
(
! Y
-.
.( ) L 0 ) . T
!3 0 )1r )
' . 6 d D8 6 ) :
1% ' . 6
0 '0
S 6 L'
' !2 ! Sight)LOS
6 L' )
.6 ) L ! @ 1#
140
! u$3 ;\
. 6 ' !2 . gain
3 ) 'M 3
\
_1 L1X
.6 ) L !
4C ) ' !2 2 ;'3
-. node-config )1.
Lf H ; 0
@ 1#
) . L' @
) 'M
L=1 9
)15 ) ' . 6 L 5#
@ 1#
0 r
;'
'
)'
) gain
'7
) '. 6
) h.
;'
6 L'
(.0 = $# ' 1#
OTcl T ) )
) @
-.
)1.
-.
s)
2
o
! F @ ' ! I!M.] !]
I!M.] !, I!M.] !]
;1
d D8 6
-.
\ ) ) !] F
3
0 1
.6 ) L ! @ 1# > 7
1 @'
S 6 ^Y
6H .
) . L' ) ;'.6
:;' 1
'! # b*Y"
. ! \
Z1X 48 16 ) L'
;1
} -# .$0
3L !
0 ' \ o
> 7
L1 6
141
L ) 'M ! %
) ;'
( . :height c -#)
' !2
'D
+ )
.C
L' L1 6
>!0 # X C
'
FX M. D8 6 ) ; 1
.Y
@ 1# @' I2 ' 0
'3
;1
-.
13'
I0 d ) 'M 0 . S1^ ) ;\ c Y
:cross over FX M. D8 6 H L'
> 7
;I! 0
> 7
Z " Y
@ 4!"
2 ;1
'!= [ 6 D8 6 0
)18
!, )
-. ) . L'
Y#
!!d#
-. Free Space
' '3 1C
L1 6 ) FX M. D8 6 b= ;
@ 0
'3 1C ) +!. H
)1.
)1.
@ 1#
-.
! u$3
&:Shadowing Model
*6
) . L'
142
0' 0
S6
W . 0\
3 ' 0
> 7 \6 ) D8 6
6 5# !!d. H !Y D8 6 H )
2 ' 17
!o #
.]2
' 0
0 "'
!o #
H L 5#
!] ' a ) .
> 7 ) L ! @ 1# D8 6
-. F% @ 1 ^
D> L'
!2
' T 1# D>
@' H
) ;\
)
6) . ) <
1%
L1 6 @ 1#
0\
! +#
!o #
-.
" ;\ \$]
L'
! [!=
' > 7
*6
L1 6
) d D8 6 )
\>]
@ 1#
3) 'M 0 '
'7
fading effects
) ;' 12
) 'M 0 I!
;\ shadowing L' 1
D8 6 @ ;' 0
'3
.2)
2 ' I2 L'
;\
.6 ) @ 1# \M!M ) ;\ )
Y #H
^1
'! ) @ 1# ! ! 1
3 ) 'M
) 'M
!!Y#
L '%
. ! D8 6 0 .
D.V 3 T!7 ) .
& 0 I !2
+!. 4> L1 6 b= ; 1
3) 'M
!2 ' dB 4>!
Z1$Y !]
2 ' I2
143
H F
.6) I3
) @ ;)
) b= ;\ '
!Y D8 6 H ) '! ) L ! @ 1# )
'
!2 ' 4>!
) 2L
F 1# >X 0 \
;1
;\
C
) !Y z 7
L '% ) ;'
: -8
\ '
I0
@ ) 'M
;I
1$
Y 1#
# 1
A ) L' H
(r!7 )
*6
) 1 )
'7
'7 >" ) 0 .
*6
D.V
3) 'M
z 7
)
) 'M
3 ) 'M
1) )
6 5# !!d.
6 5# !!d. H
' 12
0@! $
z 7
$. ) " L
\$]
D0 L1 6 shadowing L'
*6 -8 Y
! +#
shadowing L'
!!d#
)15 ' 1#
*6
TM6 3 2 @ ) 0
L'
144
: !]
2 ' I2 > 7 ) @ 1#
;I! 0
U V. '
L f TM6 3 . ) =
!> ) I!3 1C
3) 'M 0 \
) 0 shadowing L' @ 0
3 ) 'M '
1$ H
0
)1.
!> T7!
>X )
-.
*6
;\ node-config )1.
z 7
1 3 OTcl T )
;' .]3
;' 0
pre-
D>
-. ' 1#
3 '0 ;' $ Y%
)1.
I! 0
ns F %
-.
$3) '
s)
) <Ey9 [V
0 I!3 1V
H shadowing L'
=
! seed c1
raw seed
pre-defined seed
huristic seed
'! 1#
. ! ^
2 0' 0
-. defined seed
;' 1
145
) Z ) seed c1
&O >#) :
I!
3 2 !
1 )
;'
D8 6 0 '
*> T ) ) \6 )
'5 \
.
'7
) 0 H 3 Application
*$
)0
C )
;' 0 kV
.
'0 $
> 7
~ns/indep-utils/propagation/threshold.cc ) '%
> 7
2 ; 0
@
-. 456
'! 1#
) '
$ :1
~) ) .
("'
$#
% 4 6 4 R 0 'Y '
;'! 0
@ 1#
;'
threshold @
-.
H ! u$3
'! 0 4 R 0
1 )
'7
Y 4> )
kV
* <propagation-model> %
.-2 L'
X >#) distance
. W]
) . L' ) ; 1
'
-.
6 [!=
D8 6 @ ) ) !78 \6 ) x
D8 6 \ TwoRayGround or Shadowing
3 . )=
@ 0 kV
[other-option]
NE 0 '!3 1V $
-. \6 )
;'! 0 > 7
;1
)1.
) . '
0 \ r <receive-rate> Z . ) = H shadowing
$ ' 1 \6 )
> 7
* 4!"
;' 0
(inverse Q-function) Q
. EP D8 6 )
. )
(.0 = '8)
146
;\
' ) [ $
) [other-option]
3 ) 'M
&
&I
H ) ' .-2
0 \]!" 8 C )1r ) ) .
("'
)1.
)1.
3) 'M <propagation-model> ) I! 1#
0 \ ) . L' U V.
)1.
!!Y#
s)
)1.
; !2
1C
'Y )1.
;\
147
> 7
) )
~ns/indep-utils/propagation/threshold.cc ) 0 threshold
;1
-. l C X >#)
'7 ) \6 )
148
I3 ! 456
ns )
6 5#
3 !!d.
F$.+
A )
+
;\
;' 1
>!. =
*a10 ^1$+ 1C ) ns
!=
) A ) F 1#
!!d#
C L ) @1 0 I3 )
\6
( ) ) ' 1#
456
!> ; )
) '
# F 1#
!>
1C )
(" )
' 0 '!"1# )
'Y# )
' H
6 5# '^ 4M.]
)
4* ;'
H @ %
' 0 '!"1#
( % ' 1#
3 ;'
@ %
' 0 '!"1# 4 0 )
;'3
) ( %
!= H 4
RNG h 0
' 1#
;: '^ @ .6 I3
( %
r
'0 3
[!= 6 5# '^
( %W # 2 1 a ) )
*!6 2
149
6 5#
3 !!d. 2 ; 1
. ;' 0
.C
'% RNG
-.
'Y 6 5# '^
@ 1.! ) 0
!>
!"
\]
6 5# !!d. 3 '
;' 1 4M.]
) :defaultRNG
3 ) 'M @
M
'
-.
# :; 1
;\
b*!6 M! @ $ 3 . ) =
@ !$X
f0 '
'% @ %
# # '3
3 ) 1$ *
H ) *# 3
) @*
!=
;1
'
H 0
f0 '
3) # I )
6 5# '^
2' a
= '^ H
2' a 4M.]
!> 3)
-.
-.
6 5# !!d.
!> H
;:I! 0 ) *# )
!> H )
+ RNG ' '%
H!# 1# )1r 1
6 5# '^ q 'Y @ % c
6 [!= RNG H
3) *# WD,
! '1
( % @ 1 4M.]
150
'^
Z ' 1#
) *# H )
6 5# !!d. 3 ;I!
) 4M.]
3 ) *#
^ X
;I
!A1# + ) ) L1$Y F 1#
;'! 0 Y%
0\
1R$3 [!= ) 6 5#
e ) +
.*
3'0
= seed ) 'M ) 0
-. 4M.]
;'!3 !!d# P
. '
!= ) ( %
1R$3 I3
\!D
"@
1%1 F 1#
\!Y>X @
) defaultRNG ) 'M
3 ) *# ) 3 seed I!e #
$ ;'
' > s)
'% seed
-. I3 @
C ' ) @ !!d#
!!Y
T 1# '
1%
'5
; 1 '3 1C ' ) $ H
)
)#
( % 0
1R$3 '^ @ 0 . ) 2
&L f
151
global defaultRNG
$defaultRNG seed 9999
# create the RNGs and set them to the correct substream
set arrivalRNG [new RNG]
set sizeRNG [new RNG]
for {set j 1} {$j < $run} {incr j} {
$arrivalRNG next-substream
$sizeRNG next-substream
}
# arrival_ is a exponential random variable describing the time
# between consecutive packet arrivals
set arrival_ [new RandomVariable/Exponential]
$arrival_ set avg_ 5
$arrival_ use-rng $arrivalRNG
# size_ is a uniform random variable describing packet sizes
set size_ [new RandomVariable/Uniform]
$size_ set min_ 100
$size_ set max_ 5000
$size_ use-rng $sizeRNG
# print the first 5 arrival times and sizes
for {set j 0} {$j < 5} {incr j} {
puts [format "%-8.3f %-4d" [$arrival_ value] \
[expr round([$size_ value])]]
}
& 1 '3 1C
% ns rng-test.tcl 1
6.358 4783
5.828 1732
1.469 2188
0.732 3076
4.002 626
% ns rng-test.tcl 5
0.691 1187
0.204 4924
8.849 857
4*
% C
152
2.111 4505
3.200 1143
&OTcl ) 3
;' 1
\6 tools/rng.cc 4C )
'3 1C ' ) $ H
'1
10@
OTcl ) RNG h 0
' 1#
>!. =
)1.
;' 2
;' 2
; 'Y @ %
; 10@ %
) ' . ) !Y z 7
! ! H
'.
@ %
F 1# H
z 7
! ! H
I. ) " L
F 1# H
;'
\6 tcl/lib/ns-random.tcl )
'
-. OTcl 4C ) ' 1#
+ ) ' . ) !Y
RNG h 0 )
)1.
;' 1
;'
max min
+ mu
) \C 1 * F 1# H
$ F 1# H
;\ k-1 P ! \C 1 * F 1# H
153
&L f
4*
3 % C
154
187.972 4982
% ns rng-test2.tcl 5
160.993 4907
119.895 4956
149.468 5131
137.678 4985
158.936 4871
&C++ ) 3
Y# tools/rng.h )
;'
@ %
'
e ) + ) '
;\
&' 3
seed I!e # '
seed=0 2
seed
~) )
;' 2
;\ MAXINT P ! !78 '^ 0 ' 2
; 10@ %
@ %
; 'Y @ %
;\ k-1 P ! \C 1 * F 1# H
.\ r P ! \C 1 * F 1# H
b a ! \C 1 * F 1# H
)' .
L $^ h 0 1 ^ F 1#
10@
>X
;'
+ 9yP
$ F 1# H
.*
6 5# '^
;[0,1]
>!. =
155
+ k
$ F 1# H
F 1# H
F 1# H
+ ) ' . ) !Y z 7
! !
+ ) ' . ) !Y z 7
! ! H
I. ) "
&L f
3 % C
6 5#
3 !!d.
161.826 506
160.591 503
157.145 509
137.715 507
118.573 496
156
'^ @ %
'3
(.!D
H>
Z H RandomVariable h 0
Y# ~ns/ranvar.h ) h 0
&'
; ) ) 6 [!= 6 5#
8C
3) 'M
F 1# 3 ;' '
;1
&' $
.6 2 l C
-. F 1# H
'3
) 'M @'
3 F 1#
!=
h 0
Y# @1 0 I3 0
0
. )=
3 F 1#
)1r 0 6 5# !!d. H
+ )1e
1$
;\ h .
&'! 0 ) )
4 OTcl ) RandomVariable h 0
)1.
+ [10,20] ! \C 1 *
157
$u set min_ 10
$u set max_ 20
$u value
-. 4> \$] ) '
&
RandomVariable
H @ 1#
6 [!= )1r
use-rng '.
;' 0
0 '0
: . 1!= L
(> M#
&'
Integrator
h 0
Y# ~ns/integrator
& integrator.h 4 6
158