Installation & Configuration of NS2 in Linux environment and building basic LAN topology in NS2.
Aim: Installation
& Configuration of NS2 in Linux environment and building basic
LAN topology in NS2.
Apparatus
(Software): NS2 simulator.
Procedure:
Following should be studied to understand this practical.
NS2 (Network
Simulator version 2)
1. What is Network
Simulator?
Setting up a network to
do some real experiments is the best way for studying about
communication in internet. However, setting a network is not easy and
costly. For this reason, a virtual network provided by network
simulator is used for experiment in only one computer. Specially, NS2
which is free and easy to use is the popular all over the world.
For example, to observe
the communication between A,B,C,D in a network as shown in Fig. 1(a),
we can set up a network topology as shown in Fig.1(b) for simulator
to do experiment.
(a) The reality network
(b) The network for
simulation
2. NS2 Manual
NS2 use Tcl language
for creating simulation scenario file (for example, sample.tcl).
Network topology, transmission time, using protocol etc... are
defined in scenario file. If we execute this scenario file, the
simulation result will be output to out.tr and out.nam file.
out.nam contains
the data for animation of the experiment result. This file can be
execute by Nam, an animation software. The state of forwarding
packet in Nam is shown in Fig.2.
If simulation use TCP,
we can also observe the state of TCP congestion control by a trace
file.
Figure 2: Animation soft Nam
out.tcp Record
the change of TCP parameters by time. Using Gnuplot software to plot
a graph, it is easy to observe the appearance of congestion control.
This file is called as TCP trace file.
3. The following is
steps to creating a scenario file.
Step 0: Declare
Simulator and setting output file
Step 1: Setting Node
and Link
Step 2: Setting Agent
Step 3: Setting
Application
Step 4: Setting
Simulation time and schedules
Step 5: Declare finish.
3.1 Step 0:
Declare Simulator and setting output file
Declare simulator and
setting output file is written as below.
--------------------------------------------------
set ns [new Simulator]
set file [open out.tr
w]
$ns trace-all $file
set namfile [open
out.nam w]
$ns namtrace-all
$namfile
set tcpfile [open
out.tcp w]
Agent/TCP set
trace_all_oneline_ true
--------------------------------------------------
3.2 Step1: Setting
Node and Link
Setting a node is shown
as below.
-------------------------------------------------
set n0 [$ns node]
--------------------------------------------------
then the node which
have name as n0 is ready to use. (in Tcl file it will refer to $n0).
Node is numbered from 0. Link is declared as below.
--------------------------------------------------
$ns duplex-link $n0 $n2
3Mb 5ms DropTail
$ns duplex-link-op $n0
$n2 orient right-down
--------------------------------------------------
In line 1, the link
between two nodes n0 and n2 has bandwidth 3Mbps and delay 5ms. A
biconnection link between n0 and n2 is declared. DropTail is a
waiting queue type, if the queue overflow then the new entered packet
will be dropped, similar to buffer of general realistic network. Line
2 setting position of node and link for Nam. It does not affect to
the result of simulation. The length of queue is set as below
--------------------------------------------------
$ns queue-limit $n2 $n3
20
$ns duplex-link-op $n2
$n3 queuePos 0.5
--------------------------------------------------
In line 1, the length
of Queue on the link from n2 to n3 is 20[packets]. In line 2, the
position of Queue is set for executing simulation result on Nam, 0.5
is the angle between link and queue, it equal to (0.5π).
3.3 Step2: Setting
Agent
UDP Agent
Using UDP for
simulation, the sender set the Agent as UDP Agent while the receiver
set to Null Agent. Null Agents do nothing except receiving the
packet. Setting of Agent as flowing.
--------------------------------------------------
set udp [new Agent/UDP]
$ns attach-agent $n0
$udp
set null [new
Agent/Null]
$ns attach-agent $n3
$null
$ns connect $udp $null
$udp set fid_ 0
$ns color 0 blue
--------------------------------------------------
In first 4 lines, udp,
null Agent is set for n0, n3. Line 5 declared the transmission
between udp and
null. Line 6 set the
number for data flow of udp. This number will be recorded to all
packet which are sent from udp. By using this number, we can easily
observer the flow that packet is belong to by looking up trace file.
Similarly, in line 7, we mark the color to discrete packet for
showing result on Nam.
TCP Agent
Using TCP for
simulation, the sender set the Agent as TCP Agent while the receiver
set to TCPSink
Agent. When receiving a
packet, TCPSink Agent will reply an acknowledgment packet (ACK).
Setting Agent for TCP is similar to UDP.
--------------------------------------------------
set tcp [new Agent/TCP]
$ns attach-agent $n1
$tcp
set sink [new
Agent/TCPSink]
$ns attach-agent $n3
$sink
$ns connect $tcp $sink
$tcp set fid_ 1
$ns color 1 red
--------------------------------------------------
Confirm that fid and
color is differ from udp.
Trace file of TCP is
written as below.
--------------------------------------------------
$tcp attach-trace
$tcpfile
$tcp trace cwnd_
--------------------------------------------------
3.4 Step3: Setting
Application
In general, UDP Agent
use CBR Application while TCP Agent use FTP Application.
--------------------------------------------------
set cbr [new
Application/Traffic/CBR]
$cbr attach-agent $udp
set ftp [new
Application/FTP]
$ftp attach-agent $tcp
--------------------------------------------------
3.5 Step4: Setting
time schedule for simulation
Time schedule of a
simulation is setting as below:
--------------------------------------------------
$ns at 1.0 "$cbr
start"
$ns at 1.5 "$ftp
start"
$ns at 3.0 "$ftp
stop"
$ns at 3.5 "$cbr
stop"
$ns at 4.0 "finish"
proc finish {} {
global ns file namfile
tcpfile
$ns flush-trace
close $file
close $namfile
close $tcpfile
exit 0
}
--------------------------------------------------
cbr transmit data from
1.0[sec] to 3.5[sec] and ftp transmit data from 1.5[sec] to 3.0[sec].
The finish
function is use for
output data file which always at the end of simulation.
3.6 Step5: Declare
finish
After finish setting,
declare finish is written at the end of file.
--------------------------------------------------
$ns run
--------------------------------------------------
Comments
Post a Comment