1 / 33

Network Simulator – NS-2

Network Simulator – NS-2. JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15. Reference. http://140.116.72.80/~smallko/ns2/ns2.htm http://www.isi.edu/nsnam/ns/ Ns document. Outline. Introduction Installation

mboling
Download Presentation

Network Simulator – NS-2

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-2 JIA-HUI HUANG INSTITUTE OF COMPUTER SCIENCE AND INFORMATION ENGINEERING NATIONAL TAIPEI UNIVERSITY OF TECHNOLOGY 2007.10.15

  2. Reference • http://140.116.72.80/~smallko/ns2/ns2.htm • http://www.isi.edu/nsnam/ns/ • Ns document

  3. Outline • Introduction • Installation • TCL script • Related tools • New protocol for NS • Examples • Conclusion

  4. Introduction • Methods for network research • Analytical • General expression or close form • Mathematical model • Emulation • Real code • Duplicates the functions of one system with a different system • Simulation • Abstract model • Behavior of system

  5. Introduction (cont.) • Self-Developed • Without strong persuasion • Simulation frameworks • Commercial • OPNET • QualNet • OMNEST (commercial version of OMNetT++) • Free • NS-2 (network simulator version 2) • OMNetT++

  6. Introduction (cont.) • Ns-2 is a discrete event simulator • Scheduler • Advance of time depends on the timing of events • Object-oriented simulator • C++ : fast to run, slower to change – protocol implementation • Otcl : slower to run, fast to change – simulation configuration • Components • Ns – simulator itself • Nam – network animator • Visualize ns (or other) output

  7. Introduction (cont.) • Pre-processing • Traffic and topology model • Post-processing • Trace analysis, often in awk, perl, or tcl • Simulation procedure

  8. Installation • Platform • Unix • Windows (cygwin) • Packages • Tcl/tk • Otcltclcl • Ns-2 • Nam • Xgraph • C++ compiler • Ns AllInOne package

  9. Installation (cont.) • Cygwin, AllInOne installation (windows) • http://140.116.72.80/~smallko/ns2/setup_en.htm • Installation problems • http://www.isi.edu/nsnam/ns/ns-problems.html#general • Cygwin setup • gcc • Ns-2 setup • Path setting • Cygwin/home/user-name/.bashrc • Testing (startxwin.bat) - ~/ns-allinone-x.x/ns-x.x/ns-tutorial/examples

  10. TCL script • TCL script for scenario setup • Scenario script format • Simulator object • Trace file • Finish procedure • Network setup (node, link, agent, parameter…) • Other procedure, if any • Event scheduling (run simulation, stop simulation …)

  11. TCL script (cont.) • Example topology #Create a simulator object set ns [new Simulator] #Open the nam 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 the trace file close $nf #Execute nam on the trace file exec nam out.nam & exit 0 }

  12. #Create two nodes set n0 [$ns node] set n1 [$ns node] #Create a duplex link between the nodes $ns duplex-link $n0 $n1 1Mb 10ms DropTail #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 #Create a Null agent (a traffic sink) and attach it to node n1 set null0 [new Agent/Null] $ns attach-agent $n1 $null0 #Connect the traffic source with the traffic sink $ns connect $udp0 $null0 #Schedule events for the CBR agent $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run

  13. Related tools • nsBench • Graphical User Interface For NS • Language - java • Features • Nodes, simplex/duplex links and Lans • Agents: TCP, UDP, TCP/Reno, … • Application Traffic: FTP, Telnet, …. • …. • http://www.mnlab.cs.depaul.edu/projects/nsbench/

  14. Related tools (cont.) • NSG • Java based ns2 scenario generator • For wireless ad-hoc scenario • Features • wireless node • Connection between nodes • Node movement • http://wushoupong.googlepages.com/ns2scenariosgeneratorchinese

  15. Related tools (cont.) • Topology Generator • Georgia Tech Internetwork Topology Models (GT-ITM) • How closely model correlate with real network ? • Transit-Stub model • Transit domain • Interconnect stub domains • Example topology

  16. New protocol for ns • Packet type • Structure declaration – packet header • Name binding • Bind packet header to TCL interface • Usage • Routing agent • MANET routing protocol • Agent object • Tcl hook • Important functions

  17. Packet type • Packet header #include <packet.h> #define HDR_PROTONAME_PKT(p) hdr_protoname_pkt::access(p) struct hdr_protoname_pkt { …. (define some fields of packet) static int offset_; inline static int& offset() { return offset_ ; } inline static hdr_protoname_pkt* access(const Packet* p) { return (hdr_protoname_pkt*)p->access(offset_); }

  18. Packet type (cont.) • Name binding int protoname_pkt::offset_; static class ProtonameHeaderClass : public PacketHeaderClass { public: ProtonameHeaderClass() PacketHeaderClass("PacketHeader/Protoname", sizeof(hdr_protoname_pkt)) { bind_offset(&hdr_protoname_pkt::offset_); } }

  19. Packet type (cont.) • Usage Packet* p = allocpkt(); struct hdr_cmn* ch = HDR_CMN(p); struct hdr_ip* ih = HDR_IP(p); struct hdr_protoname_pkt* ph = HDR_PROTONAME_PKT(p); ph->…. ih->…. ch->…

  20. Routing agent • Agent object #include <agent.h> …. class NewProtocol : public Agent { protected : … public : NewProtocol(nsaddr_t); int command (int, const char*const*); void recv(Packet*, Handler*); …. }

  21. Routing agent (cont.) • Tcl hook • Let NewProtocl to be instantiated from Tcl. static class ProtonameClass : public TclClass { public: ProtonameClass() : TclClass("Agent/Protoname") {} TclObject* create(int argc, const char*const* argv) { assert(argc == 5); return (new Protoname((nsaddr_t)Address::instance().str2addr(argv[4]))); } }

  22. Routing agent (cont.) • Important functions • Command() • Operations that we went to make accessible from TCL • maodv-join-group • maodv-leave-group • Example - maodv.cc, MAODV_SimScript.tcl, cbr-5-3-2 • Recv () • Invoked whenever the routing agent receives a packet

  23. Needed changes • Needed changes • Packet type declaration - \ns-x.xx\common\packet.h • Tracing support - \ns-x.xx\cmu-trace.h • Tcl library • Tcl\lib\ns-packet.tcl • Tcl\lib\ns-default.tcl • Priority queue - \queue\priqueue.cc • Make file

  24. Example1 - TCP slow start • Transport layer protocol • UDP – user datagram protocol (connectionless, unreliable service) • TCP – transmission control protocol (connect-oriented, reliable, with flow and congestion control service) • Connection-oriented – three-way handshaking • Reliable – acknowledgment, retransmission • Flow control – sender won’t buffers by transmitting to much and too fast • Congestion control – to limit the total amount of data entering the internet

  25. Example1 - TCP slow start (cont.) • Important variables for congestion control – slow start • cwnd – congestion window • ssthresh – defines threshold between two slow start phase and congestion control phase • Operations – slow start • When connection begins, increase rate exponentially fast until first loss event (slow start phase) • Set ssthresh = cwnd/2 • Set cwnd = 1 and perform slow start process • For cwnd >= ssthresh, increase cwnd linearly (congestion avoidance)

  26. Example1 - TCP slow start (cont.) • TCP standards • TCP Tahoe – slow start & congestion avoidance • RFC 2581 • TCP Vegas • TCP Reno • RFC 2581 • TCP NewReno • RFC 2582 • FACK (forward acknowledgement) • SACK (selective acknowledgement) • RFC 2018

  27. Example1 - TCP slow start (cont.) • TCP experiment – congestion window • TCP Tahoe • Slow-start • Congestion avoidance Simulation topology Source1 (TCP) n0 Receiver n2 n3 n1 Source2(UDP)

  28. Example2 – queuing system • Queuing systems • M/M/1 • M/D/1 • … • Notation • Arrival process/Service time/Servers • M = exponential, D = Deterministic, ….

  29. Queuing system – M/M/1 (cont.) • Arrival & departure model • Poisson arrival • Exponential distribution • single server • Parameters • Arrival rate λ • Departure rate (service time) μ • load (stability condition : ρ < 1) • (# of packets in system)

  30. Queuing system – M/M/1 (cont.) • queue.tcl • Arrival rate : 30 • Departure rate : 33 • E[Q] = 10

  31. Tips • Ns document is not easy to understand • Error message is not very useful • Understand and Implementation • Implementation issues • Iterative design

  32. Conclusion • Basic concept of NS2 • Two levels of simulation • Exist modules for NS beginner

  33. Internet domain structure Example of Internet domain structure

More Related