Manual CN Lab 2017 PDF
Manual CN Lab 2017 PDF
Manual CN Lab 2017 PDF
Tataguni, Bangalore-82
SEMESTER –VI
Vision:
To be a Department of excellence at a global level in Electronics and Communication
Engineering education, incorporating Research & Innovation and Leadership training
components.
Mission:
The Department Will,
PO3: Design/ Development of Solutions: Design solutions for complex engineering problems
and design system components or processes that meet specified needs with appropriate
consideration for public health and safety, cultural, societal and environmental considerations.
PO5: Modern Tool Usage: Create, select and apply appropriate techniques, resources and
modern engineering and IT tools including prediction and modelling to complex engineering
activities with an understanding of the limitations.
PO6: The Engineer and Society: Apply reasoning informed by contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
professional engineering practice.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of engineering practice.
PO9: Individual and Team Work: Function effectively as an individual, and as a member or
leader in diverse teams and in multi-disciplinary settings.
PO12: Life-long Learning: Recognize the need for and have the preparation and ability to
Engage in independent and life-long learning in the broadest context of technological changes
PSO1: (Knowledge/ Skills) Explore emerging technologies in the field of Electronics &
Communication Engineering using the knowledge and skills gained.
17ECL68.1: Use the network simulator for learning and practice of networking algorithms.
17ECL68.2: Illustrate the operations of network protocols and algorithms using C
programming.
17ECL68.3: Simulate the network with different configurations to measure the performance
parameters.
17ECL68.4: Implement the data link and routing protocols using C programming.
*Levels of Corelation: 1 – Low, 2 – Medium, 3 – High
C0-PO-PSO MAPPING
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
17ECL68.1 3 3 2 2 3 2 2 2 3
17ECL68.2 3 3 2 2 3 2 2 2 3
17ECL68.3 3 3 2 2 2 2 2 2 3
17ECL68.4 3 3 2 2 2 2 2 2 3
LABORATORY IN-CHARGES
LABORATORY TECHNICIAN
Mr. Shivashankara K N, ECE
Conduct yourself in a responsible manner at all times in the laboratory. Don’t talk aloud or
crack jokes in lab.
A lab coat should be worn during laboratory experiments.
Disconnect all the equipment and switch off the power supplies before leaving.
Observe good housekeeping practices. Replace the materials in proper place after work to
keep the lab area tidy.
Arrange the chairs before leaving the lab.
Don’ts
SYLLABUS
COMPUTER NETWORKS LABORATORY
B.E., VI Semester, Electronics & Communication Engineering
[As per Choice Based Credit System (CBCS) scheme]
Laboratory Experiments
PART-A: Simulation experiments using NS2/ NS3/ OPNET/ NCTUNS/ NetSim/QualNet/ Packet
Tracer or any other equivalent tool
1. Implement a point to pint 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.
6. Implementation of Link state routing algorithm.
Course outcomes: On the completion of this laboratory course, the students will be
able to:
1. Use the network simulator for learning and practice of networking algorithms.
2. Illustrate the operations of network protocols and algorithms using C programming.
3. Simulate the network with different configurations to measure the performance
parameters.
4. Implement the data link and routing protocols using C programming.
Graduate Attributes (as per NBA)
• Engineering Knowledge.
• Problem Analysis.
• Design/Development of solutions.
LIST OF EXPERIMENTS
Page
PART-A: Simulation experiments using NS2/ NS3/ OPNET/ NCTUNS/ NetSim/QualNet/ No.
Packet Tracer or any other equivalent tool
20
Implement a point to pint network with four nodes and duplex links between them.
1
Analyze the network performance by setting the queue size and varying the bandwidth
Implement a four node point to point network with links n0-n2, n1-n2 and n2-n3. 23
Apply TCP agent between n0-n3 and UDP between n1-n3. Apply relevant applications
2
over TCP and UDP agents changing the parameter and determine the number of
packets sent by TCP/UDP.
Implement Ethernet LAN using n (6-10) nodes. Compare the throughput by changing 27
3
the error rate and data rate.
Implement Ethernet LAN using n nodes and assign multiple traffic to the nodes and 31
4
obtain congestion window for different sources/ destinations.
Implement ESS with transmission nodes in Wireless LAN and obtain the performance 35
5
parameters.
6 Implementation of Link state routing algorithm. 40
48
Write a program for a HLDC frame to perform the following.
1 i) Bit stuffing
ii) Character stuffing.
2 Write a program for distance vector algorithm to find suitable path for transmission. 50
For the given data, use CRC-CCITT polynomial to obtain CRC code. Verify the 55
program for the cases
4
a. Without error
b. With error
5 Implementation of Stop and Wait Protocol and Sliding Window Protocol 57
Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and determine 62
7
collision across different nodes. (Extra)
Simulate the different types of internet traffic such as FTP and TELNET over a 66
8
network and analyze the throughput.(Extra)
When a $ appears in a command, Tcl treats the letters and digits following it as a variable name,
and substitutes the value of the variable in place of the name. In this example, the actual
argument received by the expr command will be 32*3 (assuming that variable x was set as in the
previous example). You can use variable substitution in any word of any command, or even
multiple times within a word:
set cmd expr
set x 11
$cmd $x*$x
Command substitution:
You can also use the result of one command in an argument to another command. This is called
command substitution:
set a 44
set b [expr $a*4]
When a [ appears in a command, Tcl treats everything between it and the matching] as a nested
Tcl command. Tcl evaluates the nested command and substitutes its result into the enclosing
After these three commands are evaluated variable z will have the value 24 + 18 is 42. Everything
between the quotes is passed to the set command as a single word. Note that (a) command and
variable substitutions are performed on the text between the quotes, and (b) the quotes themselves
are not passed to the command. If the quotes were not present, the set command would have
received 6 arguments, which would have caused an error.
Curly braces provide another way of grouping information into words. They are different from
quotes in that no substitutions are performed on the text between the curly braces:
set z {$x + $y is [expr $x + $y]}
This command sets variable z to the value "$x + $y is [expr $x + $y]".
Control structures:
Tcl provides a complete set of control structures including commands for conditional execution,
looping, and procedures. Tcl control structures are just commands that take Tcl scripts as
arguments. The example below creates a Tcl procedure called power, which raises a base to an
integer power:
proc power {base p} {
set result 1
while {$p > 0} {
set result [expr $result * $base]
set p [expr $p - 1]
}
return $result
}
This script consists of a single command, proc. The proc command takes three arguments: the
name of a procedure, a list of argument names, and the body of the procedure, which is a Tcl
script. Note that everything between the curly brace at the end of the first line and the curly brace
on the last line is passed verbatim to proc as a single argument. The proc command creates a new
Tcl command named power that takes two arguments. You can then invoke power with commands
like the following:
power 2 6
power 1.15 5
When power is invoked, the procedure body is evaluated. While the body is executing it can access
its arguments as variables: base will hold the first argument and p will hold the second.
NS Simulator Preliminaries:
Initialization and termination aspects of the ns simulator.
Definition of network nodes, links, queues and topology.
Definition of agents and of applications.
The nam visualization tool.
Tracing and random variables.
Features of NS2:
NS2 can be employed in most Unix systems and windows. Most of the NS2 code is in C++. It uses
TCL as its scripting language, Otcl adds object orientation to TCL.NS(version 2) is an object
oriented, discrete event driven network simulator that is freely distributed and open source.
Traffic Models: CBR, VBR, Web etc.
Protocols: TCP, UDP, HTTP, Routing algorithms, MAC etc.
Error Models: Uniform, bursty etc.
Misc.: Radio propagation, Mobility models, Energy Models
Topology Generation tools
Visualization tools (NAM), Tracing
Structure of NS:
NS is an object oriented discrete event simulator
Simulator maintains list of events and executes one event after another
Single thread of control: no locking or race conditions
Back end is C++ event scheduler
Protocols mostly
Fast to run, more control
Front end is OTCL
Creating scenarios, extensions to C++ protocols
fast to write and change
Platforms:
It can be employed in most Unix systems (FreeBSD, Linux, Solaris) and Windows.
Source code:
Most of NS2 code is in C++
Scripting language:
It uses TCL as its scripting language OTcl adds object orientation to TCL.
Protocols implemented in NS2:
Variable trace
set par [open output/param.tr w]
$tcp attach $par
$tcp trace cwnd_
$tcp trace maxseq_
$tcp trace rtt_
Creating topology:
Two nodes connected by a link
Creating nodes
set n0 [$ns node]
set n1 [$ns node]
Creating link between nodes
$ns <link_type> $n0 $n1 <bandwidth> <delay><queue-type> $ns duplex-link$n0
$n1 1Mb 10ms DropTail
Data Sending:
Create UDP agent
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
Create CBR traffic source for feeding into UDP agent set cbr0
[new Application/Traffic/CBR]
$cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent$udp0
Create traffic sink
PROCEDURE:
STEP 1: Start
STEP 2: Create the simulator object ns for designing the given simulation
STEP 3: Open the trace file and nam file in the write mode
STEP 4: Create the nodes of the simulation using the ‘set’ command
STEP 5: Create links to the appropriate nodes using $ns duplex-link command
STEP 6: Set the orientation for the nodes in the simulation using ‘orient’ command
STEP 7: Create TCP agent for the nodes and attach these agents to the nodes
STEP 8: The traffic generator used is FTP for both node0 and node1
STEP 9: Configure node1 as the sink and attach it
STEP10: Connect node0 and node1 using ‘connect’ command
STEP 11: Setting color for the nodes
Event Time From To PKT PKT Flags Fid Src Dest Seq Pkt
Node Node Type Size Addr Addr Num id
1. The first field is the event type. It is given by one of four possible symbols r, +, -, d which
correspond respectively to receive (at the output of the link), enqueued, dequeued and
dropped.
2. The second field gives the time at which the event occurs.
3. Gives the input node of the link at which the event occurs.
4. Gives the output node of the link at which the event occurs.
7. Some flags
8. This is the flow id (fid) of IPv6 that a user can set for each flow at the input OTcl script
one can further use this field for analysis purposes; it is also used when specifying stream
color for the NAM display.
11. This is the network layer protocol’s packet sequence number. Even though UDP
implementations in a real network do not use sequence number, ns keeps track of UDP
packet sequence number for analysis purposes
XGRAPH:
The xgraph program draws a graph on an x-display given data read from either data file or from
standard input if no files are specified. It can display upto 64 independent data sets using different
colors and line styles for each set. It annotates the graph with a title, axis labels, grid lines or tick
marks, grid labels and a legend.
Syntax:
Xgraph [options] file-name
PART-A
EXPERIMENTS-1
Implement a point to pint network with four nodes and duplex links between them. Analyze the
network performance by setting the queue size and varying the bandwidth.
Design:
Note:
1. Set the queue size fixed from n0 to n2 as 10, n1-n2 to 10 and from n2-n3 as 5. Syntax: To set
the queue size
$ns set queue-limit <from> <to>
<size> Eg: $ns set queue-limit $n0 $n2
10
2. Go on varying the bandwidth from 10, 20 30. . and find the number of packets dropped at
the node 2 as shown in the Fig 1.
3. To add the agents between the nodes
AWK Script:
BEGIN
{
#include<stdio.h>
count=0;
}
{
if($1=="d") #d stands for the packets drops.
count++
}
END
{
printf("The Total no of Packets Dropped due to Congestion :
%d\n\n", count)
}
Output:
ns lab1.tcl
awk –f lab1.awk lab1.tr
The Total no of packets Dropped due to congestion:4560
EXPERIMENTS-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.
Design:
Note:
1.Calculate the total number of packets sent by TCP and UDP by changing the bandwidth from
100Mb,25Mb or 200mb in the Topology and the data rate from 0.1, 0.001 as shown below.
Eg:
#The below code is used to set the color and labels to the #links.
#The below code is used to set the packet size of ftp and #udp.
$ftp0 set packetSize_ 500
$ftp0 set interval_ 0.001
#The below code is used to increase the data rate (if the #interval is more than the more
number of packets goes to #destination).
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.001
#This code is used give a color red->tcp and blue ->udp.
$tcp0 set class_ 1
$udp1 set class_ 2
# The below code is used connect the agents. $ns connect $tcp0 $sink3
$ns connect $udp1 $null3
proc finish { } {
global ns nf tf
$ns flush-trace
close $tf
exit 0
}
EXPERIMENTS-3
Implement an Ethernet LAN using n nodes (6-10), change the error rate and data rate and compare
the throughput.
Design:
Note:
1. The lan can be created by using the command:
$ns make-lan “ $n0 $n1 $n2 $n3 ” 100Mb 10ms LL Queue/DropTail Mac/802_
2. The Error between the nodes n3 and n6 can be added as follows:
Set err [ new ErrorModel ]
$ns lossmodel $err $n3 $n6
$err set rate_ 0.1 # used to set error rate.
Now Fix the error rate to 0.1 and vary the data rate then throughput increases as shown below.
Program:
$ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3
# The below code is used to add an error model between the #nodes n3 and n6.
# This is the error rate. Change this ;#rate to add errors between n3 and n6.
proc finish { } {
global nf ns tf
exec nam lab5.nam &
close $nf
close $tf
exit 0
}
$ns at 5.0 "finish"
$ns at 0.1 "$cbr1 start"
$ns run
AWK Script:
BEGIN
{
#include <stdio.h>
pkt=0;
time=0
}
{
if($1="r" && $3=="8" && $4=="5")
{
pkt=pkt+$6
time=$2
}
}
END
{
printf(" Throughput: %fMbps\n\n",(pkt/time)*(8/1000000));
}
Output:
ns lab5.tcl
awk –f lab5.awk lab5.tr
Throughput:148Mbps
EXPERIMENTS-4
Implement Ethernet LAN using n nodes and assign multiple traffic to the nodes and obtain
congestion window for different sources/ destinations.
Design:
Step 2: Attach these files (file1.tr & file2.tr) to the agents tcp0 and tcp1 as shown
below.
Step 3: To trace the congestion window value we use the trace command to trace the
Then, the congestion window values are stored in the file1 and file2.
ns lab7.tcl
Program:
set ns [new Simulator]
set tf [open lab7.tr w]
$ns trace-all $tf
set nf [open lab7.nam w]
$ns namtrace-all $nf
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns make-lan "$n0 $n1 $n2 $n3" 10mb 10ms LL Queue/DropTail Mac/802_3
EXPERIMENTS-5
Implement ESS with transmission nodes in Wireless LAN and obtain the performance parameters.
Design:
Simulation Parameters:
Program:
set ns [new Simulator]
set tf [open lab8.tr w]
$ns trace-all $tf
set topo [new Topography]
$topo load_flatgrid 1000 1000
set nf [open lab8.nam w]
$ns namtrace-all-wireless $nf 1000 1000 $ns node-config
adhocRouting DSDV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail \
-ifqLen 50 \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \ -propType
Propagation/TwoRayGround \ -antType Antenna/OmniAntenna
\ -topoInstance $topo \
-agentTrace ON \
-routerTrace ON
create-god 3
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
$n0 label "tcp0"
$n1 label "sink1/tcp1"
$n2 label "sink2"
#The below code is used to give the initial node positions. $n0 set X_ 50
AWK Script:
BEGIN
{
#include<stdio.h>
count1=0
count2=0
pack1=0
pack2=0
time1=0
time2=0
}
{
if($1=="r"&&$3=="_1_"&&$4=="AGT")
{
count1++
pack1=pack1+$8
time1=$2
}
if($1=="r"&&$3=="_2_"&&$4=="AGT")
{
Output:
ns lab8.tcl
awk –f lab8.awk lab8.tr
The Throughput from n0 to n1: 5444Mbps
The Throughput from n1 to n2: 345Mbps
EXPERIMENTS-6
Implementation of Link state routing algorithm.
Design:
Program
set ns [new Simulator]
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
$ns rtproto LS
$ns run
PART-B
EXPERIMENTS-1
Write a program for
i) Bit stuffing ii) Character stuffing.
i) Bit stuffing
Theory:
Security and Error detection are the most prominent features that are to be provided by any
application which transfers data from one end to the other end. One of such a mechanism in
tracking errors which may add up to the original data during transfer is known as Stuffing. It is of
two types namely Bit Stuffing and the other Character Stuffing. Coming to the Bit Stuffing,
01111110 is appended within the original data while transfer of it. The following program describes
how it is stuffed at the sender end and de-stuffed at the receiver end.
Program:
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char ch, array[50]={"01111110"},read_array[50];
int counter=0, i=8,j,k;
clrscr();
printf("\n enter the original data stream for bit stuffing\t");
while ((ch=getche())!='\r')
{
if(ch=='1')
++counter;
else
counter=0;
array[i++]=ch;
if(counter==5)
{
array[i++]='0';
counter=0;
}
}
strcat(array,"01111110");
printf("\n the stuffed data stream:\t");
for(j=0;j<i+8;++j)
printf("%c",array[j]);
//DESTUFFING
counter=0;
Output:
Program:
#include<stdio.h>
#include<conio.h>
#define DLE 16
#define STX 2
#define ETX 3
#define MAX 100
void main()
{
char array[100] = {DLE,STX};
int i=2, j;
char ch;
clrscr();
printf("\n enter the data stream(ctrl+b->STX,ctrl+c->ETX,ctrl+p->DLE);\n");
while ((ch=getch())!='\r')
{
if(ch==DLE)
{
array[i++] = DLE;
printf("DLE");
}
else if(ch ==STX)
{
printf("STX");
}
else if (ch==ETX)
{
printf("ETX");
}
else
{
printf("%c",ch);
}
array[i++]=ch;
}
array[i++]=DLE;
array[i++]=ETX;
printf("\n the character stuffed data stream is:\n");
for(j=0;j<i;++j)
{
if(array[j]==DLE)
{
printf("DLE");
}
else if(array[j]==STX)
{
printf("STX");
}
else if(array[j]==ETX)
{
printf("ETX");
}
else
{
printf("%c", array[j]);
}
}
/* Character Destuffing */
printf("\n The Character destuffed data stream is: \n");
for(j=2;j<i-2;++j)
{
if(array[j] == DLE)
{
printf("DLE");
++j;
}
else if(array[j] == STX)
{
printf("STX");
}
Output:
Theory:
Distance Vector routing (DVR) algorithm is unlike Dijkstra's algorithm which is a non-adaptive
routing algorithm and means that it is purely static, that is pre-destined and fixed, not flexible in
networks where congestions are more prone to occur. DVR is an adaptive routing algorithm in
which the information from neighbours is maitained well by each and every node and this helps us
to determine the simplest path possible in a changing network. Though, one of the node may fail,
still, the destined node is reachable through other possible intermediate nodes that are found out
by the DVR algorithm. The perfectly executing program below shows it live below.
Program:
#include
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int dmat[20][20];
int n,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&n);
printf("\nEnter the cost matrix :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
Theory:
Dijkstra's algorithm is a non-adaptive routing algorithm which is very widely used to route
packets from source to detination through various routers available during the transmission. It is
implemented at the network layer of the architecture where data packets are sent through routers
which maitain routing tables that help to denote the exact location to where the destined packets
need to be delivered. Major advantage in using Dijkstra's algorithm is that it forwards the data
packets from source to destination through the most optimized path in terms of both the distance
and cost observed. It prompts the user to enter the number of nodes and the source and destination
nodes among them. In addition, the algorithm written below also asks for the neighbours to each
node with the distances to reach to them from each node is also prompted. All this data is stored
and used further to calculate and estimate the best path possible for data packets to reach their
destination from source. Program below explains it in a much better way.
Program:
#include<stdio.h>
#include<conio.h>
int n,s,nb,nbs[15],snbs[15],delay[15][15],i,j,temp[15],ze=0;
void min();
void main()
{
clrscr();
printf("Enter the no.of nodes:");
scanf("%d",&n);
printf("\nEnter the source node:");
scanf("%d",&s);
printf("\nEnter the no.of Neighbours to %d:",s);
scanf("%d",&nb);
printf("\nEnter the Neighbours:");
for(i=1;i<=nb;i++)
scanf("%d",&nbs[i]);
printf("\nEnter the timedelay form source to nbs:");
for(i=1;i<=nb;i++)
scanf("%d",&snbs[i]);
for(i=1;i<=nb;i++)
{
printf("\nEnter the timedelay of %d: ",nbs[i]);
for(j=1;j<=n;j++)
sum=temp[1]+snbs[1];
for(y=2;y<=nb;y++)
{
if(sum>temp[y]+snbs[y])
{
sum=temp[y]+snbs[y];
store=y;
}
}
if(s==i)
printf("\n\t%d+\t%d =\t%d --",ze,ze,ze);
else
printf("\n\t%d +\t%d =\t%d\t%d",temp[store],snbs[store],sum,nbs[store]);
}
}
Output:
Theory:
CRC means Cyclic Redundancy Check. It is the most famous and traditionally successful
mechanism used in error detection through the parity bits installed within the data and obtaining
checksum which acts as the verifier to check whether the data retrieved at the receiver end is
genuine or not. Various operations are involved in implementing CRC on a data set through CRC
generating polynomials. In the program, I have also provided the user to opt for Error detection
whereby he can proceed for it. Understand the program below as it is much simpler than pretended
to be so.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define N strlen(g)
void xor() {
for(c=1;c}
void crc() {
for(e=0;e do {
if(cs[0]=='1') xor();
for(c=0;c cs[c]=t[e++];
}while(e<=a+N-1);
}
void main() {
clrscr();
printf("\nEnter poly : "); scanf("%s",t);
printf("\nGenerating Polynomial is : %s",g);
a=strlen(t);
for(e=a;e
printf("\nModified t[u] is : %s",t);
crc();
Output:
EXPERIMENTS-5
Implementation of Stop and Wait Protocol and Sliding Window Protocol
i) Program: Stop and Wait Protocol
include<stdio.h>
int timer=0,wait_for_ack=-1,frameQ=0,cansend=1,t=0;
main()
{
int i,j,k;
int frame[5];
//clrscr();
printf("enter the time when data frame will be ready\n");
for(j=0;j<3;j++)
{
sender( i, &frame);
recv(i);
}
}
{
wait_for_ack++;
if(wait_for_ack==3)
{
}
if(i==frame[t])
{
frameQ++;
t++;
}
if(frameQ==0)
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
• Also, when the bucket is full, any additional water that enters into the bucket spills over the sides
and is lost.
• The same concept can be applied to packets in the network. Consider that data is coming from
the source at variable speeds. Suppose that a source sends data at 12 Mbps for 4 seconds. Then
there is no data for 3 seconds. The source again transmits data at a rate of 10 Mbps for 2 seconds.
Thus, in a time span of 9 seconds, 68 Mb data has been transmitted.
If a leaky bucket algorithm is used, the data flow will be 8 Mbps for 9 seconds. Thus constant flow
is maintained.
Algorithm:
1. Start
2. Set the bucket size or the buffer size.
3. Set the output rate.
4. Transmit the packets such that there is no overflow.
5. Repeat the process of transmission until all packets are transmitted. (Reject packets where its
size is greater than the bucket size)
6. Stop
Code
#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 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 contiue or 0 to quit..........");
scanf("%d",&ch);
}
while(ch);
nsec=i;
printf("\n second \t recieved \t sent \t dropped \t remained \n");
for(i=0;count || i<nsec;i++)
{
printf(" %d",i+1);
printf(" \t%d\t ",inp[i]);
printf(" \t %d\t ",MIN((inp[i]+count),orate));
if((x=inp[i]+count-orate)>0)
{
if(x>cap)
{
count=cap;
drop=x-cap;
Note:
1. The collision of packets takes place at the nodes n0, n1 and n2. The “c” in the trace file
indicating the collision has been occurred at the nodes.
2. The command -trace on is used to see the collision “c” in the trace file as shown below.
$ns make-lan -trace on “$n0 $n1 $n2 $n3” 10Mb 10ms LL
Queue/DropTail Mac/802_3
3. The number of collisions occurred at different nodes are obtained by running the awk script.
Program:
set ns [new Simulator]
set tf [open lab6.tr w]
$ns trace-all $tf
AWK Script:
BEGIN{
#include<stdio.h>
count=0
}
{
if($1=="c") {
printf("The [ %s ] Packet occured collision at the
node:[ %s ]\n",$5,$3);
}
END{
printf("\n***************************************\n");
printf("\nThe Total Packet Collision %d", count);
printf("\n***************************************\n");
}
Design:
Note:
1. Change the data rate or the bandwidth of either tcp or the telnet and analyze the throughput
Eg: To vary the data rate of telnet or tcp we use:
$telnet1 set interval_ 0.01 & $ftp0 set interval_ 0.0001
To vary the packet size of telnet or ftp we use
$telnet1 set packetSize_ 5000 & $ftp0 set paceketSize_ 2000
Program:
set ns [new Simulator]
set tf [open lab3.tr w]
$ns trace-all $tf
set nf [open lab3.nam w]
$ns namtrace-all $nf
set n0 [$ns node]
set n1 [$ns node]