LAN Example in ns2
(Obsolete: work with ns-2.1b4a)
This section contains a pointer to an example LAN simulation script and shows its network topology and simulation scenario. Download "ex-lan.tcl" file that is modified a little bit from "ns-2/tcl/ex/lantest.tcl" and examine it yourself.
Figure 32. LAN simulation network topology and scenario
Multicasting Example
(Obsolete: work with ns-2.1b4a)
Figure 33. The NAM screen capture of the multicasting simulation
NS FAQ
- Is there an NS tutorial somplace?
Try: http://www.isi.edu/nsnam/ns/tutorial/
- How do setup to use NS on nile?
Add/users/ns/bin
is in your path:
set path=(/users/ns/bin $path) # for csh/tcsh
Make a working directory for your scripts:
cd /users/claypool mkdir my-sim
Then, make sims and run normally.
- How do setup to modify NS (edit the simulator) on nile?
Check that you are part of the "ns" group:
groups (if you don't see "ns" send email to claypool@cs)
Set yourCVSROOT
variable (for tcsh):
setenv CVSROOT /users/cvsroot (put in your .tcshrc)
Make a working directory:
cd /users/claypool mkdir my-ns
Check out ns-2:
cd /users/claypool/my-ns cvs co ns-2
Link in supporting directories:
cd /users/claypool/my-ns ln -s /users/ns/* . (will give error for ns-2 link, but that's ok)
Compile ns:
cd /users/claypool/my-ns/ns-2 make
Make sure your scripts now use your NEW ns under/users/claypool/my-ns/ns-2/ns
! Then, make sims and run normally.
To edit a file:
cd /users/claypool/my-ns/ns-2 (edit file) (compile, debug, test, compile, debug test...) (MAKE SURE YOUR CODE COMPILES AND WORKS BEFORE SUBMITTING) cvs commit
To add a file:
cd /users/claypool/my-ns/ns-2 (edit new file) (compile, debug, test, compile, debug test...) (MAKE SURE YOUR CODE COMPILES AND WORKS BEFORE SUBMITTING) cvs add cvs commit
- Where are some sample scripts I can start from?
Many sample scripts can be found in the NS distribution in/users/ns-2/ns-2/tcl/ex
and/users/ns/ns-2/tcl/test
. You might also try/users/ns/ns-2/tcl/ns-tutorial/
.
- Entering flows by hand is a pain. How do you "generate", say, 200 flows automatically?
You can do so with a for loop. Here is an example:
####################### # Creat Network Topology # ####################### #Set number of TCP connections set tcp_num 50 #Making two network nodes set n(1) [$ns node] set n(2) [$ns node] #Making edge nodes for {set i 1} {$i <= $tcp_num} {incr i} { set s($i) [$ns node] set r($i) [$ns node] } #Creating the network link $ns duplex-link $n(1) $n(2) 20Mb 20ms DropTail #Creating edge links for {set i 1} {$i <= $tcp_num} {incr i} { $ns duplex-link $s($i) $n(1) 20Mb 5ms DropTail $ns duplex-link $n(2) $r($i) 20Mb 5ms DropTail } ######################### # Setup FTP-TCP connections # ######################### #Setup TCP for {set i 1} {$i <= $tcp_num} {incr i} { set tcp($i) [new Agent/TCP/Reno] set sink($i) [new Agent/TCPSink] $ns attach-agent $s($i) $tcp($i) $ns attach-agent $r($i) $sink($i) $ns connect $tcp($i) $sink($i) $tcp($i) set ecn_ true $tcp($i) set fid_ $i $tcp($i) set window_ 20 $tcp($i) set packetSize_ 1000 } #Setup FTP Applications for {set i 1} {$i <= $tcp_num} {incr i} { set ftp($i) [new Application/FTP] $ftp($i) attach-agent $tcp($i) $ftp($i) set type_ FTP } ########################## # Start FTP Applications # ########################## for {set i 1} {$i <= $tcp_num} {incr i} { $ns at 0 "$ftp($i) start" $ns at 80 "$ftp($i) stop" } $ns run
- How do I measure things like packet loss, throughput, etc?
You pull data you need from the trace file NS produces. That file is in text format, so you can parse it by whatever tools you would like. For example, to calculate throughput you'd look for how many packets arrived per second at a node coming from another node maybe with the protocol TCP.
- Where are the defaults kept for the NS objects?
/users/ns/ns-2/tcl/lib
- Are there some tools somewhere that do some things I would like?
Not as many as we'd like. But there is a start in:/users/ns/tools
- Does NS simulate the 3-way TCP handshake?
Yes. You set thesyn_
variable to TRUE inAgent/TCP
in order to simulate the 3-way handshake. In ns-2.1b7a, syn_ is set to FALSE by default. However since ns-2.1b8, the default setting for syn_ has been changed to TRUE.
- I get the exact same drops every time with my RED router. Is there a way to "seed" the NS random number generator?
You do it with the RNG class from OTcl. For example, a new RNG is created and seeded with:
set rng [new RNG] $rng seed 0 # seeds the RNG heuristically; $rng seed n # seeds the RNG with value n;
Other uses could be:
$rng next-random # return the next random number; $rng uniform a b # return a number uniformly distributed on [a, b]; $rng integer k # return an integer uniformly distributed on [0, (k-1)]; $rng exponential # return a number from an exponential distribution # with average 1.;
Currently there is no way to select predefined seeds from OTcl.
No comments:
Post a Comment