CN Lab Manual Print PDF
CN Lab Manual Print PDF
CN Lab Manual Print PDF
VI SEMESTER
CBCS 2017 scheme
Lab Incharge
Prof. Mohammed Jebran P
Lab Instructor
Mr. Asif Pasha
a. Without error
b. With error
5. Implementation of Stop and Wait Protocol and Sliding Window Protocol
6. Write a program for congestion control using leaky bucket algorithm
Course outcomes: On the completion of this laboratory course, the students will be able to:
• Use the network simulator for learning and practice of networking algorithms. Illustrate
the operations of network protocols and algorithms using C programming.
• Simulate the network with different configurations to measure the performance parameters.
• Implement the data link and routing protocols using C programming.
Conduct of Practical Examination:
• All laboratory experiments are to be included for practical examination.
• For examination one question from software and one question from hardware or only one
hardware experiments based on the complexity to be set.
• Students are allowed to pick one experiment from the lot.
• Strictly follow the instructions as printed on the cover page of answer script for breakup of
marks.
• Change of experiment is allowed only once and Marks allotted to the procedure part to be
made zero.
B.E: Electronics & Communication Engineering
Introduction to Simulation
Emulator
A device on the [LAN], Real network, actual equipment, real software or a part of the
real system is replaced by a model. This model is called Emulator. Properties of an
existing part are simulated (only the part of the real system). A network emulator
emulates the network, imitates the behavior of application traffic.
Objective:
➢ To test control systems, under realistic condition.
➢ To do analysis.
➢ To access the performance.
➢ To predict the impact of change
➢ To optimize technology decision-making.
Advantage:
Reflect results precisely
Disadvantage:
▪ Must run in real time
▪ Expensive
▪ Requires a lot of setup
▪ We won’t use emulation for experimentation.
Simulator
Network simulators are typically programs which run on a single computer, take
an abstract description of the network traffic (such as a flow arrival process) and yield
performance statistics (such as buffer occupancy as a function of time).
Objective:
To test and develop different solutions and finally to arrive at a best solution.
Advantage:
▪ Cost effective
▪ Flexible.
▪ No risk involved. Extensive experiments can be done.
▪ Easier to analyze.
Disadvantage:
Not just a part but a complete network simulator needs to simulate
networking devices and application programs.
Needs network utility programs to configure and monitor.
Simulation model maintains its own simulation clock. When a decision is
taken within the model, the simulation clock does not advance until the
necessary calculations have been performed.
Results are not convincing.
NCTUns
• Open source,
• high quality
• support many type of networks
• Extensible. Can be used as emulator also.
• Uses real-life Linux’s TCP/IP protocol
• Uses real-life UNIX network configuration.
• Can simulate various networking devices.
• Can simulate various network protocols
• Simulation speed is high.
• It uses kernel re-enter methodology. For this it uses tunnel network interface.
Tunnel devices are available in most UNIX machines.
• NCTUns modifies the kernel to use a special virtual timer. The kernel code is
modified. Each kernel on which NCTUns runs need to be patched. Kernel
needs to be patched on all simulation machines.
NCTUns Architecture
NCTUns uses distributed Architecture.
NCTUns has following components. They
are:
a. GUI Operating Environment (nctunsclient)
b. Simulation Engine
c. Protocol and job Dispatcher
d. Coordinator
e. Kernel modification
f. User-level daemon and real-world application program
g. Remote, concurrent and Parallel simulation
v.Kernel Modification
vi.User-level Daemon and real-world application program:
The NCTUns real-world application programs run at the user level to generate
network traffic, configure network, or monitor network traffic, etc. For
example, the tcpdump program can run on a simulated network to capture
packets flowing over a link and the trace route program can run on a simulated
network to find out the routing path traversed by a packet.
vii.Remote, concurrent and parallel simulations.
NCTUns uses a distributed architecture, by which simulation machines can be
far away from the machines where the GUI programs are run. For example, the
simulation service machines may reside at NCTU in Taiwan while the GUI
users come from many different places of the world. Multiple simulation jobs
can be concurrently simulated on different machines (one machine serves one
job) to increase the total simulation throughput. When the NCTUns simulation
jobsare run on multiple machines, we say that NCTUns is operating in the
“multiple machine‟ mode [13]. This mode supports remote and concurrent
simulations. In the “single-machine‟ mode, the simulation jobs run on the
same machine. With the inter-process communication (IPC) design, NCTUns
can be used for either mode without changing its program code. Only the mode
parameter in its configuration file needs to be changed.
STEP 1: # cd /usr/local/nctuns/bin
STEP 2: #. /dispatcher <enter key>
Right click on the blank space of the screen and select open
tab STEP 3: #. /coordinator <enter key>
Right click on the blank space of the screen and select open
tab STEP 4: #. /nctunsclient <enter key>
4. Post analysis P
Select
Draw topology
D
Edit property
E
Run Simulation
R
Play back
P
Delete
X
Label
A
Moving path
A user can draw a new network topology or change an existing simulation topology
only in the Draw topology mode. Draw topology mode is the default mode of
NCTUNs.
PART A Programs
Start up
Experiment No 1
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.
Topology:
STEPS:
1. Select the host icon on the toolbar and drag it onto the working window. Repeat
this for another host icon. Select the link icon on the toolbar and drag it on the screen
from host [node 1] to the hub and again
from host [node2] to the hub. Here the hub acts as node 3 in the point-to-point
network. This leads to the creation of the 3-node point-to-point network topology.
[We can see the ip address of the host by moving the mouse pointer on host]
2. Click on the Add button and enter the command (at the sender)
stg [-u udp][-t duration (sec)] [-p port number]HostIPaddr and set the
simulation time 0 to 40 sec then click ok
3. Click on the node editor and you can see the different layers-
interface, ARP, FIFO, MAC, TCPDUMP, Physical
layers.
4. Select MAC and then select full-duplex for switches and routers and half-
duplex for hubs, and check the log packet statistics check box,
5. Select output throughput log file etc (at sender), select the number of
drop packets, number of collisions.
At Receiver: Steps
1. Click on the Add button and enter the command (at the
receiver) rtg [-t] [-w log] [-p port number] and clickOK.
2. Click on the node editor and you can see the different layers-interface,
ARP, FIFO, MAC, TCPDUMP, Physical layers.
3. Select input throughput log file etc (at receiver), select the number of drop
packets, number of collisions. Click OK.
1. Now click on the R button (Run simulation). By doing such a user can
run/pause/continue/stop/abort/disconnect/reconnect/submit a simulation. No
simulation settings can be changed in this mode.
To start the playback, the user can left-click the start icon ( |>) of the time bar
located at the bottom. The animation player will then start playing the recorded
packet animation.
The results are stored in file.results folder(“file” is the same name given by the
user to the simulation file).
You will see the following log files in the folder: file.results
Filename.8023_N2_P1_OutThrput.log
Filename.8023_N3_P1_InThrput.log
Filename..8023_n2_p1_coll.log
Filename.8023_N2_P1_Drop.log
Here the drop and collision files do not have data, because of point to point connection
no drop, no collision
Change the bandwidth say, 9 Mbps or less, and run the simulation and
compare the two results. To view the results go to the filename.results
folder.
Experiment No 2
Topology:-
Sender:-
stcp –p 3000 –l 1024 1.0.1.3
stg –u 1024 1.0.1.3
Receiver:-
rtcp –p 3000 –l 1024
rtg –u 3000
Parameters:-
Throughput of incoming and outgoing Packets
Experiment No 3
Topology: -
Sender: -
stcp –p 2000 –l 1024 1.0.1.4
Receiver:-
rtcp –p 2000 –l 1024
Results
Table:
Experiment No 4
Topology:-
Sender:-
stcp –p 2000 –l 1024 1.0.1.4
Receiver:-
rtcp –p 2000 –l 1024
Parameters:-
Collision Packets and Drop Packets (Optional)
1. Place and click on nodes 4,5,6 acting as senders and
add the command
“stcp –p 3000 –l 1024 1.0.1.4 and similarly consider for nodes 7,8,9 as receiver
and
add command “rtcp –p 3000 –l 1024”
4. Consider UDP too and add sender command “stg –u 3000 1024
1.0.1.5”
and receiver command “rtg –u 3000 1024”
5. Click on node editor, select the MAC layer and check for the log
packet logistics with parameters out throughput, drop and collision
packets.
Results:
Experiment No 5
Topology:-
Configurations
1. Double click on host (node & add the command “ttcp -r -u -s -
p 8001”)
2. Repeat similarly by adding the same command with 8002, 8003,
8004.
3. Click on node editor of host→ MAC → In throughput. OK and
Exit the window.
4. Double click on MN1 to open the mobile node window →
application tab → Add→“ttcp -r -u -s -p 8001 1.0.2.2”
5. Add Out throughput in MAC.
Repeat 4 & 5 for MN2, MN3 & MN4 with respective IP addresses.
6. Double click on router → node editor→ stacks
7. Simulate & Run. When played we observe the mobile nodes
moves across the data transmission path.
8. Run and then play to plot the graph.
Double click on Router -> Node Editor and then Left stack ->
throughput of Incoming packets Right stack -> throughput of
Outgoing packets
Mobile Host 1
ttcp –t –u –s –p 3000 1.0.1.1
Mobile Host 1
ttcp –t –u –s –p 3001 1.0.1.1
Host (Receiver)
ttcp –r –u –s –p 3000
ttcp –r –u –s –p 3001
Results:
PART B
Theory
i) Bit Stuffing:
Use reserved bit patterns to indicate the start and end of a frame. For instance, use the 4-bit sequence
of 0111 to delimit consecutive frames. A frame consists of everything between two delimiters.
Problem: What happens if the reserved delimiter happens to appear in the frame itself? If we don't
remove it from the data, the receiver will think that the incoming frame is actually two smaller frames!
Solution: Use bit stuffing. Within the frame, replace every occurrence of two consecutive 1's with
110. E.g., append a zero bit after each pair of 1's in the data. This prevents 3 consecutive 1's from
ever appearing in the frame.
Likewise, the receiver converts two consecutive 1's followed by a 0 into two 1's, but recognizes the
0111 sequence as the end of the frame.
Example: The frame ``1011101'' would be transmitted over the physical layer as
``0111101101010111''.
Note: When using bit stuffing, locating the start/end of a frame is easy, even when frames are
damaged. The receiver simply scans arriving data for the reserved patterns. Moreover, the receiver
will resynchronize quickly with the sender as to where frames begin and end, even when bits in the
frame get garbled.
The main disadvantage with bit stuffing is the insertion of additional bits into the data stream, wasting
bandwidth. How much expansion? The precise amount depends on the frequency in which the
reserved patterns appear as user data.
Use reserved characters to indicate the start and end of a frame. For instance, use the two-character
sequence DLE STX (Data-Link Escape, Start of TeXt) to signal the beginning of a frame, and the
sequence DLE ETX (End of TeXt) to flag the frame's end.
Problem: What happens if the two-character sequence DLE ETX happens to appear in the frame
itself?
Solution: Use character stuffing; within the frame, replace every occurrence of DLE with the two-
character sequence DLE DLE. The receiver reverses the processes, replacing every occurrence of
DLE DLE with a single DLE.
Example: If the frame contained ``A B DLE D E DLE'', the characters transmitted over the channel
would be ``DLE STX A B DLE DLE D E DLE DLE DLE ETX''.
Disadvantage: character is the smallest unit that can be operated on; not all architectures are byte
oriented.
a. BIT STUFFING
#include<stdio.h>
int main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter the length of the frame : \n");
scanf("%d",&n);
printf(" Enter the bit of the frame : \n");
for(i=0;i<n;i++)
{
printf("\n element[%d]:",i);
scanf("%d",&a[i]);
}
i=0;
count=1;
j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1 &&k<n && count<5;k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
count=1;
i++;j++;
}
Bit Stuffing output:
element[0]:0
element[1]:1
element[2]:1
element[3]:1
element[4]:1
element[5]:1
element[6]:1
element[7]:1
b. CHARACTER STUFFING
#include<stdio.h>
#include<string.h>
int main()
{
char a[20],s[40];
char *fb = "dlestx";
char *fe= "dleetx";
int i, j, n;
while(i<n)
{
if(a[i] =='d' && a[i+1] == 'l' && a[i+2] == 'e')
{
s[j] ='\0';
strcat(s,"dle");
strcat(s,"dle");
j=j+6;
i=i+3;
}
else
{
s[j] = a[i];
i++;
j++;
}
}
s[j] = '\0';
strcat(s,fe);
[root@localhost partb]#
[root@localhost partb]# gcc char.c
[root@localhost partb]# ./a.out
Enter the string: abcdelfgh
Experiment. 2: WAP for Distance vector algorithm to find suitable path for transmission
Theory
Routing algorithm is a part of network layer software which is responsible for deciding
which output line an incoming packet should be transmitted on. If the subnet uses
datagram internally, this decision must be made anew for every arriving data packet since
the best route may have changed since last time. If the subnet uses virtual circuits
internally, routing decisions are made only when a new established route is being set up.
The latter case is sometimes called session routing, because a rout remains in force for
an entire user session (e.g., login session at a terminal or afile).
Routing algorithms can be grouped into two major classes: adaptive and nonadaptive.
Nonadaptive algorithms do not base their routing decisions on measurement or estimates
of current traffic and topology. Instead, the choice of route to use to get from I to J (for all
I and J) is compute in advance, offline, and downloaded to the routers when the network
ids booted. This procedure is sometime called staticrouting.
Adaptive algorithms, in contrast, change their routing decisions to reflect changes in the
topology, and usually the traffic as well. Adaptive algorithms differ in where they get
information (e.g., locally, from adjacent routers, or from all routers), when they change the
routes (e.g., every T sec, when the load changes, or when the topology changes), and what
metric is used for optimization (e.g., distance, number of hops, or estimated transit time).
Two algorithms in particular, distance vector routing and link state routing are the most
popular. Distance vector routing algorithms operate by having each router maintain a table
(i.e., vector) giving the best known distance to each destination and which line to get
there. These tables are updated by exchanging information with the neighbors.
The distance vector routing algorithm is sometimes called by other names, including the
distributed B e l l m a n -Ford r o u t i n g algorithm and the Ford- Fulkerson algorithm,
after the researchers who developed it (Bellman, 1957; and Ford and Fulkerson, 1962). It
was the original ARPANET routing algorithm and was also used in the Internet under
the RIP and in early versions of DECnet and Novell’s IPX. AppleTalk and Cisco routers
use improved distance vector protocols.
In distance vector routing, each router maintains a routing table indexed by, and containing
one entry for, each router in subnet. This entry contains two parts: the preferred out going
line to use for that destination, and an estimate of the time or distance to that destination.
The metric used might be number of hops, time delay in milliseconds, total number of
packets queued along the path, or something similar.
The router is assumed to know the “distance” to each of its neighbor. If the metric is hops,
the distance is just one hop. If the metric is queue length, the router simply examines each
queue. If the metric is delay, the router can measure it directly with special ECHO packets
hat the receiver just time stamps and sends back as fast as possible.
the line to A to send traffic to X. In one vector exchange, the good news is processed.
To see how fast good news propagates, consider the five node (linear) subnet of
following figure, where the delay metric is the number of hops. Suppose A is down
initially and all the other routers know this. In other words, they have all recorded the
delay to A as infinity.
A B C D E A B C D E
∞ ∞ ∞∞Initially 1 2 3 4
Initially
1 ∞ ∞ ∞ After1exchange 3 2 3 4
After1exchange
1 2 ∞ ∞After 2exchange 3 3 3 4
After2exchange
1 2 3 ∞After 3exchange 5 3 5 4
After3exchange
1 2 3 4 After4exchange 5 6 5 6 After
4 exchange
7 6 7 6 After
5 exchange
7 8 7 8 After
6 exchange
:
:
:
∞∞ ∞∞
Theory
Let the node at which we are starting be called the initial node. Let the distance of node
Y be the distance from the initial node to Y. Dijkstra’s algorithm will assign some initial
distance values and will try to improve them step by step.
1. Assign to every node a tentative distance value: set it to zero for our initial node and to
infinity for all other nodes.
2. Mark all nodes unvisited. Set the initial node as current. Create a set of the unvisited
nodes called the unvisited set consisting of all the nodes except the initial node.
3. For the current node, consider all of its unvisited neighbors and calculate
their tentative distances. For example, if the current node A is marked with a distance
of 6, and the edge connecting it with a neighbor B has length 2, then the distance to B
(through A) will be 6+2=8. If this distance is less than the previously recorded tentative
distance of B, then overwrite that distance. Even though a neighbor has been examined,
it is not marked as “visited” at this time, and it remains in the unvisited set.
4. When we are done considering all of the neighbors of the current node, mark the current
node as visited and remove it from the unvisited set. A visited node will never be
checked again.
5. If the destination node has been marked visited (when planning a route between two
specific nodes) or if the smallest tentative distance among the nodes in the unvisited
set is infinity (when planning a complete traversal), then stop. The algorithm has
finished.
6. Select the unvisited node that is marked with the smallest tentative distance, and set it
as the new “current node” then go back to step 3.
DJIKTRA’S ALGORITHM
#include<stdio.h>
int main()
{
int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;
printf("\n enter the cost matrix\n");
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
scanf("%d",&a[i][j]);
printf("enter no of paths\n");
scanf("%d",&p);
printf("\n enter possible paths\n");
for(i=1;i<=p;i++)
for(j=1;j<=5;j++)
scanf("%d",&path[i][j]);
for(i=1;i<=p;i++)
{
t[i]=0;
stp=st;
for(j=1;j<=5;j++)
{
edp=path[i][j];
t[i]=t[i]+a[stp][edp];
if(edp==ed)
break;
else
stp=edp;
}
}
min=t[st];
index=st;
for(i=1;i<=p;i++)
{
if(min>t[i])
{
min=t[i];
index=i;
}
}
printf("min cost %d",min);
printf("\n shrtest path");
for(i=1;i<=5;i++)
{
printf("-->%d",path[index][i]);
if(path[index][i]==ed)
break;
}
return 0;
}
Experiment 4. For a given data use CRC-CCITT polynomial to obtain CRC code .
Verify the program for the cases
a. without error b. with error
#include<stdio.h>
#include<string.h>
#define N strlen(g)
char t[28],cs[28],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);
}
int main()
{
printf("\n enter data:");
scanf("%s",t);
printf("\n generator polynomial: %s", g);
a=strlen(t);
//#define a strlen(t)
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\n modified data is : %s",t);
crc();
printf("\n checksum is :%s", cs);
for(e=a;e<a;e++)
t[e]=cs[e-a];
printf("\n frame transmnitted msg(mode word)is :%s",t);
printf("\n test error detectio0nh 0(yes), 1(no) ?:");
scanf("%d",&e);
if(e==0)
{
do
{
printf("enter the position where error is to be inserted :");
scanf("%d",&e);
}
while(e==0||e>a+N-1);
t[e-1]=(t[e-1]=='o')? '1' : '0';
printf("\n erroreous data recieved : %s\n",t);
crc();
for(e=0;(e<N-1) && (cs[e]!='1');e++);
if(e<N-1)
printf("\n error detected");
}
else
printf("\n no error dected");
return 0;
}
enter data:1101
Theory:
Stop-and-wait ARQ, also referred to as alternating bit protocol, is a method
in telecommunications to send information between two connected devices. It ensures that
information is not lost due to dropped packets and that packets are received in the correct order.
It is the simplest automatic repeat-request (ARQ) mechanism. A stop-and-wait ARQ sender
sends one frame at a time; it is a special case of the general sliding window protocol with
transmit and receive window sizes equal to one and greater than one respectively. After sending
each frame, the sender doesn't send any further frames until it receives
an acknowledgement (ACK) signal. After receiving a valid frame, the receiver sends an ACK.
If the ACK does not reach the sender before a certain time, known as the timeout, the sender
sends the same frame again. The timeout countdown is reset after each frame transmission. The
above behavior is a basic example of Stop-and-Wait. However, real-life implementations vary
to address certain issues of design.
Typically the transmitter adds a redundancy check number to the end of each frame. The receiver
uses the redundancy check number to check for possible damage. If the receiver sees that the
frame is good, it sends an ACK. If the receiver sees that the frame is damaged, the receiver
discards it and does not send an ACK—pretending that the frame was completely lost, not merely
damaged.
One problem is when the ACK sent by the receiver is damaged or lost. In this case, the sender
doesn't receive the ACK, times out, and sends the frame again. Now the receiver has two copies
of the same frame and doesn't know if the second one is a duplicate frame or the next frame of
the sequence carrying identical data.
Another problem is when the transmission medium has such a long latency that the sender's
timeout runs out before the frame reaches the receiver. In this case the sender resends the same
packet. Eventually the receiver gets two copies of the same frame, and sends an ACK for each
one. The sender, waiting for a single ACK, receives two ACKs, which may cause problems if it
assumes that the second ACK is for the next frame in the sequence.
To avoid these problems, the most common solution is to define a 1 bit sequence number in the
header of the frame. This sequence number alternates (from 0 to 1) in subsequent frames. When
the receiver sends an ACK, it includes the sequence number of the next packet it expects. This
way, the receiver can detect duplicated frames by checking if the frame sequence numbers
alternate. If two subsequent frames have the same sequence number, they are duplicates, and the
second frame is discarded. Similarly, if two subsequent ACKs reference the same sequence
number, they are acknowledging the same frame.
Stop-and-wait ARQ is inefficient compared to other ARQs, because the time between packets,
if the ACK and the data are received successfully, is twice the transit time (assuming the
turnaround time can be zero). The throughput on the channel is a fraction of what it could be. To
solve this problem, one can send more than one packet at a time with a larger sequence number
and use one ACK for a set. This is what is done in Go-Back-N ARQ and the Selective Repeat
ARQ.
ALGORITHM:
int main()
{
int i,j,noframes,x,x1=10,x2;
for(i=0;i<200;i++)
noframes=19200/200;
i=1;
j=1;
noframes = noframes / 8;
printf("\n number of frames is %d",noframes);
while(noframes>0)
{
printf("\nsending frame%d",i);
srand(x1++);
x =rand()%10;
if(x%2 ==0)
{
for (x2=1; x2<2; x2++)
{
printf("waiting for %d seconds\n", x2);
sleep(x2);
}
printf("\nsending frame %d",i);
srand(x1++);
x = rand()%10;
}
printf("\nack for frame %d",j);
noframes-=1;
i++; j++;
}
printf("\n end of stop and wait protocol");
number of frames is 12
sending frame1
ack for frame 1
sending frame2
ack for frame 2
sending frame3waiting for 1 seconds
sending frame 3
ack for frame 3
sending frame4
ack for frame 4
sending frame5
ack for frame 5
sending frame6waiting for 1 seconds
sending frame 6
ack for frame 6
sending frame7waiting for 1 seconds
sending frame 7
ack for frame 7
sending frame8
ack for frame 8
sending frame9waiting for 1 seconds
sending frame 9
ack for frame 9
sending frame10waiting for 1 seconds
sending frame 10
ack for frame 10
sending frame11
ack for frame 11
sending frame12
ack for frame 12
end of stop and wait protocol[root@localhost partb]#
int main()
{
int temp1,temp2,temp3,temp4,temp5,i,winsize=8,noframes,moreframes; char c;
int reciever(int);
int simulate(int);
int nack(int);
temp4=0,temp1=0,temp2=0,temp3=0,temp5 = 0;
for(i=0;i<200;i++)
noframes=1200/200;
printf("\n number of frames is %d",noframes);
moreframes=noframes;
while(moreframes>=0)
{
temp1=simulate(winsize);
winsize-=temp1;
temp4+=temp1;
if(temp4 >noframes)
temp4 = noframes;
for(i=noframes - moreframes;i<=temp4;i++)
printf("\nsending frame %d",i);
temp2=reciever(temp1);
temp3+=temp2;
if(temp3 > noframes) temp3 = noframes;
temp2 = nack(temp1);
temp5+=temp2;
if (temp5 !=0)
{
printf("\n No acknowledgement for the frame %d",temp5);
for(i=1;i<temp5;i++)
;
printf("\n Retransmitting frame %d",temp5);
}
moreframes-=temp1; if(winsize<=0) winsize=8;
}
printf("\n end of sliding window protocol Selective Reject");
number of frames is 6
sending frame 0
sending frame 1
sending frame 2
sending frame 3
No acknowledgement for the frame 2
Retransmitting frame 2
sending frame 3
sending frame 4
No acknowledgement for the frame 2
Retransmitting frame 2
sending frame 4
sending frame 5
sending frame 6
No acknowledgement for the frame 5
Retransmitting frame 5
end of sliding window protocol Selective Reject[root@localhost partb]#
Problem Statement
Write a program for congestion control using Leaky bucket algorithm.
Theory
The congesting control algorithms are basically divided into two groups: open loop and
closed loop. Open loop solutions attempt to solve the problem by good design, in essence,
to make sure it does not occur in the first place. Once the system is up and running,
midcourse corrections are not made. Open loop algorithms are further divided into ones
that act at source versus ones that act at the destination.
In contrast, closed loop solutions are based on the concept of a feedback loop if there is any
congestion. Closed loop algorithms are also divided into two subcategories: explicit
feedback and implicit feedback. In explicit feedback algorithms, packets are sent back from
the point of congestion to warn the source. In implicit algorithm, the source deduces
the existence of congestion by making local observation, such as the time needed for
acknowledgment tocome back.
The presence of congestion means that the load is (temporarily) greater than the resources
(in part of the system) can handle. For subnets that use virtual circuits internally, these
methods can be used at the network layer.
Another open loop method to help manage congestion is forcing the packet to be
transmitted at a more predictable rate. This approach to congestion management is widely
used in ATM networks and is called traffic shaping.
The other method is the leaky bucket algorithm. Each host is connected to the network by
an interface containing a leaky bucket, that is, a finite internal queue. If a packet arrives at
the queue when it is full, the packet is discarded. In other words, if one or more process are
already queued, the new packet is unceremoniously discarded. This arrangement can be
built into the hardware interface or simulate d by the host operating system. In fact, it is
nothing other than a single server queuing system with constant service time.
The host is allowed to put one packet per clock tick onto the network. This mechanism
turns an uneven flow of packet from the user process inside the host into an even flow of
packet onto the network, smoothing out bursts and greatly reducing the chances of
congestion.
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
LEAKY BUCKET
#include<stdio.h>
#include<string.h>
int main()
{
int drop=0,mini,nsec,cap,count=0,i,inp[25],out;
printf("\nenter the bucket size:");
scanf("%d",&cap);
printf("\nenter the output rate:");
scanf("%d",&out);
printf("\nenter the number of sec you want to simulate:");
scanf("%d",&nsec);
for(i=0;i<nsec;i++)
{
printf("\nenter the size of the packets entering at %d sec\n",i+1);
scanf("%d",&inp[i]);
}
for(i=0;i<nsec;i++)
{
count=count+inp[i];
if(count>cap)
{
drop=count-cap;
count=cap;
}
printf("%d",i+1);
printf("\t%d",inp[i]);
mini=min(count,out);
printf("\t\t%d",mini);
count=count-mini;
printf("\t\t%d",count);
printf("\t\t%d\n",drop);
}
return 0;
}
All commands related to Network configuration which includes how to switch to privilege mode
and normal mode and how to configure router interface and how to save this configuration to
flash memory or permanent memory.
Ping (8) sends an ICMP ECHO_REQUEST packet to the specified host. If the host responds, you get an
ICMP packet back. Sound strange? Well, you can “ping” an IP address to see if a machine is alive. If
there is no response, you know something is wrong.
Traceroute:
Tracert is a command which can show you the path a packet of information takes from your computer
to one you specify. It will list all the routers it passes through until it reaches its destination or fails to
and is discarded. In addition to this, it will tell you how long each 'hop' from router to router takes.
nslookup:
pathping:
A better version of tracert that gives you statics about packet lost and latency.
Getting Help
In any command mode, you can get a list of available commands by entering a question mark (?).
Router>?
To obtain a list of commands that begin with a particular character sequence, type in those
haracters followed immediately by the question mark (?).
Router#co?
configure connect copy
To list keywords or arguments, enter a question mark in place of a keyword or argument. Include
a space before the question mark.
Router#configure ?
memory Configure from NV memory network Configure from a TFTP network host terminal
Configure from the terminal
You can also abbreviate commands and keywords by entering just enough characters to make the
command unique from other commands. For example, you can abbreviate the show command to
sh.
Configuration Files
Any time you make changes to the router configuration, you must save the changes to memory
because if you do not they will be lost if there is a system reload or power outage. There are two
types of configuration files: the running (current operating) configuration and the startup
configuration.
DEPARTMENT OF ECE 50 HKBKCE
Computer Networks Lab Manual 17ECL68 2019-20
Use the following privileged mode commands to work with configuration files.
Viva Questions
1.What do you mean by data communication?
2.What is simplex?
3.What is half-duplex?
4.What is full duplex?
5.What is a network?
6.What is distributed processing?
7.What is point to point connection?
8.What is multipoint connection?
9.What is a topology?
10.Define LAN, MAN and WAN.
11.Define internet?
12.What is a protocol?
13.What is TCP/IP protocol model?
14.Describe the functions of five layers?
15.What is ISO-OSI model?
16. What is multiplexing?
17.What is switching?
18.How data is transmitted over a medium?
19. Compare analog and digital signals?
20.Define bandwidth?
21.What are the factors on which data rate depends?
22.Define bit rate and bit interval?
23.What is Nyquist bit rate formula?
24.Define Shannon Capacity?
25.What is sampling?
26.Define pulse amplitude modulation?
27.Define pulse code modulation?
28.What is Nyquist Theorem?
29.What are the modes of data transmission?
30.What is Asynchronous mode of data transmission?
31.What is Synchronous mode of data transmission?
32.What are the different types of multiplexing?
33.What is FDM?
34.What is TDM?
35.What are the different transmission media?
36.What are the different Guided Media?
37.Describe about the different Guided Medias.
38.What do you mean by wireless communication?
39.What are the switching methods?
40.What are the duties of data link layer?
41.What are the types of errors?
42.What do you mean by redundancy?
43.Define parity check.
44. Define cyclic redundancy check (CRC).
45. What is hamming code?
46.What do you mean by flow control?
47.What do you mean by error control?
48.Define stop and wait ARQ.
49.Define Go-Back-N ARQ?
50.Define Selective Repeat ARQ?
50.What do you mean by pipelining, is there any pipelining in error control?
51.What is HDLC?
52.What do you mean by point to point protocol?
53. What do you mean by point to point protocol stack?
DEPARTMENT OF ECE 51 HKBKCE
Computer Networks Lab Manual 17ECL68 2019-20
54.What do you mean by line control protocol?
REFERENCES
1. Data Communications and Networking , Forouzan, 5th Edition, McGraw Hill, 2016
ISBN: 1-25-906475-3
2. Communication Networks: Fundamental Concepts and Key Architectures -
Alberto Leon, Garcia and Indra Widjaja, 3rd Edition, Tata McGraw- Hill, 2004.
3. Data and Computer Communication, William Stallings, 8th t Edition, Pearson
Education, 2007.
4. Computer Networks: A Systems Approach - Larry L. Peterson and Bruce S. David,
4th Edition, Elsevier, 2007.
5. Introduction to Data Communications and Networking – Wayne Tomasi, Pearson
Education, 2005.
6. Communication Networks – Fundamental Concepts and Key architectures –
Alberto Leon- Garcia and Indra Widjaja:, 2rd Edition, Tata McGraw-Hill, 2004
7. Computer and Communication Networks – Nader F. Mir:, Pearson Education, 2007.