CN LAB Programs Part-A
CN LAB Programs Part-A
Node Configuration
NS-2 is an event driven simulation tool, which is 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.
Ex: r 40.639943289 _1_ AGT--- 1569 tcp 1032 [a2 1 2 800] ------- [0:0 1:0 32 1] [35 0] 2 0
The meanings of the fields are:
1. The first field is the event type. It is given by one of five possible symbols r, +, −, d, h, which
correspond respectively to receive (at the output of the link), enqueued, dequeued, dropped and hop.
2. The second field gives the time at which the event occurs.
3. The third field gives the input node of the link at which the event occurs.
4. The fourth field gives the output node of the link at which the event occurs.
5. The fifth field gives the packet type (for example, CBR, or TCP). The type corresponds to the name
that we gave to those applications.
6. The sixth field gives the packet size.
7. Some flags follow
8. This is the flow id (fid) of IPv6 that a user can set for each flow at the input OTcl script. One can
further use this field for analysis purposes; it is also used when specifying stream color for the
NAM display.
9. This is the source address given in the form of “node port".
10. This is the destination address, given in the same form.
11. This is the network layer protocol’s packet sequence number. Even though UDP implementations in
a real network do not use sequence number, NS-2 keeps track of UDP packet sequence number for
analysis purposes.
12. The last field shows the unique id of the packet.
XGRAPH
The xgraph program draws a graph on an x-display given data read from either data file or
from standard input if no files are specified. It can display upto 64 independent data sets using
different colors and line styles for each set. It annotates the graph with a title, axis labels, grid lines or
tick marks, grid labels and a legend.
Syntax: Xgraph file-name.xg
Ex: r 40.639943289 _1_ AGT--- 1569 tcp 1032 [a2 1 2 800] ------- [0:0 1:0 32 1] [35 0] 2 0
The first field is a letter that can have the values r,s,f,D for “received", “sent", “forwarded" and
“dropped", respectively. It can also be M for giving a location or a movement indication, this is
described later.
The second field is the time.
The third field is the node number.
The fourth field is MAC to indicate if the packet refers to a MAC layer; it is AGT to indicate the
transport layer (e.g., tcp) packet, or RTR if it refers to the routed packet. It can also be IFQ to
indicate events related to the interference priority queue (like drop of packets).
After the dashes, the global sequence number of the packet (this is not the tcp sequence number).
At the next field comes more information on the packet type (e.g., tcp, ack or udp).
Then the packet size in bytes.
Mac layer information.
o The first hexadecimal number, a2 (which equals 162 in decimal) specifies the expected time in
seconds to send this data packet over the wireless channel. The second number, 1, stands for the
MAC-id of the sending node, and the third, 2, is that of the receiving node. The fourth number,
800, specifies that the MAC type is ETHERTYPE_IP.
o The next numbers in the second square brackets refer to the IP source and destination addresses,
then the ttl (Time To Live) of the packet.
o The third brackets concern the tcp information: its sequence number and the acknowledgement
number.
Where the first number is the time, the second is the node number, then comes the origin and
destination locations, and finally the speed is given.
Network Animator [NAM] is an animation tool for viewing network simulation traces.
3. Shape of Node
o $n1 shape box (or instead of “box" one can use “hexagon" or
“circle")
Keywords
set : to assign a value to a variable
# : comment
PART-A
PART-A:
1. Implement a point to point network with four nodes and duplex links between
them. Analyze the network performance by setting the queue size and varying the
bandwidth.
2. Implement a four node point to point network with links n0-n2, n1-n2 and n2-n3.
Apply TCP agent between n0-n3 and UDP between n1-n3. Apply relevant
applications over TCP and UDP agents changing the parameter and determine the
number of packets sent by TCP/UDP.
4. Implement Ethernet LAN using n nodes and assign multiple traffic to the nodes
and obtain congestion window for different sources/ destinations.
5. Implement ESS with transmission nodes in Wireless LAN and obtain the
performance parameters.
1. Implement a point to point network with four nodes and duplex links
between them. Analyze the network performance by setting the queue size
and varying the bandwidth.
Description:
A duplex data transmission means that data can be transmitted in both directions on a signal carrier
at the same time.
Network performance refers to measures of service quality of a network.
There are many different ways to measure the performance of a network, they are
o Bandwidth commonly measured in bits/second is the maximum rate that information can be transferred
o Throughput is the actual rate that information is transferred
o Latency the delay between the sender and the receiver decoding it, this is mainly a function of the signals
travel time, and processing time at any nodes the information traverses
o Jitter variation in packet delay at the receiver of the information
o Error rate the number of corrupted bits expressed as a percentage or fraction of the total sent
CBR stands for constant bitrate, and is an encoding method that keeps the bitrate the same.
Design:
Source code:
proc finish {} {
global f nf ns
$ns flush-trace
close $f
close $nf
exec nam lab1.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 0.3Mb 10ms DropTail #vary bandwidth 0.3, 0.4, 0.5 0.7
$ns duplex-link $n1 $n2 0.3Mb 20ms DropTail #vary bandwidth 0.3, 0.4, 0.5 0.7
$ns duplex-link $n2 $n3 0.3Mb 20ms DropTail #vary bandwidth 0.3, 0.4, 0.5 0.7
Write the value of network performance in observation sheet. Repeat the above step by changing the
bandwidth to [0.3Mb, 0.4Mb, 0.5Mb, 0.7Mb]
1. 0.3
2. 0.4
3. 0.5
4. 0.7
2. Implement a four node point to point network with links n0-n2, n1-n2
and n2-n3. Apply TCP agent between n0-n3 and UDP between n1-n3.
Apply relevant applications over TCP and UDP agents changing the
parameter and determine the number of packets sent by TCP/UDP.
Description:
The TCP and UDP protocols are two different protocols that handle data communications
between terminals in an IP network (the Internet).
Transmission Control Protocol (TCP) is one of the main protocols in TCP/IP networks. Whereas
the IP protocol deals only with packets, TCP enables two hosts to establish a connection and
exchange streams of data. TCP guarantees delivery of data and also guarantees that packets will
be delivered in the same order in which they were sent.
User Datagram Protocol (UDP) is part of the Internet Protocol suite used by programs running
on different computers on a network. UDP is used to send short messages called datagrams but
overall, it is an unreliable, connectionless protocol.
File Transfer Protocol (FTP) is the commonly used protocol for exchanging files over
the Internet. FTP uses the Internet's TCP/IP protocols to enable data transfer. FTP promotes
sharing of files via remote computers with reliable and efficient data transfer
Design:
Source code:
proc finish {} {
global ns f nf
$ns flush-trace
close $f
close $nf
exec nam lab2.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
Design:
Source code:
proc finish { } {
global nf ns tf
exec nam lab3.nam &
close $naf
close $trf
exit 0
}
set n0 [$ns node]
set n1 [$ns node
$ns make-lan "$n0 $n1 $n3 $n2" 10Mb 10ms LL Queue/DropTail Mac/802_3
$ns make-lan "$n5 $n6 $n4" 10Mb 10ms LL Queue/DropTail Mac/802_3
Calculation of Throughput
Write the value of throughput in observation sheet. Repeat the above step by changing the error rate
to the following line of the program
$err set rate_ 0.7 #vary error rate 0, 0.4, 0.8 and 1.0
1. 0
2. 0.4
3. 0.8
4. 1.0
4. Implement Ethernet LAN using n nodes and assign multiple traffic to the
nodes and obtain congestion window for different sources/
destinations.
Description:
Congestion means Blockage of traffic (or) Heavy traffic (or) Crowded traffic.
During “Multiple Traffic Transmission”, the congestion of traffic is occurred. Hence the
throughput is decreased substantially.
Here Congestion window determines the number of bytes outstanding at a time. Its size varies
according to the network state.
TCP follows the following steps to avoid the Congestion:
o Initially the window size increases rapidly
o When it reaches a large value, it grows slowly.
o When congestion is detected, the window size decreases drastically.
o This mechanism allows resolving congestion rapidly and yet using efficiently the network’s
bandwidth.
Design:
Source code:
proc finish { } {
global ns f nf outFile1 outFile2
$ns flush-trace
close $f
close $nf
exec nam lab4.nam &
exec xgraph Congestion1.xg Congestion2.xg -geometry 400x400 &
exit 0
}
$ns make-lan "$n0 $n1 $n2 $n3 $n4 $n5 " 10Mb 30ms LL Queue/DropTail Mac/802_3
#vary bandwidth 1, 10
5. Implement ESS with transmission nodes in Wireless LAN and obtain the
performance parameters.
Description:
Wireless LAN: It is a type of network where the data is not transmitted via cables but over the air
through the use of wireless transmitters and receivers. Most modern WLANs are based on IEEE
802.11 standards.
Important Parameters related to wireless network:
o Stations [STA]: All components that can connect into a wireless medium in a network are referred to as
stations.
o Basic service set [BSS]: The basic service set (BSS) is a set of all stations that can communicate with each
other at PHY layer.
o Extended service set [ESS]: An extended service set (ESS) is a set of connected BSSs.
List of basic parameters which need to be assigned (configured) for wireless node
o Channel type- Wireless Channel
o Radio Propagation type- TwoRayGround
o Routing Protocol- DSDV
o
o Network Interface type- WirelessPhy
(Physical Layer Type)
o Link layer type- LL Mac Type- 802_11
o Antenna Type- Omni Antenna
o Interface Queue Type- Queue/DropTail/PriQueue
o Queue Length- 50
o Number of mobile nodes- 2
o agentTrace ON
o routerTrace ON
In wired nodes, connectivity is determined by wires (defined by duplex-link, simplex-link).
But, the connectivity of wireless nodes is determined by their distance from one another.
Because wireless nodes can MOVE, their distances from one another change over time
To keep track of their positions in the topology grid, we need to create a General Operations
Director (GOD) object.
The God object stores:
o the total number of mobile nodes
o a table of shortest number of hops required to reach from one node to another.
Design:
Source code:
$n0 set X_ 10
$n0 set Y_ 600
$n0 set Z_ 0
$n1 set X_ 80
$n1 set Y_ 600
$n1 set Z_ 0
$n2 set X_ 1200
$n2 set Y_ 600
$n2 set Z_ 0
proc finish { } {
global ns nf tf
$ns flush-trace
exec nam lab5.nam &
close $tf
exit 0
}
$ns at 20 "finish"
$ns run
1 2 3 4 5 6 7 8 9 10 11 12
IP Src.
MAC
Node Global Pkt. Pkt. & TCP
Event Time MAC ---- Layer ----
Number Seq. No. Type Size Dst. Info
Info.
addr.
Description:
A router is a networking device that forwards data packets between computer networks.
When a data packet comes in on one of the lines, the router reads the network address
information in the packet to determine the ultimate destination.
Routing is the process of selecting paths in a network along which to send network traffic.
Goals of routing are correctness, simplicity, robustness, stability, fairness & optimality.
Routing is performed for many kinds of network, including the telephone network, electronic
data network & transportation networks.
Routing algorithms can be classified based on the following:
o Static or Dynamic routing
o Distributed or Centralized
o Single path or Multi-path
o Flat or Hierarchical
o Intra Domain or Inter Domain
o Link State or Distance vector
The basic concept of link-state routing is that every node constructs a map of the connectivity to the
network, in the form of a graph, showing which nodes are connected to which other nodes.
Each node then independently calculates the next best logical path from it to every possible
destination in the network. Each collection of best paths will then form each node's routing table.
Design:
Source code:
$ns rtproto LS
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam lab6.nam &
exit 0
}
for {set i 0} {$i < 7} {incr i} {
set n($i) [$ns node]
}
for {set i 0} {$i < 7} {incr i} {
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
}
$ns run
Steps for execution:
Open gedit editor & type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# gedit lab6.tcl
Save the program and quit.
Run the simulation program
[root@localhost~]# ns lab6.tcl
Dept. of ECE, BITM, Ballari Page 24