DCN LAB File
DCN LAB File
LAB File
1|Page
INDEX
1. INTRODUCTION TO ns -2 3
2. Fabrications of Cables 12
4. Star Topology 18
5. IPv4 Addressing 21
Experiment 1
2|Page
Aim: After completing this experiment you will be able to:
Learn the basic concepts about open source network simulator NS-2, and
how to download, install and work with NS-2
Defining the different agents and their applications like TCP, FTP over TCP,
UDP, CBR over UDP
Identifying and solving typical errors encountered during installation of
NS-2
THEORY:
Network Simulator version 2 (NS-2) is discrete event packet level simulator. The
network simulator covers a very large number of application of different kind of
protocols of different network types consisting of different network elements
and traffic models. NS-2 is a package of tools that simulates behavior of
networks such as creating network topologies, log events that happen under
any load, analyze the events and understand the network. The aim of this first
experiment is to learn how to use NS-2, to get acquainted with the simulated
objects and understand the operations of network simulation. We will also look
at how to analyze the outcome of a simulation.
Platform required to run network simulator
Unix and Unix like systems
o Linux
o Free BSD
o SunOS/Solaris
Windows 95/98/NT/2000/XP (requires Cygwin)
Backend Environment of Network Simulator
Network Simulator is based on two languages: C++ and OTcl. OTcl is the object
oriented version of Tool Command Language. While the core of NS-2 is written
in C++, one uses OTcl to write simulation scripts. C++ helps in the following way:
It helps to increase the efficiency of simulation.
Its is used to provide details of the protocols and their operation.
3|Page
It is used to reduce packet and event processing time.
OTcl helps in the following way:
With the help of OTcl we can describe different network topologies
It helps us to specify the protocols and their applications
It allows fast development
Tcl is compatible with many platforms and it is flexible for integration
Tcl is very easy to use and it is available in free
And of course, there is a linkage between C++ and OTcl, which allows us to run
the simulation scripts.
Basics of Tcl Programming for NS-2
Network simulation with NS-2 would involve the following general steps:
1. Initialization and termination aspects of network simulator object
2. Defining the network topology: nodes, links, queues, mobility of nodes, if
any
3. Defining the network traffic: creating agents and their applications
4. Setting trace for Network Animator (NAM) [optional]
5. Tracing
In this section, we provide a brief overview of the most commonly used features
of NS-2. This summary has been prepared based on various tutorials on, and the
manual for, NS-2. See the References section for some of the different tutorials
available.
Initialization
To create a new simulator we write
1 set ns [new Simulator]
From the above command we get that a variable ns is being initialized by using
the set command. Here the code [new Simulator] is a instantiation of the class
Simulator which uses the reserved word new. So we can call all the methods
present inside the class simulator by using the variable 'ns'.
4|Page
Creating the output files
1 # Create the trace files
2 set tracefile [open out.tr w]
3 $ns trace-all $tracefile
4
5 # Create the nam files
6 set namfile [open out.nam w]
7 $ns namtrace-all $namfile
In the above we create a output trace file 'out.tr' and a NAM visualization file
'out.nam'. But in the Tcl script they are not called by their names declared, while
they are called by the pointers initialized for them such as 'tracefile' and
'namfile' respectively.The line which starts with # are commented. The next line
opens the file 'out.tr' which is used for writing is declared 'w'. The next line uses
a simulator method trace-all by which we will trace all the events in a particular
format.
The termination program is done by using a 'finish' procedure
1 # Defining the 'finish' procedure'
2
3 proc finish {} {
4 global ns tracefile namfile
5 $ns flush-trace
6 close $tracefile
7 close $namfile
8 exit 0
9 }
In the above, the keyword proc is used to declare a procedure called 'finish'. The
keyword global is used to tell what variables are being used outside the
procedure.
flush-trace is a simulator method that dumps the traces on the respective files.
The command close is used to close the trace files and the command exec is
used to execute the NAM visualization. The command exit closes the application
and returns zero as default for clean exit.
In ns we end the program by calling the 'finish' procedure
1 # End the program
2 $ns at 125.0 "finish"
Thus the entire operation ends at 125 seconds.To begin the simulation we will
use the command
5|Page
1 # Start the the simulation process
2 $ns run
In the above we created a node that is pointed by a variable n0. While referring
the node in the script we use $n0. Similarly we create another node n2. Now we
will set a link between the two nodes.
1 $ns duplex-link $n0 $n2 10Mb 10ms DropTail
6|Page
15 $ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
The command set tcp [new Agent/TCP] gives a pointer called 'tcp' to the TCP
agent object of ns. The command $ns attach-agent $n0 $tcp defines the source
node of TCP connection. Next the command set sink [new
Agent/TCPSink] defines the destination of TCP by a pointer called 'sink'. The
next command $ns attach-agent $n4 $sink defines the destination node as n4.
Next, the command $ns connect $tcp $sink makes the TCP connection between
the source and the destination i.e n0 and n4. When we have several flows (such
as TCP, UDP) in a network, to identify these flows we set their flow ID by using
the command $tcp set fid_1. In the last line we set the packet size of TCP as 552
byte. The default packet size of TCP is 1000 B.
FTP over TCP
7|Page
File Transfer Protocol (FTP) is a standard mechanism provided by the Internet
for transferring files from one host to another. FTP differs from other client
server applications in that it establishes two connections between the client and
the server. One connection is used for data transfer and other one is used for
providing control information. FTP uses the services of the TCP. The well Known
port 21 is used for control connections and the other port 20 is used for data
transfer.
Here we will learn in how to run a FTP connection over a TCP:
1 # Initiating FTP over TCP
2
3 set ftp [new Application/FTP]
4 $ftp attach-agent $tcp
In above,the command set ftp [new Application/FTP] gives a pointer called 'ftp'
which indicates the FTP application. Next, we attach the ftp application with tcp
agent as FTP uses the services of TCP.
UDP
The User datagram Protocol is one of the main protocols of the Internet
protocol suite. UDP helps the host to send send messages in the form of
datagrams to another host which is present in a Internet protocol network
without any kind of requirement for channel transmission setup. UDP provides a
unreliable service and the datagrams may arrive out of order, appear
duplicated, or go missing without notice. UDP assumes that error checking and
correction is either not necessary or performed in the application, avoiding the
overhead of such processing at the network interface level. Time-sensitive
applications often use UDP because dropping packets is preferable to waiting
for delayed packets, which may not be an option in a real-time system.
Now we will learn how to create a UDP connection in network simulator.
1 # Setup a UDP connection
2 set udp [new Agent/UDP]
3 $ns attach-agent $n1 $udp
4 $set null [new Agent/Null]
5 $ns attach-agent $n5 $null
6 $ns connect $udp $null
7 $udp set fid_ 2
The command set udp [new Agent/UDP] gives a pointer called 'udp' which
indicates the udp agent which is a object of ns. Then the command $ns attach-
8|Page
agent $n1 $udp defines the source node of UDP connection. Next the
command set null [new Agent/Null] defines the destination of udp by a pointer
called null. The next command $ns attach-agent $n5 $null defines the
destination node as n5. Next, the command $ns connect $udp $null makes the
UDP connection between the source and the destination i.e n1 and n5. To
identify a particular flow we mark it using the command $udp set fid_2.
Constant Bit Rate (CBR)
Constant Bit Rate (CBR) is a term used in telecommunications, relating to the
quality of service.When referring to codecs, constant bit rate encoding means
that the rate at which a codec's output data should be consumed is constant.
CBR is useful for streaming multimedia content on limited capacity channels
since it is the maximum bit rate that matters, not the average, so CBR would be
used to take advantage of all of the capacity. CBR would not be the optimal
choice for storage as it would not allocate enough data for complex sections
(resulting in degraded quality) while wasting data on simple sections.
CBR over UDP Connection
1 # Setup CBR over UDP
2
3 set cbr [new Application/Traffic/CBR]
4 $cbr attach-agent $udp
5 $cbr set packetSize_ 1000
6 $cbr set rate_ 0.01Mb
7 $cbr set random_ false
In the above we define a CBR connection over a UDP one. Well we have already
defined the UDP source and UDP agent as same as TCP. Instead of defining the
rate we define the time interval between the transmission of packets in the
command $cbr set rate_ 0.01Mb. Next, with the help of the command $cbr set
random_ false we can set random noise in cbr traffic. We can keep the noise by
setting it to false or we can set the noise on by the command $cbr set random_
1. We can set by packet size by using the command $cbr set packetSize_. The
packet size is specified in bytes.
Scheduling Events
In ns the tcl script defines how to schedule the events or in other words at what
time which event will occur and stop. This can be done using the command $ns
9|Page
at time event. Here in our program we will schedule when the ftp and cbr traffic
should start and stop.
1 # Scheduling the events
2
3 $ns at 0.1 "$cbr start"
4 $ns at 1.0 "$ftp start"
5 $ns at 124.0 "$ftp stop"
6 $ns at 124.5 "$cbr stop"
Network Animator (NAM)
When we will run the above program in ns then we can can visualize the
network in the NAM. But instead of giving random positions to the nodes, we
can give suitable initial positions to the nodes and can form a suitable topology.
So, in our program we can give positions to the nodes in NAM in the following
way
1 # Give position to the nodes (for NAM)
2
3 $ns duplex-link-op $n0 $n2 orient-right-down
4 $ns duplex-link-op $n1 $n2 orient-right-up
5 $ns simplex-link-op $n2 $n3 orient-right
6 $ns simplex-link-op $n3 $n2 orient-left
7 $ns duplex-link-op $n3 $n4 orient-right-up
8 $ns duplex-link-op $n3 $n5 orient-right-down
We can also define the color of CBR and TCP packets for identification in NAM.
For this we use the following command
1 # Marking the flows (for NAM)
2 $ns color1 Blue
3 $ns color2 Red
Tracing
Tracing Objects
NS-2 simulation can produce visualization trace as well as ASCII file
corresponding to the events that are registered at the network. While tracing ns
inserts four objects: EnqT, DeqT, RecvT, and DrpT. EnqT registers information
regarding the arrival of packet and is queued at the input queue of the link.
When overflow of a packet occurs, then the information of the dropped packet
is registered in DrpT. DeqT holds the information about the packet that is
dequeued instantly. RecvT hold the information about the packet that has been
received instantly.
10 | P a g e
Fi
gure-01: NS-2 trace file format (wired networks)
11 | P a g e
Experiment 2
Theory:
A twisted pair consists of two insulated conductor twisted together in the shape
of a spiral. It can be shielded or unshielded. The unshielded twisted pair cables
are very cheap and easy to install. But they are very badly affected by the
electromagnetic noise interference.
Twisting of wires will reduce the effect of noise or external interference. The
induced Emf into the two wires due to interference tends to cancel each other
due to twisting. Number of twists per unit length will determine the quality of
cable. More twists means better quality.
A. Straight-through cable
Straight-Through refers to cables that have the pin assignments on each end of
the cable. In other words, pin 1 connector A goes to Pin 1 on connector B, pin 2
to Pin 2 etc. Straight-Through wired cables are most commonly used to connect
a host to client. When we talk about cat5e patch cables, the Straight-Through
wired cat5e patch cable is used to connect computers, printers and other
network client devices to the router switch or hub (the host device in this
instance).
B. Crossover cable
Crossover wired cables (commonly called crossover cables) are very much like
Straight-Through cables with the exception that TX and RX lines are crossed
(they are at opposite positions on either end of the cable. Using the 568-B
standard as an example below you will see that Pin 1 on connector A goes to Pin
3 on connector B. Pin 2 on connector A goes to Pin 6 on connector B etc.
12 | P a g e
Crossover cables are most commonly used to connect two hosts directly.
Examples would be connecting a computer directly to another computer,
connecting a switch directly to another switch, or connecting a router to a
router. Note: While in the past when connecting two host devices directly a
crossover cable was required. Now days most devices have auto sensing
technology that detects the cable and device and crosses pairs when needed.
C. Roll-over cable
Rollover wired cables most commonly called rollover cables, have opposite Pin
assignments on each end of the cable or in other words it is "rolled over". Pin 1
of connector A would be connected to Pin 8 of connector B. Pin 2 of connector
A would be connected to Pin 7 of connector B and so on. Rollover cables,
sometimes referred to as Yost cables are most commonly used to connect to a
devices console port to make programming changes to the device. Unlike
crossover and straight-wired cables, rollover cables are not intended to carry
data but instead create an interface with the device.
Procedure:
1) The aim is to Fabricate a UTP Cable.
2) To perform the experiment follow the below steps
3) A choice list would be given that which type of cable is to be fabricated
4) Select the choice out of the three choices given
5) Once a selection is done then the user have to make the cable ready
6) In-order to do so select the colour codes on both the sides i.e. Switch port
and PC port.
7) After assigning the colour codes click on the Start button to observe that the
cable made is correct or not.
8) Based on the observations made select if cable made is correct or not.
13 | P a g e
Simulation:
Experiment 3
Aim: 1) To construct Peer to Peer Topology
Theory:
14 | P a g e
The word physical network topology is used to explain the manner in which a
network is physically connected. Devices or nodes in a network get connected
to each other via communication links and all these links are related to each
other in one way or the other. The geometric representation of such a
relationship of links and nodes is known as the topology of that network.
Peer to peer is the relationship where the devices share the link equally. The
examples are ring and mesh topologies.
In Primary - Secondary relationship, one device controls and the other devices
have to transmit through it. For example star and tree topology.
15 | P a g e
Procedure:
1) The aim is to Create the topology.
2) To perform the experiment follow the below steps
3)A blank square area would be given which defines the working area
4)A series of components would be given
5)In order to build a topology first select on the component and then
immediately click on the working area to place it
6)To draw a line between two components first select the line click on the port
of first component and then immediately click on the port of second component
7)Once the topology is built then click on the Submit button to test whether the
give topology is built correctly or not.
Simulation:
16 | P a g e
Experiment 4
Aim: 1) To construct Star Topology
Theory:
17 | P a g e
The word physical network topology is used to explain the manner in which a
network is physically connected. Devices or nodes in a network get connected
to each other via communication links and all these links are related to each
other in one way or the other. The geometric representation of such a
relationship of links and nodes is known as the topology of that network.
Peer to peer is the relationship where the devices share the link equally. The
examples are ring and mesh topologies.
In Primary - Secondary relationship, one device controls and the other devices
have to transmit through it. For example star and tree topology.
Procedure:
18 | P a g e
1) The aim is to Create the topology.
2) To perform the experiment follow the below steps
3)A blank square area would be given which defines the working area
4)A series of components would be given
5)In order to build a topology first select on the component and then
immediately click on the working area to place it
6)To draw a line between two components first select the line click on the port
of first component and then immediately click on the port of second component
7)Once the topology is built then click on the Submit button to test whether the
give topology is built correctly or not.
Simulation:
19 | P a g e
Experiment 5
Aim: 1) To give IP Address of different classes in given network ID.
20 | P a g e
Theory:
IP addresses enable computers to communicate by providing unique identifiers
for the computer itself and for the network over which it is located. An IP
address is a 32 bit value that contains a network identifier(net -id) and a host
identifier (host-id).
The 32 bit IPv4 address is grouped into groups of eight bits, separated by dots.
Each 8-bit group is then converted into its equivalent binary number. Thus each
octet (8bit) can take value from 0 to 255. The IPv4 in the dotted decimal
notation can range from 0.0.0.0 to 255.255.255.255. The IPv4 Address are
classified into 5 types as follows:
1. Class A 2. Class B
3. Class C 4. Class D
5. Class E
Class A
The first bit of the first octet is always set to 0 (zero). Thus the first octet ranges
from 1-127 i.e.
00000000 - 01111111
1-127
Class A addresses only include IP starting from 1.x.x.x to 126.x.x.x only. The IP
range 127.x.x.x is reserved for loopback IP addresses. The default subnet mask
for class Class A IP address is 255.0.0.0 which implies that Class A addressing can
have 126 networks and 167777214 hosts. Class A IP address format is thus :
0NNNNNNN.HHHHHHHH.HHHHHHHH.HHHHHHHH
Class B
An IP address which belongs to class B has the first two bits in the first octet set
to 10, i.e.
10000000 - 10111111
21 | P a g e
128 - 191
Class B IP Addresses range from 128.0.x.x to 191.255.x.x. The default subnet
mask for Class B is 255.255.x.x. Class B has 16384 Network addresses and 65534
Host addresses. Class B IP addresses format is:
10NNNNNN.NNNNNNNN.HHHHHHHH.HHHHHHHH
Class C
The first octet of Class C IP address has its first 3 bits set to 110,that is:
11000000 - 11011111
192 - 223
Class C IP addresses range from 192.0.0.x to 223.255.255.x. The default subnet
mask for Class C is 255.255.255.x. Class C gives 2097152 Network addresses and
254 Host addresses. Class C IP address format is:
110NNNNN.NNNNNNNN.NNNNNNNN.HHHHHHHH
Procedure:
1) The aim is to Give IP Addresses to the PCs.
2) To perform the experiment follow the below steps
3) A choice list would be given defining the Classes
4) The user has to select the class in which they choose to give IP Addresses
5) After that a Network ID would be given and the user has to enter the IP
Addresses according to the Network ID.
6) Click on submit to test whether the IP address given to PCs make them into
Network or not.
Simulation:
22 | P a g e
Experiment 6
Class B
By default, using Glassful Networking, 14 bits are used as Network bits providing
16384 Networks and 65534 Hosts. Class B IP Addresses can be subsetted the
same way as Class A addresses, by borrowing bits from Host bits. Below is given
all possible combination of Class B sub netting:
24 | P a g e
Class C
Class C IP addresses are normally assigned to a very small size networks because
it can only have 254 hosts in a network. Given below is a list of all possible
combination of subsetted Class B IP addresses:
Procedure:
1) The aim is to Give IP Addresses to the PCs.
2) To perform the experiment follow the below steps
3) A choice list would be given defining the Classes
4) The user has to select the class in which they choose to give IP Addresses
5) After that a Network ID would be given and the user has to enter the IP
Addresses according to the Network ID.
25 | P a g e
6) Click on submit to test whether the IP address given to PCs make them into
Network or not.
Simulation:
26 | P a g e
Experiment 7
Aim: 1) To share a folder from a computer and access the shared folder
from another computer.
Theory:
It’s a common situation — you have several computers near each other and you
want to transfer files between them. You don’t have to pull out a USB drive, nor
do you have to send them over email — there are faster, easier ways.
This is easier than it was in the past, as you don’t have to mess with any
complicated Windows networking settings. There are lots of ways to share files,
but we’ll cover some of the best.
Procedure:
1) The aim is to Share the files between Two Pc’s.
2) To perform the experiment follow the below steps
3) Click on the first Pc
4) Follow the step to share a folder from the given location
5) Close the Pc by clicking on the black bar
6) Click on second Pc
7) follow the step to access the files
8) Close the Pc
9) If all the steps are performed correctly then Experiment is successful
10)Else Need to do it again
28 | P a g e