Sei sulla pagina 1di 43

EXPERIMENT – 1

Aim :Introduction to Computer Network laboratory: Introduction to Discrete Event Simulation,


Discrete Event Simulation Tools - ns2/ns3, Omnet++

Objective:
1. To briefly describe the role of network simulator
2. To provide a list of different simulators and give a brief introduction of NS2/NS3 and
OMNET++
3. to provide resource of the network simulator NS-2
4. To give all dependency details for installing the NS
5. To give installation steps of the NS

Outcome: After doing this experiment student will be able to :


1. understand the various simulators and their installation
2. to work on the basic commands related to network simulators
3. Watch the result in various files such as .tr and .nam files
4. To see the plot on the animator (NAM)

Introduction to Computer Network Laboratory Simulators:


Computer networks is defined as the interconnection of different computing devices through a
communication channels to facilitate communication and resource-sharing among a wide range
of users. The devices communicate with each other following a certain protocol.
Need for Netwrok Simulators:
Performance of the network can be measured in many ways, including transmut time and
response time. Transmit time is the amount of time required for a message to travel from one
device to another. Response time is the time elapsed between and enquiry and a response. The
performance of the network depends on a number of factors, including the number of users, and
type of transmission medium, the capability of the connected hardware, and the efficiency of the
software.
Performance is evaluated by two network metrics: throughput and delay. We often need more
throughput and less delay. However, these criteria are often contradictory. If we try to send more
data to the network, we may increase the throughput but we increase the delay because of traffic
congestion in the network.
Reliability: in addition to the accuracy of the delivery, network re;liability is measured by the
frequency of failure, the time it take the link to recover from a failure, and the network's
roboustness in a catastrophe.
Simulators an introduction:
Network simulation is an important tool in developing, testing and evaluatingnetwork protocols.
Simulation can be used without the target physical hardware, making it economical and practical

ABHISHEK ECE-B(G2) 40720807317 1


40920802816
for almost any scale of network topology and setup. It is possible to simulate a link of any
bandwidth and delay, even if such a link is currently impossible in the real world. With
simulation, it is possible to set each simulated node to use any desired software. This means that
meaning deploying software is not an issue. Results are also easier to obtain and analyze,
because extracting information from important points in thesimulated network is as done by
simply parsing the generated trace files. Different simulators that are available are:
 MIT's NETSIM
 NIST
 CPSIM
 INSANE
 NEST
 REAL
 NS
 OMNET++
 OPNET
 NCTUns

Classification of Simulations :
In classical thinking there are three types of simulation; discrete event, continuous, and
MonteCarlo. They were articulated by Nance (1993) as:
a. Discrete event simulation : It utilizes a mathematical/logical model of a physicalsystem
that portrays state changes at precise points in simulated time. Both the nature of the state change
and the time at which the change occurs mandate precise description. Customers waiting for
service, the management of parts inventory or military combat are typical domains of discrete
event simulation.
b. Continuous simulation: It uses equational models, often of physical systems, which do
not portray precise time and state relationships that result in discontinuities. The objective of
studies using such models do not require the explicit representation of state and time
relationships. Examples of such systems are found in ecological modeling, ballistic reentry, or
large scale economic models.
c. Monte Carlo simulation : the name given by John van Neumann and Stanislaw M.
Ulam to reflect its gambling similarity, utilizes models of uncertainty where representation of
time is unnecessary. The term originally attributed to "a situation in which a difficult non-
probabilistic problem is solved through the invention of a stochastic process that satisfies the
relations of the deterministic problem". A more recent characterization is that Monte Carlo is
"the method of repetitive trials. Typical of Monte Carlo simulation is the approximation of a
definite integral by circumscribing the region with a known geometric shape, then generating
random points to estimate the area of the region through the proportion of points falling within
the region boundaries.

ABHISHEK ECE-B(G2) 40720807317 2


40920802816
Features of Network Simulator NS2

NS (Network Simulator) consists of group of series of distinct occurrencecomplex simulators,


specifically NS-1, NS-2 and NS-3. All of them are discrete-eventnetwork simulator, mainly used
in investigating and training.

NS-2 is a very popular discrete event Network Simulator, which is widely used in the research
field of Wired, Wireless and Satellite Networks across both academia andindustry as a way of
designing, testing and evaluating new and existing protocolsand architectures, and has also
proven a very useful tool for teaching purposes.

NS-2 comes fully equipped of protocols, models, algorithms and accessory tools. NS-2 is an
open source network simulator which is freely available for academic research purpose.
Therefore, in terms of scientific acceptance, a number of tools/modules andcost, NS-2 would be
a sort of ideal choice.

NS is a discrete event simulator targeted at networking research. NS provides substantial support


for simulation of TCP, routing, and multicast protocols over wired andwireless (local and
satellite) networks.

NS-2 started as a variant of the REAL network simulator in 1989 and has since been supported
by the Virtual InterNetwork Testbed (VINT) project that is a DARPA-funded research project
whose aim is to build a network simulator.

WHY NS2?

When the system under research is complex to either follow an analyticalapproach or implement
it in real time to study its behavior, simulation is thesolution that ultimately makes it feasible by
modeling it and closely mimickingthe actual process. Network researches wholly depend on the
availability ofnumerous simulation tools like OPNET, NS2, OMNET++ and so on. Withoutthese
tools it would be difficult to even imagine the advancements we havereached in networking. Of
the numerous tools available, Network Simulator or NS2(as it is famously called) stands distinct
from the rest of the simulators.

To create an ns-2 simulation, we need to do the following (in addition to a modest amount of
standard housekeeping).

 define the network topology, including all nodes, links and router queuing rules

 create some TCP (or UDP) connections, called Agents, and attach them to nodes

 create some Applications – usually FTP for bulk transfer or telnet for intermittent random
packet generation – and attach them to the agents

 start the simulation

ABHISHEK ECE-B(G2) 40720807317 3


40920802816
Once started, the simulation runs for the designated amount of time, driven by the packets
generated by the Application objects. As the simulated applications generate packets for
transmission, the ns-2 system calculates when these packets arrive and depart from each node, and
generates simulated acknowledgment packets as appropriate. Unless delays are explicitly
introduced, node responses – such as forwarding a packet or sending an ACK – are instantaneous.
That is, if a node begins sending a simulated packet from node N1 to N2 at time T=1.000 over a
link with bandwidth 60 ms per packet and with propagation delay 200 ms, then at time T=1.260
N2 will have received the packet. N2 will then respond at that same instant, if a response is
indicated, egby enqueuing the packet or by forwarding it if the queue is empty.
Introduction to OMNeT++
OMNeT++ is a modular, component-based C++ simulation library and framework, primarily for
building network simulators. It could be used to simulate different routing protocols, whether
MANET or WSN, OMNeT++ has a lot of examples to illustrate how these protocols work in
details. OMNET provide the following:

 C++ class library


– Simulation kernel
–Utility classes (for random number generation, statistics collection, topology
discovery etc.)
-> use to create simulation components (simple modules and channels)
• Infrastructure to assemble simulations
– Network Description Language (NED)
–.ini files
• Runtime user interfaces
– Tkenv
–Cmdenv
• Tools to facilitate creating simulations and evaluating results
–GNED
–Scalars
–Plove
• Tools to document large simulation models
–opp_neddoc
• Extension interfaces for real-time simulation, emulation, MRIP, parallel distributed
simulation, database connectivity and so on

ABHISHEK ECE-B(G2) 40720807317 4


40920802816
Installalation of NS2
Step1:SettingupthePrerequisites

1. First of all, download Network Simulator (NS-2.35) from here.I assume you have downloaded
itintoyour'/home/ECE/Local'directory.

2 [Optional]. Now we have to update the Ubuntu with its latest components. Open up a terminal
and run these commands:

1 sudo apt-get update


2 sudo apt-get dist-upgrade
3 sudo apt-get update
Make sure that your Ubuntu is fully updated ( i.e. there should be no pending updates in your
UbuntuSoftwareCenterandinSoftwareUpdater).

3. Before installing the NS we have to install some essential packages required by the NS. So run
the following commands:

1 sudo apt-get install build-essential autoconfautomake


2 sudo apt-get install tcl8.5-dev tk8.5-dev
3 sudo apt-get install perlxgraphlibxt-dev libx11-dev libxmu-dev
4 sudo apt-get install gcc-4.4

Step2:ExtractandInstallNS

1. Extract the downloaded NS package either using the right click context menu "Extract here" or
using the following commands from a terminal:

1 cd /home/ ECE/Local
2 tar -xvzf ns-allinone-2.35.tar.gz
2. After extracting the "ns-allinone-2.35" folder, open up the file "/ns-allinone-2.35/ns-
2.35/linkstate/ls.h" in an editor. You can do it either from the terminal or from the file explorer
(Nautilus). We have to make some changes in the ls.h file else it will show an error while
installing the NS. Once you have opened the file move to the line 137 and replace the erase
(image 1) with this—>erase (image 2) and save the file.
3. Now its time to finally install the NS. Open up a terminal and move to the directory where you
have extracted the package, in our case its '/home/ECE/Local' and install NS using the following
commands (image 4):

1 cd /home/ECE/Local/ns-allinone-2.35

ABHISHEK ECE-B(G2) 40720807317 5


40920802816
2 sudo ./install
It will some time here so have patience.
Step3:SettheEnvironmentVariables

1. Assuming everything went well in the previous step and you have successfully installed your
NS. Now that NS is installed, there are some environment variables that need to be added to your
profile. This can be done by editing the .bashrc file. Open a new terminal and open the file
using:

1 sudogedit .bashrc

NOTE: You may want to create a backup of the .bashrc before editing, the easiest way is to copy
the file to a different location. Later you can replace the edited .bashrc with the copied one in
case something goes sideways or if you want to remove the NS.
2. Add the following lines AT THE END of the file. Be sure to change "/path_to" to the path of
where you have extracted the NS (e.g. '/home/ECE/Local').
exportPATH=$PATH:/home/ece/Public/ns-allinone-2.35/bin:/home/ece/Public/ns-allinone-
2.35/tcl8.5.10/unix:/home/ece/Public/ns-allinone-2.35/tk8.5.10/unix
exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ece/Public/ns-allinone-2.35/otcl-
1.14:/home/ece/Public/ns-allinone-2.35/libexport
TCL_LIBRARY=$TCL_LIBRARY:/home/ece/Public/ns-allinone-2.35/tcl8.5.10/library
Now save and close the file-descriptor
Step4:ValidatetheInstallation

You need to validate NS to check if everything is OK but keep in mind that it will take a lot of
time (about 1:30 hrs). Open up a terminal and move to the directory ‘/home/ece/Local/ns-
allinone-2.35/ns-2.35/'andrun:
And That isit! You can now run ns from a terminal window by executing: ns
If you received the "%" sign, it means that NS is running (image 5). Congratulations !!
Introduction to TCL Scripts:
Now that the NS2 is installed on your system. You need to know a bit about the scripting. The
scripting interface for ns-2 uses the language Tcl, pronounced “tickle”; more precisely it is
object-Tcl, or OTcl. For simple use, learning the general Tcl syntax is not necessary; one can
proceed quite successfully by modifying standard examples.
However, Tcl is a powerful scripting language that runs under Unix, Linux, VMS,
DOS/Windows, OS/2, and MacOS (at least). It provides all the usual high-level programming
features that we've come to expect from languages like the Unix shell, Awk, Perl, or Rexx, such

ABHISHEK ECE-B(G2) 40720807317 6


40920802816
as:
 Variable-length strings
 Associative arrays
 Lists
 Keyed lists (aka structs, structures or records)
 Pattern matching with regular expressions
 Ability to define or redefine procedures at run-time
 Full file access
 Error handling

Use of set, puts, incr, and set n [expr $n + 1] commands in tcl

Arrays in TcL

ABHISHEK ECE-B(G2) 40720807317 7


40920802816
EXPERIMENT – 2
Aim :Using Free Open Source Software tools for network simulation – I Preliminary usage of the
tool ns3 Simulate telnet and ftp between N sources - N sinks (N = 1, 2, 3). Evaluate the effect of
increasing data rate on congestion.

Software Used : Network Simulator 2


TCL Script :
#Create NS Object :
set ns [new Simulator]

#Open the nam trace file

set nf [open out.nam w]

$ns namtrace-all $nf

#Define a 'finish' procedure

proc finish {} {

global ns nf

$ns flush-trace

#Close the trace file

close $nf

#Execute nam on the trace file

exec nam –a out.nam&

exit 0

}
#Create two nodes

set n0 [$ns node]

set n1 [$ns node]

#Create a duplex link between the nodes

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

ABHISHEK ECE-B(G2) 40720807317 8


40920802816
#Call the finish procedure after 5 seconds of simulation time

$ns at 5.0 "finish"

#Run the simulation

$ns run

#Execute a ns-2 script:

ns example1a.tcl

PART-B : To attach traffic from node 0 to node 1


set ns [new Simulator]
#open Trace Files
set f [open out.tr w]
$ns trace-all $f
set nf [open out.nam w]
$ns namtrace-all $nf
#define "finish" procedure
proc finish {} {
global ns
$ns flush-trace
#Execute the nam animation file
exec namout.nam&
exit 0
} n0 N1
#creating Node

set n0 [$ns node] udp

set n1 [$ns node]

#creating link and Queue

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

#create UDP agent and attach it to nod 0

ABHISHEK ECE-B(G2) 40720807317 9


40920802816
set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

#Adding Traffic to link


#create cbr traffic source and attach it to udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005500

$cbr0 attach-agent $udp0

#Adding Traffic to link ; create null agent (a traffic sink) and attach it to node n1

n0 n0

udp
null
cbr

set null0 [new Agent/Null]

$ns attach-agent $n1 $null0

#connect traffic source with the traffic sink

n0 n0

udp
null
cbr

$ns connect $udp0 $null0

ABHISHEK ECE-B(G2) 40720807317 10


40920802816
#schedule event for CBR agent

$ns at 0.5 "$cbr0 start"

$ns at 4.5 "$cbr0 stop"

$ns at 5.0 "finish"

#start ns
$ns run

#stop ns
exit 0
Output :

Fig. Command window(Terminal) and Output for TCL Script

ABHISHEK ECE-B(G2) 40720807317 11


40920802816
EXPERIMENT –3
Aim :Simulating the effect of queuing disciplines on network performance . Write a simple tcl
script that creates the simple network configuration and runs the simulation scenario shown
below:

Software Used : Network Simulator 2


Theory and Specifications:

Figure . A
Simple Network Topology and Simulation Scenario
This network consists of 4 nodes (n0, n1, n2, n3) as shown in above figure. The duplex links
between n0 and n2, and n1 and n2 have 2 Mbps of bandwidth and 10 ms of delay. The duplex
link between n2 and n3 has 1.7 Mbps of bandwidth and 20 ms of delay. Each node uses a
DropTail queue, of which the maximum size is 10. A "tcp" agent is attached to n0, and a
connection is established to a tcp "sink" agent attached to n3. As default, the maximum size of a
packet that a "tcp" agent can generate is 1KByte. A tcp "sink" agent generates and sends ACK
packets to the sender (tcp agent) and frees the received packets. A "udp" agent that is attached to
n1 is connected to a "null" agent attached to n3. A "null" agent just frees the packets received. A
"ftp" and a "cbr" traffic generator are attached to "tcp" and "udp" agents respectively, and the
"cbr" is configured to generate 1 KByte packets at the rate of 1 Mbps. The "cbr" is set to start at

ABHISHEK ECE-B(G2) 40720807317 12


40920802816
0.1 sec and stop at 4.5 sec, and "ftp" is set to start at 1.0 sec and stop at 4.0 sec.
TcLScript:-

set ns [new Simulator]

#Define different colors for data flows (for NAM)

$ns color 1 Blue


$ns color 2 Red
#Open the NAM and Trace file

set nf[open out.tr w]

$ns trace-all $nf

set nf [open out.nam w]

$ns namtrace-all $nf

#Define a 'finish' procedure

proc finish {} {

global ns nf

$ns flush-trace

#Close the NAM trace file

close $nf

#Execute NAM on the trace file

exec namout.nam&

exit 0

#Create four nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

ABHISHEK ECE-B(G2) 40720807317 13


40920802816
set n3 [$ns node]

#Create links between the nodes

$ns duplex-link $n0 $n2 2Mb 10ms DropTail

$ns duplex-link $n1 $n2 2Mb 10ms DropTail

$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

#Set Queue Size of link (n2-n3) to 10

$ns queue-limit $n2 $n3 10

#Give node position (for NAM)

$ns duplex-link-op $n0 $n2 orient right-down

$ns duplex-link-op $n1 $n2 orient right-up

$ns duplex-link-op $n2 $n3 orient right

#Monitor the queue for link (n2-n3). (for NAM)

$ns duplex-link-op $n2 $n3 queuePos 0.5

#Setup a TCP connection

set tcp [new Agent/TCP]

$tcp set class_ 2

$ns attach-agent $n0 $tcp

set sink [new Agent/TCPSink]

$ns attach-agent $n3 $sink

$ns connect $tcp $sink

$tcp set fid_ 1

#Setup a FTP over TCP connection

set ftp [new Application/FTP]

ABHISHEK ECE-B(G2) 40720807317 14


40920802816
$ftp attach-agent $tcp

$ftp set type_ FTP

#Setup a UDP connection

set udp [new Agent/UDP]

$ns attach-agent $n1 $udp

set null [new Agent/Null]

$ns attach-agent $n3 $null

$ns connect $udp $null

$udp set fid_ 2

#Setup a CBR over UDP connection

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set type_ CBR

$cbr set packet_size_ 1000

$cbr set rate_ 1mb

$cbr set random_ false

#Schedule events for the CBR and FTP agents

$ns at 0.1 "$cbr start"

$ns at 1.0 "$ftp start"

$ns at 4.0 "$ftp stop"

$ns at 4.5 "$cbr stop"

#Detach tcp and sink agents (not really necessary)

$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"

ABHISHEK ECE-B(G2) 40720807317 15


40920802816
#Call the finish procedure after 5 seconds of simulation time

$ns at 5.0 "finish"

#Print CBR packet size and interval

puts "CBR packet size = [$cbr set packet_size_]"

puts "CBR interval = [$cbr set interval_]"

#Run the simulation

$ns run

Output :

ABHISHEK ECE-B(G2) 40720807317 16


40920802816
Fig. Output for TCL Script

AWK Script to analyse the performance

Fig. Command Window (Terminal)

ABHISHEK ECE-B(G2) 40720807317 17


40920802816
BEGIN {
pktDrop = 0;
ByteDrop=0;
pktRcd = 0;
ByteRcd =0;
}
{
if ($1=="d" && $5=="tcp" || $5=="cbr")
{
pktDrop += 1;
ByteDrop += $6;
}
if ($1=="r" && $5=="TCP" || $5=="cbr")
{
pktRcd += 1;
ByteRcd += $6;
}
}

END {
printf("\nNo of Packet Drop = %d \nNo of Bytes Drop = %d \nNo of Packet Received = %d
\nNo of Bytes Received = %d \n", pktDrop, ByteDrop, pktRcd, ByteRcd);
}

ABHISHEK ECE-B(G2) 40720807317 18


40920802816
EXPERIMENT – 4
Aim : Using Free Open Source Software tools for network simulation – I Preliminary usage of
the tool ns3 Simulate telnet and ftp between N sources - N sinks (N = 1, 2, 3). Evaluate the effect
of increasing data rate on congestion.

Software Used : Network Simulator 2


Basic and Specifications:
An Otcl program experiment-4.tcl used to simulate the network in problem. A simulation is
defined by a Tcl program. To simulate a four node point-to-point network the links are connected
as: n0-n2,n1-n2 and n2-n3. Hence this network consists of 4 nodes (n0,n1,n2,n3) as shown in the
figure below. Nodes 0 and 1 have a bandwidth of 2Mb with a delay of 10ms and node 2 and 3
have a bandwidth of 1Mb with a delay of 10ms. There are duplex links existing between nodes 0
and 2 and nodes 1 and 2. Nodes 2 and 3 are connected using simplex links. TCP agent is applied
between nodes 0 and 3 and UDP agent between nodes 1 and 3. Once the links are set, a Drop
Tail queue, of size 10 is set for each node and the FTP traffic is attached to the TCP connections
and Telnet is attached to the UDP part of the connection. Once both the links and the queue size
are set the timing for the Telnet to start is set at 0.5 and is made to stop at 24.5. Similarly the
timing for FTP is set at 0.5 and is made to stop at 24.5 and thus the events are scheduled. The
simulation is run via the ns run command, and continues until there are no more events to be
processed. The total running time for the whole simulation is 25.

TCL Script:-
#create Simulator
set ns [new Simulator]
#Open Trace and NAM Trace File
set ntrace [open ex3.tr w]
$ns trace-all $ntrace
set namfile [open ex3.nam w]
$ns namtrace-all $namfile
#Finish Procedure
proc Finish {} {
global ns ntracenamfile

#Dump all trace data and close the files


$ns flush-trace

ABHISHEK ECE-B(G2) 40720807317 19


40920802816
close $ntrace
close $namfile
#Execute the nam animation file
exec nam ex3.nam &
exit 0
}
$ns color 1 Blue
$ns color 2 Red
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 1Mb 10ms DropTail
$ns simplex-link $n3 $n2 1Mb 10ms DropTail
#Set queue size and Monitor the queue
$ns queue-limit $n0 $n2 10
$ns simplex-link-op $n0 $n2 queuePos 0.5
#Set TCP Connection between n0 and n3
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
$ns connect $tcp0 $sink0
$tcp0 set fid_ 1

ABHISHEK ECE-B(G2) 40720807317 20


40920802816
#Attach FTP Application over TCP
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ftp0 set type_ FTP
#Set TCP Connection between n1 and n3
set tcp1 [new Agent/TCP]
$ns attach-agent $n1 $tcp1
set sink1 [new Agent/TCPSink]
$ns attach-agent $n3 $sink1
$ns connect $tcp1 $sink1
$tcp1 set fid_ 2
#Attach Telnet Application over UDP
set telnet [new Application/Telnet]
$telnet attach-agent $tcp1
$telnet set type_ Telnet
#Schedule Events
$ns at 0.5 "$telnet start"
$ns at 0.5 "$ftp0 start"
$ns at 24.5 "$telnet stop"
$ns at 24.5 "$ftp0 stop"
$ns at 25.0 "Finish"
$ns run

ABHISHEK ECE-B(G2) 40720807317 21


40920802816
OUTPUT :

Fig. Output for TCL Script

ABHISHEK ECE-B(G2) 40720807317 22


40920802816
AWK Script:-
An awk-script given below is used to calculate the amount of throughput of FTP and Telnet.
BEGIN {
numTCP1=0;
tcpSize1=0;
numTCP2=0;
tcpSize2=0;
totaltcp1=0;
totaltcp2=0;
}
{
event=$1;
pkttype= $5;
fromnode=$9;
tonode=$10;
pktsize=$6;
if(event == "r" &&pkttype == "tcp" &&fromnode == "0.0" &&tonode == "3.0")
{
numTCP1++;
tcpSize1 = pktsize;
}
if(event == "r" &&pkttype == "tcp" &&fromnode == "1.0" &&tonode == "3.1")
{
numTCP2++;
tcpSize2 = pktsize;
}
}
END {

ABHISHEK ECE-B(G2) 40720807317 23


40920802816
totaltcp1=numTCP1*tcpSize1*8;
totaltcp2=numTCP2*tcpSize2*8;
throughputtcp1= totaltcp1/24; # because simulation time is 24.5 0.5 = 24
throughputtcp2= totaltcp2/24; # because simulation time is 24.5 0.5 = 24
printf("\n\nThe Throughput of FTP application is %d \n", throughputtcp1);
printf("\n\nThe Throughput of TELNET application is %d \n\n", throughputtcp2);
}

Fig. Command Window(Terminal)

ABHISHEK ECE-B(G2) 40720807317 24


40920802816
EXPERIMENT –5
Aim :Create and Simulate a LAN of 6 nodes in NS-2, attach the traffic and simulate
Software Used : Network Simulator 2
Basic:-
In Bus Network Topology a single cable is used to connect all devices on the net. This cable is
often referred to as the network Backbone. When communication occurs between nodes the
device sending the message broadcasts to all nodes on the network, but only the desired recipient
digests the message. Advantages of this type of Physical Topology include ease of installation
and minimization of the required cabling.
Further, failure of a node attached to the network has no effect on other nodes attached to the
network. Also messages from one node can be seen near simultaneously by all other nodes on
the network. Disadvantages of this configuration include performance limits on the number of
network nodes, and complete network communication stoppage if the cable fails
Specification:
i. LAN containing 6 node
ii. Use full-duplex link with 2 MB, 100ms and droptail
iii. Attach CBR traffic
iv. Store the complete network statistics in LAN-1.tr file
v. Use nam to animate
vi. Use awk program to display the network performance

TCL Script:-

#Lan simulation
set ns [new Simulator]
#define color for data flows
$ns color 1 Blue
$ns color 2 Red
#open tracefiles
set tracefile1 [open out.tr w]
set winfile [open winfile w]
$ns trace-all $tracefile1
#open nam file

ABHISHEK ECE-B(G2) 40720807317 25


40920802816
set namfile [open out.nam w]
$ns namtrace-all $namfile
#define the finish procedure
proc finish {} {
global ns tracefile1 namfile
$ns flush-trace
close $tracefile1
close $namfile
exec namout.nam&
exit 0
}
#create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$n1 color Red
$n1 shape box
#create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
#Give node position
$ns duplex-link-op $n0 $n2 orient right-down

ABHISHEK ECE-B(G2) 40720807317 26


40920802816
$ns duplex-link-op $n1 $n2 orient right-up
$ns simplex-link-op $n2 $n3 orient right
$ns simplex-link-op $n3 $n2 orient left
#set queue size of link(n2-n3) to 20
$ns queue-limit $n2 $n3 20
#setup TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set packet_size_ 552
#set ftp over tcp connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
#setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
#setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000

ABHISHEK ECE-B(G2) 40720807317 27


40920802816
$cbr set rate_ 0.01Mb
$cbr set random_ false
#scheduling the events
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 125.5 "$cbr stop"
proc plotWindow {tcpSource file} {
global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file"
}
$ns at 0.1 "plotWindow $tcp $winfile"
$ns at 125.0 "finish"
$ns run
OUTPUT :

ABHISHEK ECE-B(G2) 40720807317 28


40920802816
Fig. Output for TCL Script
AWK Script:-
Now To analyse the trace file for network performance we write the awk script. The script reads
the .tr file and computes the data received, data lost, total transmission size.

Fig. Command Window(Terminal)

ABHISHEK ECE-B(G2) 40720807317 29


40920802816
BEGIN {
pktDropped=0;
byteDropped=0;
byteSent=0;
bytesReceived=0;
Total=0;
}
{

if ($1=="+")
{
byteSent += $6;
}
if($1=="r")
{
bytesReceived += $6;
}
if($1=="d")
{
pktDropped += 1;
byteDropped += $6;
}
Total=bytesReceived + byteDropped;
}
END {
printf("\n Total bytes sent= %d\nno. of bytes received=%d\n no. of packets dropped=%d
\n no. of bytes dropped=%d \n ",Total, bytesReceived, pktDropped, byteDropped);
}

ABHISHEK ECE-B(G2) 40720807317 30


40920802816
EXPERIMENT –6
Aim :Simulate and create Mesh Topology using NS2 simulator.
Software Used : Network Simulator 2
Basic :

A mesh topology can be a full mesh topology or a partially connected mesh topology.
In a full mesh topology, every computer in the network has a connection to each of the other
computers in that network. The number of connections in this network can be calculated using
the following formula (n is the number of computers in the network): n(n-1)/2
Specifications:
i. A Mesh Topology of 5 nodes
ii. Full-duplex links, 1 Mb, delay 2ms and queue type: droptail
iii. Traffic TCP with CBR
iv. Orient the nodes to look like a mesh network
TCL Script :
set ns [new Simulator]
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf

ABHISHEK ECE-B(G2) 40720807317 31


40920802816
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec namout.nam&
exit0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
$ns duplex-link $n0 $n1 1Mb 2ms DropTail
$ns duplex-link $n0 $n2 1Mb 2ms DropTail
$ns duplex-link $n0 $n3 1Mb 2ms DropTail
$ns duplex-link $n0 $n4 1Mb 2ms DropTail
$ns duplex-link $n1 $n2 1Mb 2ms DropTail
$ns duplex-link $n1 $n3 1Mb 2ms DropTail
$ns duplex-link $n1 $n4 1Mb 2ms DropTail
$ns duplex-link $n2 $n3 1Mb 2ms DropTail
$ns duplex-link $n2 $n4 1Mb 2ms DropTail
$ns duplex-link $n3 $n4 1Mb 2ms DropTail
$ns duplex-link-op $n0 $n4 orient right
$ns duplex-link-op $n1 $n0 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right-down
$ns duplex-link-op $n3 $n4 orient left-down

ABHISHEK ECE-B(G2) 40720807317 32


40920802816
$ns duplex-link-op $n3 $n2 orient right-down
set tcp0 [new Agent/TCP]
set ftp0 [new Application/FTP]
set tcp1 [new Agent/TCPSink]
$ns attach-agent $n1 $tcp0
$ns attach-agent $n4 $tcp1
$ftp0 attach-agent $tcp0
$ns connect $tcp0 $tcp1
#Schedule events for the CBR agents
$ns at 0.5 "$ftp0 start"
$ns at 4.5 "$ftp0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
BEGIN {
PktRcd =0;ByteRcd = 0;
ackCount=0;
}
{
if ($1=="r")
{
PktRcd += 1;

ByteRcd += $6;
}
if ($5=="ack")
{
ackCount += 1;
}
}
END {

ABHISHEK ECE-B(G2) 40720807317 33


40920802816
printf ("\nPackets Received = %d\n Byte Received =%d \n Acknowledgementreceived =%d\n",
PktRcd, ByteRcd, ackCount);
}

Output :

Fig. Output for TCL Script

ABHISHEK ECE-B(G2) 40720807317 34


40920802816
AWK PROGRAM :

Fig. Command Window(Terminal)

ABHISHEK ECE-B(G2) 40720807317 35


40920802816
EXPERIMENT –7
Aim :Simulate and study Ring Topology using NS2 Simulator.
Software Used : Network Simulator 2
Theory
lternatively referred to as a ring network, a ring topology is a computer network configuration
where the devices are connected to each other in a circular shape. Each packet is sent around the
ring until it reaches its final destination. Ring topologies are used in both local area network
(LAN) and wide area network (WAN) setups. The picture to the right is a visual example of a
network using the ring topology to connect several computers together.

Advantages of ring topology


 All data flows in one direction, reducing the chance of packet collisions.
 A network server is not needed to control network connectivity between each
workstation.
 Data can transfer between workstations at high speeds.
 Additional workstations can be added without impacting performance of the network.

Disadvantages of ring topology


 All data being transferred over the network must pass through each workstation on the
network, which can make it slower than a star topology.
 The entire network will be impacted if one workstation shuts down.
 The hardware needed to connect each workstation to the network is more expensive than
Ethernet cards and hubs/switches.

ABHISHEK ECE-B(G2) 40720807317 36


40920802816
Specification:
Ring Topology with 7 nodes
Use Distance Vector Protocol.
Link Connection: 1Mb 10ms DropTail
Traffic between Node-1 and Node-3
Set network dynamic by making link between node-0 and node-1 down and up again
TCL Script :
#Create a simulator object
set ns [new Simulator]
#Tell the simulator to use dynamic routing
$ns rtproto DV
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec namout.nam&
exit 0
}
#Create seven nodes
for {set i 0} {$i< 7} {incri} {
set n($i) [$ns node]
}
#Create links between the nodes
for {set i 0} {$i< 7} {incri} {

ABHISHEK ECE-B(G2) 40720807317 37


40920802816
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
}
#Create a UDP agent and attach it to node n(0)
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n(3)
set null0 [new Agent/Null]
$ns attach-agent $n(3) $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
#Schedule events for the CBR agent and the network dynamics
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n(1) $n(2)
$ns rtmodel-at 2.0 up $n(1) $n(2)
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run

ABHISHEK ECE-B(G2) 40720807317 38


40920802816
Output :

Fig. Command Window (Terminal)

ABHISHEK ECE-B(G2) 40720807317 39


40920802816
EXPERIMENT –8
Aim :Simulate the different type of internet traffic such as FTP and TELNET over a network and
analyze the throughput using NS-2.
Software Used : Network Simulator 2
TCL Script :
#Create Simulator
set ns [new Simulator]

#Open Trace and NAM Trace File


set ntrace [open prog3.tr w]
$ns trace-all $ntrace
set namfile [open prog3.nam w]
$ns namtrace-all $namfile

#Finish Procedure
proc Finish {} {
global ns ntracenamfile

#Dump all trace data and close the files


$ns flush-trace
close $ntrace
close $namfile

#Execute the nam animation file


exec nam prog3.nam &

#Calculate throughput = (number of packets received/time taken for simulation)


set numTcp [exec grep "^r" prog3.tr | grep "tcp" | tail -n 1 | cut -d " " -f 6]

ABHISHEK ECE-B(G2) 40720807317 40


40920802816
set TcpSize [exec grep "^r" prog3.tr | grep -c "tcp"]
set tcpTime 24.0
set numUdp [exec grep "^r" prog3.tr | grep "udp" | tail -n 1 | cut -d " " -f 6]
set UdpSize [exec grep "^r" prog3.tr | grep -c "udp"]
set udpTime 23.9
puts "The throughput of FTP is "
puts "[expr ($numTcp*$TcpSize)/$tcpTime] bytes per second"
puts "The throughput of Telnet is "
puts "[expr ($numUdp*$UdpSize)/$udpTime] bytes per second"
exit 0
}

#Create four nodes


set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

#Create links between the nodes


$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 1Mb 10ms DropTail
$ns simplex-link $n3 $n2 1Mb 10ms DropTail

#Set queue size and Monitor the queue


$ns queue-limit $n0 $n2 10
$ns simplex-link-op $n0 $n2 queuePos 0.5

ABHISHEK ECE-B(G2) 40720807317 41


40920802816
#Set TCP Connection between n0 and n3
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
$ns connect $tcp0 $sink0

#Attach FTP Application over TCP


set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ftp0 set type_ FTP

#Set UDP Connection between n1 and n3


set udp0 [new Agent/UDP]
$ns attach-agent $n1 $udp0
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
$ns connect $udp0 $null0

#Attach Telnet Application over UDP


set telnet [new Application/Telnet]
$telnet attach-agent $udp0
$telnet set type_ Telnet

#Schedule Events
$ns at 0.1 "$telnet start"
$ns at 0.5 "$ftp0 start"

ABHISHEK ECE-B(G2) 40720807317 42


40920802816
$ns at 24.0 "$telnet stop"
$ns at 24.5 "$ftp0 stop"
$ns at 25.0 "Finish"
#Run Simulation
$ns run

Output :

Fig. Command window(Terminal) and Output for TCL Script

ABHISHEK ECE-B(G2) 40720807317 43


40920802816

Potrebbero piacerti anche