1 / 50

Network Simulator(NS) Tutorial

Network Simulator(NS) Tutorial. These slides can be downloaded from: http://networks.cs.ucdavis.edu/~lijian/289I/. Agenda. What Is NS? Elements of Simulation NS Architecture NS Internals Summary. What is NS. Discrete event simulator Packet-level Protocol stack

kynan
Télécharger la présentation

Network Simulator(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. Network Simulator(NS) Tutorial These slides can be downloaded from: http://networks.cs.ucdavis.edu/~lijian/289I/ Lijian@cs.ucdavis.edu

  2. Agenda • What Is NS? • Elements of Simulation • NS Architecture • NS Internals • Summary Lijian@cs.ucdavis.edu

  3. What is NS • Discrete event simulator • Packet-level • Protocol stack • Link layer and up for wired networks; • Physical layer and up for wireless networks • Wired and wireless(both local and satellite) Detour Lijian@cs.ucdavis.edu

  4. History and Status • Now part of VINT(Virtual InterNet Testbed) project • Columbia NEST --> UCB REAL --> NS-1 --> NS-2 • Users from approximately • 600 institutes • 50 countries • Releases • Periodic releases (currently 2.1b9, April 2002) • Nightly snapshots (probably compiles and works, but “unstable”) • Available from: USC/ISI, UC Berkeley, UK mirror Lijian@cs.ucdavis.edu

  5. Platforms • Most UNIX and UNIX-like systems • FreeBSD or *BSD • Linux • Sun Solaris • HP, SGI • Window 95/98/NT • Some work, some does not • (Emulation only for FreeBSD for now) Lijian@cs.ucdavis.edu

  6. Functionality of NS • Wired world • Point-to-point link, LAN • Unicast/multicast routing • Transport • Application layer • Wireless • Mobile IP • Ad hoc routing • Tracing, visualization, various utilities Lijian@cs.ucdavis.edu

  7. Visualization Tools • nam-1 (Network AniMator Version 1) • Packet-level animation • Well supported by ns • xgraph • Conversion from ns trace to xgraph format Lijian@cs.ucdavis.edu

  8. Getting Started • NS official site: • http://www.isi.edu/nsnam/ns/ • A painless tutorial by Marc Greis: • http://www.isi.edu/nsnam/ns/tutorial/index.html • Another good tutorial from WPI • http://nile.wpi.edu/NS/ Lijian@cs.ucdavis.edu

  9. Getting Help & Reference • Building NS • http://www.isi.edu/nsnam/ns/ns-build.html • NS user mailing list • http://mailman.isi.edu/mailman/listinfo/ns-users • NS manual • http://www.isi.edu/nsnam/ns/ns-documentation.html Lijian@cs.ucdavis.edu

  10. Agenda • What Is NS? • Elements of Simulation • NS Architecture • NS Internals • Summary Lijian@cs.ucdavis.edu

  11. Elements of Simulation • Create the event scheduler • [Turn on tracing] • Create network • Setup routing • [Insert errors] • Create traffic • Start simulation • Post-process trace Detour Lijian@cs.ucdavis.edu

  12. Creating Event Scheduler • Create event scheduler • set ns [new Simulator] • Schedule events • $ns at <time> <event> • <event>: any legitimate ns/tcl commands • Start scheduler • $ns run Lijian@cs.ucdavis.edu

  13. Tracing • Trace packets on all links • $ns trace-all [open test.out w] <event> <time> <from> <to> <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 • Trace packets on all links in nam-1 format • $ns namtrace-all [open test.nam w] • Turn on tracing on specific links • $ns trace-queue $n0 $n1 • $ns namtrace-queue $n0 $n1 • Must appear immediately after creating scheduler Lijian@cs.ucdavis.edu

  14. Creating Network • Nodes • set n0 [$ns node] • set n1 [$ns node] • Links and queuing • $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type> • <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR Lijian@cs.ucdavis.edu

  15. Creating Network: LAN • 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 Lijian@cs.ucdavis.edu

  16. Inserting Errors • 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 Lijian@cs.ucdavis.edu

  17. Network Dynamics • Link failures • Hooks in routing module to reflect routing changes • Four models $ns rtmodel Trace <config_file> $n0 $n1 $ns rtmodel Exponential {<params>} $n0 $n1 $ns rtmodel Deterministic {<params>} $n0 $n1 $ns rtmodel-at <time> up|down $n0 $n1 • Parameter list [<start>] <up_interval> <down_interval> [<finish>] Lijian@cs.ucdavis.edu

  18. 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 Lijian@cs.ucdavis.edu

  19. Creating Connection: UDP or TCP • 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 • 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 Lijian@cs.ucdavis.edu

  20. Creating Traffic: On Top of UDP • CBR • set src [new Application/Traffic/CBR] • Exponential or Pareto on-off • set src [new Application/Traffic/Exponential] • set src [new Application/Traffic/Pareto] Lijian@cs.ucdavis.edu

  21. Creating Traffic: On Top of TCP • FTP • set ftp [new Application/FTP] • $ftp attach-agent $tcp • Telnet • set telnet [new Application/Telnet] • $telnet attach-agent $tcp Lijian@cs.ucdavis.edu

  22. 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) Lijian@cs.ucdavis.edu

  23. Application-Level Simulation • Features • Build on top of existing transport protocol • Transmit user data, e.g., HTTP header • Two different solutions • TCP: Application/TcpApp • UDP: Agent/Message Lijian@cs.ucdavis.edu

  24. Agenda • What Is NS? • Elements of Simulation • NS Architecture • NS Internals • Summary Detour ends. Lijian@cs.ucdavis.edu

  25. NS Architecture • Object-oriented (C++, OTcl) • Scalability + Extensibility • Control/”data” separation • Split C++/OTcl object • Modular approach • Fine-grained object composition Detour ends. Lijian@cs.ucdavis.edu

  26. C++/OTcl Split Objects Pure OTcl objects Pure C++ objects 100K 70K C++ OTcl C++/OTcl split objects NS Lijian@cs.ucdavis.edu

  27. C++/OTcl Linkage Lijian@cs.ucdavis.edu

  28. TclObject: Hierarchy and Shadowing C++ class hierarchy OTcl class hierarchy TclObject TclObject Agent Agent TcpAgent Agent/TCP *tcp _o123 Agent/TCP OTcl shadow object Agent/TCP C++ object Lijian@cs.ucdavis.edu

  29. The Merit of OTcl • Smoothly adjust the granularity of scripting to balance extensibility and performance • With complete compatibility with existing simulation scripts Program size, complexity low high OTcl C/C++ split objects Lijian@cs.ucdavis.edu

  30. Scalability vs Flexibility • It’s tempting to write all-OTcl simulation • Benefit: quick prototyping • Cost: memory + runtime • Solution • Control the granularity of your split object by migrating methods from OTcl to C++ Lijian@cs.ucdavis.edu

  31. Object Granularity Tips • Functionality • Per-packet processing  C++ • Hooks, frequently changing code  OTcl • Data management • Complex/large data structure  C++ • One-time configuration variables  OTcl Lijian@cs.ucdavis.edu

  32. Agenda • What Is NS? • Elements of Simulation • NS Architecture • NS Internals • Summary Lijian@cs.ucdavis.edu

  33. NS Internals • Discrete event scheduler • Network topology • Routing • Transport • Packet flow • Packet format • Application Lijian@cs.ucdavis.edu

  34. head_ -> handler_ -> handle() reschedule insert time_, uid_, next_, handler_ Discrete Event Scheduler • Three types of schedulers • List: simple linked list, order-preserving, O(N) • Heap: O(logN) • Calendar: hash-based, fastest, O(1) time_, uid_, next_, handler_ head_ -> Lijian@cs.ucdavis.edu

  35. n0 n1 Port Classifier Multicast Node dmux_ Addr Classifier classifier_ Node entry Node entry dmux_ entry_ entry_ Multicast Classifier classifier_ multiclassifier_ Network Topology: Node Unicast Node Lijian@cs.ucdavis.edu

  36. n0 n1 duplex link n1 entry_ head_ enqT_ queue_ deqT_ link_ ttl_ drophead_ drpT_ tracing simplex link Network Topology: Link Lijian@cs.ucdavis.edu

  37. n0 n1 Port Classifier Addr Classifier n1 entry_ 0 Node entry head_ dmux_ enqT_ queue_ deqT_ link_ ttl_ 1 entry_ classifier_ drophead_ drpT_ Routing Lijian@cs.ucdavis.edu

  38. n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier 0 1 dmux_ dmux_ 0 1 entry_ entry_ classifier_ classifier_ Link n1-n0 Routing (con’t) Link n0-n1 Lijian@cs.ucdavis.edu

  39. dst_=0.0 dst_=1.0 Agent/TCP Agent/TCPSink agents_ agents_ 1 0 0 1 Transport n0 n1 Port Classifier Port Classifier Addr Classifier Addr Classifier 0 0 dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0 Lijian@cs.ucdavis.edu

  40. Application/FTP dst_=0.0 dst_=1.0 0 1 1 0 Application: Traffic Generator n0 n1 Port Classifier Port Classifier Agent/TCPSink Addr Classifier Addr Classifier Agent/TCP 0 0 agents_ agents_ dmux_ dmux_ Link n0-n1 entry_ entry_ classifier_ classifier_ Link n1-n0 Lijian@cs.ucdavis.edu

  41. dst_=0.0 dst_=1.0 0 1 1 0 Plumbing: Packet Flow n0 n1 Application/FTP Port Classifier Port Classifier Agent/TCPSink Addr Classifier Addr Classifier Agent/TCP 0 0 Link n0-n1 entry_ entry_ Link n1-n0 Lijian@cs.ucdavis.edu

  42. ts_ cmn header ptype_ ip header uid_ tcp header size_ rtp header iface_ trace header ... Packet Format header data Lijian@cs.ucdavis.edu

  43. Abstract the Real Wireless World • Packet headers • Mobile node • Wireless channel • Forwarding and routing • Visualization Lijian@cs.ucdavis.edu

  44. ts_ cmn header ptype_ IP header uid_ ...... size_ LL iface_ MAC 802_11 ARP ...... Wireless Packet Format header data Wireless headers Lijian@cs.ucdavis.edu

  45. Mobile Node Abstraction • Location • Coordinates (x,y,z) • Movement • Speed, direction, starting/ending location, time ... Lijian@cs.ucdavis.edu

  46. Classifier: Forwarding Agent: Protocol Entity Node Entry LL: Link layer object IFQ: Interface queue MAC: Mac object PHY: Net interface Portrait of A Mobile Node port classifier Node protocol agent 255 routing agent addr classifier defaulttarget_ ARP LL LL LL IFQ IFQ MAC MAC Propagation and antenna models PHY PHY MobileNode CHANNEL Lijian@cs.ucdavis.edu

  47. Wireless Channel • Duplicate packets to all mobile nodes attached to the channel except the sender • It is the receiver’s responsibility to decide if it will accept the packet • Collision is handled at individual receiver • O(N2) messages  grid keeper Lijian@cs.ucdavis.edu

  48. Agenda • What Is NS? • Elements of Simulation • NS Architecture • NS Internals • Summary Lijian@cs.ucdavis.edu

  49. Summary • What can we do with NS? • Architectural overview of NS • split C++/OTcl Object • Inside NS • node, link, routing, tcp, app, wireless extension • how it works Lijian@cs.ucdavis.edu

  50. References • http://www.isi.edu/nsnam/dist/ns-workshop00/ • http://www.isi.edu/nsnam/ns/ Lijian@cs.ucdavis.edu

More Related