NS2 - the network simulator which is proved useful in studying the dynamic nature of communication networks. Simulation of wired as well as wireless network functions and protocols( e.g. routing algorithms, TCP, UDP ) can be done using NS2
2. TRANSPORT LAYER
Flow Control and Error Control
Two transport protocols.
* Transmission Control Protocol (TCP)
* User Datagram Protocol (UDP)
3. SYSTEM MODELLING APPROACH
Analytical Approach - describe the system
mathematically, and apply numerical methods.
Simulating Approach - recreates real-world
scenarios using computer programs and
simulation usually requires fewer simplification
assumptions.
4. PARTS OF GENERAL SIMULATION IN
COMPUTER NETWORKS
1. Planning
2. Implementing
a) Initialization
b) Result Generation
c) Post simulation Processing
3. Testing
8. NS2
NS2-Network Simulator (Version 2), widely known as
NS2, is simply an event-driven simulation tool that has
proved useful in studying the dynamic nature of
communication networks. Simulation of wired as well as
wireless network functions and protocols (e.g., routing
algorithms, TCP, UDP) can be done using NS2.
9. NS2 –TWO KEY LANGUAGES
C++ - The internal mechanism (i.e., a backend) of the simulation
Object-Oriented Tool Command Language (OTcL) - Sets up
simulation by assembling and configuring the objects as well as
scheduling discrete events (i.e., a frontend)
C++ and OTcL are linked together using TclCL
12. INSTALLATION OF NS2
NS2 builds and runs under windows using Cygwin.
Cygwin provides Linux like environment under
windows.
Download Cygwin from following link
http://www.cygwin.com/setup.exe
28. CONTROL STRUCTURE
Selection Structure
if.. else, elseif ,and switch are the selection
structure.
Their syntaxes are shown below:
if {<condition1>} { <actionSet1> }
elseif {<condition2>} { <actionSet2> }
...
else { <actionSetN> }
switch <variable> {
<pattern_1> { <actionSet1> }
<pattern_2> { <actionSet2> }
...
default { <actionSetN> }
}
29. Repetition Structure
The commands “while,” “for,” and “foreach” are
used when actions need to be repeated for several
times.
while {<condition>} { <actions> }
for {<init>} {<condition>} {<mod>} { <actions> }
foreach {<var>} {<list>} { <actions> }
30. Jumping Structure
The structure “break” and “continue” are used
to stop the iterative flow of the above “while,” “for,”
and “foreach” repetitive structures.
31. Packet tracing- records the detail of packet flow during a
simulation.
Packet tracing can be classified based on
1. Text Based Packet Tracing
2. NAM Packet Tracing
Text Based Packet Tracing
Text-based packet tracing records the detail of packets
passing through network checkpoints (e.g., nodes and queues).
it is invoked by
>>$ns trace-all $file
32. Network AniMation (NAM) Packet Tracing
Many visualization features are available in
NAM. These features are for example animating
colored packet flows, dragging and dropping nodes
(positioning), labeling nodes at a specified instant,
shaping the nodes, coloring a specific link, and
monitoring a queue.
It is Invoked by
>>nam filename.nam
33. EXAMPLE
# myfirst_ns.tcl
# Create a Simulator
1 set ns [new Simulator]
# Create a trace file
2 set mytrace [open out.tr w]
3 $ns trace-all $mytrace
# Create a NAM trace file
4 set myNAM [open out.nam w]
5 $ns namtrace-all $myNAM
34. # Define a procedure finish
6 proc finish { } {
7 global ns mytrace myNAM
8 $ns flush-trace
9 close $mytrace
10 close $myNAM
11 exec nam out.nam &
12 exit 0
13 }
36. # Create a UDP agent
25 set udp [new Agent/UDP]
26 $ns attach-agent $n0 $udp
27 set null [new Agent/Null]
28 $ns attach-agent $n3 $null
29 $ns connect $udp $null
30 $udp set fid_ 1
# Create a CBR traffic source
31 set cbr [new Application/Traffic/CBR]
32 $cbr attach-agent $udp
33 $cbr set packetSize_ 1000
34 $cbr set rate_ 2Mb
37. # Create a TCP agent
35 set tcp [new Agent/TCP]
36 $ns attach-agent $n1 $tcp
37 set sink [new Agent/TCPSink]
38 $ns attach-agent $n4 $sink
39 $ns connect $tcp $sink
40 $tcp set fid_ 2
# Create an FTP session
41 set ftp [new Application/FTP]
42 $ftp attach-agent $tcp
38. # Schedule events
43 $ns at 0.05 "$ftp start"
44 $ns at 0.1 "$cbr start"
45 $ns at 60.0 "$ftp stop"
46 $ns at 60.5 "$cbr stop"
47 $ns at 61 "finish“
# Start the simulation
48 $ns run
We run the above simulation script by executing
>>ns myfirst_ns.tcl
39. The Text-Based Packet Tracing for the example
“myfirst_ns.tcl” is
...
+ 0.110419 1 2 tcp 1040 ------- 2 1.0 4.0 5 12
+ 0.110419 1 2 tcp 1040 ------- 2 1.0 4.0 6 13
r 0.115348 1 2 tcp 1040 ------- 2 1.0 4.0 3 10
+ 0.115348 2 4 tcp 1040 ------- 2 4.0 4.0 3 10
- 0.115348 2 4 tcp 1040 ------- 2 4.0 2.0 3 10
r 0.115376 2 3 cbr 1000 ------- 1 4.0 3.0 1 7
r 0.115431 1 2 tcp 1040 ------- 2 1.0 4.0 4 11
...
Format of each line in normal Trace line
40.
41. SUMMARY
Transport Layer
Modeling Approach
Parts of Simulation
Simulation Performance
Simulation Types
NS2
Installation of NS2
Terminologies
Basics of TcL
Packet Tracing
Example