NS2 summary.ppt

Embed Size (px)

Citation preview

  • Network Simulator (NS-2)

    Varaprasad Reddy

  • *AgendaOverview of NS-2HistoryPlatforms SupportedDiscrete Event SimulatorNS-2 EnvironmentNS-2 HierarchyNS-2 ArchitectureNode ArchitectureMulticast Node ArchitecturePacket StructureLinksTraffic FlowExample

  • *Overview of NS-2Discrete Event SimulatorPacket levelModeling Network protocolsCollection of Various protocols at multiple layersTCP(reno, tahoe, vegas, sack)MAC(802.11, 802.3, TDMA)Ad-hoc Routing (DSDV, DSR, AODV, TORA)Sensor Network (diffusion, gaf)Multicast protocols, Satellite protocols, and many others

  • *Overview of NS-2Maintained through VINT projectNS2 :collaborative simulation environment Freely distributed and open sourceSupports NT research and educationProtocol design , traffic analysis etc.Provides common reference

  • *History1995 : Developed by LBL through support of DARPA1996: NS was extended and distributed by VINT project1997: Satellite models added @ UCB1999: Wireless models added @ CMUincorporation of emulation

  • * Platforms supportedMost UNIX and UNIX-like systems FreeBSD LinuxSolarisWindows 98/2000/2003/XPCygwin required Some work , some doesnt

  • *NS-2 : ComponentsNS SimulatorNAM Network AniMator visual demonstration of NS outputPreprocessingHandwritten TCL orTopology generatorPost analysisTrace analysis using Perl/TCL/AWK/MATLAB

  • *Users PerspectiveFrom the users perspective, NS2 is an OTcl interpreter that takes an OTcl script as input and produces a trace file as output.

  • *Discrete event simulatorns-2 is an discrete event driven simulationPhysical activities are translated to eventsEvents are queued and processed in the order of their scheduled occurrencesTime progresses as the events are processed

  • *Discrete Event Schedulertime_, uid_, next_, handler_head_ ->handler_ -> handle()time_, uid_, next_, handler_inserthead_ ->Event Scheduler

  • * Event SchedulerNon-Real time schedulersImplementations : List , Heap , Calender Calender is defaultReal time schedulersUsed for emulation for direct interaction with real NT. Basic use of an event scheduler:schedule simulation events, such as when to start an FTP application, when to finish a simulation, or for simulation scenario generation prior to a simulation run.

  • *NS-2 EnvironmentTcl Scriptset ns_ [new Simulator] set node_(0) [$ns_ node] set node_(1) [$ns_ node] class MobileNode : public Node {friend class PositionHandler;public: MobileNode();}

  • * tcl Interpreter With Extentsotcl: Object-oriented supporttclcl: C++ and otcl linkageDiscrete event schedulerData network components

    tcl8.0otcltclclns-2EventSchedulerNetworkComponent

  • *NS-2 Hierarchy

  • *NS-2 Hierarchy

  • * NS-2 Directory Structuretcl codeexamplevalidation testC++ codetcl code core

  • * Node ArchitectureAgents are either protocol endpoints or related objects that generate/fill-in packet fields.Classifiers: packet demultiplexers.

  • *Multicast Node architecture

  • *Packets (events)packetSize determined at simulation config time

    Packet Structure

  • *LinksLinks: keeps track of from and to node objects.blocked

  • *

  • *C++ is used for the creation of objects because of speed and efficiency.

    NS-2 : C++ / OTCLNS-2 Code contains two sets of languages, namely C++ and OTcl.OTcl is used as a front-end to setup the simulator, configure objects and schedule events because of its ease of use.

  • *Why two languages? (Tcl & C++)C++: Detailed protocol simulations require systems programming language byte manipulation, packet processing, algorithm implementationRun time speed is importantTurn around time (run simulation, find bug, fix bug, recompile, re-run) is slowerTcl: Simulation of slightly varying parameters or configurationsquickly exploring a number of scenariositeration time (change the model and re-run) is more important

  • *Tcl or C++?TclSimple Configuration, Setup, ScenarioIf its something that can be done without modifying existing Tcl module. C++Anything that requires processing each packetNeeds to change behavior of existing module

  • * ShadowingTclObjectAgentAgent/DSDVAgent/DSDV OTcl shadow objectAgent/DSDV C++ objectTclObject()Agent()DSDVAgent()OTcl classhierarchyC++ classhierarchy

  • *TCLC++ Object Correspondence

  • * NS-2 Directory Structuretcl codeexamplevalidation testC++ codetcl code core

  • *Making Changes in C++ SpaceExisting coderecompileAdditionchange Makefile and recompile

  • *Making Changes in otcl SpaceExisting coderecompilesourceAdditionsourcechange Makefile (NS_TCL_LIB), tcl/ns-lib.tcl (source) and recompile

  • *InstallationUnix variantsDownload NS-allinone-2.27 packageContainsTCL/TK 8.4.5oTCL 1.8Tclcl 1.15Ns2 Nam -1

  • *Installation After successful downloading and unzipping install allinone package , install NS by install by calling ~/ns-allinone-2.27/install After successful installation , Validate the scripts by running ./validate in ~/ns-allinone-2.27/ns-2.27/ Its now all set to work with NS

  • *Code for simple topologyCreating a Simulator Objectset ns [new Simulator] Setting up files for trace & NAMset trace_nam [open out.nam w]set trace_all [open all.tr w] Tracing files using their commands$ns namtrace-all $trace_nam$ns trace-all $trace_all

  • *Code for simple topologyClosing trace file and starting NAMproc finish { } {global ns trace_nam trace_all $ns flush-traceclose $trace_namclose $trace_allexec nam out.nam &exit 0 }

  • *Code for simple topologyCreating LINK & NODE topologyCreating NODESset n1 [$ns node]set n2 [$ns node]set n3 [$ns node]set n4 [$ns node]set r1 [$ns node]set r2 [$ns node]

  • *Code for simple topologyCreating LINKS$ns duplex-link $N1 $R1 2Mb 5ms DropTailset DuplexLink0 [$ns link $N1 $R1]$ns duplex-link $N2 $R1 2Mb 5ms DropTailset DuplexLink1 [$ns link $N2 $R1]$ns duplex-link $R1 $R2 1Mb 10ms DropTailset DuplexLink2 [$ns link $R1 $R2]$ns duplex-link $R2 $N3 2Mb 5ms DropTailset DuplexLink3 [$ns link $R2 $N3]$ns duplex-link $R2 $N4 2Mb 5ms DropTailset DuplexLink4 [$ns link $R2 $N4]

  • *Code for simple topologyOrientation of links$ns duplex-link-op $N1 $R1 orient right-down$ns duplex-link-op $N2 $R1 orient right-up$ns duplex-link-op $R1 $R2 orient right$ns duplex-link-op $R2 $N3 orient right-up$ns duplex-link-op $R2 $N4 orient right-down

  • *Final topology Generated

  • *Traffic topology aimed at

  • *Generating TrafficAttaching AGENT TCP to NODE 1set TCP1 [new Agent/TCP]$ns attach-agent $N1 $TCP1Attaching AGENT TCP to NODE 2set TCP2 [new Agent/TCP]$ns attach-agent $N2 $TCP2Attaching AGENT TCP to NODE 3set TCP3 [new Agent/TCPSink]$ns attach-agent $N2 $TCP3Attaching AGENT TCP to NODE 4set TCP4 [new Agent/TCPSink]$ns attach-agent $N2 $TCP4

  • *Generating TrafficAttaching Application (FTP)set FTP0 [new Application/FTP]set FTP1 [new Application/FTP]$FTP0 attach-agent $TCP0$FTP1 attach-agent $TCP1

  • *Setting simulation times$ns at 0.5 "$FTP0 start"$ns at 0.5 "$FTP1 start"$ns at 10.0 "$FTP0 stop"$ns at 10.0 "$FTP1 stop$ns at 10.0 finishMaking NS run $ns run

  • *

  • *

    *This section talks about the discrete event schedulers of NS. As described in the Overview section, the main users of an event scheduler are network components that simulate packet-handling delay or that need timers. Figure shows each network object using an event scheduler. Note that a network object that issues an event is the one who handles the event later at scheduled time. Also note that the data path between network objects is different from the event path. Actually, packets are handed from one network object to another using send(Packet* p) {target_->recv(p)}; method of the sender and recv(Packet*, Handler* h = 0) method of the receiver*