NS2 Simulator 2008 01 31 Contents About NS
NS-2 Simulator 최종훈 2008. 01. 31.
Contents ± ± About NS Installation ® Based on Linux ® Based on Windows ± ± Architecture Using NS-2 Example References 2
About NS History ± NEST – Testbed ® Columbia University ± REAL network simulator ® UC Berkley in 1988 ± NS-1 ® In 1995 ® VINT project at LBL, Xerox PARK, UCB, USC/ISI ± NS-2 ® In 1996 ® C++ and OTCL developed by MIT instead of TCL ± NS-3 ® started on July 1, 2006 3
About NS Introduction ± ± ± Discrete event simulator Targeted at network research Packet-level Link layer and up Wired and wireless 4
About NS Platforms ± Most UNIX and UNIX-like systems ® Free. BSD or Net. BSD ® Linux ® Sun Solaris ± Windows 9 x/2000/XP ® With Cygwin (http: //www. cygwin. com/) ® With VMWare (http: //www. vmware. com/download/player/) 5
About NS Functionality of NS ± Wired ® ® ± Point-to-point link, LAN Unicast/multicast routing Transport Application layer Wireless ® Mobile IP ® Ad hoc routing ® Sensor network ± Tracing, visualization, various utilities 6
Installation Getting NS-2 ± Getting the pieces or everything at once ® http: //www. isi. edu/nsnam/ns/ns-build. html ± Current Version ® Sep. 3, 2007 : ns-2. 32 released. ® Mar. 10, 2007: ns-2. 31 released. ± Getting manuals ® http: //www. isi. edu/nsnam/ns/tutorial/index. html ® http: //www-sop. inria. fr/maestro/personnel/Eitan. Altman/COURS- NS/n 3. pdf ® http: //www. isi. edu/nsnam/ns/ns-documentation. html ® http: //nile. wpi. edu/NS/ 7
Installation on UNIX system tar -xzf ns-allinone-2. 29. 3. tar. gz cd ns-allinone-2. 29. /install Please put /home/myusername/ns-allinone-2. 29/bin: /home/myusername/ns-allinone 2. 29/tcl 8. 4. 11/unix: /home/myusername/ns-allinone-2. 29/tk 8. 4. 11/unix into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph. IMPORTANT NOTICES: (1) You MUST put /home/myusername/ns-allinone-2. 29/otcl-1. 11, /home/myusername/nsallinone-2. 29/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> 8
Installation on UNIX system (2) You MUST put /home/myusername/ns-allinone-2. 29/tcl 8. 4. 11/library into your TCL_LIBRARY environmental variable. Otherwise ns/nam will complain during startup. (3) [OPTIONAL] To save disk space, you can now delete directories tcl 8. 4. 11 and tk 8. 4. 11. They are now installed under /home/myusername/ns-allinone-2. 29/{bin, include, lib} cd ns-2. 29. /validate 9
Installation on Windows system ± http: //nsnam. isi. edu/nsnam/index. php/Running_Ns_and_Nam_Und er_Windows_9 x/2000/XP_Using_Cygwin ± http: //www. cygwin. com/ ± Since version 2. 1 b 9, ns has used Cygwin/gcc instead of Visual C++ 10
Architecture Object-Oriented ± ± C++ and OTcl Modular approach ® Reusability ® Maintenance ± Data/Control separation ® Scalability ® Split C++/OTcl object ® C++ for data ® Per packet action ® OTcl for control ® Periodic or triggered action 11
Architecture Class Hierarchy 12
Architecture Directory Structure ns-allinone Tcl 8. 0 TK 8. 0 OTcl tclcl. . . tcl ex examples test validation tests ns-2 lib nam-1 C++ code mcast . . . OTcl code 13
Using NS Problem Result analysis Simulation model Modify ns Setup/run simulation with ns 14
Using NS Interactive Mode # ns % set _o 3 % $ns 1 % $ns 2 % $ns Hello # ns [new Simulator] at 1 “puts “Hello World!”” at 1. 5 “exit” run World! 15
Using NS Batch Mode simple. tcl set $ns $ns ns [new Simulator] at 1 “puts “Hello World!”” at 1. 5 “exit” run # ns simple. tcl Hello World! # 16
Using NS Tutorial-1 set ns [new Simulator] set nf [open out. nam w] $ns namtrace-all $nf set tf [open out. tr w] $ns trace-all $tf proc finish {} { global ns nf tf $ns flush-trace close $nf close $tf exec nam out. nam & exit 0 } $ns at 5. 0 "finish" $ns run Create the simulator object Open a file for nam trace data Open a file for trace data “finish” procedure Closes the trace file and starts nam Execute the finish procedure after 5. 0 seconds 17
Using NS Tutorial-2 set n 0 [$ns node] set n 1 [$ns node] $ns duplex-link $n 0 $n 1 1 Mb 10 ms Drop. Tail Creates two nodes and assigns them to the handle “n 0” and “n 1” connect the nodes n 0 and n 1 with a duplex link with the bandwidth 1 Megabit, a delay of 10 ms and a Drop. Tail queue 18
Using NS Tutorial-3 set udp 0 [new Agent/UDP] $ns attach-agent $n 0 $udp 0 set cbr 0 [new Application/Traffic/CBR] $cbr 0 set packet. Size_ 500 $cbr 0 set interval_ 0. 005 $cbr 0 attach-agent $udp 0 set null 0 [new Agent/Null] $ns attach-agent $n 1 $null 0 $ns connect $udp 0 $null 0 Create a UDP agent and attach it to node n 0 Create a CBR traffic source and attach it to udp 0 Create a Null agent and attach it to node n 1 Connect the two agents 19
Using NS Tutorial-4 $ns at 0. 5 "$cbr 0 start" $ns at 4. 5 "$cbr 0 stop" tell the CBR agent when to send data and when to stop sending 20
Using NS Visualization Tools ± nam-1 (Network Ani. Mator Version 1) ® Packet-level animation ® Well supported by ns ± xgraph ® Convert from ns trace to xgraph format 21
Using NS NAM set nf [open out. nam w] $ns namtrace-all $nf 22
Using NS xgraph set tf [open out. tr w] $ns trace-all $tf <event> <time> <from> <to> < pkt> > <seq > <attr > pkt> <size> -- <fid> < src> <dst> <seq> <attr> + 1 0 2 cbr 210 ------- 0 0. 0 3. 1 0 0 - 1 0 2 cbr 210 ------- 0 0. 0 3. 1 0 0 r 1. 00234 0 2 cbr 210 ------- 0 0. 0 3. 1 0 0 ± raw 2 xg를 이용한 xgraph 변환 ± <DIR>/ns-allinone-2. 29/ns-2. 29/bin/raw 2 xg ± Raw 2 xg –a out. tr > out. xg 23
Using NS xgraph 24
Example 25
- Slides: 26