SlideShare a Scribd company logo
1 of 32
1
NS--2 IntroductionIntroduction
byby
Venkatamangarao NampallyVenkatamangarao Nampally
KattangurKattangur
2
OutlineOutline
• BackgroundBackground
• ArchitectureArchitecture
• UsageUsage
• SimulationSimulation
• NS-programmingNS-programming
• ExampleExample
• SummarySummary
3
ns-2, the Network Simulatorns-2, the Network Simulator
• AA discrete event simulatordiscrete event simulator modellingmodelling
network protocolsnetwork protocols
– Packets, links, queues, protocolsPackets, links, queues, protocols
– Visualizer (Visualizer (NAMNAM))
– Trace playbackTrace playback
– Error modelsError models
• Targeted at networking researchTargeted at networking research
• Supports for all types of simulationsSupports for all types of simulations
4
HistoryHistory
• 1989:1989: REALREAL by Keshavby Keshav
• 1995:1995: nsns by Floyd, McCanne at LBLby Floyd, McCanne at LBL
• 1997:1997: ns-2ns-2 by the VINT projectby the VINT project
((Virtual InterNetwork TestbedVirtual InterNetwork Testbed) at) at
LBL, Xerox PARC, UCB, USC/ISILBL, Xerox PARC, UCB, USC/ISI
• 1999: Wireless models added @ CMU1999: Wireless models added @ CMU
• Now:Now: ns-2.29ns-2.29 maintained at USC/ISImaintained at USC/ISI
– ns-2.30ns-2.30 pending releasepending release
NS-2 OverviewNS-2 Overview
• TCP/IP NS2 OSI 7-LayerTCP/IP NS2 OSI 7-Layer
5
•Application
•Presentation
•Session
•Transport
•Network
•Data Link
•Physical
•Application
•Agent
•Node
•Link
•Application
•TCP/UDP
•IP
•Network
•Access
Platforms SupportedPlatforms Supported
• Most UNIX and UNIX-like systemsMost UNIX and UNIX-like systems
 FreeBSDFreeBSD
 LinuxLinux
 SolarisSolaris
• Windows 98/2000/2003/XPWindows 98/2000/2003/XP
– Cygwin requiredCygwin required
– Some work , some doesntSome work , some doesnt
6
User’s PerspectiveUser’s Perspective
• From the user’s perspective, NS−2 isFrom the user’s perspective, NS−2 is
an OTcl interpreter that takes an OTclan OTcl interpreter that takes an OTcl
script as input and produces a tracescript as input and produces a trace
file as output.file as output.
7
8
NS-2 EnvironmentNS-2 Environment
•Simulation
Scenario
•Tcl Script
•C++
Implementation
•1 •2
•set ns_ [new Simulator]
•set node_(0) [$ns_ node]
•set node_(1) [$ns_ node]
•class MobileNode : public Node
•{
• friend class PositionHandler;
•public:
• MobileNode();
• •
• •
•}
9
ComponentsComponents
• ns-2ns-2, the simulator itself, the simulator itself
– Specify simulation, generate tracesSpecify simulation, generate traces
– Depends on Tcl/Tk, OTcl, TclCLDepends on Tcl/Tk, OTcl, TclCL
• namnam, the network animator, the network animator
– Animate traces from simulationAnimate traces from simulation
– GUI for constructing simple simulationsGUI for constructing simple simulations
• Pre-processingPre-processing
– Traffic, topology generationTraffic, topology generation
• Post-processingPost-processing
– Analyse trace output withAnalyse trace output with awkawk, etc, etc
NS ModelsNS Models
• Traffic models and applications:Traffic models and applications:
– Web, FTP, telnet, constant-bit rateWeb, FTP, telnet, constant-bit rate
• Transport protocols:Transport protocols:
– unicast: TCP (Reno, Vegas, etc.), UDPunicast: TCP (Reno, Vegas, etc.), UDP
– Multicast: SRMMulticast: SRM
• Routing and queueing:Routing and queueing:
– Wired routing, ad hoc rtgWired routing, ad hoc rtg
– queueing protocols: RED, drop-tail, etcqueueing protocols: RED, drop-tail, etc
• Physical media:Physical media:
– Wired (point-to-point, LANs), wirelessWired (point-to-point, LANs), wireless
(multiple propagation models), satellite(multiple propagation models), satellite
10
Basic ArchitectureBasic Architecture
11
•An executable command ns
•Input: tcl simulation scripting file
•Output: trace file  Animation by NAM or
plotting graph by Xgraph (gunplot)
NS2-GoalsNS2-Goals
To support networking research andTo support networking research and
educationeducation
–– Protocol design, traffic studies, etc.Protocol design, traffic studies, etc.
–– Protocol comparison;Protocol comparison;
–– New architecture designs are alsoNew architecture designs are also
supported.supported.
•• To provideTo provide collaborativecollaborative environmentenvironment
–– Freely distributed, open source;Freely distributed, open source;
–– Increase confidenceIncrease confidence in resultin result
12
13
UsingUsing nsns
Simulation
model
Define
problem
Post-process
results
Execute
simulation
Extend
simulator
14
UsingUsing nsns
• Create simulationCreate simulation
– Describe network, protocols, sources, sinksDescribe network, protocols, sources, sinks
– Interface via OTcl which controls C++Interface via OTcl which controls C++
• Execute simulationExecute simulation
– Simulator maintains event list (packet list), executesSimulator maintains event list (packet list), executes
next event (packet), repeats until donenext event (packet), repeats until done
– Events happen instantly inEvents happen instantly in virtual timevirtual time but could takebut could take
arbitrarily longarbitrarily long real timereal time
– Single thread of control, no locking, races, etcSingle thread of control, no locking, races, etc
• Post-process resultsPost-process results
– Scripts (awk, perl, python) to process text outputScripts (awk, perl, python) to process text output
– No standard library but some available on webNo standard library but some available on web
15
LanguagesLanguages
• C++ forC++ for datadata
– Per-packet processing, the core ofPer-packet processing, the core of nsns
– Fast to run, detailed, complete controlFast to run, detailed, complete control
• OTcl forOTcl for controlcontrol
– Simulation descriptionSimulation description
– Periodic or triggered actionsPeriodic or triggered actions
– Manipulating existing C++ objectsManipulating existing C++ objects
– Faster to write and change codeFaster to write and change code
» (a matter of opinion)(a matter of opinion)
16
Basic TclBasic Tcl
# Variables:# Variables:
setset x 10x 10
setset xx
putsputs “x is $x”“x is $x”
# Functions and expressions:# Functions and expressions:
setset y [pow x 2]y [pow x 2]
setset y [expr x*x]y [expr x*x]
# Control flow:# Control flow:
ifif {$x > 0} {{$x > 0} { returnreturn $x }$x } elseelse {{
returnreturn [expr -$x] }[expr -$x] }
whilewhile { $x > 0 } {{ $x > 0 } {
putsputs $x$x
incrincr x –1x –1
}}
forfor {{setset i 0} {$i<10} {i 0} {$i<10} {incrincr i} {i} {
putsputs “$i == $i”“$i == $i”
}}
# Procedures:# Procedures:
procproc pow {x n} {pow {x n} {
ifif {$n == 1} {{$n == 1} { returnreturn $x }$x }
setset part [part [powpow x [x [exprexpr $n-1]]$n-1]]
returnreturn [[exprexpr $x*$part]$x*$part]
}}
# Files:# Files:
setset file [file [open “open “nstrace.txt” w]nstrace.txt” w]
setset line [line [getsgets $file]$file]
puts –nonewlineputs –nonewline $file “hello!”$file “hello!”
closeclose $file$file
17
App1
Agent1
App2
Agent2
Node
From Network to SimulationFrom Network to Simulation
Application,
Agent & Node
LinkNode
App1
Agent1
App2
Agent2
Node
App1
Agent1
App2
Agent2
Node
App1
Agent1
App2
Agent2
Node
Node Node Node
Link
Link
Link Link
Link
Link
Link
Link
App1
Agent1
App2
Agent2
Node
App1
Agent1
App2
Agent2
Node
Visualization ToolsVisualization Tools
18
•nam-1 (Network AniMator Version 1)
•Packet-level animation
•Well supported by ns
•xgraph
•Simulation results
NAMNAM
19
Elements for NS-2 simulationElements for NS-2 simulation
20
•Create the event scheduler
•Turn on tracing
•Create network
•Setup routing
•Create transport connection
•Create traffic
•Transmit application-level data
Creating Simulation environmentCreating Simulation environment
21
 Create event scheduler
 set ns [new Simulator]
 Schedule events
 $ns at <time> <event>
 <event>: any legitimate ns/tcl commands
 Start scheduler
 $ns run
TracingTracing
22
 Turn on tracing on specific links
 $ns trace-queue $n0 $n1
 $ns namtrace-queue $n0 $n1
Creating nodes, links and queuesCreating nodes, links and queues
23
 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
Creating connection :UDPCreating connection :UDP
24
 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
Creating Traffic : on top of UDPCreating Traffic : on top of UDP
25
 CBR
 set src [new
Application/Traffic/CBR]
Creating connection : TCPCreating connection : TCP
26
 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
Creating Traffic : on top of TCPCreating Traffic : on top of TCP
27
 FTP
 set ftp [new Application/FTP]
 $ftp attach-agent $tcp
 Telnet
 set telnet [new
Application/Telnet]
 $telnet attach-agent $tcp
Simple Simulation ExampleSimple Simulation Example
28
•This network consists of 4 nodes (n0, n1, n2, n3)
•The duplex links between n0 and n2, and n1 and n2 have
•The duplex link between n2 and n3 has 1.7 Mbps of bandwidth and 20 ms of
delay 2 Mbps of bandwidth and 10 ms of delay.
•Each node uses a DropTail queue,of which the maximum size is 10
•ftp session is based on tcp
•tcp agent: generate packet (l=1k bytes)
•sink: generate ack and free packets
•cbr session is based on udp
•udp agent: generate packet (l=1k bytes)
@ 1 Mbps
•null: free packets
Script structureScript structure
29
# parameters and options
set ns [new Simulator]
# [Turn on tracing]
# Create topology
# Setup packet loss, link dynamics
# Create routing agents
# Create:
# - protocol agents
# - application and/or setup traffic sources
# Post-processing procs
# Start simulation
Final Topology Generated (final screenshot)Final Topology Generated (final screenshot)
30
31
SummarySummary
• BackgroundBackground
• ArchitectureArchitecture
• UsageUsage
• SimulationSimulation
• NS-programmingNS-programming
• ExampleExample
• SummarySummary
32
Thank You!Thank You!

More Related Content

What's hot

Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
Shaikhul Islam Chowdhury
 

What's hot (20)

Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
 
Ns2
Ns2Ns2
Ns2
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
 
Ns2
Ns2Ns2
Ns2
 
Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 
Profiling Ruby
Profiling RubyProfiling Ruby
Profiling Ruby
 
Ns2 introduction 2
Ns2 introduction 2Ns2 introduction 2
Ns2 introduction 2
 
Ns2
Ns2Ns2
Ns2
 
Ns2programs
Ns2programsNs2programs
Ns2programs
 
Ns fundamentals 1
Ns fundamentals 1Ns fundamentals 1
Ns fundamentals 1
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
 
Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
 
Real-time streams and logs with Storm and Kafka
Real-time streams and logs with Storm and KafkaReal-time streams and logs with Storm and Kafka
Real-time streams and logs with Storm and Kafka
 
A22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle HaileyA22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle Hailey
 
Rust "Hot or Not" at Sioux
Rust "Hot or Not" at SiouxRust "Hot or Not" at Sioux
Rust "Hot or Not" at Sioux
 
Network Simulation
Network SimulationNetwork Simulation
Network Simulation
 

Similar to Venkat ns2

NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
Wajath
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
AAKASH S
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
Jayaprasanna4
 

Similar to Venkat ns2 (20)

Ns2pre
Ns2preNs2pre
Ns2pre
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Ns2
Ns2Ns2
Ns2
 
Ns2 by khan
Ns2 by khan Ns2 by khan
Ns2 by khan
 
Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
 
LF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecases
LF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecasesLF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecases
LF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecases
 
The Art of Grey-Box Attack
The Art of Grey-Box AttackThe Art of Grey-Box Attack
The Art of Grey-Box Attack
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
 
Dc project 1
Dc project 1Dc project 1
Dc project 1
 
Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?
 
Wuala, P2P Online Storage
Wuala, P2P Online StorageWuala, P2P Online Storage
Wuala, P2P Online Storage
 
cscn1819.pdf
cscn1819.pdfcscn1819.pdf
cscn1819.pdf
 
ns2-lecture.ppt
ns2-lecture.pptns2-lecture.ppt
ns2-lecture.ppt
 
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in GoCapturing NIC and Kernel TX and RX Timestamps for Packets in Go
Capturing NIC and Kernel TX and RX Timestamps for Packets in Go
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
 

Recently uploaded

GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
Lokesh Kothari
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
Sérgio Sacani
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Sérgio Sacani
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
Sérgio Sacani
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Sérgio Sacani
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
RizalinePalanog2
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
RohitNehra6
 

Recently uploaded (20)

GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C P
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
CELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdfCELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdf
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdf
 
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdf
 
Creating and Analyzing Definitive Screening Designs
Creating and Analyzing Definitive Screening DesignsCreating and Analyzing Definitive Screening Designs
Creating and Analyzing Definitive Screening Designs
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
 
Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)Recombinant DNA technology (Immunological screening)
Recombinant DNA technology (Immunological screening)
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 

Venkat ns2

  • 2. 2 OutlineOutline • BackgroundBackground • ArchitectureArchitecture • UsageUsage • SimulationSimulation • NS-programmingNS-programming • ExampleExample • SummarySummary
  • 3. 3 ns-2, the Network Simulatorns-2, the Network Simulator • AA discrete event simulatordiscrete event simulator modellingmodelling network protocolsnetwork protocols – Packets, links, queues, protocolsPackets, links, queues, protocols – Visualizer (Visualizer (NAMNAM)) – Trace playbackTrace playback – Error modelsError models • Targeted at networking researchTargeted at networking research • Supports for all types of simulationsSupports for all types of simulations
  • 4. 4 HistoryHistory • 1989:1989: REALREAL by Keshavby Keshav • 1995:1995: nsns by Floyd, McCanne at LBLby Floyd, McCanne at LBL • 1997:1997: ns-2ns-2 by the VINT projectby the VINT project ((Virtual InterNetwork TestbedVirtual InterNetwork Testbed) at) at LBL, Xerox PARC, UCB, USC/ISILBL, Xerox PARC, UCB, USC/ISI • 1999: Wireless models added @ CMU1999: Wireless models added @ CMU • Now:Now: ns-2.29ns-2.29 maintained at USC/ISImaintained at USC/ISI – ns-2.30ns-2.30 pending releasepending release
  • 5. NS-2 OverviewNS-2 Overview • TCP/IP NS2 OSI 7-LayerTCP/IP NS2 OSI 7-Layer 5 •Application •Presentation •Session •Transport •Network •Data Link •Physical •Application •Agent •Node •Link •Application •TCP/UDP •IP •Network •Access
  • 6. Platforms SupportedPlatforms Supported • Most UNIX and UNIX-like systemsMost UNIX and UNIX-like systems  FreeBSDFreeBSD  LinuxLinux  SolarisSolaris • Windows 98/2000/2003/XPWindows 98/2000/2003/XP – Cygwin requiredCygwin required – Some work , some doesntSome work , some doesnt 6
  • 7. User’s PerspectiveUser’s Perspective • From the user’s perspective, NS−2 isFrom the user’s perspective, NS−2 is an OTcl interpreter that takes an OTclan OTcl interpreter that takes an OTcl script as input and produces a tracescript as input and produces a trace file as output.file as output. 7
  • 8. 8 NS-2 EnvironmentNS-2 Environment •Simulation Scenario •Tcl Script •C++ Implementation •1 •2 •set ns_ [new Simulator] •set node_(0) [$ns_ node] •set node_(1) [$ns_ node] •class MobileNode : public Node •{ • friend class PositionHandler; •public: • MobileNode(); • • • • •}
  • 9. 9 ComponentsComponents • ns-2ns-2, the simulator itself, the simulator itself – Specify simulation, generate tracesSpecify simulation, generate traces – Depends on Tcl/Tk, OTcl, TclCLDepends on Tcl/Tk, OTcl, TclCL • namnam, the network animator, the network animator – Animate traces from simulationAnimate traces from simulation – GUI for constructing simple simulationsGUI for constructing simple simulations • Pre-processingPre-processing – Traffic, topology generationTraffic, topology generation • Post-processingPost-processing – Analyse trace output withAnalyse trace output with awkawk, etc, etc
  • 10. NS ModelsNS Models • Traffic models and applications:Traffic models and applications: – Web, FTP, telnet, constant-bit rateWeb, FTP, telnet, constant-bit rate • Transport protocols:Transport protocols: – unicast: TCP (Reno, Vegas, etc.), UDPunicast: TCP (Reno, Vegas, etc.), UDP – Multicast: SRMMulticast: SRM • Routing and queueing:Routing and queueing: – Wired routing, ad hoc rtgWired routing, ad hoc rtg – queueing protocols: RED, drop-tail, etcqueueing protocols: RED, drop-tail, etc • Physical media:Physical media: – Wired (point-to-point, LANs), wirelessWired (point-to-point, LANs), wireless (multiple propagation models), satellite(multiple propagation models), satellite 10
  • 11. Basic ArchitectureBasic Architecture 11 •An executable command ns •Input: tcl simulation scripting file •Output: trace file  Animation by NAM or plotting graph by Xgraph (gunplot)
  • 12. NS2-GoalsNS2-Goals To support networking research andTo support networking research and educationeducation –– Protocol design, traffic studies, etc.Protocol design, traffic studies, etc. –– Protocol comparison;Protocol comparison; –– New architecture designs are alsoNew architecture designs are also supported.supported. •• To provideTo provide collaborativecollaborative environmentenvironment –– Freely distributed, open source;Freely distributed, open source; –– Increase confidenceIncrease confidence in resultin result 12
  • 14. 14 UsingUsing nsns • Create simulationCreate simulation – Describe network, protocols, sources, sinksDescribe network, protocols, sources, sinks – Interface via OTcl which controls C++Interface via OTcl which controls C++ • Execute simulationExecute simulation – Simulator maintains event list (packet list), executesSimulator maintains event list (packet list), executes next event (packet), repeats until donenext event (packet), repeats until done – Events happen instantly inEvents happen instantly in virtual timevirtual time but could takebut could take arbitrarily longarbitrarily long real timereal time – Single thread of control, no locking, races, etcSingle thread of control, no locking, races, etc • Post-process resultsPost-process results – Scripts (awk, perl, python) to process text outputScripts (awk, perl, python) to process text output – No standard library but some available on webNo standard library but some available on web
  • 15. 15 LanguagesLanguages • C++ forC++ for datadata – Per-packet processing, the core ofPer-packet processing, the core of nsns – Fast to run, detailed, complete controlFast to run, detailed, complete control • OTcl forOTcl for controlcontrol – Simulation descriptionSimulation description – Periodic or triggered actionsPeriodic or triggered actions – Manipulating existing C++ objectsManipulating existing C++ objects – Faster to write and change codeFaster to write and change code » (a matter of opinion)(a matter of opinion)
  • 16. 16 Basic TclBasic Tcl # Variables:# Variables: setset x 10x 10 setset xx putsputs “x is $x”“x is $x” # Functions and expressions:# Functions and expressions: setset y [pow x 2]y [pow x 2] setset y [expr x*x]y [expr x*x] # Control flow:# Control flow: ifif {$x > 0} {{$x > 0} { returnreturn $x }$x } elseelse {{ returnreturn [expr -$x] }[expr -$x] } whilewhile { $x > 0 } {{ $x > 0 } { putsputs $x$x incrincr x –1x –1 }} forfor {{setset i 0} {$i<10} {i 0} {$i<10} {incrincr i} {i} { putsputs “$i == $i”“$i == $i” }} # Procedures:# Procedures: procproc pow {x n} {pow {x n} { ifif {$n == 1} {{$n == 1} { returnreturn $x }$x } setset part [part [powpow x [x [exprexpr $n-1]]$n-1]] returnreturn [[exprexpr $x*$part]$x*$part] }} # Files:# Files: setset file [file [open “open “nstrace.txt” w]nstrace.txt” w] setset line [line [getsgets $file]$file] puts –nonewlineputs –nonewline $file “hello!”$file “hello!” closeclose $file$file
  • 17. 17 App1 Agent1 App2 Agent2 Node From Network to SimulationFrom Network to Simulation Application, Agent & Node LinkNode App1 Agent1 App2 Agent2 Node App1 Agent1 App2 Agent2 Node App1 Agent1 App2 Agent2 Node Node Node Node Link Link Link Link Link Link Link Link App1 Agent1 App2 Agent2 Node App1 Agent1 App2 Agent2 Node
  • 18. Visualization ToolsVisualization Tools 18 •nam-1 (Network AniMator Version 1) •Packet-level animation •Well supported by ns •xgraph •Simulation results
  • 20. Elements for NS-2 simulationElements for NS-2 simulation 20 •Create the event scheduler •Turn on tracing •Create network •Setup routing •Create transport connection •Create traffic •Transmit application-level data
  • 21. Creating Simulation environmentCreating Simulation environment 21  Create event scheduler  set ns [new Simulator]  Schedule events  $ns at <time> <event>  <event>: any legitimate ns/tcl commands  Start scheduler  $ns run
  • 22. TracingTracing 22  Turn on tracing on specific links  $ns trace-queue $n0 $n1  $ns namtrace-queue $n0 $n1
  • 23. Creating nodes, links and queuesCreating nodes, links and queues 23  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
  • 24. Creating connection :UDPCreating connection :UDP 24  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
  • 25. Creating Traffic : on top of UDPCreating Traffic : on top of UDP 25  CBR  set src [new Application/Traffic/CBR]
  • 26. Creating connection : TCPCreating connection : TCP 26  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
  • 27. Creating Traffic : on top of TCPCreating Traffic : on top of TCP 27  FTP  set ftp [new Application/FTP]  $ftp attach-agent $tcp  Telnet  set telnet [new Application/Telnet]  $telnet attach-agent $tcp
  • 28. Simple Simulation ExampleSimple Simulation Example 28 •This network consists of 4 nodes (n0, n1, n2, n3) •The duplex links between n0 and n2, and n1 and n2 have •The duplex link between n2 and n3 has 1.7 Mbps of bandwidth and 20 ms of delay 2 Mbps of bandwidth and 10 ms of delay. •Each node uses a DropTail queue,of which the maximum size is 10 •ftp session is based on tcp •tcp agent: generate packet (l=1k bytes) •sink: generate ack and free packets •cbr session is based on udp •udp agent: generate packet (l=1k bytes) @ 1 Mbps •null: free packets
  • 29. Script structureScript structure 29 # parameters and options set ns [new Simulator] # [Turn on tracing] # Create topology # Setup packet loss, link dynamics # Create routing agents # Create: # - protocol agents # - application and/or setup traffic sources # Post-processing procs # Start simulation
  • 30. Final Topology Generated (final screenshot)Final Topology Generated (final screenshot) 30
  • 31. 31 SummarySummary • BackgroundBackground • ArchitectureArchitecture • UsageUsage • SimulationSimulation • NS-programmingNS-programming • ExampleExample • SummarySummary

Editor's Notes

  1. what is it? -- history -- code stats -- tree layout goals, accomplishments, status ns architecture/history/perspective target audience, tutorial outline state of the software and distributions
  2. what does it do? -- tcp, higher protocols, packets, links, queuing disciplines -- visualizer (NAM) -- trace playback -- error models what does it not do? -- routing, ip, L2, routing
  3. basic structure -- setup simulation -- objects -&amp;gt; events -&amp;gt; schedule -&amp;gt; repeat -- trace files -&amp;gt; post processing -&amp;gt; graphs -- (example trace) Model world as events Simulator has list of events Process: take next one, run it, until done Each event happens in an instant of virtual (simulated) time, but takes an arbitrary amount of real time Ns uses simple model: single thread of control =&amp;gt; no locking or race conditions to worry about (very easy)