simplex stop and_wait_protocol

25
SIMPLEX STOP AND WAIT PROTOCOL by AF.Musfira 2010/ICT/38 8/10/2016 2010/ICT/38 1

Upload: musfira-ameer

Post on 22-Jan-2018

310 views

Category:

Technology


0 download

TRANSCRIPT

SIMPLEX STOP AND WAIT

PROTOCOL

by

AF.Musfira

2010/ICT/38

8/10/2016 2010/ICT/38 1

• Flow control deals with problem thatsender transmits frames faster thanreceiver can accept, and solution isto limit sender into sending no fasterthan receiver can handle

8/10/2016 2010/ICT/38 2

• Consider the simplex case: datais transmitted in one direction

8/10/2016 2010/ICT/38 3

• Stop and wait: sender sends onedata frame, waits foracknowledgement (ACK) fromreceiver before proceeding totransmit next frame

– This simple flow control will breakdown if ACK gets lost or errorsoccur → sender may wait for ACKthat never arrives

8/10/2016 2010/ICT/38 4

Simplex Protocol for a Noisy Channel

• For noisy link, pure stop and wait protocolwill break down, and solution is toincorporate some error control mechanism

8/10/2016 2010/ICT/38 5

Automatic Repeat reQuest

• Is an error-control method for data transmission

• uses acknowledgements and timeouts to achieve reliable data transmission over an unreliable service.

8/10/2016 2010/ICT/38 6

STOP AND WAIT ARQ

8/10/2016 2010/ICT/38 7

Stop and wait with ARQ: Is an errorcontrol method, is incorporated withstop and wait protocol

• A transmits frame one • B receives A1 • B generates ACK • ACK is lost • A times out, retransmits • B gets duplicate copy (sending on to network layer)

8/10/2016 2010/ICT/38 8

• If error is detected by receiver, it discards the frame and send a negative ACK (NAK), causing sender to re-send the frame

• In case a frame never got to receiver, sender has a timer: each time a frame is sent, timer is set → If no ACK or NAK is received during timeout period, it re-sends the frame

• Timer introduces a problem: Suppose timeout and sender retransmits a frame but receiver actually received the previous transmission → receiver has duplicated copies

• To avoid receiving and accepting two copies of same frame, frames and ACKs are alternatively labeled 0 or 1: ACK0 for frame 1, ACK1 for frame 0

8/10/2016 2010/ICT/38 9

FramesPacket Error Free Packet

Transmitter Receiver

Information Frame

Control Frame

Timer is set after each frame transmission

8/10/2016 2010/ICT/38 10

Information Frame

Acknowledgement Frame

header Information Packet CRC

Header CRC

8/10/2016 2010/ICT/38 11

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

8/10/2016 2010/ICT/38 12

Need for sequence numbers

• 1 bit sequence number in the header of the frame, alternating (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.

8/10/2016 2010/ICT/38 13

Case 1

• Sender sends the frame 0 to the destination and simultaneously a timer is started.

• The destination accepts the frame since it was expecting frame 0.

• Receiver sends an acknowledgement ACK 1 informing the sender that it has successfully received frame 0 and is expecting for frame 1.

• This acknowledgement reaches sender before the timer of frame 0 expires.

8/10/2016 2010/ICT/38 14

0 1 0 1 0 1

0 1 0 1 0 1

0 1 0 1 0 1

Request

Arrived

Sn

Sn

Rn

Sender Receiver

Start

Stop

Arrived

8/10/2016 2010/ICT/38 15

Case 2

• Sender sends frame 0 to the destination and simultaneously timer is started.

• Frame 0 is lost before reaching the destination.

• Since destination didn’t receive frame 0 no acknowledgement is sent.

• Eventually timer for frame 0 expires and sender resends frame 0.

• This process continues until it reaches acknowledgement for frame 1.

8/10/2016 2010/ICT/38 16

0 1 0 1 0 1

Request

0 1 0 1 0 1

0 1 0 1 0 1

0 1 0 1 0 1

timeout

Arrived

Sn

Sn

Rn

Arrived

Stop8/10/2016 2010/ICT/38 17

Case 3• Sender sends frame 0 to the destination and simultaneously timer

is started.• The destination accepts the frame since it was expecting frame 0.

• Receiver sends an acknowledgement ACK 1 informing the sender that it has successfully received frame 0 and is expecting for frame 1.

• The acknowledgement gets lost and it doesn’t reach the sender.• Eventually timer for frame 0 expires and sender resends frame 0.

• Now since the receiver is expecting for frame 1, it will safely discard the frame 0 and once again sends acknowledgement ACK 1.

8/10/2016 2010/ICT/38 18

010101RequestSn

Start

0 1 0 1 0 1

Rn

Arrived

ACK 1

Lost010101

0 1 0 1 0 1

0 1 0 1 0 1

Arrived

Sn

Sn

Rn

Discard, Duplicate

timeout

Stop8/10/2016 2010/ICT/38 19

Sender-site algorithm for stop and

wait ARQ

Sn=0;

Cansend=true;

While(true)

{

Waitforevent()

If(event(requesttosend)AND cansend)

{

Getdata();

Makeframe(Sn);

Storeframe(Sn)

Sendframe(Sn);

Starttimer()

Cansend=false

}

8/10/2016 2010/ICT/38 20

Contd

Waitforevent();if(event(arrivalnotification)

{

Receiveframe(ackno);

If(ackno==Sn)

{

Stoptimer();

Purge(Sn-1);

Cansend=true;

}

}

If(event(timeout))

{

Starttimer();

Resendframe(Sn-1);

}

}8/10/2016 2010/ICT/38 21

Receiver-site algorithm for

Stop and Wait ARQRn = 0;

While (true)

{

WaitForEvent ( );

If (Event (ArrivalNotification) )

{

ReceiveFrame ( );

If (corrupted (frame) );

sleep ( );

{

ExtractData ( );

DelieverData ( );

Rn = Rn + 1;

}

SendFrame (Rn);

}

}8/10/2016 2010/ICT/38 22

Advantages of Stop and Wait ARQ over

simple Stop and Wait protocol

1. It can be used for noisy channels

2. It has both error and flow control mechanism

3. It has a timer implementation

8/10/2016 2010/ICT/38 23

• Efficiency is very less.

• Only 1 frame is sent at a time.

• Timer should be set for each individual

frame.

• No pipelining.

• Sender window size is 1 ( disadvantage

over go back n ARQ).

• Receiver window size is 1 ( disadvantage

over selective repeat ARQ).

Disadvantages of Stop and Wait ARQ

8/10/2016 2010/ICT/38 24

THANK YOU

8/10/2016 2010/ICT/38 25