NS-2 Tutorial Biplab Sikdar Associate Professor Department of ECSE Rensselaer Polytechnic institute Troy, NY 12180 USA
NS-2 TutorialBiplab SikdarAssociate ProfessorDepartment of ECSERensselaer Polytechnic instituteTroy, NY 12180 USA
AcknowledgementsImportant input from students and colleagues: Sampad Mishra, David DoriaSome slides based on those of Padmaparna Haldar, Ya Xu, Aga Zhang and Polly Huang
OutlineNS fundamentalsExample walkthroughData Collection and VisualizationSimulating WiMAX scenariosConclusions
NS BackgroundStarted as REAL in 1989Discrete event packet level simulatorWritten in C++ with Otcl frontendWired, wireless and emulation modesLink layer and up for most wiredAdditional lower layers for wireless
ATG ExtensionsIEEE 802.16 MAC layerTDD operationUGS, rtPS and BE service classesBlock ARQOFDMA PHY layerITU PDP modulesPHY layer model libraryMobility extensions
PlatformsMost UNIX and UNIX-like systemsLinuxFreeBSDSunOS/SolarisHP/SGI (with some tweaking)Windows 95/98/NT/ME/2000
NS: Basic ModelDiscrete event simulatorScheduler main controller of eventsScheduler clock - simulator virtual time[$ns_ now] returns the current simulator timeEvent queue - holds events in the order of their firing timesEvents have a firing time and a handler function
Scheduler OperationEvent-driven simulatorMaintain a sorted event queue Dequeue head event Packet arrivalAssign event to its handler At TCP agentHandler processes eventUpdate Window Enqueue more events in the event queueSchedule delivery of ACK
Exampletime_, uid_, next_, handler_Four types of scheduler:List: simple linked list, order-preserving, O(N) Heap: O(logN)Calendar: hash-based, fastest, default, O(1)Real-time: subclass of list, sync with real-time, O(N)EventQueueDequeDispatchReschedule
NS ArchitectureBack-end C++Protocols & FrameworkFront-end Otcl (Object-Oriented Tcl)Scenarios, configuration (one time stuff)Split ObjectObject created in otcl has a corresponding object in C++Fast to run and easy to reconfigureThis tutorial only deals with tcl
Getting startedDownload the latest code (all-in-one package strongly recommended) from http://www.isi.edu/nsnam/nsDownload 802.16 extensionsCompile and installBasic skills:TclC++
C++ and OTcl SeparationC++ for dataPer packet actionOTcl for controlConfiguration, one-time taskAdvantage: Compromise between composibility and speedDisadvantage: Learning and debugging
OTcl and C++: The Duality
Short Introduction to tclVariablesset v1 10 set v2 $v1Array (String indexed)a($i)Printingputs $filename string (default filename is stdout)Arithmetic Expressionsset value [expr $v1+($v2 * 5.2)]Control Structuresif {condition} then {.}for {set i 0} {$i < 10} {incr i 2} {}Proceduresproc proc_name {arg1 arg2} { }
NS Communication ModelNodesHostsRoutersBase stationsLinksQueue managementQueue monitoringAgentsProtocols
Elements of a NS SimulationCreate the event scheduler[Turn on tracing]Create networkSetup routing[Insert errors]Create transport connectionCreate traffic
A Simple Script# Create a topologyset ns [new Simulator]set n0 [$ns node]set n1 [$ns node]$ns duplex-link $n0 $n1 1Mb 10ms DropTail
# Add Transport agentsset tcp [new Agent/TCP]$ns attach-agent $n0 $tcpset tcpsink [new Agent/TCPSink]$ns attach-agent $n1 $tcpsink$tcp connect $tcpsink
# Add applicationset ftp [new Application/FTP]$ftp attach-agent $tcp
# Create a schedule
$ns at 0.5 "$ftp start"$ns at 4.5 "$ftp stop"
#Run the simulation$ns run
Script (cont.)Run your program % ns Simple.tcl
Script (cont.)
Script (cont.)
Script (cont.)
Script (cont.)
Setting up NS Nodes
Setting up a Network Link
Routing
Transportset tcp [new Agent/TCP]$ns attach-agent $n0 $tcp
Applicationset ftp [new Application/FTP]$tcp attach-agent $ftp
Packet Flown0n1Addr ClassifierPort Classifierentry_0Agent/TCPAddr ClassifierPort Classifierentry_Link n0-n1Link n1-n00Agent/TCPSinkApplication/FTP
Tracing and VisualizationTrace packets on all links$ns trace-all [open test.out w] -- + 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0- 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0
Trace packets on all links in nam format$ns namtrace-all [open test.nam w]$ns namtrace-all-wireless [open wtest.nam w]
Visualization ToolsNam-1 (Network AniMator Version)Packet-level animationWell-supported by nsXgraphConvert trace output into xgraph format
Simulating WiMAX ScenariosExtensions developed by RPI under the aegis of AATGOther parties: NIST, Washington University, BUPT and ICU FeaturesIEEE 802.16 MAC layer OFDMA based PHYExtensions for mobility
Define MAC/PHY ParametersWimaxScheduler set dlratio_ 0.6Mac/802_16 set fbandwidth_ 20e+6set diuc 7Mac/802_16 set rtg_ 20Mac/802_16 set ttg_ 20Mac/802_16 set frame_duration_ 0.005Mac/802_16 set ITU_PDP_ 1Phy/WirelessPhy/OFDMA set g_ 0.25Phy/WirelessPhy set Pt_ 0.2 Phy/WirelessPhy set RXThresh_ 1.90546e-16Phy/WirelessPhy set CSThresh_ [expr 0.9*[Phy/WirelessPhy set RXThresh_]]
Parameters for Wireless Nodesset opt(chan) Channel/WirelessChannel set opt(prop) Propagation/OFDMA set opt(netif) Phy/WirelessPhy/OFDMA set opt(mac) Mac/802_16 set opt(ifq) Queue/DropTail/PriQueue set opt(ant) Antenna/OmniAntennaset opt(ifqlen) 50 set opt(x) 670set opt(y) 670set prop_inst [$ns set propInstance_]$prop_inst ITU_PDP VEHIC_A
Creating Base Stations$ns node-config -adhocRouting $opt(adhocRouting) \ -llType $opt(ll) \ -macType Mac/802_16/BS \ -ifqType $opt(ifq) \ -ifqLen $opt(ifqlen) \ -antType $opt(ant) \ -propType $opt(prop) \ -phyType $opt(netif) \ -channel $channel \ -topoInstance $topo \ -wiredRouting ON \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace OFF
Base Station (cont.)set bstation [$ns node 1.0.0] $bstation random-motion 0
$bstation set X_ 300.0$bstation set Y_ 300.0$bstation set Z_ 0.0
[$bstation set mac_(0)] set-channel 0
Creating Mobile Stations$ns node-config -macType Mac/802_16/SS \ -wiredRouting OFF \ -macTrace OFF
set wl_node [$ns node 1.0.0] $wl_node random-motion 0$wl_node base-station [AddrParams addr2id [$bstation node-addr]] $wl_node set X_ 100.0 $wl_node set Y_ 200.0$wl_node set Z_ 0.0[$wl_node set mac_(0)] set-channel 0 [$wl_node($i) set mac_(0)] setflow UL 10000 BE 700 2 0 0.05 15 1 0 0 0 0 0 0 0 0 0 0}
Other Utilities in NSNam editorAvailable as part of nam-1Tcl debuggerFor source and documentation, seehttp://www.isi.edu/nsnam/ns/ns-debugging.htmlTopology generatorhttp://www.isi.edu/nsnam/ns/ns-topogen.htmlScenario generatorhttp://www.isi.edu/nsnam/ns/ns-scengeneration.html
Other NS FeaturesOther areas in wired domainLANsDiffservMulticast Full TCPApplications like web-cachingWireless domainAd hoc routingMobile IPSatellite networkingDirected diffusion (sensor networks)
Other NS FeaturesEmulatorConnect simulator in a real networkCan receive and send out live packets from/into the real world
NS Related ResourcesNS distribution downloadhttp://www.isi.edu/nsnam/ns/ns-build.htmlInstallation problems and bug-fixhttp://www.isi.edu/nsnam/ns/ns-problems.htmlNs-users mailing [email protected] http://www.isi.edu/nsnam/ns/ns-lists.htmlArchives from above URL
More ResourcesMarc Greis tutorialhttp://www.isi.edu/nsnam/ns/tutorialNs-users archiveNs-manualhttp://www.isi.edu/nsnam/ns/ns-documentation.htmlTcl (Tool Command Language)http://dev.scriptics.com/scriptingPractical programming in Tcl and Tk, Brent WelchOtcl (MIT Object Tcl)~otcl/doc/tutorial.html (in distribution)
Extra Slides
Otcl BasicsCreating a classClass class_nameClass class_name superclass Base_classDefining instance proceduresclass_name instproc proc_name {args} {..}Defining instance variables$self instvar variable_name (inside a class method)Creating an instanceset new_inst [new class_name] Using value of an instance variable$new_inst set v1 10 or set v2 [$new_inst set v1]
Packet Formatheaderdata