Sunteți pe pagina 1din 60

COMPUTER NETWORKS LABORATORY(15ECL68)

PART A

DEPT. of ECE, KVGCE, SULLIA, D.K Page 1


COMPUTER NETWORKS LABORATORY(15ECL68)

1. Implement four nodes point – to – point network with duplex links between
them. Analyze the network performance by setting the queue size, vary the
bandwidth and find the number of packets dropped.

PROCEDURE

 Open the terminal.


 Execute java –jar nsg2.jar.
 In scenario, select new wired scenario.
 Select nodes, create three nodes.
 In links,select duplex-link and connect.
 Apply tcp and tcpsink between two nodes and establish a peer-peer connection between them.
 Set bandwidth and queue - size
 In application,select ftp for tcp agent.
 In parameters set the simulation time.
 Gototcl and code will be generated.

# This script is created by NSG2 beta1


# <http://wushoupong.googlepages.com/nsg>
#KVGCE
#===================================
# Simulation parameters setup
#===================================
setval(stop) 20.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


settracefile [open p1.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


setnamfile [open p1.nam w]
$ns namtrace-all $namfile

#===================================
# Nodes Definition
#===================================
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]

DEPT. of ECE, KVGCE, SULLIA, D.K Page 2


COMPUTER NETWORKS LABORATORY(15ECL68)
set n2 [$ns node]
set n3 [$ns node]

#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 .1Mb 10ms DropTail
$ns queue-limit $n0 $n1 20
$ns duplex-link $n1 $n2 20Mb 10ms DropTail
$ns queue-limit $n1 $n2 20
$ns duplex-link $n2 $n3 20Mb 10ms DropTail
$ns queue-limit $n2 $n3 20

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient left-down
$ns duplex-link-op $n2 $n3 orient left

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n3 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 20.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnam p1.nam &
puts "Number of pkts dropped"
execgrep -c "^d" p1.tr &
DEPT. of ECE, KVGCE, SULLIA, D.K Page 3
COMPUTER NETWORKS LABORATORY(15ECL68)
set t [exec grep "^+" p1.tr | grep -c "tcp"]
#set r [exec grep "^r" p1.tr | grep -c "tcp"]
puts "Throughput is [expr $t/20] packtes per secs"

exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

DEPT. of ECE, KVGCE, SULLIA, D.K Page 4


COMPUTER NETWORKS LABORATORY(15ECL68)

DEPT. of ECE, KVGCE, SULLIA, D.K Page 5


COMPUTER NETWORKS LABORATORY(15ECL68)
2. Implement a four node point-to-point network with dulpex links connected as
follows: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.

 Open the terminal.


 Execute java –jar nsg2.jar.
 In scenario, select new wired scenario.
 Select nodes, create four nodes.
 In links,select duplex-link and connect.
 Apply tcp and tcpsink between two nodesudp and null agent between two nodes and establish a
peer-peer connection between them.
 Set bandwidth and queue - size
 In application ,select ftp for tcp agent and cbr for udp agent.
 In parameters set the simulation time.
 Gototcl and code will be generated.

#program 2
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
setval(stop) 20 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
$ns color 1 blue
$ns color 2 red
#Open the NS trace file
settracefile [open kv.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


setnamfile [open kv.nam w]
$ns namtrace-all $namfile

#===================================
# Nodes Definition
#===================================
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

DEPT. of ECE, KVGCE, SULLIA, D.K Page 6


COMPUTER NETWORKS LABORATORY(15ECL68)

#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 100Mb 10ms DropTail
$ns queue-limit $n0 $n1 50

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


$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100Mb 10ms DropTail
$ns queue-limit $n2 $n3 50

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient left-down

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp1 [new Agent/TCP]
$ns attach-agent $n0 $tcp1
set sink2 [new Agent/TCPSink]
$ns attach-agent $n3 $sink2
$ns connect $tcp1 $sink2
$tcp1 set packetSize_ 1500

#Setup a UDP connection


set udp4 [new Agent/UDP]
$ns attach-agent $n1 $udp4
set null5 [new Agent/Null]
$ns attach-agent $n3 $null5
$ns connect $udp4 $null5
$udp4 set packetSize_ 1000

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp1
$ns at 1.0 "$ftp0 start"
$ns at 20.0 "$ftp0 stop"

#Setup a CBR Application over UDP connection


set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp4
$cbr1 set packetSize_ 1000
$cbr1 set rate_ 1.0Mb
$cbr1 set random_ null
$ns at 1.0 "$cbr1 start"
DEPT. of ECE, KVGCE, SULLIA, D.K Page 7
COMPUTER NETWORKS LABORATORY(15ECL68)
$ns at 20.0 "$cbr1 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnamkv.nam&
set a [ exec grep "^+" kv.tr | grep -c "tcp" ]
set b [ exec grep -c "^+" kv.tr ]
puts "number of tcp packets sent is $a"
puts "number of udp packets sent is $b"
#exec grep "^+" kv.tr | cut -d " " -f 5 | grep -c "cbr" &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

DEPT. of ECE, KVGCE, SULLIA, D.K Page 8


COMPUTER NETWORKS LABORATORY(15ECL68)

DEPT. of ECE, KVGCE, SULLIA, D.K Page 9


COMPUTER NETWORKS LABORATORY(15ECL68)
3. Implement Ethernet LAN using n nodes (6-10). Compare the throughput changing
error rate and data rate .
PROCEDURE

 Open the terminal.


 Execute java –jar nsg2.jar.
 In scenario, select new wired scenario.
 Select nodes, create 6-10 nodes
 In links, select duplex-link and connect.
 Apply tcp and tcpsink between two nodes udp and null agent between two nodes and establish a
peer-peer connection between them.
 In application, select ftp for tcp agent and cbr for udp agent.
 Set bandwidth and queue - size
 In parameters set the simulation time.
 Goto tcl and code will be generated.

# This script is created by NSG2 beta1


# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
setval(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

$ns color 1 Blue


$ns color 2 Red

#Open the NS trace file


settracefile [open etr.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


setnamfile [open etr.nam w]
$ns namtrace-all $namfile

#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

DEPT. of ECE, KVGCE, SULLIA, D.K Page 10


COMPUTER NETWORKS LABORATORY(15ECL68)
set n4 [$ns node]
set n5 [$ns node]

#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50

setlan [$ns newLan "$n3 $n4 $n5 " 0.5Mb 40ms LL Queue/DropTail MAC/802_3 Channel]

#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

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n4 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#Setup a UDP connection


set udp2 [new Agent/UDP]
$ns attach-agent $n1 $udp2
set null3 [new Agent/Null]
$ns attach-agent $n5 $null3
$ns connect $udp2 $null3
$udp2 set packetSize_ 1500

set loss [new ErrorModel ]


$loss ranvar [new RandomVariable/Uniform ]
$loss drop-target [new Agent/Null ]
$ns lossmodel $loss $n2 $n3

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
DEPT. of ECE, KVGCE, SULLIA, D.K Page 11
COMPUTER NETWORKS LABORATORY(15ECL68)
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#Setup a CBR Application over UDP connection


set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp2
$cbr1 set packetSize_ 1000
$cbr1 set rate_ 1.0Mb
$cbr1 set random_ null
$ns at 1.0 "$cbr1 start"
$ns at 20.0 "$cbr1 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnametr.nam&

#set TcpSize 1540

setTcpSize [ exec grep "^r" etr.tr | grep "tcp" | tail -n 1 | cut -d " " -f 6]
setnumTcp [ exec grep "^r" etr.tr | grep -c "tcp" ]
settcpTime 19.0
#set UdpSize 1000
setUdpSize [ exec grep "^r" etr.tr | grep "cbr" | tail -n 1 | cut -d " " -f 6]
setnumUdp [ exec grep "^r" etr.tr | grep -c "cbr" ]
setudpTime 19.0
puts "the throughput of FTP is"
puts "[expr (($numTcp * $TcpSize)/$tcpTime)] bytes per second "
puts "the throughput of UDP is"
puts "[expr (($numUdp * $UdpSize)/$udpTime)] bytes per second "
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

DEPT. of ECE, KVGCE, SULLIA, D.K Page 12


COMPUTER NETWORKS LABORATORY(15ECL68)

DEPT. of ECE, KVGCE, SULLIA, D.K Page 13


COMPUTER NETWORKS LABORATORY(15ECL68)
4. Implement Ethernet LAN using n nodes and assign multiple traffic nodes and obtain
congestion window for different sources /destinations.
PROCEDURE

 Open the terminal.


 Execute java –jar nsg2.jar.
 In scenario, select new wired scenario.
 Select nodes, create 6-10 nodes.
 In links, select duplex-link and connect.
 Apply 2tcp and 2tcpsink between two nodes and establish a peer-peer connection between them.
 In application, select ftp for tcp agent.
 Set bandwidth and queue - size
 In parameters set the simulation time.
Goto tcl and code will be generated
#pr4 renovegas
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================
setval(stop) 20.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


settracefile [open v5.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


setnamfile [open v5.nam w]
$ns namtrace-all $namfile

set r [open reno w]


set n [open new w]
set v [open vegas w]

#===================================
# Nodes Definition
#===================================
#Create 9 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

DEPT. of ECE, KVGCE, SULLIA, D.K Page 14


COMPUTER NETWORKS LABORATORY(15ECL68)
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]
set n8 [$ns node]

#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 0.5Mb 100ms DropTail
$ns queue-limit $n0 $n2 3
$ns duplex-link $n1 $n2 0.5Mb 100ms DropTail
$ns queue-limit $n1 $n2 3
$ns duplex-link $n2 $n3 0.5Mb 100ms DropTail
$ns queue-limit $n2 $n3 3

setlan [$ns newLan "$n3 $n4 $n5 $n6 $n7 $n8" 0.5Mb 200ms LL Queue/DropTail MAC/802_3 Channel]

#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

#===================================
# Agents Definition
#===================================
#Setup a TCP/Reno connection
set tcp0 [new Agent/TCP/Reno]
$ns attach-agent $n0 $tcp0
set sink2 [new Agent/TCPSink]
$ns attach-agent $n7 $sink2
$ns connect $tcp0 $sink2
$tcp0 set packetSize_ 1500

#Setup a TCP/Newreno connection


set tcp1 [new Agent/TCP/Newreno]
$ns attach-agent $n1 $tcp1
set sink3 [new Agent/TCPSink]
$ns attach-agent $n8 $sink3
$ns connect $tcp1 $sink3
$tcp1 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP/Reno connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 1.0 "plot $tcp0 $r"
$ns at 20.0 "$ftp0 stop"

DEPT. of ECE, KVGCE, SULLIA, D.K Page 15


COMPUTER NETWORKS LABORATORY(15ECL68)
#Setup a FTP Application over TCP/Newreno connection
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns at 1.0 "$ftp1 start"
$ns at 1.0 "plot $tcp1 $n"
$ns at 20.0 "$ftp1 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnam v5.nam &
execxgraph -m reno new &
exit 0
}

proc plot {tcps file} {


global ns
setnw [$ns now]
setcw [$tcps set cwnd_]
puts $file "$nw $cw"
$ns at [expr $nw+0.1] "plot $tcps $file"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

DEPT. of ECE, KVGCE, SULLIA, D.K Page 16


COMPUTER NETWORKS LABORATORY(15ECL68)

DEPT. of ECE, KVGCE, SULLIA, D.K Page 17


COMPUTER NETWORKS LABORATORY(15ECL68)
5. Implement ESS with transmission nodes in wireless LAN and obtain the
performance parameters.

PROCEDURE

 Open the terminal.


 Execute java –jar nsg2.jar.
 In scenario, select new wireless scenario.
 Select nodes, create nodes.
 In links,select duplex-link and connect.
 Apply udpand null between two nodes and establish a peer-peer connection between them.
 In application ,selectcbr for udp agent.
 Set bandwidth and queue - size
 In parameters set the simulation time.
 Gototcl and code will be generated.

# This script is created by NSG2 beta1


# <http://wushoupong.googlepages.com/nsg>

#===================================
# Simulation parameters setup
#===================================

setval(chan) Channel/WirelessChannel ;# channel type


setval(prop) Propagation/TwoRayGround ;# radio-propagation model
setval(netif) Phy/WirelessPhy ;# network interface type
setval(mac) Mac/802_11 ;# MAC type
setval(ifq) Queue/DropTail/PriQueue ;# interface queue type
setval(ll) LL ;# link layer type
setval(ant) Antenna/OmniAntenna ;# antenna model
setval(ifqlen) 50 ;# max packet in ifq
setval(nn) 7 ;# number of mobilenodes
setval(rp) DSDV ;# routing protocol
setval(x) 900 ;# X dimension of topography
setval(y) 100 ;# Y dimension of topography
setval(stop) 200.0 ;# time of simulation end

#===================================
# Initialization
#===================================

#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]

DEPT. of ECE, KVGCE, SULLIA, D.K Page 18


COMPUTER NETWORKS LABORATORY(15ECL68)
$topoload_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file


settracefile [open out8.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


setnamfile [open out8.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
setchan [new $val(chan)];#Create wireless channel

#===================================
# Mobile node parameter setup
#===================================

$ns node-config -adhocRouting $val(rp) \


-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON

#===================================
# Nodes Definition
#===================================

#Create 7 nodes
set n0 [$ns node]
$n0 set X_ 384
$n0 set Y_ 332
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 238
$n1 set Y_ 331
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 589
DEPT. of ECE, KVGCE, SULLIA, D.K Page 19
COMPUTER NETWORKS LABORATORY(15ECL68)
$n2 set Y_ 330
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 107
$n3 set Y_ 320
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 258
$n4 set Y_ 102
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 530
$n5 set Y_ 106
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
set n6 [$ns node]
$n6 set X_ 720
$n6 set Y_ 316
$n6 set Z_ 0.0
$ns initial_node_pos $n6 20

#===================================
# Agents Definition
#===================================

#Setup a UDP connection


set udp0 [new Agent/UDP]
$ns attach-agent $n3 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n6 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================

#Setup a CBR Application over UDP connection


set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 200.0 "$cbr0 stop"

#===================================
# Termination
#===================================

#Define a 'finish' procedure


DEPT. of ECE, KVGCE, SULLIA, D.K Page 20
COMPUTER NETWORKS LABORATORY(15ECL68)
proc finish {} {
global ns tracefilenamfile
$ns flush-trace
close $tracefile
close $namfile
execnam out8.nam &
set s [exec grep "^s" out8.tr | grep -c "_3_ AGT" ]
set r [exec grep "^r" out8.tr | grep -c "_6_ AGT" ]

exec echo "number of packets sent = $s" &


exec echo " number of packet received = $r" &
exit 0
}
$ns at 50.0 "$n6 setdest 779 45 20"
$ns at 95.0 "$n6 setdest 440 90 20"
for {set i 0} {$i< $val(nn) } { incri } {
$ns at $val(stop) "\$n$i reset"
}
k$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

DEPT. of ECE, KVGCE, SULLIA, D.K Page 21


COMPUTER NETWORKS LABORATORY(15ECL68)

PART B

DEPT. of ECE, KVGCE, SULLIA, D.K Page 22


COMPUTER NETWORKS LABORATORY(15ECL68)

1. Write a program for a HDLC frame to perform the following.


a. Bit stuffing
b. Character stuffing.

 Theory:
 High-Level Data Link Control (HDLC) is a bit-oriented code-transparent
synchronous data link layer protocol developed by the International Organization
for Standardization (ISO) providing services like:
 Framing
 Error detection and frame retransmission
 Flow control
 HDLC provides both connection-oriented and connectionless service.
 HDLC can be used for point-to-multipoint connections, but is now used almost
exclusively to connect one device to another, using Asynchronous Balanced
Mode (ABM). The original master-slave modes Normal Response Mode (NRM)
and Asynchronous Response Mode (ARM) are rarely used.
 HDLC defines three types of frames:
 Information frames (I-frames): It is used to transport user data and
control information relating to user data.
 Supervisory frames (S-frames): It is used only to transport control
information-frames are reserved for system management
 Unnumbered frames (U-frames): It is intended for managing the link
itself.
 HDLC Framing methods:
 Starting and ending flags, with bit stuffing
 Starting and ending characters, with character stuffing
 Character count
 Physical layer coding violations

DEPT. of ECE, KVGCE, SULLIA, D.K Page 23


COMPUTER NETWORKS LABORATORY(15ECL68)
1. Bit stuffing:
 In a bit-oriented protocol, the data section of a frame is a sequence of bits to be
interpreted by the upper layer as text, graphic, audio, video, and so on.
 However, in addition to headers (and possible trailers), we still need a delimiter to
separate one frame from the other.
 Most protocols use a special 8-bit pattern flag 01111110 as the delimiter to define the
beginning and the end of the frame, as shown in figure below

Figure: A Frame in a Bit-Oriented Protocol

 This flag can create a type of problem .That is, if the flag pattern appears in the data,
we need to somehow inform the receiver that this is not the end of the frame.
 It is done by stuffing 1 single bit (instead of 1 byte) to prevent the pattern from
looking like a flag. The strategy is called bit stuffing.
 Bit stuffing is the process of adding one extra 0 whenever five consecutive 1s follow
a 0 in the data, so that the receiver does not mistake the pattern 0111110 for a flag.
 Scenario:
 Figure below shows bit stuffing at the sender and bit removal at the receiver.

DEPT. of ECE, KVGCE, SULLIA, D.K Page 24


COMPUTER NETWORKS LABORATORY(15ECL68)
Figure: Bit stuffing and unstuffing
 Note that even if we have a 0 after five 1s, we still stuff a 0. The 0 will be removed by
the receiver.
 This means that if the flag like pattern 01111110 appears in the data, it will change to
011111010 (stuffed) and is not mistaken as a flag by the receiver.
 The real flag 01111110 is not stuffed by the sender and is recognized by the receiver.
 Each frame begins and ends with a special bit pattern called a flag byte here it is
taken as 01111110.

 Just one flag required between consecutive frames.


 Whenever sender data link layer encounters five consecutive ones in the data stream, it
automatically stuffs a 0 bit into the outgoing stream

DEPT. of ECE, KVGCE, SULLIA, D.K Page 25


COMPUTER NETWORKS LABORATORY(15ECL68)
Code:
#include<stdio.h>
#include<string.h>
void main()
{
int i,j,count=0;
char str[100],dest[100]="";
clrscr();
printf("enter the bit string: ");
gets(str);
for (i=0;i<strlen(str);)
{

count=0;
//the following code search the five ones in given
string
for (j=i;j<(i+5)&&str[j]!='\0';j++)
{
if(str[j]=='1')
{
count++;
}
}
//if there is five ones then following code execute to bit
stuffing after five ones
if(count==5)
{
strcat(dest,"111110");
i=i+5;
}
else
{
char temp[2];
temp[0]=str[i];
temp[1]='\0';
strcat(dest,temp);
i++;
}
}

DEPT. of ECE, KVGCE, SULLIA, D.K Page 26


COMPUTER NETWORKS LABORATORY(15ECL68)
printf("After Stuffing\n");
puts(dest);
getch();
}

Output:

b. Byte Stuffing:
 In byte stuffing (or character stuffing), a special byte is added to the data section of the
frame when there is a character with the same pattern as the flag.
 The data section is stuffed with an extra byte. This byte is usually called the escape
character (ESC), which has a predefined bit pattern.
 Whenever the receiver encounters the ESC character, it removes it from the data section
and treats the next character as data, not a delimiting flag.
 Figure below describes the scenario

Figure: Frame Format in a character-oriented protocol

DEPT. of ECE, KVGCE, SULLIA, D.K Page 27


COMPUTER NETWORKS LABORATORY(15ECL68)
 Limitation of byte stuffing:
 Fixed character size of 8 bits can’t handle heterogeneous environment.
 Ex., Unicode, have 16-bit and 32-bit characters that conflict with 8-bit characters.

Code:
#include<stdio.h>
#include<string.h>
int main()
{
char str[50],dest[50]="";
int i;
printf("enter the character string: ");
gets(str);
printf("\noriginal data:\n");
puts(str);
strcat(dest,"dlestx");
for(i=0;i<strlen(str);)
{
if((str[i]=='d'&&str[i+1]=='l'&& str[i+2]=='e'))
{
else
{
strcat(dest,"dledle");
i=i+3;
}
else
{
char temp[2];
temp[0]=str[i];
temp[1]='\0';

DEPT. of ECE, KVGCE, SULLIA, D.K Page 28


COMPUTER NETWORKS LABORATORY(15ECL68)
strcat(dest,temp);
i++;
}
}
strcat(dest,"dleetx");
printf("\nStuffed data: \n");
puts(dest);
getchar();
}

Output:

DEPT. of ECE, KVGCE, SULLIA, D.K Page 29


COMPUTER NETWORKS LABORATORY(15ECL68)
2.Write a program for distance vector algorithm to find suitable path for
transmission.

Theory:
 In computer communication theory relating to packet-switched networks, a distance-
vector routing protocol is one of the two major classes of intra domain routing protocols,
the other major class being the link-state protocol. Distance-vector routing protocols use
the Bellman–Ford algorithm, Ford–Fulkerson algorithm, or DUAL FSM (in the case
of System’s protocols) to calculate paths.
 A distance-vector routing protocol requires that a router inform its neighbors of topology
changes periodically.
 A distance-vector routing protocol requires that a router inform its neighbors of topology
changes periodically.
 The term distance vector refers to the fact that the protocol manipulates vectors (arrays)
of distances to other nodes in the network. The distance vector algorithm was the
original ARPANET routing algorithm and was also used in the Internet under the name
of RIP (Routing Information Protocol).
 Examples of distance-vector routing protocols include RIPv1 and RIPv2, IGRP, EIGRP,
and Babel.
Scenario:

DEPT. of ECE, KVGCE, SULLIA, D.K Page 30


COMPUTER NETWORKS LABORATORY(15ECL68)
Code:
#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int costmat[20][20];
int nodes,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
printf("\nEnter the cost matrix :\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];
rt[i].from[j]=j;
}
}
do
{
count=0;
for(i=0;i<nodes;i++)
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j]; rt[i].from[j]=k;
count++;
}
}while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
//getch();
}

DEPT. of ECE, KVGCE, SULLIA, D.K Page 31


COMPUTER NETWORKS LABORATORY(15ECL68)

Output:

DEPT. of ECE, KVGCE, SULLIA, D.K Page 32


COMPUTER NETWORKS LABORATORY(15ECL68)
3. Implement Dijkstra’s algorithm to compute the shortest routing path.
Theory:
 Dijkstra's algorithm, named after its discoverer, Dutch computer scientist Edsger
Dijkstra, is a greedy algorithm that solves the single-source shortest path problem for a
directed graph with non negative edge weights.
 Scenario:
 If the vertices (nodes) of the graph represent cities and edge weights represent
driving distances between pairs of cities connected by a direct road, Dijkstra's
algorithm can be used to find the shortest route between two cities. Also, this
algorithm can be used for shortest path to destination in traffic network.

Algorithm:

Scenario:

DEPT. of ECE, KVGCE, SULLIA, D.K Page 33


COMPUTER NETWORKS LABORATORY(15ECL68)

Code:
#include<stdio.h>
void dijikstras(int cost[10][10],int dist[10],int n,int v)
{
int i,u,w,count,flag[10],min;
for(i=1;i<=n;i++)
{
flag[i]=0;
dist[i]=cost[v][i];
}
flag[v]=1; dist[v]=0;
count=2;
while(count<n)
{
for(i=1,min=999;i<=n;i++)
{
if(dist[i]<min &&! flag[i])
{
min=dist[i];
u=i;
}
}
flag[u]=i; count++;
for(w=1;w<=n;w++)
{
if(dist[u]+cost[u][w]<dist[w] &&! flag[w])

DEPT. of ECE, KVGCE, SULLIA, D.K Page 34


COMPUTER NETWORKS LABORATORY(15ECL68)
dist[w]=dist[u]+cost[u][w];
}
}
}
int main()
{
int n,cost[10][10],source,i,j,dist[10];
//clrscr();
printf("Enter the number of vertices\n"); scanf("%d",&n);
printf("Enter the cost matrix\n");
for(i=1;i<=n;i++) for(j=1;j<=n;j++)
{
scanf("%d",&cost[i][j]);
if(cost[i][j]==0)
cost[i][j]=999;
}
printf("source\n");
scanf("%d",&source);
dijikstras(cost,dist,n,source);
printf("Vertex \t Destination\t Cost\n"); for(i=1;i<=n;i++)
if(source!=i)
printf("%d\t%d\t%d\n",source,i,dist[i]);
//getch();
getchar();
}

DEPT. of ECE, KVGCE, SULLIA, D.K Page 35


COMPUTER NETWORKS LABORATORY(15ECL68)
Output:

DEPT. of ECE, KVGCE, SULLIA, D.K Page 36


COMPUTER NETWORKS LABORATORY(15ECL68)
4.For the given data, use CRC-CCITT polynomial to obtain CRC code. Verify
the program for the cases 1.Without error 2.With error

Theory:
In networking, error detection refers to the techniques used to detect noise or other impairments
introduced into data while it is transmitted from source to destination. Error detection ensures
reliable delivery of data across vulnerable networks.

Reasons for using Error Detection and correction methods:


Reliable delivery of digital data over unreliable communication channels.
Transmitted data will get corrupted due to noisy communication channel due to which
errors will get introduced in the original message.
Therefore we need Error detection and correction methods.

Advantages:
Error detection minimizes the probability of passing incorrect frames to the destination,
known as undetected error probability.
Checks consistency of the delivered message, and to recover data that has been
determined to be corrupted by adding some redundancy (i.e., some extra data) to a
message, which receivers can use.
Recovers data that has been determined to be corrupted.

Error Detecting Codes:


Basic approach used for error detection is the use of redundancy, where additional bits
are added to facilitate detection and correction of errors. Popular techniques are:
1. Simple Parity check
2. Two-dimensional Parity check
3. Checksum
4. Cyclic redundancy check

Cyclic Redundancy Check (CRC):

This Cyclic Redundancy Check is the most powerful and easy to implement technique.
CRC is based on binary division.

DEPT. of ECE, KVGCE, SULLIA, D.K Page 37


COMPUTER NETWORKS LABORATORY(15ECL68)
In CRC, a sequence of redundant bits, called cyclic redundancy check bits, are appended
to the end of data unit so that the resulting data unit becomes exactly divisible by a
second, predetermined binary number.
At the destination, the incoming data unit is divided by the same number. If at this step
there is no remainder, the data unit is assumed to be correct and is therefore accepted.
A remainder indicates that the data unit has been damaged in transit and therefore must
be rejected.

The Generalized Technique Can Be Explained As Follows:

If a k bit message is to be transmitted, the transmitter generates an r-bit sequence, known


as Frame Check Sequence (FCS) so that the (k+r) bits are actually being transmitted.
r- bit FCS is generated by dividing the original number, appended by r zeros, by a
predetermined number. This number, which is (r+1) bit in length, can also be considered
as the coefficients of a polynomial, called Generator Polynomial.
The remainder of this division process generates the r-bit FCS.
On receiving the packet, the receiver divides the (k+r) bit frame by the same
predetermined number and if it produces no remainder, it can be assumed that no error
has occurred during the transmission.
Operations at both the sender and receiver end are shown in the Figure below

Figure: Operations at sender and receiver for CRC

Case A: No Error in Transmission

DEPT. of ECE, KVGCE, SULLIA, D.K Page 38


COMPUTER NETWORKS LABORATORY(15ECL68)

Data Sent: 100100001

Receiver Side:

Here the remainder is all zeros, hence the data received has no error

Case B: With Error in Transmission

DEPT. of ECE, KVGCE, SULLIA, D.K Page 39


COMPUTER NETWORKS LABORATORY(15ECL68)
Actual Data Sent: 100100001
Due to channel distortion data get corrupted and now the new data at the
receiver is 100100 000
To show the above said practical scenario error has been inserted in the 9th bit
position of received data = 100100 000

Remainder ≠ 0, hence the data received is incorrect

DEPT. of ECE, KVGCE, SULLIA, D.K Page 40


COMPUTER NETWORKS LABORATORY(15ECL68)
Code:
#include<stdio.h>
#include<string.h>
#define N strlen(g)

char t[128],cs[128],g[]="10001000000100001";
int a,e,c;
void xor()
{
for(c=1;c<N;c++)
cs[c]=((cs[c]==g[c])?'0':'1');
}
void crc()
{
for(e=0;e<N;e++)
cs[e]=t[e];
do{
if(cs[0]=='1')
xor();
for(c=0;c<N-1;c++)
{
cs[c]=cs[c+1];
}
cs[c]=t[e++];
}while(e<=a+N-1);
}

void main()
{
printf("\nEnter the polynomial:");
scanf("%s",t);
printf("\nGenerator polynomial is:%s",g); a=strlen(t);
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\nModified t[u] is: %s",t);
crc();
printf("\nChecksum is:%s",cs);
for(e=a;e<a+N-1;e++)
t[e]=cs[e-a];

DEPT. of ECE, KVGCE, SULLIA, D.K Page 41


COMPUTER NETWORKS LABORATORY(15ECL68)
printf("\nFinal codeword is:%s",t); printf("\nTest
error detection 0(yes) 1(no) ?:"); scanf("%d",&e);
if(e==0)
{
printf("enter the position where the error is to be inserted:");
scanf("%d",&e);
e=e-1;
t[e]=(t[e]=='0')?'1':'0';
printf("Errorneous data: %s\n",t);
}
crc();
for(e=0;(e<N-1)&&(cs[e]!='1');e++) ;
if(e<N-1==1)
printf("Error detected.");
else
printf("No error detected.");
}

Output:
Case 1: Without Error

Case 1: With Error

DEPT. of ECE, KVGCE, SULLIA, D.K Page 42


COMPUTER NETWORKS LABORATORY(15ECL68)
5.Implementation of Stop and Wait Protocol and Sliding Window
Protocol.

Design of Stop and Wait Protocol

DEPT. of ECE, KVGCE, SULLIA, D.K Page 43


COMPUTER NETWORKS LABORATORY(15ECL68)
Algorithm Sender-site algorithm for Stop-and-Wait Protocol

Algorithm Receiver-site algorithm for Stop-and-Wait Protocol

Figure shows an example of communication using this protocol. It is still very simple. The sender sends
one frame and waits for feedback from the receiver. When the ACK arrives, the sender sends the next
frame. Note that sending two frames in the protocol involves the sender in four events and the
receiver in two events.

DEPT. of ECE, KVGCE, SULLIA, D.K Page 44


COMPUTER NETWORKS LABORATORY(15ECL68)

CODE:
#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>

#define MAX_SEQ 1
#define TOT_PACKETS 8
#define inc(k) if(k<MAX_SEQ) k++; else k=0;
typedef struct
{
int data;
}packet;
typedef struct
{
int seq;
int ack;
packet info;
DEPT. of ECE, KVGCE, SULLIA, D.K Page 45
COMPUTER NETWORKS LABORATORY(15ECL68)
}frame;

frame DATA;
typedef enum{frame_arrival} event_type;

void from_network_layer(packet *);


void to_network_layer(packet *);
void to_physical_layer(frame *);
void from_physical_layer(frame *);
void wait_for_event_sender(event_type *);
void wait_for_event_reciever(event_type *);
void reciever();
void sender();

int i=1; //Data to be sent by sender


char turn; //r , s
int DISCONNECT=0;
/*__________________________________________________________________________*/
void main()
{
clrscr();
randomize();
while(!DISCONNECT)
{
sender();
delay(400);
reciever();
}
getch();
}
/*__________________________________________________________________________*/
void sender()
{
static int frame_to_send=0;
static frame s;

DEPT. of ECE, KVGCE, SULLIA, D.K Page 46


COMPUTER NETWORKS LABORATORY(15ECL68)
packet buffer;
event_type event;
static int flag=0;

if(flag==0)
{
from_network_layer(&buffer);
s.info = buffer;
s.seq = frame_to_send;
printf("SENDER : Info = %d Seq No = %d ",s.info,s.seq);
turn = 'r';
to_physical_layer(&s);
flag = 1;
}
wait_for_event_sender(&event);
if(turn=='s')
{
from_network_layer(&buffer);
inc(frame_to_send);
s.info = buffer;
s.seq = frame_to_send;
printf("SENDER : Info = %d Seq No = %d ",s.info,s.seq);
turn = 'r';
to_physical_layer(&s);

}
}
/*__________________________________________________________________________*/
void reciever()
{
static int frame_expected=0;
frame r,s;
event_type event;
wait_for_event_reciever(&event);
if(turn=='r')

DEPT. of ECE, KVGCE, SULLIA, D.K Page 47


COMPUTER NETWORKS LABORATORY(15ECL68)
{

from_physical_layer(&r);
if(r.seq==frame_expected)
{
to_network_layer(&r.info);
inc(frame_expected);
}

turn = 's';
to_physical_layer(&s);
}

}
/*__________________________________________________________________________*/
void from_network_layer(packet *buffer)
{
(*buffer).data = i;
i++;
}
/*___________________________________________________________________________*/
void to_physical_layer(frame *s)
{
DATA = *s;
}
/*___________________________________________________________________________*/
void to_network_layer(packet *buffer)
{
printf("RECIEVER :Packet %d recieved , Ack Sent\n",(*buffer).data);
if(i>TOT_PACKETS) //if all packets recieved then disconnect
{
DISCONNECT = 1;
printf("\nDISCONNECTED");
}
}

DEPT. of ECE, KVGCE, SULLIA, D.K Page 48


COMPUTER NETWORKS LABORATORY(15ECL68)
/*___________________________________________________________________________*/
void from_physical_layer(frame *buffer)
{
*buffer = DATA;
}
/*___________________________________________________________________________*/
void wait_for_event_sender(event_type * e)
{
if(turn=='s')
*e = frame_arrival;
}
/*____________________________________________________________________________*/
void wait_for_event_reciever(event_type * e)
{
if(turn=='r')
*e = frame_arrival;
}

output:

SENDER : Info = 1 Seq No = 0 RECIEVER :Packet 1 recieved , Ack Sent


SENDER : Info = 2 Seq No = 1 RECIEVER :Packet 2 recieved , Ack Sent
SENDER : Info = 3 Seq No = 0 RECIEVER :Packet 3 recieved , Ack Sent
SENDER : Info = 4 Seq No = 1 RECIEVER :Packet 4 recieved , Ack Sent
SENDER : Info = 5 Seq No = 0 RECIEVER :Packet 5 recieved , Ack Sent
SENDER : Info = 6 Seq No = 1 RECIEVER :Packet 6 recieved , Ack Sent
SENDER : Info = 7 Seq No = 0 RECIEVER :Packet 7 recieved , Ack Sent
SENDER : Info = 8 Seq No = 1 RECIEVER :Packet 8 recieved , Ack Sent

Sliding Window Protocol


Figure Design of Go-Back-N ARQ

DEPT. of ECE, KVGCE, SULLIA, D.K Page 49


COMPUTER NETWORKS LABORATORY(15ECL68)

DEPT. of ECE, KVGCE, SULLIA, D.K Page 50


COMPUTER NETWORKS LABORATORY(15ECL68)
Algorithm Go-Back-N sender algorithm

DEPT. of ECE, KVGCE, SULLIA, D.K Page 51


COMPUTER NETWORKS LABORATORY(15ECL68)

DEPT. of ECE, KVGCE, SULLIA, D.K Page 52


COMPUTER NETWORKS LABORATORY(15ECL68)
AlgorithmGo-Back-N receiver algorithm

Figure Send window for Go-Back-N ARQ

Figure Receive window for Go-Back-N ARQ

Notes

 In the Go-Back-N Protocol, the sequence numbers are modulo 2m, where m is the size of
the sequence number field in bits.
 The send window is an abstract concept defining an imaginary box of size 2m − 1 with
three variables: Sf, Sn, and Ssize.
 The send window can slide one or more slots when a valid acknowledgment arrives.
 The receive window is an abstract concept defining an imaginary box
 of size 1 with one single variable Rn. The window slides when a correct frame has
arrived; sliding occurs one slot at a time.

DEPT. of ECE, KVGCE, SULLIA, D.K Page 53


COMPUTER NETWORKS LABORATORY(15ECL68)
In Go-Back-N ARQ, the size of the send window must be less than 2m ; the size of the receiver
window is always 1.

CODE:#include<stdio.h>
int main()
{
int w,i,f,frames[50];
printf("Enter window size: ");
scanf("%d",&w);
printf("\nEnter number of frames to
transmit: "); scanf("%d",&f);
printf("\nEnter %d frames: ",f);
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner
(assuming no corruption of frames)\n\n");

printf("After sending %d frames at each stage sender waits for acknowledgement


sent by the receiver\n\n",w);

for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);

printf("Acknowledgement of above frames sent is received by sender\n\n");


}
else
printf("%d ",frames[i]);
}

DEPT. of ECE, KVGCE, SULLIA, D.K Page 54


COMPUTER NETWORKS LABORATORY(15ECL68)
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by sender\n");

return 0;
}

output:

Enter the no. of packets to be sent 5


Enter data for packet1 :100
Enter data for packet2 :200
Enter data for packet3 :300
Enter data for packet4 :400
Enter data for packet5 :500

The packet number 3 is not received

Resending packet 3
Received data of packet 3 is 300
Received data of packet 4 is 400
Received data of packet 5 is 500
All packets sent successfully

DEPT. of ECE, KVGCE, SULLIA, D.K Page 55


COMPUTER NETWORKS LABORATORY(15ECL68)
6.Write a program for congestion control using leaky bucket algorithm.

Theory

Theory:
Congestion Control
 Congestion is a situation in Communication Networks in which too many packets are
present in a network.

 Congestion in a network may occur when the load on the network i.e. the number of
packets sent to the network is greater than the capacity of the network i.e. the number of
packets a network can handle.

Causes Of Congestion
 Congestion can occur due to several reasons. Below are listed important causes:
 The major cause of congestion is often the bursty nature of traffic
 Long queue of steam of packets and insufficient memory at the router to process
the queued up packets on several input lines which need to be out on the same
output line, in that case packet loss occurs
 Timed-out(repeatedly) of the packets though routers are facilitated with more
memory
 Packets arrive at the destination, the will be discarded, due to time out, so
instead of been dropped at any intermediate router (in case memory is restricted)
 Slow processors also cause Congestion. router CPU is slow at performing the
task required for them (Queuing buffers, updating tables, reporting any exceptions
etc.), queue can build up even if there is excess of line capacity.
 Low-Bandwidth lines can also cause congestion.

Effects of Congestion
 Increases the load to the network
 Reduces the throughput and increases the delay

Congestion Control Technique


Traffic Shaping:
 This is a mechanism to control the amount and the rate of the traffic sent to the network.

DEPT. of ECE, KVGCE, SULLIA, D.K Page 56


COMPUTER NETWORKS LABORATORY(15ECL68)
 Congestion Control refers to techniques and mechanisms that can either prevent
congestion, before it happens, or remove congestion, after it has happened.
 Congestion control mechanisms are divided into two categories, one category
prevents the congestion from happening and the other category removes
congestion after it has taken place.

Congestion control algorithms


Leaky Bucket Algorithm
 Imagine a bucket with a small hole at the bottom.
 The rate at which the water is poured into the bucket is not fixed and can vary but it
leaks from the bucket at a constant rate. Thus as long as water is present in bucket, the
rate at which the water leaks does not depend on the rate at which the water is input to
the bucket.

DEPT. of ECE, KVGCE, SULLIA, D.K Page 57


COMPUTER NETWORKS LABORATORY(15ECL68)

LEAKY BUCKET
#include<stdio.h>
#include<time.h>
void main()
{
int a[5],buck_rem=0,buck_cap=0,rate=0,i,sent,recv;
clrscr();
printf("\n enter the bucket capacity \n");
scanf("%d",&buck_cap);
printf("enter the rate of transmission \n");
scanf("%d",&rate);
srand(time(NULL));
for(i=0;i<5;i++)
a[i]=rand()%80+1;
printf("CLOCK PKT_SIZE RECEIVED SENT REMAINING \n");
for(i=0;i<5;i++)
{
if((buck_rem+a[i])>buck_cap)
recv=-1;
else
{
recv=a[i];
buck_rem=buck_rem+a[i];
}

if(buck_rem!=0)
{
sleep(1);
if(buck_rem<rate)
{
sent=buck_rem;
buck_rem=0;
}
else
{
sent=rate;
buck_rem=buck_rem-rate;
}
}
else
sent=0;
if(recv==-1)
printf("\n%d\t%d\t[d]\t%d\t%d\t\n",i,a[i],sent,buck_rem);
else
printf("\n%d\t%d\t%d\t%d\t%d\n",i,a[i],recv,sent,buck_rem);

DEPT. of ECE, KVGCE, SULLIA, D.K Page 58


COMPUTER NETWORKS LABORATORY(15ECL68)

}
getch();
}

Viva Questions
1. Explain the functions of OSI layers ?
2. Differentiate between TCP/IP Layers and OSI Layers
3. Why header is required?
4. What is the use of adding header and trailer to frames?
5. What is encapsulation?
6. Why fragmentation requires?
7. What is MTU?
8. Which layer imposes MTU?
9. Differentiate between flow control and congestion control.
10. Differentiate between Point-to-Point Connection and End-to-End connections.
11. What are protocols running in different layers?
12. What is Protocol Stack?
13. Differentiate between TCP and UDP.
14. Differentiate between Connectionless and connection oriented connection.
15. Why frame sorting is required?
16. What is meant by subnet?
17. What is meant by Gateway?
18. What is an IP address?
19. What is MAC address?
20. Why IP address is required when we have MAC address?
21. What is meant by port?
22. What are ephemerical port number and well known port numbers?
23. What is a socket?
24. What are the parameters of socket()?
25. Describe bind(), listen(), accept(),connect(), send() and recv().
26. What are system calls? Mention few of them.
27. What is IPC? Name three techniques.
28. Explain mkfifo(), open(), close() with parameters.
29. What is meant by file descriptor?
30. What is meant by traffic shaping?
31. How do you classify congestion control algorithms?
32. Differentiate between Leaky bucket and Token bucket.
33. How do you implement Leaky bucket?

DEPT. of ECE, KVGCE, SULLIA, D.K Page 59


COMPUTER NETWORKS LABORATORY(15ECL68)
34. How do you generate bursty traffic?
35. What is the polynomial used in CRC-CCITT?
36. What are the other error detection algorithms?
37. What is difference between CRC and Hamming code?
38. Why Hamming code is called 7,4 code?
39. What is odd parity and even parity?
40. What is meant by syndrome?
41. What is generator matrix?
42. What are Routing algorithms?
43. How do you classify routing algorithms? Give examples for each.
44. What are drawbacks in distance vector algorithm?
45. How routers update distances to each of its neighbor?

DEPT. of ECE, KVGCE, SULLIA, D.K Page 60

S-ar putea să vă placă și