Académique Documents
Professionnel Documents
Culture Documents
ASSIGNMENT 2:
NETWORK SIMULATOR 2 (NS2)
GROUP MEMBERS:
1) NURIZAN BINTI TAHIR (MKE161006)
2) AIDAYU DELAILA BINTI DAHLAN (MKE161002)
3) M TIGHAZZA (MKE161 )
LECTURER:
PROF. MADYA DR. SHARIFAH HAFIZAH BINTI SYED ARIFFIN
Assignment 2
Network Simulator 2 (NS2)
1.0 INTRODUCTION
Figure1: NS
working process
Another major component of NS beside network objects is the event scheduler. An event in
NS is a packet ID that is unique for a packet with scheduled time and the pointer to an object that
handles the event. In NS, an event scheduler keeps track of simulation time and fires all the
events in the event queue scheduled for the current time by invoking appropriate network
components, which usually are the ones who issued the events, and let them do the appropriate
action associated with packet pointed by the event.
Network components communicate with one another passing packets, however this does
not consume actual simulation time. All the network components that need to spend some
simulation time handling a packet (i.e. need a delay) use the event scheduler by issuing an event
for the packet and waiting for the event to be fired to itself before doing further action handling
the packet. Timers use event schedulers in a similar manner that delay does. The only difference
is that timer measures a time value associated with a packet and does an appropriate action
related to that packet after a certain time goes by, and does not simulate a delay.
a)Droptail Queuing
It is one of the simplest queuing mechanisms that are used by routers when packets should
be dropped. In this mechanism, similar treatment of packets is applied to each packet and when
queue is filled to its maximum capacity, the newly coming packets are dropped until the queue
has sufficient space to accept new incoming packets [2]
2.0 METHODOLOGY
The NS2 is installed in directory nsallinone-2.35. Figure 2 shows the directory structure
under directory nsallinone-2.35. Based on the figure, directory nsallinone-2.30 is on the Level 1.
At Level 2, there is directory tclcl-1.18 contains classes in TclCL such as Tcl, TclObject, and
TclClass. All NS2 simulation modules are in directory ns-2.35 on the Level 2. Meanwhile, at
Level 3, the modules in the interpreted hierarchy are under directory tcl. Among these modules,
the frequently-used ones for instance ns-lib.tcl, ns-node.tcl, ns-link.tcl are stored under directory
lib on Level 4.
Figure 2: Directory structure of NS2 [4]
There are three important steps for network simulation simulation using NS2:
The rst step in simulating a network using NS2 is to design the simulation. The user
should determine the simulation purposes, network congurations and assumptions, the
performance measures, and the type of expected results.
This step implements the design in the rst step, the simulation design. It consists of two
phases: network conguration phase and simulation phase. The network phase created and
configured network components such as node, UDO and TCP and the events like data transfer
are scheduled to start at certain time. The simulation phase starts the simulation that is
configured in the step 2. While simulating, the simulation clock is maintains and executes event
chronologically. Normally, it is convenient to dene a simulation scenario in a tcl scripting le
(e.g., <file>) and feed the le as an input argument of an NS2 invocation such as executing ns
<file>).
Step 3: Post Simulation Processing
The main tasks in this step include verifying the integrity of the program and evaluating
the performance of the simulated network.
This section divide the source code by section so that the workflow of the constructing the
code is able to illustrate and understand. The sections is as below:
Simulator object is allows for the creation of nodes, links and connecting agents used in
creating a network topology in determining network performance . The simulator class has all the
basic functions to perform this task and the functions belonging to the simulator class can be
used by appending $ns at the beginning of the code since the simulator object are design to be
b) Trace file
Trace file is use in collecting data for determining the simulation results and the aid of
NS2 trace file shows drop or arrival of packet that occurs in queue or in a link. The code is:
A simulator object is used to create five nodes which are assign to be handle s0, s1, s2, G, r.
The handles are used when referring to those nodes and traffic sources, FTP and CBR are
attached to the traffic agents called TCP and UDP. These traffic agents are attached to the nodes
#G acts as a gateway.
set G [$ns node]
#r acts as a receiver.
set r [$ns node]
The traffic used can be differentiated from one another by assigning colour to the traffic. The
Links are required to connect all the different nodes together. The output queue and the queue
type of a node are implemented as part of the link. There are two types of links called simplex
and duplex but in this simulation all links are design to be duplex. The command for duplex link
connection between all the sources S0, S1 and S2, gateway and the receiver using Droptail
queuing mechanism are:
From the code section above, it could be seen that the duplex link connection the sources
to the gateway have a bandwidth of 8Mb and a delay of 1ms. The duplex link between the
gateway and the receiver has a bandwidth of 8Mb and delay of 1ms.
The Queuing size between the gateway and the receiver using this code:
#Define the queue size for the link between node G and r
$ns queue-limit $G $r 5
g) Topology layout
There is need to set up the layout of the network topology comprises of a collections of links
and nodes.
packets in the queue or number of packets drops, this therefore make it possible to track the
statistics of arrivals, departures and drops.
UDP and TCP sources be connected with traffic sinks to terminate the flow of information
without any processing.
The code below shows the scheduling of the FTP and label of nodes:
$ns at 0.0 $s1 label Sender1
$ns at 0.0 $s2 label Sender2
$ns at 0.0 $s3 label Sender3
$ns at 0.0 $G label Gateway
$ns at 0.0 $r label Receiver
$ns at 0.1 $ftp1 start
$ns at 0.1 $ftp2 start
$ns at 0.1 $ftp3 start
$ns at 5.0 $ftp1 stop
$ns at 5.0 $ftp2 stop
$ns at 5.0 $ftp3 stop
$ns at 5.25 finish
$ns run
NAM trace function as is records simulation detail in a text le, and uses the text le the
play backs the simulation using animation [4]. NAM trace is activated by the command $ns
namtrace-all $file, where ns is the simulator handle. The file is a handle associated with the le
which stores the NAM trace information. Then, after obtaining a NAM trace le, the animation
can be initiated directly at the command prompt through the following command. The NAM file
is an animation tools to illustrate the network after simulating the code. The NAM file helps user
to illustrate the node energy, packet filter, highlight leaf trees and showing annotations.
The Figure 3 shows the whole network. It contains three sender or node with label, S1,
S2, and S3. These three nodes communicate to the gateway. Then from the gateway, the network
connected to the receiver. This NAM file appeared right after the play button is clicked. Figure
4 and Figure 5 shows the TCP connection for sender 1, sender 2 and sender 3. In addition, Figure
6, Figure 7 and Figure 8 shows the packet drop in the gateway for each sender when the buffer is
full.
Figure 3: The whole network simulation
Figure 4: the TCP connection for sender 1 and 3
Figure 5: The TCP connection for sender 1 and 2
Figure 6: Packet drop from sender 1 at gateway when buffer is full
Figure 7: Packet drop from sender 2 at gateway when buffer is full
Figure 8: Packet drop from sender 3 at gateway when buffer is full
[2]Mohit Agrawal1, Navneet Tiwari , Lalla Atul Singh Chaurasia and Jatan Saraf, Performance
Comparison of Active Queue Management Algorithms, 2009 International Symposium on
Computing, Communication, and Control (ISCCC 2009) Proc .of CSIT vol.1 (2011) (2011)
IACSIT Press, Singapore
[4] Issariyakul, Teerawat, and Ekram Hossain. An introduction to network simulator NS2.
Springer, 2012.