1 / 70

NS-tutorial

NS-tutorial. 2003. 5. 14 통신 프로토콜 설계와 해석 HPMN Lab. 석사 2 학기 한제찬. Contents. Part I. NS(Network Simulator) 소개 NS(Network Simulator) reference site NS Status and Modules NS 설치 방법 - on window, on linux Part II. NS Architecture NS 구성 – C++, tcl Part III. Wired Simulation in NS

ella
Download Presentation

NS-tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NS-tutorial 2003. 5. 14 통신 프로토콜 설계와 해석 HPMN Lab. 석사 2학기 한제찬

  2. Contents • Part I. NS(Network Simulator) 소개 • NS(Network Simulator) reference site • NS Status and Modules • NS 설치 방법- on window, on linux • Part II. NS Architecture • NS 구성 – C++, tcl • Part III. Wired Simulation in NS • Part IV. Wireless Simulation in NS • Part V. Tracing & Monitoring • Trace file • nam HPMN Lab.

  3. Part I. NS Introduction

  4. Ns Goals • Support networking research and education • Protocol design, traffic studies, etc • Protocol comparison • Provide a collaborative environment • Freely distributed, open source • Share code, protocols, models, etc • Allow easy comparison of similar protocols • Increase confidence in results • More people look at models in more situations • Experts develop models • Multiple levels of detail in one simulator HPMN Lab.

  5. Ns Status • The most recent release (ns-2.26, Feb 2003) • Periodical release (ns-2.1b9a, July 2002) • Stability validation • http://www.isi.edu/nsnam/ns/ns-tests.html • Platform support • FreeBSD, Linux, Solaris, Windows and Mac HPMN Lab.

  6. Ns Functionalities • Wired • Routing DV, LS, PIM-SM • Transportation: TCP and UDP • Traffic sources:web, ftp, telnet, cbr, stochastic • Queuing disciplines:drop-tail, RED, FQ, SFQ, DRR • QoS: IntServ and Diffserv • Emulation • Wireless • Ad hoc routing and mobile IP • Directed diffusion, sensor-MAC • Tracing, visualization, various utilities HPMN Lab.

  7. “Ns” Components • Ns, the simulator itself • Nam, the network animator • Visualize ns (or other) output • Nam editor: GUI interface to generate ns scripts • Pre-processing: • Traffic and topology generators • Post-processing: • Simple trace analysis, often in Awk, Perl, or Tcl HPMN Lab.

  8. Ns Models • Traffic models and applications: • Web, FTP, telnet, constant-bit rate, real audio • Transport protocols: • unicast: TCP (Reno, Vegas, etc.), UDP • Multicast: SRM • Routing and queueing: • Wired routing, ad hoc rtg and directed diffusion • queueing protocols: RED, drop-tail, etc • Physical media: • Wired (point-to-point, LANs), wireless (multiple propagation models), satellite HPMN Lab.

  9. Installation(1/2) • Getting the pieces • Tcl/TK 8.x (8.3.2 preferred): http://resource.tcl.tk/resource/software/tcltk/ • Otcl and TclCL: http://otcl-tclcl.sourceforge.net • ns-2 and nam-1: http://www.isi.edu/nsnam/dist • Other utilities • http://www.isi.edu/nsnam/ns/ns-build.html • http://www.isi.edu/nsnam/dist HPMN Lab.

  10. Installation(2/2) • http://www.isi.edu/nsnam/ns/ns-build.html • Building ns on Linux • Source : ns-allinone-2.26.tar.gz • Building ns on windows • Source • tcl8.3.2.tar.gz • tk8.3.2.tar.gz • tclcl-src-1.0b12.tar.gz • otcl-1.0a8.tar.gz • ns-src-2.1b9a.tar.gz • Building ns-2/nam under cygwin HPMN Lab.

  11. Help and Resources • Ns and nam build questions • http://www.isi.edu/nsnam/ns/ns-build.html • Ns mailing list: ns-users@isi.edu • Ns manual and tutorial (in distribution) • TCL: http://dev.scriptics.com/scripting • Otcl tutorial (in distribution): ftp://ftp.tns.lcs.mit.edu/pub/otcl/doc/tutorial.html HPMN Lab.

  12. Part II. NS Architecture

  13. Ns Architecture • Uses both C++ and OTcl • Object-oriented (C++, OTcl) • Modular approach • Fine-grained object composition HPMN Lab.

  14. C++ and OTcl Separation • “data” / control separation • C++ for “data”: • per packet processing, core of ns • fast to run, detailed, complete control • OTcl for control: • Simulation scenario configurations • Periodic or triggered action • Manipulating existing C++ objects • fast to write and change HPMN Lab.

  15. Otcl and C++: The Duality • OTcl (object variant of Tcl) and C++ share class hierarchy • TclCL is glue library that makes it easy to share functions, variables, etc C++ C++/OTcl split objects otcl HPMN Lab.

  16. tclcl • The code to interface with the Otcl resides in the directory, ‘tclcl’ • The six classes defined in ‘tclcl/’ • Class Tcl • Class TclObject • Class TclClass • Class TclCommand • Class EmbeddedTcl • Class InstVar • Refer Chapter 3. OTcl Linkage of NS Manual HPMN Lab.

  17. Class hierarchy • Class hierarchy (contributed by Antoine Clerget) “http://www-sop.inria.fr/planete/software/ns-doc/ns-current/” HPMN Lab.

  18. Part III. Wired Simulation in NS

  19. Ns programming • Create the event scheduler • Turn on tracing • Create network • Create transport connection • Create traffic • Setup routing • Insert errors HPMN Lab.

  20. Creating Event Scheduler • Create event scheduler set ns [new Simulator] • Schedule events $ns at <time> <event> • <event>: any legitimate ns/tcl commands $ns at 5.0 “finish” • Start scheduler $ns run HPMN Lab.

  21. Creating Event Scheduler • Finish function 정의 proc finish {} { global ns nf tracefd $ns flush-trace close $nf close $tracefd exit 0 } $ns at <time> “finish” HPMN Lab.

  22. Turn on tracing • Packet tracing • On all links: set <변수명> [open filename mode] $ns trace-all $<변수명> Ex) $ns tracefd [open out.tr w] $ns trace-all $tracefd • Visualize trace in nam set 변수명 [open *.nam w] $ns namtrace-all $<변수명> HPMN Lab.

  23. Creating Network • Nodes set n0 [$ns node] set n1 [$ns node] • Links and queuing $ns <link_type> $n0 $n1 <bandwidth> <delay> <queue_type> • <link_type>: duplex-link, simplex-link • <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR, diffserv RED queues Ex) $ns duplex-link $n0 $n1 0.1Mb 100ms DropTail HPMN Lab.

  24. Creating Network: LAN $ns make-lan <node_list> <bandwidth> <delay> <ll_type> <ifq_type> <mac_type> <channel_type> <ll_type>: LL <ifq_type>: Queue/DropTail, <mac_type>: MAC/802_3 <channel_type>: Channel HPMN Lab.

  25. Creating Connection and Traffic FTP/Telnet TCP connection TCP TCPsink Node 0 Node 1 Duplex link CBR/Exp UDP connection TCP NULL Node 0 Node 1 Duplex link HPMN Lab.

  26. UDP set udp [new Agent/UDP] set null [new Agent/Null] $ns attach-agent $n0 $udp $ns attach-agent $n1 $null $ns connect $udp $null UDP details Chapter 30 of ns Manual Creating Connection and Traffic HPMN Lab.

  27. Creating Connection and Traffic • CBR set cbr0 [new Application/Traffic/CBR] • CBR details $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 • Locate CBR on transport layer $cbr0 attach-agent $udp • Exponential or Pareto on-off set src [new Application/Traffic/Exponential] set src [new Application/Traffic/Pareto] HPMN Lab.

  28. TCP set tcp [new Agent/TCP] set tcpsink [new Agent/TCPSink] $ns attach-agent $n0 $tcp $ns attach-agent $n1 $tcpsink $ns connect $tcp $tcpsink TCP details Chapter 31 of ns Manual Creating Connection and Traffic II HPMN Lab.

  29. Creating Connection and Traffic II • FTP set ftp [new Application/FTP] $ftp attach-agent $tcp • Telnet set telnet [new Application/Telnet] $telnet attach-agent $tcp HPMN Lab.

  30. Example1b.tcl • Trace file • Packet trace : out.tr • Nam trace : out.nam • Topology • Two nodes: n0, n1 • Duplex link • Udp and cbr Example1.tcl HPMN Lab.

  31. Example1b.tcl # Create NS simulator instance set ns [new simulator] # Create trace files - nam file set tf [open out.tr w] $ns trace-all $tf set nf [open out.nam w] $ns namtrace-all $nf # Create topology - nodes and links set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n1 1Mb 10ms DropTail # Create transport protocol set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 set null0 [new Agent/Null] $ns attach-agent $n1 $null0 $ns connect $udp0 $null0 # Create Traffic set cbr0 [new Application/Traffic/CBR] $cbr0 set packetsize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 # Define finish function proc finish{} { global ns nf $ns flush-trace close $nf exit 0 } # Setup evnets $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" $ns at 5.0 "finish" # Run NS $ns run HPMN Lab.

  32. Inserting Errors • ErrorModel types • Class ErrorModel/Uniform • Class ErrorModel/Expo • Class ErrorModel/Empirical • Two state error model • Multi state error model HPMN Lab.

  33. Inserting Errors -Uniform • Creating Error Module set loss_module [new ErrorModel] $loss_module set rate_ 0.01 $loss_module unit pkt $loss_module ranvar [new RandomVariable/Uniform] $loss_module drop-target [new Agent/Null] • Inserting Error Module $ns lossmodel $loss_module $n0 $n1 HPMN Lab.

  34. Setup Routing • Unicast $ns rtproto <type> <type>: Static, Session, DV, cost, multi-path • Multicast $ns multicast (right after [new Simulator]) $ns mrtproto <type> <type>: CtrMcast, DM, ST, BST • Other types of routing supported: source routing, hierarchical routing HPMN Lab.

  35. Creating Traffic: Trace Driven • Trace driven set tfile [new Tracefile] $tfile filename <file> set src [new Application/Traffic/Trace] $src attach-tracefile $tfile <file>: • Binary format (native!) • inter-packet time (msec) and packet size (byte) HPMN Lab.

  36. Marking flows • $<agent name> set class_ <fid> ex) $udp0 set class_ 1 • $ns color <fid> <color> ex) $ns color 1 Blue HPMN Lab.

  37. Creating a larger topology • for 구문 for {변수 초기화} {조건} {변수 값 변경} { … } • 변수 초기화: set <변수 명> <값> • 조건: $<변수 명> • 변수 값 변경 Ex) for {set I 0} {$I < 7} {incr I} { set n($I) [$ns node] } Ex) for {set I 0} {$I <7} {incr I} { $ns duplex-link $n($I) $n([expr ($I+1)%7]) 1Mb 10ms DropTail } HPMN Lab.

  38. Link failure • 특정 시각에 link 끊기 $ns rtmodel-at <time> down $<node name> $<node name> • 특정 시각에 끊긴 link 다시 연결하기 $ns trmodel-at <time> up $<node name> $<node name> HPMN Lab.

  39. IV. Wireless Simulation in NS

  40. Running Wireless Simulations in ns • define components and options of mobile nodes • creating an instance of the simulator • setup trace support • create a topology object • create the object GOD • create mobile nodes • create agent and traffic • setup Event HPMN Lab.

  41. ad-hoc network(1/8) • define components of mobile nodes At the beginning of a wireless simulation, we need to define the type for each of these network components. HPMN Lab.

  42. ad-hoc network : Ex_wireless1.tcl (2/8) • creating an instance of the simulator Set ns_ [new Simulator] • setup trace support Set tracefd [open ex_wl1.tr w] $ns_ trace-all $tracefd • create a topology object Set topo [new Topography] $topo load_flatgrid 500 500 • create the object GOD Create-god $val(nn) HPMN Lab.

  43. ad-hoc network : Ex_wireless1.tcl(3/8) • Topology Object : keep track of movement of mobile nodes • God (General Operations Director) : the object that is used to store global information about the state of the environment & network • total number of mobile nodes • a table of shortest number of hops required to reach from one node to another. • The next hop information is normally loaded into god object from movement pattern files, before simulation begins. • the God object is called internally by MAC objects in mobile nodes. HPMN Lab.

  44. # $ns_ node-config -addressingType flat or hierarchical or expanded # -adhocRouting DSDV or DSR or TORA # -llType LL # -macType Mac/802_11 # -propType "Propagation/TwoRayGround" # -ifqType "Queue/DropTail/PriQueue" # -ifqLen 50 # -phyType "Phy/WirelessPhy" # -antType "Antenna/OmniAntenna" # -channelType "Channel/WirelessChannel" # -topoInstance $topo # -energyModel "EnergyModel" # -initialEnergy (in Joules) # -rxPower (in W) # -txPower (in W) # -agentTrace ON or OFF # -routerTrace ON or OFF # -macTrace ON or OFF # -movementTrace ON or OFF ad-hoc network : Ex_wireless1.tcl (4/8) • create mobile nodes • Node configuration HPMN Lab.

  45. ad-hoc network : Ex_wireless1.tcl (5/8) 2. Create the 2 mobile nodes set node_(0) [$ns_ node ] $node_(0) random-motion 0 ;# disable random motion set node_(1) [$ns_ node ] $node_(1) random-motion 0 3. Give nodes position to start with $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 HPMN Lab.

  46. ad-hoc network : Ex_wireless1.tcl (6/8) 4. Set node movements $ns_ at <time> “$<node name> setdest <목적위치> <속도> Ex) $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“ HPMN Lab.

  47. ad-hoc network : Ex_wireless1.tcl (7/8) • create agent and traffic set tcp [new Agent/TCP] $tcp set class_ 2 set sink [new Agent/TCPSink] $ns_ attach-agent $node_(0) $tcp $ns_ attach-agent $node_(1) $sink $ns_ connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns_ at 10.0 "$ftp start" HPMN Lab.

  48. ad-hoc network : Ex_wireless1.tcl (8/8) • Define Events • Reset mobile nodes $ns_ at 150.0 “$node_(0) reset” $ns_ at 150.0 “$node_(1) reset” • Simulation stop $ns_ at 150.0001 "stop" $ns_ at 150.0002 "puts \"NS EXITING...\" ; $ns_ halt“ proc stop {} { global ns_ tracefd close $tracefd } puts "Starting Simulation..." $ns_ run HPMN Lab.

  49. Using node-movement files & traffic-pattern files • Node-movement file • CMU’s node-movement generator • Traffic-pattern file • CMU’s TCP/CBR traffic generator • Load node-movement file & traffic-generator file(in tcl script file) Ex) source “../mobility/scene/scen-3-test” source “../mobility/scene/cbr-3-test” HPMN Lab.

  50. Creating wired-cum-wireless in ns • a simple wired-cum-wireless scenario • 2 Wired nodes: • w(0),w(1) • 3 mobile nodes • 1 base-station node HPMN Lab.

More Related