cn exp12-15
cn exp12-15
cn exp12-15
Aim:
To study about NS2 simulator in detail.
Theory:
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. In general, NS2 provides users with a way of specifying such network
protocols and simulating their corresponding behaviors. Due to its flexibility and
modular nature, NS2 has gained constant popularity in the networking research
community since its birth in 1989. Ever since, several revolutions and revisions
have marked the growing maturity of the tool, thanks to substantial contributions
from the players in the field. Among these are the University of California and
Cornell University who developed the REAL network simulator, the foundation
which NS is based on. Since 1995 the Defense Advanced Research Projects
Agency (DARPA) supported development of NS through the Virtual Inter Network
Testbed (VINT) project. Currently the National Science Foundation (NSF) has
joined the ride in development. Last but not the least, the group of Researchers and
developers in the community are constantly working to keep NS2 strong and
versatile.
Tcl scripting
Tcl is a general purpose scripting language. [Interpreter]
• Tcl runs on most of the platforms such as Unix, Windows, and Mac.
• The strength of Tcl is its simplicity.
• It is not necessary to declare a data type for variable prior to the usage.
Basics of TCL
Syntax: command arg1 arg2 arg3
Hello World!
puts stdout{Hello, World!} Hello, World!
Variables Command Substitution set a 5 set len
[string length foobar] set b $a set len [expr [string
length foobar] + 9]
Wired TCL Script Components
Create the event scheduler
Open new files & turn on the tracing Create the nodes
Setup the links
Configure the traffic type (e.g., TCP, UDP, etc) Set the time of traffic generation
(e.g., CBR, FTP) Terminate the simulation.
NS Simulator Preliminaries.
1. Initialization and termination aspects of the ns simulator.
2. Definition of network nodes, links, queues and topology.
3. Definition of agents and of applications.
4. The nam visualization tool.
5. Tracing and random variables.
Which is thus the first line in the tcl script. This line declares a new variable as
using the set command, you can call this variable as you wish, In general people
declares it as ns because it is an instance of the Simulator class, so an object the
code[new Simulator] is indeed the installation of the class Simulator using the
reserved word new.
In order to have output files with data on the simulation (trace files) or files used
for visualization (nam files), we need to create the files using ―open command:
Within the tcl script, these files are not called explicitly by their names, but instead
by pointers that are declared above and called ―tracefile1 and ―namfile
respectively. Remark that they begins with a # symbol.
The second line open the file ―out.tr to be used for writing, declared with the letter
―w. The third line uses a simulator method called trace-all that have as parameter
the name of the file where the traces will go.
Software Requirements:
NS-2 Simulator
Theory:
Stop and Wait is a reliable transmission flow control protocol. This protocol works
only in Connection Oriented (Point to Point) Transmission. The Source node has
window size of ONE. After transmission of a frame the transmitting (Source) node
waits for an Acknowledgement from the destination node. If the transmitted frame
reaches the destination without error, the destination transmits a positive
acknowledgement. If the transmitted frame reaches the Destination with error, the
receiver destination does not transmit an acknowledgement. If the transmitter
receives a positive acknowledgement it transmits the next frame if any. Else if its
acknowledgement receive timer expires, it retransmits the same frame.
Start with the window size of 1 from the transmitting (Source) node
After transmission of a frame the transmitting (Source) node waits for a reply
(Acknowledgement) from the receiving (Destination) node.
If the transmitted frame reaches the receiver (Destination) without error, the
receiver (Destination) transmits a Positive Acknowledgement.
If the transmitted frame reaches the receiver (Destination) with error, the
receiver (Destination) do not transmit acknowledgement.
If the transmitter receives a positive acknowledgement it transmits the next
frame if any. Else if the transmission timer expires, it retransmits the same
frame again.
If the transmitted acknowledgment reaches the Transmitter (Destination)
without error, the Transmitter (Destination) transmits the next frame if any.
If the transmitted frame reaches the Transmitter (Destination) with error, the
Transmitter (Destination) transmits the same frame.
This concept of the Transmitting (Source) node waiting after transmission
for a reply from the receiver is known as STOP and WAIT.
Algorithm:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file,
and execute nam on trace file.
4. Create two nodes that forms a network numbered 0 and 1
5. Create duplex links between the nodes to form a STAR Topology
6. Setup TCP Connection between n(1) and n(3)
7. Apply CBR Traffic over TCP
8. Schedule events and run the program.
Output:
EXPERIMENT-15
Aim:
To simulate and study the Distance Vector routing algorithm using simulation.
Software Requirements:
NS-2
Theory:
Distance Vector Routing is one of the routing algorithm in a Wide Area Network
for computing shortest path between source and destination. The Router is one
main devices used in a wide area network. The main task of the router is Routing. It
forms the routing table and delivers the packets depending upon the routes in the
table- either directly or via an intermediate devices.
Each router initially has information about its all neighbors. Then this information
will be shared among nodes.
Algorithm:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and
execute nam on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose distance vector routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.
PROGRAM:
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_500
$cbr0 set interval_0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
$ns rtproto DV
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
Output: