Digital Communication
Digital Communication
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
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.
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-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
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:
3. Before installing the NS we have to install some essential packages required by the NS. So run
the following commands:
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
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
Arrays in TcL
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
}
#Create two nodes
$ns run
ns example1a.tcl
#Adding Traffic to link ; create null agent (a traffic sink) and attach it to node n1
n0 n0
udp
null
cbr
n0 n0
udp
null
cbr
#start ns
$ns run
#stop ns
exit 0
Output :
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
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec namout.nam&
exit 0
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
$ns run
Output :
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);
}
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
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
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);
}
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
ByteRcd += $6;
}
if ($5=="ack")
{
ackCount += 1;
}
}
END {
Output :
#Finish Procedure
proc Finish {} {
global ns ntracenamfile
#Schedule Events
$ns at 0.1 "$telnet start"
$ns at 0.5 "$ftp0 start"
Output :