Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Micro project on ARQ
1. MICRO PROJECT
COMPUTER NETWORKS LAB
COURSE CODE: CS-692
TEAM MEMBERS:
NAME: CLASS ROLL NO: UNIVERSITY ROLL
NO:
FAIZAAN AHMED
KHAN
(CSE/2013/089) 11700113029
GIRI SWAGARIKA
JAHARLAL
(CSE/2014/B03) 11700213023
ABHIPSA
CHAKRABORTY
(CSE/2014/B02) 11700213002
SHREYA DAS (CSE/2014/B05) 11700213067
2. GO BACK N ARQ:
AIM:
Go Back n is a connection oriented protocol in which the transmitter has a window of
sequence numbers that may be transmitted without acknowledgment. The receiver will
only accept the next sequence number it is expecting - other sequence numbers are silently
ignored. In this portion we will know about how the protocol works.
THEORY:
Go-Back-N ARQ is a specific instance of the automatic repeat request (ARQ) protocol, in
which the sending process continues to send a number of frames specified by a window
size even without receiving an acknowledgement (ACK) packet from the receiver. It is a
special case of the general sliding window protocol with the transmit window size of N and
receive window size of 1. It can transmit N frames to the peer before requiring an ACK.
The receiver process keeps track of the sequence number of the next frame it expects to
receive, and sends that number with every ACK it sends. The receiver will discard any
frame that does not have the exact sequence number it expects (either a duplicate frame it
already acknowledged, or an out-of-order frame it expects to receive later) and will resend
an ACK for the last correct in-order frame. Once the sender has sent all of the frames in
its window, it will detect that all of the frames since the first lost frame are outstanding, and
will go back to the sequence number of the last ACK it received from the receiver process
and fill its window starting with that frame and continue the process over again.
Go-Back-N ARQ is a more efficient use of a connection than Stop-and-wait ARQ, since unlike
waiting for an acknowledgement for each packet, the connection is still being utilized as
packets are being sent. In other words, during the time that would otherwise be spent
waiting, more packets are being sent. However, this method also results in sending frames
multiple times – if any frame was lost or damaged, or the ACK acknowledging them was
lost or damaged, then that frame and all following frames in the window (even if they were
received without error) will be re-sent. To avoid this, Selective Repeat ARQ can be used.
3. Go-Back-N ARQ protocol : To understand this protocol you should first understand
what is window size. I'll assume that you already know it. consider above scenario
there are four frames 0,1,2,3 respectively. Now as sending window size is 3 it'll send
frame 0,1,2 at a time.
At receiver side frame 0 arrives it sends ack for that.
Now at sender side window shift at frame 3 and it sends frame no 3.
At receiver side frame 1 arrives it sends ack for that.
Now at sender side window shift at frame 0 and it sends frame no 0. (this is not
previous frame 0)
Now receiver detects frame 2 is missing or lost. It'll send NAK for that.
Sender receives NAK at this point sending window is pointing towards frame 2,3 and
next frame 0.
With same scenario Stop-N-Wait protocol re-transmits all frames that are pointed by
sending window. But in Go-Back-N only frame 2 is re-transmits. and repeat this until it
gets ack for frame 2.
So Go-Back-N is more efficient.
4. Features required for Go-Back-N ARQ
To support Go-Back-N ARQ, a protocol must number each PDU which is sent. (PDUs
are normally numbered using modulo arithmetic, which allows the same number to
be re-used after a suitably long period of time. The time period is selected to ensure
the same PDU number is never used again for a different PDU, until the first PDU has
"left the network" (e.g. it may have been acknowledged)).
The local node must also keep a buffer of all PDUs which have been sent, but have
not yet been acknowledged.
The receiver at the remote node keeps a record of the highest numbered PDU which
has been correctly received. This number corresponds to the last acknowledgement
PDU which it may have sent.
Recovery of lost PDUs using Go-Back-N
The recovery of a corrupted PDU proceeds in three stages:
First, the corrupted PDU is discarded at the remote node's receiver.
Second, the remote node requests retransmission of the missing PDU using a control
PDU (sometimes called a NACK or REJECT). The receiver discards all PDUs which do
not have the number of the requested PDU.
The final stage consists of retransmission of the lost PDU(s).
Retransmission using Go-Back-N
A remote node may request retransmission of corrupted PDUs by initiating Go-Back-N
error recovery by sending a control PDU indicating the last successfully received PDU.
This allows the remote node to instruct the sending node where to begin retransmission of
5. PDUs. The remote node does not store any out-of-sequence PDUs and therefore
must discard all received PDUs until one is received with the expected sequence number.
Upon receipt of a Go-Back-N control PDU (by the local node), the transmitter winds-
back the sequence of PDUs pending transmission to the indicated PDU in its buffer of
unacknowledged PDUs. The transmitter then retransmits (Goes Back-to-N) the requested
PDU followed by all successive PDUs. This is sometimes known as "wind back" of the
transmitter.
Example of Go-Back-N:
The sender in this example transmits four PDUs (1-4) and the first one (1) of these is not
successfully received. The receiver notes that it was expecting a PDU numbered 1 and
actually receives a PDU numbered 2. It therefore deduces that (1) was lost. It requests
retransmission of the missing PDU by sending a Go-Back-N request (in this case N=1), and
discards all received PDUs with a number greater than 1.The sender receives the Go-Back-
N request and retransmits the missing PDU (1), followed by all subsequently sent PDUs (2-
4) which the receiver the correctly receives and acknowledges.
If the retransmission is not successful, the protocol relies upon a protocol timer in the local
node to detect that no acknowledgment was received. The lost PDUs may then be
recovered by Polling.
CODE:
#include<stdio.h>
int main()
{
int windowsize,sent=0,ack,i;
printf("enter window sizen");
scanf("%d",&windowsize);
6. while(1)
{
for( i = 0; i < windowsize; i++)
{
printf("Frame %d has been transmitted.n",sent);
sent++;
if(sent == windowsize)
break;
}
printf("nPlease enter the last Acknowledgement received.n");
scanf("%d",&ack);
if(ack == windowsize)
break;
else
sent = ack;
}
return 0;
}
OUTPUT:
enter window size
8
Frame 0 has been transmitted.
Frame 1 has been transmitted.
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
Frame 6 has been transmitted.
Frame 7 has been transmitted.
Please enter the last Acknowledgement received.
2
Frame 2 has been transmitted.
Frame 3 has been transmitted.
Frame 4 has been transmitted.
Frame 5 has been transmitted.
Frame 6 has been transmitted.
Frame 7 has been transmitted.
Please enter the last Acknowledgement received.
8
--------------------------------
7. STOP AND WAIT ARQ:
AIM:
"Stop-n-wait" (sometimes known as "positive acknowledgement with retransmission") is
the fundamental technique to provide reliable transfer under unreliable packet delivery
system. In this portion we will know about how the protocol works.
THEORY AND DIAGRAM:
Stop-and-wait ARQ also can be referred as alternating bit protocol is a method used
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 kind of automatic repeat-request (ARQ) method. A stop-and-wait
ARQ sender sends one frame at a time; it is a special case of the general sliding window
protocol with both transmit and receive window sizes equal to 1 and more 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 good 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. Timer is set after each frame transmission.
The above behavior is the simplest Stop-and-Wait implementation. However, in a real life
implementation there are problems to be addressed.
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.
8. 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.
How this protocol works..
1) Normal operation:
After transmitting one packet, the sender
waits for an acknowledgment (ACK) from
the receiver before transmitting the next
one. In this way, the sender can recognize
that the previous packet is transmitted
successfuly and we could say "stop-n-wait"
guarantees reliable transfer between
nodes.
To support this feature, the sender keeps a
record of each packet it sends.
Also, to avoid confusion caused by delayed
or duplicated ACKs, "stop-n-wait" sends
each packets with unique sequence
numbers and receives that numbers in each
ACKs.
9. 2) Timeout:
If the sender doesn't receive ACK for previous sent packet after a certain period of time, the
sender times out and retransmit that packet again. There are two cases when the sender
doesn't receive ACK; one is when the ACK is lost and the other is when the frame itself is
not transmitted.
To support this feature, the sender keeps timer per each packet.
3. How it is shown in nam (network animator)..
"stop-n-wait" protocol can be shown as below in nam.
11. 2. Packet_1 is sent and ACK_1 is received
3. Packet_2 will be sent and be received and so on..
12. Shortcoming:
The main shortcoming of the stop-and-wait algorithm is that it allows the sender to have
only one outstanding frame on the link at a time. The sender should wait till it gets an ACK
of previous frame before it sends next frame. As a result, it wastes a substantial amount of
network bandwidth. To improve efficiency while providing reliability, "sliding window"
protocol is appeared.
CODE:
#include<stdio.h>
#define MAXSIZE 100
typedef struct
{
unsigned char data[MAXSIZE];
}packet;
typedef enum{data,ack}frame_kind;
typedef struct
{
frame_kind kind;
int sq_no;
int ack;
packet info;
}frame;
typedef enum{frame_arrival}event_type;
typedef enum{true_false}boolean;
void frame_network_layer(packet *p)
{
printf("n from network arrival");
}
void to_physical_layer(frame *f)
{
printf("n to physical layer");
}
void wait_for_event(event_type *e)
{
printf("n waiting for event n");
}
void sender(void)
{
frame s;
packet buffer;
event_type event;