18ECL76_LAB MANUAL_UPDATED_2022 scheme.pdf

kavana86600 9 views 51 slides Oct 29, 2025
Slide 1
Slide 1 of 51
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51

About This Presentation

BEC702 CN LAB Manual Latest 22 scheme jain institute of technology


Slide Content

Arka Educational & Cultural Trust (Regd.)
Jain Institute of Technology, Davangere.
(A Unit of Jain Group of Institutions, Bangalore)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING







COMPUTER NETWORKS LAB
(18ECL76)
LAB MANUAL






Prepared By
ANUSHA K
Assistant Professor
Dept. of E&CE, JIT, Davanagere

List of Conducting Experiments

Expt
No.
Name of the Experiment
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
3
Implement Ethernet LAN using n (6-10) nodes. Compare the throughput by
changing the error rate and data rate.
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.
PART B
6
Write a program for a HLDC frame to perform the following.
i) Bit stuffing
ii) Character stuffing.
7
Write a program for distance vector algorithm to find suitable path for
transmission.
8 Implement Dijkstra’s algorithm to compute the shortest routing path.
9
For the given data, use CRC-CCITT polynomial to obtain CRC code. Verify the
program for the cases
a. Without error
b. With error
10 Implementation of Stop and Wait Protocol and Sliding Window Protocol
11 Write a program for congestion control using leaky bucket algorithm

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 1

PART A
Simulation experiments using NS2/ NS3/ OPNET/ NCTUNS/ NetSim/QualNet or any
other equivalent tool
Experiment 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.

Step 1 : Draw Topology
1. Select Host icon on the tool bar and place it on the editor. Select Create label icon on the
tool bar to rename the host drawn as HOST-1. Repeat the same procedure to place HOST-
2,HOST-3 and HOST-4 on the editor.
2. Select Hub icon on the tool bar and place it on the editor. Select Create label icon on the
tool bar to rename it as HUB.
3. Select Create a Point-to-point link icon on the tool bar to create Point-to-point link between
the Hosts and Hub placed on the editor to create Star topology as shown in the above
figure.
4. Select Editor Mode ‘E’ on the tool bar to save the topology. save the file using .tpl
extension.( Ex: [experiment name].tpl)
Step 2 : Edit Configuration
At Sender
1. Double click on HOST-1 to open Host- edit window. Select ADD button on edit window
to invoke command window
2. Provide start and stop time and Sender Command
Sender Command : stg –u 1024 100 Receiver IP Address
Where, Stg -u: Sender Topology in UDP mode
1024 : Payload size
100 : Port Number

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 2


In this case consider Host-4 as receiver and add HOST-4 IP Address in place of Receiver
IP Address in the command.
3. Select NODE EDITOR on the Host-edit window  select MAC tab from the pop-up window
 select mode( Half/ full duplex) by ticking the checkbox  select LOG STATISTICS by
ticking checkbox  select Collision, drop and out throughput. Repeat the same steps for
HOST-2 and HOST-3

At Receiver

4. Double click on HOST-4 to open Host- edit window. Select ADD button on edit window
to invoke command window
5. Provide start and stop time and receiver Command
Receiver Command : rtg –u –w log1
Where,
rtg –u : Receiver topology in UDP Mode
-w : write the input and save as log file
6. Select NODE EDITOR on the Host-edit window  select MAC8023 tab from the pop-up
window  select mode( Half/ full duplex) by ticking the checkbox  select LOG
STATISTICS by ticking checkbox  select Collision, drop and In-throughput then select
OK.
7. Select FIFO Tab on the node editor window set queue size = 50  select OK to exit from
the node editor window.

To Set Bandwidth:
Double click on Hub and set the bandwidth as 10Mbps for the first case and without changing
any properties of any other nodes change the bandwidth to 100Mbps for the second case and
verify the output.

Step 3: Simulation

1. Select ‘R’ icon on the tool bar
2. Select ‘Yes’ for the window that popsup to save the current topology settings.
3. Select Simulation in menubar and select Run option in the drop down box. Then the file
transfer will be done and simulation will shift to PLAY mode.
Step 4: Play Back
Select Play button at the bottom right corner of the NCTUNS window to see the file transfer
across the network drawn.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 3


To view the Result:
Step 1: Minimize the NCTUNS Client window and select ROOT’S HOME icon on the
display.
Step 2: select the result folder of the current topology saved. (ex: Exp1. Results).open the
file to get the collision , drop and data transmission values saved in different log files.
Tabulate the Maximum and Minimum values with corresponding time for the two cases.
Output:
Case 1: Queue size=50 ; Bandwidth = 10Mbps
Collision Drop Throughput
Max(sec) Min(sec) Max(sec) Min(sec) Max(sec) Min(sec)
N1-P1
N2-P1
N3-P1
N4-P1

Case 2: Queue size=50 ; Bandwidth = 100Mbps
Collision Drop Throughput
Max(sec) Min(sec) Max(sec) Min(sec) Max(sec) Min(sec)
N1-P1
N2-P1
N3-P1
N4-P1

Result: Analysed the data transmission by setting queue size and varying the bandwidth.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 4


Experiment 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.


Step 1 : Draw Topology
1. Select Host icon on the tool bar and place it on the editor as shown in the above
topology. Select Create label icon on the tool bar to rename the host drawn as N0-TCP
Sender. Repeat the same procedure to place HOST-2 and HOST-3 on the editor and
rename them as N1- UDP Sender and N3-Receiver (TCP & UDP) respectively.
2. Select Hub icon on the tool bar and place it on the editor. Select Create label icon on
the tool bar to rename it as N2-HUB.
3. Select Create a Point-to-point link icon on the tool bar to create Point-to-point link
between the Hosts and Hub placed on the editor to create Star topology as shown in
the figure.
4. Select Editor Mode ‘E’ on the tool bar to save the topology. save the file using .tpl
extension.( Ex: [experiment name].tpl)


Step 2 : Edit Configuration
At Sender

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 5

1. Double click on HOST-1 to open Host- edit window. Select ADD button on edit
window to invoke command window
2. Provide start and stop time and Sender TCP Command
Sender TCP Command : stcp –p 3000 –l 1024 Receiver IP Address
Where, Stcp: Sender TCP mode
-p 3000: Port Number 3000
-l 1024 : Payload size
Receiver IP address : IP address of HOST 3

In this case consider Host-3 as receiver and add HOST-3 IP Address in place of Receiver
IP Address in the command.

3. Select NODE EDITOR on the Host-edit window  select MAC tab from the pop-up
window  select mode( Half/ full duplex) by ticking the checkbox  select LOG
STATISTICS by ticking checkbox  select Collision, drop and out throughput.

4. Double click on HOST-2 to open Host- edit window. Select ADD button on edit
window to invoke Sender command window
Sender UDP Command : stg –u 1024 100 Receiver IP Address
Where, Stg -u: Sender Topology in UDP mode
1024 : Payload size
100 : Port Number
Receiver IP address : IP address of HOST 3
In this case consider Host-3 as receiver and add HOST-3 IP Address in place of
Receiver IP Address in the command.
5. Select NODE EDITOR on the Host-edit window  select MAC tab from the pop-up
window  select mode( Half/ full duplex) by ticking the checkbox  select LOG
STATISTICS by ticking checkbox  select Collision, drop and out throughput.

At Receiver

1. Double click on HOST-3 to open Host- edit window. Select ADD button on edit window
to invoke command window
2. Provide start and stop time and add receiver TCP & UDP Command
Receiver TCP Command : rtcp –p 3000 –l 1024
Receiver UDP Command : rtg –u –w log1
Where,
rtg –u : Receiver topology in UDP Mode ; -w : write the input and save as log file
rtcp : Receiver in TCP mode ; -p 3000: Port Number 3000 ; -l 1024 : Payload size

3. Select NODE EDITOR on the Host-edit window  select MAC8023 tab from the pop-up
window  select mode( Half/ full duplex) by ticking the checkbox  select LOG

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 6

STATISTICS by ticking checkbox  select Collision, drop and In-throughput then select
OK.
4. Select FIFO Tab on the node editor window set queue size = 50  select OK to exit from
the node editor window.

At Hub : Set Bandwidth
Double click on Hub and set the bandwidth as 10Mbps
Step 3: Simulation

1. Select ‘R’ icon on the tool bar
2. Select ‘Yes’ for the window that popsup to save the current topology settings.
3. Select Simulation in menubar and select Run option in the drop down box. Then the
file transfer will be done and simulation will shift to PLAY mode.
Step 4: Play Back
Select Play button at the bottom right corner of the NCTUNS window to see the file transfer
across the network drawn.
To view the Result:
Step 1: Minimize the NCTUNS Client window and select ROOT’S HOME icon on the
display.
Step 2: select the result folder of the current topology saved. (ex: Exp1. Results).open the
file to get the collision , drop and data transmission values saved in different log files.
Tabulate the values with corresponding time.

Output:
Queue size=50 ; Bandwidth = 10Mbps
Collision Drop Throughput
Max(sec) Min(sec) Max(sec) Min(sec) Max(sec) Min(sec)
N1-P1
N2-P1
N3-P1
N4-P1

Result : Verified data transmission through TCP and UDP connections. UDP exhibits high
throughput compared to TCP

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 7


Experiment 3 : Implement Ethernet LAN using n (6-10) nodes. Compare the throughput
by changing the error rate and data rate


Step 1 : Draw Topology
1. Select Host icon on the tool bar and place it on the editor to create Sender and Receiver sites
as shown in the above topology. Select Create label icon on the tool bar to rename the hosts
drawn as HOST-1, HOST-2, HOST-3 on the Sender site and HOST-4, HOST-5, HOST-6 on
the Receiver site.
2. Select Hub icon on the tool bar and place it on the editor as shown in topology. Select Create
label icon on the tool bar to rename it as HUB-1 and HUB-2.
3. Select Switch icon on the tool bar and place it on the editor as shown in topology. Select
Create label icon on the tool bar to rename it as SWITCH.
4. Select Create a Point-to-point link icon on the tool bar to create Point-to-point link between
the Hosts ,Hub and switch placed on the editor to create a topology as shown in the above
figure.
5. Select Editor Mode ‘E’ on the tool bar to save the topology. save the file using .tpl extension.(
Ex: [experiment name].tpl)
Step 2 : Edit Configuration
At Sender
1. Double click on HOST-1 to open Host- edit window. Select ADD button on edit window to
invoke command window

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 8

2. Provide start and stop time and Sender Command
Sender Command : stg –u 1024 100 Receiver IP Address
Where, Stg -u: Sender Topology in UDP mode
1024 : Payload size
100 : Port Number
Receiver IP Address : IP address of HOST_4

In this case consider Host-4 as receiver and add HOST-4 IP Address in place of Receiver
IP Address in the command.
3. Select NODE EDITOR on the Host-edit window  select MAC tab from the pop-up
window  select mode( Half/ full duplex) by ticking the checkbox  select LOG
STATISTICS by ticking checkbox  select out throughput.
4. Repeat the above steps for HOST-2 and HOST-3. Consider HOST-5 as Receiver for HOST-
2 and HOST-6 as Receiver for HOST-3.

At Receiver

5. Double click on HOST-4 to open Host- edit window. Select ADD button on edit window
to invoke command window
6. Provide start and stop time and receiver Command
Receiver Command : rtg –u –w log1
Where,
rtg –u : Receiver topology in UDP Mode ; -w : write the input and save it as log file.

7. Select NODE EDITOR on the Host-edit window  select MAC8023 tab from the pop-up
window  select mode( Half/ full duplex) by ticking the checkbox  select LOG
STATISTICS by ticking checkbox  select In-throughput then select OK.
8. Select FIFO Tab on the node editor window set queue size = 50  select OK to exit from
the node editor window.
9. Repeat the above steps for HOST-5 and HOST-6 at the receiver site.

At Switch : To set Bit Error Rate and Data rate

1. Double click on Switch to invoke editor window  select Node Editor  select Phy tab
(shown in figure 1 below) Set Bandwidth as 10 Mbps and Bit error rate as 0.1 for first
case.
2. Select MAC8023 tab connected to HUB-1 in the node editor  select LOG
STATISTICS by ticking checkbox  select In-throughput then select OK.
3. Select MAC8023 tab connected to HUB-2 in the node editor  select LOG
STATISTICS by ticking checkbox  select Out-throughput then select OK.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 9

4. Then change the Bit error rate to 0.001 by keeping bandwidth as 10 Mbps for the second
Case.

Figure 1: Node editor window for switch

Step 3: Simulation

1. Select ‘R’ icon on the tool bar
2. Select ‘Yes’ for the window that popsup to save the current topology settings.
3. Select Simulation in menubar and select Run option in the drop down box. Then the
file transfer will be done and simulation will shift to PLAY mode.
Step 4: Play Back
Select Play button at the bottom right corner of the NCTUNS window to see the file
transfer across the network drawn.
To view the Result:
Step 1: Minimize the NCTUNS Client window and select ROOT’S HOME icon on the
display.
Step 2: select the result folder of the current topology saved. (ex: Exp1. Results).open the
file to get the throughput values saved in log files. Tabulate the Maximum and Minimum
values with corresponding time for the two cases.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 10


Output:
Case 1 : Bit Error Rate : 0.1 ; Data rate = 10Mbps
Out throughput In throughput
Max(sec) Min(sec) Min(sec)
N1-P1 N4-P2
N2-P1 N5-P2
N3-P1 N6-P2

Case 2 : Bit Error Rate : 0.001 ; Data rate = 10Mbps
Out throughput In throughput
Max(sec) Min(sec) Min(sec)
N1-P1 N4-P2
N2-P1 N5-P2
N3-P1 N6-P2

Result : Verified the Through for different Bit Error rates and tabulated the results.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 11



Experiment 4 : Implement Ethernet LAN using n nodes and assign multiple traffic to the
nodes and obtain congestion window for different sources/ destinations.


Step 1 : Draw Topology
1. Select Host icon on the tool bar and place it on the editor to create Sender and Receiver sites
as shown in the above topology. Select Create label icon on the tool bar to rename the hosts
drawn as HOST-1, HOST-2, HOST-3 on the Sender site and HOST-4, HOST-5, HOST-6 on
the Receiver site.
2. Select Hub icon on the tool bar and place it on the editor as shown in topology. Select Create
label icon on the tool bar to rename it as HUB-1 and HUB-2.
3. Select Switch icon on the tool bar and place it on the editor as shown in topology. Select Create
label icon on the tool bar to rename it as SWITCH.
4. Select Create a Point-to-point link icon on the tool bar to create Point-to-point link between the
Hosts ,Hub and switch placed on the editor to create a topology as shown in the above figure.
5. Select Editor Mode ‘E’ on the tool bar to save the topology. save the file using .tpl extension.(
Ex: [experiment name].tpl)
Step 2 : Edit Configuration
At Sender

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 12

1. Double click on HOST-1 to open Host- edit window. Select ADD button on edit window to
invoke command window
Provide start and stop time and Sender Command
Sender Command : stg –u 1024 100 Receiver IP Address
Where, Stg -u: Sender Topology in UDP mode
1024 : Payload size
100 : Port Number
Receiver IP Address : IP address of HOST_4

In this case consider Host-4 as receiver and add HOST-4 IP Address in place of Receiver
IP Address in the command.
2. Select NODE EDITOR on the Host-edit window  select MAC tab from the pop-up window
 select mode( Half/ full duplex) by ticking the checkbox  select LOG STATISTICS by
ticking checkbox  select COLLISION and DROP then select OK.
3. Repeat the above steps for HOST-2 and HOST-3. Consider HOST-5 as Receiver for HOST-
2 and HOST-6 as Receiver for HOST-3.

At Receiver

4. Double click on HOST-4 to open Host- edit window. Select ADD button on edit window to
invoke command window
5. Provide start and stop time and receiver Command
Receiver Command : rtg –u –w log1
Where,
rtg –u : Receiver topology in UDP Mode ; -w : write the input and save it as log file.

6. Select NODE EDITOR on the Host-edit window  select MAC8023 tab from the pop-up
window  select mode( Half/ full duplex) by ticking the checkbox  select LOG
STATISTICS by ticking checkbox  select COLLISION and DROP then select OK.
7. Select FIFO Tab on the node editor window set queue size = 50  select OK to exit from
the node editor window.
8. Repeat the above steps for HOST-5 and HOST-6 at the receiver site.

At Switch : To set Bit Error Rate and Data rate

5. Double click on Switch to invoke editor window  select Node Editor  select Phy tab
(shown in figure 1 below) Set Bandwidth as 10 Mbps and Bit error rate as 0.1.
6. Select MAC8023 tab connected to HUB-1 in the node editor  select LOG STATISTICS
by ticking checkbox  select In-throughput then select OK.
7. Select MAC8023 tab connected to HUB-2 in the node editor  select LOG STATISTICS
by ticking checkbox  select Out-throughput then select OK.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 13



Figure 1: Node editor window for switch

Step 3: Simulation

4. Select ‘R’ icon on the tool bar
5. Select ‘Yes’ for the window that popsup to save the current topology settings.
6. Select Simulation in menubar and select Run option in the drop down box. Then the
file transfer will be done and simulation will shift to PLAY mode.
Step 4: Play Back
Select Play button at the bottom right corner of the NCTUNS window to see the file
transfer across the network drawn.
To view the Result:
Step 1: Minimize the NCTUNS Client window and select ROOT’S HOME icon on the
display.
Step 2: select the result folder of the current topology saved. (ex: Exp1. Results).open the
file to get the throughput values saved in log files. Tabulate the Maximum and Minimum
values with corresponding time for the two cases.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 14


Output:
Case 1 : Bit Error Rate : 0.1 ; Data rate = 10Mbps
Collision Drop
Max(sec) Min(sec) Max(sec) Min(sec)
N1-P1
N2-P1
N3-P1
N4-P1
N5-P1
N6-P1

Case 2 : Bit Error Rate : 0.1 ; Data rate = 10Mbps
Collision Drop
Max(sec) Min(sec) Max(sec) Min(sec)
N1-P1
N2-P1
N3-P1
N4-P1
N5-P1
N6-P1

Result : Analysed the traffic window for different sender and receiver by Recording the Maximum
& Minimum values of collision and drop packet at sender and receiver.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 15


Experiment 5 : Implement ESS with transmission nodes in Wireless LAN and obtain the
performance parameters.

Topology :

Step 1 : Draw Topology
1. Select IEEE 802.11(e) Accesspoint on the tool bar and place it on the editor. Select LABEL icon
on the tool bar and rename it as Accesspoint-1. Repeat the same step to place Accesspoint-2 on
the editor as shown in above topology.
2. Select IEEE 802.11(e) Mobile Node icon on the tool bar and place it on the editor window as
shown in topology. Select user QoS priority as ‘0’ for all the mobile nodes. Select LABEL icon

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 16

on the tool bar and rename it as Mobile Host-1. Repeat the same step and place Mobile Node-2,
Mobile Node-3, Mobile Node-4 on the editor to form the topology as shown in above figure.
Figure : User QoS Priority to select IEEE 802.11(e) Mobile Node
3. Select ROUTER on the tool bar and place it on the editor as shown in above topology.
4. Select HOST on the tool bar and place it on the editor as shown in above topology.
5. Select POINT-TO-POINT link icon on the tool bar and connect Access Point -1 to Router,
AccessPoint-2 to Router and Router to Host.
6. Select CREATE MOVING PATH icon on the tool bar and select/click on Mobile Node-1 by
selecting left button on the mouse and draw a moving path that spans Mobile Node-1, Mobile
Node-2 and Access Point -1 then select right button on the mouse to finish creation of path.
Assume default moving speed as 10m/sec. Repeat the same step to create a moving path that
includes Mobile Node-3, Mobile Node-4 and Access Point -2.
Figure : Default moving speed to create moving path

7. Select WIRELESS NODES TO FORM A SUBNET icon on the tool bar and select/click on
Mobile Node-1,Mobile Node-2 and AccessPoint-1 while selecting left button on the mouse
then click right button on mouse to create subnet by selecting OK on the window that pop-
up. Repeat same step to create subnet for Mobile Node-3,Mobile Node-4 and AccessPoint-2

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 17


Figure: Nodes Chosen to create Subnet
8. Select Editor Mode ‘E’ on the tool bar to save the topology. save the file using .tpl extension.(
Ex: [experiment name].tpl)
Step 2: Edit Property
1. Double click on Mobile Node-1  select Application tab on the node editor window 
select ADD tab on the editor window to add start and stop time and Sender command
select OK  select Node Editor tab on the editor window  select 802.11e tab  enable
LOG STATISTICS select throughput of Outgoing packets select OK

Sender Command for Mobile Node-1: ttcp –t –u –s -p 8001 1.0.3.2 (Receiver IP Address)
Where , ttcp -t -u : test TCP while transmitting in UDP mode
-s : source
-p : port number 8001
Receiver IP address : As the HOST is considered as Receiver here. Put the IP address
of HOST in place of receiver IP Address.
Repeat the same steps for Mobile Node-2, Mobile Node-3 and Mobile-4 by using the following
sender commands for respective Mobile Nodes.
Mobile Node-2: ttcp –t –u –s -p 8002 1.0.3.2
Mobile Node-3: ttcp –t –u –s -p 8003 1.0.3.2
Mobile Node-4: ttcp –t –u –s -p 8004 1.0.3.2
2. Double click on ROUTER to invoke Node editor window  select NODE EDITOR tab on
the editor windowselect MAC8023 connected to Accesspoint-1  enable Log statistics
select Throughput of Incoming Packets  Select OK.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 18

Then select MAC8023 connected to Accesspoint-2  enable Log statistics select
Throughput of Incoming Packets  Select OK.
Then select MAC8023 connected to HOST  enable Log statistics select Throughput of
Outgoing Packets  Select OK.

Figure : Node editor window for ROUTER



3. Double click on HOST to invoke Node editor window  select ADD tab on the window 
add start and stop time and Receiver Command  select NODE EDITOR enable log
statistics select throughput of Incoming Packets.
Receiver Command: ttcp –r –u –s -p 8001
Where , ttcp -r -u : test TCP while receiving in UDP mode
-s : sink
-p : port number 8001
Then select ADD to add the Receiver Commands for Receiver Command for respective
Mobile Nodes
ttcp –r –u –s -p 8002
ttcp –r –u –s -p 8003
ttcp –r –u –s -p 8004

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 19



Step 3: Simulation

1. Select ‘R’ icon on the tool bar
2. Select ‘Yes’ for the window that popsup to save the current topology settings.
3. Select Simulation in menubar and select Run option in the drop down box. Then the file
transfer will be done and simulation will shift to PLAY mode.
Step 4: Play Back
Select Play button at the bottom right corner of the NCTUNS window to see the file transfer
across the network drawn.
To view the Result:
Step 1: Minimize the NCTUNS Client window and select ROOT’S HOME icon on the display.
Step 2: select the result folder of the current topology saved. (ex: Exp1. Results).open the file
to get the throughput values saved in log files. Record the Maximum and Minimum values with
corresponding seconds.

Result : verified the throughput by implementing ESS with transmission nodes in wireless
LAN.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 20

PART-B : Implement the following in C/C++

EXPERIMENT 1 : WRITE A PROGRAM FOR A HLDC FRAME TO
PERFORM THE FOLLOWING.
I) BIT STUFFING
II) CHARACTER STUFFING

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.
In bit-oriented framing, 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
This flag can create the same type of problem we saw in the character-oriented
protocols. 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. We do this by stuffing 1 single bit
(instead of 1 byte) to prevent the pattern from looking like a flag. The strategy is called
bit stuffing. In bit stuffing, if a 0 and five consecutive 1 bits are encountered, an extra 0
is added. This extra stuffed bit is eventually removed from the data by the receiver. Note
that the extra bit is added after one 0 followed by five 1s regardless of the value of the
next bit. This guarantees that the flag field sequence does not inadvertently appear in
the frame.
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 for a flag by the receiver. The real
flag 01111110 is not stuffed by the sender and is recognized by the receiver.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 21

Design :




PROGRAM:
#include<string.h>
#include<stdio.h>
int main()
{

char a[20],fs[50]="",t[6],r[5];
int i,j,p=0,q=0;
printf("enter the bit string:");
scanf("%s",a);
strcat(fs,"01111110_");
if(strlen(a)<5)
{
strcat(fs,a);
}

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 22

else
{
for(i=0;i<strlen(a)-4;i++)
{

for(j=i;j<i+5;j++)
{

t[p++]=a[j];
}
t[p]='\0';
if(strcmp(t,"11111")==0)
{
strcat(fs,"111110");
i=j-1;
}
else
{
r[0]=a[i];
r[1]='\0';
strcat(fs,r);
}
p=0;
}
for(q=i;q<strlen(a);q++)
{
t[p++]=a[q];
}
t[p]='\0';
strcat(fs,t);
}
strcat(fs,"_01111110");
printf("after stuffing : %s",fs);
}

OUTPUT:
enter the bit string:011111010111111110
after stuffing : 01111110_01111100101111101110_01111110

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 23

CHARACTER STUFFING
Byte stuffing is the process of adding one extra byte whenever there is a flag or escape
character in the text.
In character-oriented (or byte-oriented) framing, data to be carried are 8-bit characters
from a coding system such as ASCII (see Appendix A). The header, which normally
carries the source and destination addresses and other control information, and the
trailer, which carries error detection redundant bits, are also multiples of 8 bits. To
separate one frame from the next, an 8-bit (1-byte) flag is added at the beginning and
the end of a frame. The flag, composed of protocol-dependent special characters, signals
the start or end of a frame.
Character-oriented framing was popular when only text was exchanged by the data-link
layers. The flag could be selected to be any character not used for text communication.
Now, however, we send other types of information such as graphs, audio, and video;
any character used for the flag could also be part of the information. If this happens, the
receiver, when it encounters this pattern in the middle of the data, thinks it has reached
the end of the frame. To fix this problem, a byte-stuffing strategy was added to
character-oriented framing. 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) and 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 as a delimiting flag. If the escape character is part of the text, an
extra one is added to show that the second one is part of the text.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 24

Design:




PROGRAM:
#include<string.h>
#include<stdio.h>
#include<conio.h>
main()
{
char a[30],fs[50]="",t[3],sd[2],ed[2],x[3],s[3],d[3],y[3];
int i,j,p=0,q=0;
printf("\n enter the string to be stuffed:");
scanf("%s",&a);
printf("\n enter the character that represents starting delimiter:");
scanf("%s",&sd);
printf("\n enter the character that represents ending delimiter:");

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 25

scanf("%s",&ed);
x[0]=s[0]=s[1]=sd[0];
x[1]=s[2]='\0';
y[0]=d[0]=d[1]=ed[0];
d[2]=y[1]=sd[1]=ed[1]='\0';
strcat(fs,x);
for(i=0;i<strlen(a);i++)
{
t[0]=a[i];
t[1]='\0';
if(t[0]==sd[0])
strcat(fs,s);
else
{

if(t[0]==ed[0])
strcat(fs,d);
else
strcat(fs,t);
}
}
strcat(fs,y);
printf("\n after byte stuffing: %s",fs);
getch();
}

OUTPUT:
enter the string to be stuffed:/*assignment_1*/

enter the character that represents starting delimiter:*

enter the character that represents ending delimiter:s

after byte stuffing: */**assssignment_1**/s

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 26

EXPERIMENT 2: WRITE A PROGRAM FOR DISTANCE V ECTOR
ALGORITHM TO FIND SUITABLE PATH FOR TRANSMISSION.

Distance vector routing is a Dynamic Routing algorithm in which each router computes
a distance vector table and updates it all its directly connected nodes.
All the nodes in the network updates their vector table according the distance vector
table received from its corresponding neighbours.
Distance vector Routing uses Bellman-Ford equation to calculate the shortest path.
&#3627408439;
&#3627408485;&#3627408486; = min { (&#3627408438;
&#3627408485;&#3627408462;+ &#3627408439;
&#3627408462;&#3627408486;) , (&#3627408438;
&#3627408485;&#3627408463;+ &#3627408439;
&#3627408463;&#3627408486;) , (&#3627408438;
&#3627408485;&#3627408464;+ &#3627408439;
&#3627408464;&#3627408486;)}
Where, X: Source Node ; Y: Destination Node ; A,B,C are Intermediate nodes
between source and destination
Purpose: To find shortest path with minimum intermediate nodes and least cost
between the source and destination
Internet is modelled as a weighted graph, wherein, routers are termed as nodes and the
connected links are termed as Edges / links and distance between any 2 nodes is termed
as Cost.
Algorithm:
Step1: Initialize the system
Step 2: By convention, the distance of a node to itself as assigned to zero and the
distance between a node to its far away nodes/ unreachable nodes (not directly
connected nodes) is taken to be Infinity ( taken as 999)
Step3: accept the input distance matrix from the user (Costmat[][]) that represents the
distance between each node in the Network.
Step 4: Store the distance between the nodes in a suitable variable.
Step 5: Calculate the minimum distance between any two nodes by updating distance
vector table at regular intervals. If the distance between two nodes is larger than the
calculated alternate path, replace the existing distance with the calculated distance.
Step 6: Print the shortest path calculated.
Step 7: stop.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 27


PROGRAM :
#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("\n enter the number of nodes:");
scanf("%d",&nodes);
printf("\n enter 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]=rt[i].from[k];
count++;
}
}
while(count!=0);
for(i=0;i<nodes;i++)

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 28

{
printf("\n\n for router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\n node%d via%d distance %d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}

printf("\n\n");
}

Consider the Following Network Model to demonstrate Distance Vector Routing:

OUTPUT:
Enter the number of nodes:5

Enter the cost matrix:
0 1 5 999 999
1 0 3 999 9
5 3 0 4 999
999 999 4 0 2
999 9 999 2 0

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 29

for router 1
node1 via1 distance 0
node2 via2 distance 1
node3 via2 distance 4
node4 via2 distance 8
node5 via2 distance 10

for router 2
node1 via1 distance 1
node2 via2 distance 0
node3 via3 distance 3
node4 via3 distance 7
node5 via5 distance 9

for router 3
node1 via2 distance 4
node2 via2 distance 3
node3 via3 distance 0
node4 via4 distance 4
node5 via4 distance 6

for router 4
node1 via3 distance 8
node2 via3 distance 7
node3 via3 distance 4
node4 via4 distance 0
node5 via5 distance 2

for router 5
node1 via2 distance 10
node2 via2 distance 9
node3 via4 distance 6
node4 via4 distance 2
node5 via5 distance 0

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 30

EXPERIMENT 3: IMPLEMENT DIJKSTRA’S ALGORITHM TO COMPUTE
THE SHORTEST ROUTING PATH.
Dijkstra‘s algorithm progressively identifies the closest no Dijkstra‘s algorithm
progressively identifies the closest nodes from the source node in order of increasing
path cost. The algorithm is iterative. The Dijkstra‘s algorithm calculates the shortest
path between two points on a network using a graph made up of nodes and edges The
algorithm divides the nodes into two sets : tentative and permanent . It chooses nodes,
makes them tentative, examines them and if they pass the criteria makes them
permanent.
PROGRAM:
void dijkstras(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])
dist[w]=dist[u]+cost[u][w];
}

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 31

}
}
int main()
{
int n,cost[10][10],source,i,j,dist[10];
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("Enter the source\n");
scanf("%d",&source);
dijkstras(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]);

}


Consider the following weighted graph and calculate the shortest path and least cost
tress using Dijkstra’s algorithm

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 32


Least cost Tree for Router A (R1) is as shown below:


OUTPUT:
Enter the number of vertices
5
Enter the cost matrix
0 5 2 3 999
5 0 4 999 3
2 4 0 999 4
3 999 999 0 999
999 3 4 999 0
Enter the source
1
vertex destination cost
1 2 5
1 3 2
1 4 3
1 5 6

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 33


EXPERIMENT 4: FOR THE GIVEN DATA, USE CRC -CCITT POLYNOMIAL
TO OBTAIN CRC CODE. VERIFY THE PROGRAM FOR THE CASES
A. WITHOUT ERROR
B. WITH ERROR
CRC-CCITT Stands for Cyclic Redundancy Check – Consultative Committee for
International Telephony and Telegraphy.
Whenever digital data is stored or interfaced, data corruption might occur. Since the
beginning of computer science, developers have been thinking of ways to deal with this
type of problem. For serial data they came up with the solution to attach a parity bit to
each sent byte. This simple detection mechanism works if an odd number of bits in a
byte changes, but an even number of false bits in one byte will not be detected by the
parity check. To overcome this problem developers have searched for mathematical
sound mechanisms to detect multiple false bits. The CRC calculation or cyclic
redundancy check was the result of this. Nowadays CRC calculations are used in all
types of communications. All packets sent over a network connection are checked with
a CRC.
All of the CRC formulas you will encounter are simply checksum algorithms based on
modulo-2 binary division where we ignore carry bits and in effect the subtraction will
be equal to an exclusive or operation.
The Mathematical process used in CRC calculation as follows:
ï‚· A generator polynomial of n bits is taken as divisor. It is common for both sender
and receiver side.
ï‚· Message bits to be transmitted is the actual data. This message bits are appended
with n-1 zeros at the first. The resultant data sequence is called as Modified data
and is taken as dividend at the sender side.
ï‚· The reminder of division process at the sender side is the checksum value. It is
added to the Actual data to form a Final code word. This is the encoded data to
be transmitted to the receiver.
ï‚· At the receiver this coded data is again divided by the same divisor and reminder/
checksum is calculated.
1. If reminder=0: No error detected in the data transmission
2. If reminder≠0: Error detected in the data transmission

 Generator Polynomial: n-bits
 Modified data = Actual data + (n-1) Zeros.

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 34

 Final Codeword = Actual data + Checksum ( or reminder= (n-1) bits)

PROGRAM :
#include<stdio.h>
#include<string.h>
#define N strlen(g)
char t[50],cs[50],g[]="1011";
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++];
}

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 35

while(e<=a+N-1);
}
void main()
{
printf("\n Enter the polynomial:");
scanf("%s",t);
printf("\n generator polynomial is:%s",g);
a=strlen(t);
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\n modified t[u] is:%s",t);
crc();
printf("\n checksum is:%s",cs);
for(e=a;e<a+N-1;e++)
t[e]=cs[e-a];
printf("\n Final codeword is:%s",t);

printf("\n enter the received data:");
scanf("%s",t);
crc();
for(e=0;(e<N-1)&&(cs[e]!='1');e++);
if(e<N-1)
printf("\n Error detected\n\n");
else
printf("\n No Error detected\n\n");
}

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 36

OUTPUT:
Enter the polynomial:1001
generator polynomial is:1011
modified t[u] is:1001000
checksum is:110
Final codeword is:1001110

Case-1 : enter the received data: 1001110
No Error detected

Case-2 : enter the received data: 1011110
Error detected

CALCULATION:
Division at CRC Encoder is depicted as follows:

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 37


Division at CRC Decoder is depicted as follows for the two cases:

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 38


EXPERIMENT 5: IMPLEMENTATION OF STOP AND WAIT PROTOCOL
AND SLIDING WINDOW PROTOCOL

STOP AND WAIT PROTOCOL
If data frames arrive at the receiver site faster than they can be processed, the frames must
be stored until their use. The protocol we discuss now is called the Stop-and-Wait Protocol
because the sender sends one frame, stops until it receives confirmation from the receiver
(okay to go ahead), and then sends the next frame. We still have unidirectional
communication for data frames, but auxiliary ACK frames (simple tokens of
acknowledgment) travel from the other direction, so that we add flow control.
In this protocol, the sender sends one frame at a time and waits for an acknowledgment
before sending the next one. To detect corrupted frames, we need to add a CRC to each data
frame. When a frame arrives at the receiver site, it is checked. If its CRC is incorrect, the
frame is corrupted and silently discarded.
The main disadvantage of this stop and wait protocol is only one frame is sent at a time and
this results in poor utilization of channel efficiency.
Design of Stop and wait protocol

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 39



Flow chart:

Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,j=1,numofframes=10,x1,x;
printf("number of frames is %d", numofframes);
while(numofframes>0)
{
printf("\n sending frame is %d",i);
x=rand()%10;
if(x%10==0)

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 40

{
for(x1=1;x1<2;x1++)
{
printf("waiting for %d seconds\n",x1);
sleep(x1);
}
printf("\n sending frames %d\n",i);
x=rand()%10;
}
printf("\n ack for frame %d\n",i);
numofframes=numofframes-1;
i++;
j++;
}
printf("\n end of stop and wait protocol\n");
getch();
}

OUTPUT:

Number of frames is 10
sending frame is 1
ack for frame 1

sending frame is 2
ack for frame 2

sending frame is 3
ack for frame 3

sending frame is 4waiting for 1 seconds

sending frames 4

ack for frame 4

sending frame is 5
ack for frame 5

sending frame is 6

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 41

ack for frame 6

sending frame is 7
ack for frame 7

sending frame is 8
ack for frame 8

sending frame is 9
ack for frame 9

sending frame is 10
ack for frame 10

end of stop and wait protocol

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 42

SLIDING WINDOW PROTOCOL
It allows multiple frames to be in transmit as compared to stop and wait protocol. In this
the receiver has buffer of length W. Transmitter can send up to W frames without ACK.
An imaginary window slides over the total no. of frames to be transmitted at the sender
side after getting acknowledgement for each transmitted frame and selects next frames
to transmit according to the size of window defined. Each frame is numbered according
to modular arithmetic. ACK includes number of next frame expected. Sequence number
bounded by size of field.

Design of Sliding Window Protocol

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 43

Flow diagram

PROGRAM:
#include<stdio.h>
int main()
{
int w,i,f,frames[50];
printf("enter window size: ");
scanf("%d",&w);
printf("enter number of frames to transmit: \n");

scanf("%d",&f);
printf("enter %d frames: ",f);
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("In sliding window protocol, the frames are sent in the following
manner\n");
printf("After sending %d frames,at each stage sender waits for ack sent by the
receiver\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 44

{
printf("%d\n",frames[i]);
printf("ack of above frames sent is received by sender\n");
}
else
printf("%d\n",frames[i]);
}
if(i%w!=0)
printf("Ack of above frame sent is received by sender\n");
return 0;
}

OUTPUT:
enter window size: 4
enter number of frames to transmit:
9
enter 9 frames: 10 20 30 40 50 60 75 85 90
In sliding window protocol, the frames are sent in the following manner
After sending 4 frames,at each stage sender waits for ack sent by the receiver
10
20
30
40
ack of above frames sent is received by sender
50
60
75
85
ack of above frames sent is received by sender
90
Ack of above frame sent is received by sender

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 45

EXPERIMENT 6: WRITE A PROGRAM FOR CONGESTION CONTROL
USING LEAKY BUCKET ALGORITHM
Leaky bucket algorithm is of the congestion control algorithm used in data transmission.
Congestion is a situation in computer networks where more no.of packets are present
over a limited bandwidth in a network. This increases load on the network and reduces
the throughput as the network becomes overwhelmed and drops the packets.
The main concept of the leaky bucket algorithm is that the output data flow remains
constant despite the variant input traffic, such as the water flow in a bucket with a small
hole at the bottom. In case the bucket contains water (or packets) then the output flow
follows a constant rate, while if the bucket is full any additional load will be lost because
of spill over. In a similar way if the bucket is empty the output will be zero. From
network perspective, leaky bucket consists of a finite queue (bucket) where all the
incoming packets are stored in case there is space in the queue, otherwise the packets
are discarded. In order to regulate the output flow, leaky bucket transmits one packet
from the queue in a fixed time (e.g. at every clock tick). In the following figure we can
notice the main rationale of leaky bucket algorithm, for both the two approaches (e.g.
leaky bucket with water (a) and with packets (b).
Design of Leaky Bucket Algorithm:

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 46

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#define MIN(x,y)(x>y)?y:x
int main()
{
int orate,drop=0,cap,x,count=0,inp[10]={0},i=0,nsec,ch;
printf("\n enter the bucket size: ");
scanf("%d",&cap);
printf("\n enter output rate:");
scanf("%d",&orate);
do
{
printf("\n enter number of packets coming at second %d: ",i+1);
scanf("%d",&inp[i]);
i++;
printf("\n enter 1 to continue or 0 to quit----: ");
scanf("%d",&ch);
}
while(ch);
nsec=i;
printf("\n \t second \t received \t sent \t dropped \t remained \n");
for(i=0;count||i<nsec;i++)
{
printf("\t %d",i+1);
printf("\t \t %d",inp[i]);
printf("\t \t %d", MIN((inp[i]+count),orate));
if((x=inp[i]+count-orate)>0)
{
if(x>cap)
{
count=cap;
drop=x-cap;
}
else
{
count=x;
drop=0;
}

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 47

}
else
{
drop=0;
count=0;

}
printf("\t %d \t\t %d\n",drop,count);
}
return 0;
}


OUTPUT:
enter the bucket size: 4

enter output rate:3

enter number of packets coming at second 1: 6

enter 1 to continue or 0 to quit----: 1

enter number of packets coming at second 2: 8

enter 1 to continue or 0 to quit----: 1

enter number of packets coming at second 3: 9

enter 1 to continue or 0 to quit----: 0

second received sent dropped remained
1 6 3 0 3
2 8 3 4 4
3 9 3 6 4
4 0 3 0 1
5 0 1 0 0

COMPUTER NETWORKS LAB (18ECL76)


Dept. of E&CE, JIT, Davangere 48