49

Reliablt transmission

Embed Size (px)

Citation preview

RELIABLE TRANSMISSION

RELIABLE TRANSMISSIONConcept of data flow between sender and receiver

using OSI Model

RELIABLE TRANSMISSIONSender Side:

Network Layer (N/L) waits for an EVENT EVENT : (Request To Send) the data is made by sender When sender wants to send data

Network Layer Gets Data from upper Layers

Data-Link Layer packages the data and Makes FramePhysical Layer Sends Frame in form of signal

Receiver Side:Physical Layer waits for an EVENT

EVENT :(Arrival Notification) of frame is made to Data-Link Layer When the frame arrives at the receiver

Physical layer Receives Frame

Data-Link Layer Extracts Data from the frame and Delivers Datato Network Layer

Network

Data Link

Physical

Network

Data Link

Physical

Waiting for EVENTRequest To Send

Sender wants to send data Gets Data

Sends Frame in signal form

Get Data( ) Make Frame ( ) Send Frame( )

Waiting for EVENT

Makes Frame

Arrival Notification

Frame arrives at receiver Receives FrameExtracts DataDelivers Data

Receive Frame( ) Extract Data ( )Deliver Data( )

while(true) {

WaitForEvent( ) If Event( RequestToSend( ) ) {

Get Data ( ) Make Frame( ) Send Frame( )

}

}

while(true) {

WaitForEvent( ) If Event( ArrivalNotification( ) ) {

Receive Frame ( ) Extract Data( ) Deliver Data( )

}

}

Request To Send

Network

Data Link

Physical Arrival Notification Physical

Data Link

Network

RELIABLE TRANSMISSIONWhen an error is introduced into the frames and they get

corrupted.

We can use some Error Correction Scheme (ECS) to correct them

But ECS produce a very large overhead

Or even some errors are to severe to be corrected by ECS

So ultimately we need to discard the frames

We need some strategy to RECOVER these discarded frames

Flow Control: Sender needs to make sure that it is not sending “more data” then the capacity of receiver

RELIABLE TRANSMISSIONEvery strategy used for recovering frames involves two common

conceptsAcknowledgement (Ack)

Whenever frame arrives at the receiver and it is not corrupted Receiver sends a control frame back to sender for confirmation purpose This control frame is called Acknowledgement (Ack) frame

TimeoutWhenever sender transmits a frame it then waits for the

acknowledgement by starting a timerThis waiting time is usually equal to Round Trip Time (RTT) If the acknowledgement does not come back with in waiting time,

an EVENT occurs called “Timeout” When “Timeout” event occurs sender retransmits the frame

RELIABLE TRANSMISSIONThe general strategy to implement Acknowledgements &

Timeout is sometimes called

ARQ ( Automatic Repeat Request )

We will study the following ARQ Algorithms

Stop-And-Wait ARQ

Go-Back-N ARQ

Selective Repeat ARQ

Stop-And-Wait ARQStop-And-Wait ARQ

The simplest ARQ scheme is the stop-and-wait algorithm

After transmitting one frame, the Sender

Starts the timer and STOPS the transmission

WAITS for an acknowledgment until the timer expires

If the acknowledgement comes back before the expiration of timer only then next frame is transmitted

If the acknowledgment does not arrive before the expiration of timer

the sender times out and retransmits the original frame.

Stop-And-Wait ARQ

Stop-And-Wait ARQ

Problem: Receiver has duplicate frames

Stop-And-Wait ARQSo apart from corrupted frames RECEIVER may also face

problems of Duplicated frames and Out-Of-Order frames (Lost frames)

A corrupted frame can be detected by an error detection strategy

For detecting Duplicated frames and Lost framesEvery fame is given a special number called SEQUENCE NUMBER

If two received frames have same sequence number, it indicates that frames are duplicated

If two frames come out of order, it means that a frame in between may have been lost

Stop-And-Wait ARQLike data frames acknowledgements are also given Sequence

Numbers (or Acknowledgement Number)

The Acknowledgement Number is actually the sequence number of next Expected Frame i.e. Ack_No:= Seq_No + 1

So when a receiver accepts a Data Frame with Seq_No:=3 Receiver sends an acknowledgement back to sender with Ack_No:=4

When sender receives the Acknowledgement with Ack_No:=4,

This tells the sender that receiver has received the frame with Seq_No:=3

And now it is expecting the next frame with Seq_No:=4

Stop-And-Wait ARQHow many frames can be counted by the Sequence Number?

If M bits are used for the sequence number

It can count 2M frames

Where the count begins from zero and goes up to 2M - 1

If there are more then 2M frames, the counting is again repeated from 0 to 2m - 1

For example if 3 bits are used for the sequence number

It can count 23 frames, i.e. 8 frames

Where the count goes from 0 to 7

If there are 8th, 9th and 10th frames, they will be numbered 0, 1 and 2

The size of sequence number field should be chosen to minimize the size of frames

Stop-And-Wait ARQFor the sake of Stop-and-Wait ARQ, there can only be at

most two frames on the communication line

Data Frame and Acknowledgement Frame

So one bit is enough to count the frame and acknowledgement, i.e. using one bit possible values = 0, 1

The 4 frames will be counted like this: 0, 1, 0, 1

Now if sender sends a frame with Seq_No:= 0

The Receiver will send an Acknowledgement with Ack_No:=1

Stop-And-Wait ARQ

DataFrame Sn = 0

Event

canSend

Sequence Number

True

Sn = 0

RequestToSend

Frame Sn = 0

Sn = 1

False

Frame Ackn = 1

Arrival Notification

True

DataFrame Sn = 0

Event

canSend

Sequence Number

True

Sn = 0

RequestToSend

Frame Sn = 0

Sn = 1

False

Arrival NotificationEvent TimeOut ( )

Frame Sn = 0

SN = 0;

canSend = True;

While ( true ) {WaitForEvent( );

If Event( RequestToSend( ) And canSend = True ) { Get Data ( );

Make Frame ( SN );

Store Frame ( SN );

Send Frame ( SN );

Start Timer ( );

SN = ( SN + 1 ) % 2

canSend = False;

}

WaitForEvent ( );

If Event( Arrival Notification( ) ) {Receive Frame ( AckN );

If ( (Not Corrupted) And AckN = SN ) {

Stop Timer ( );

Purge Frame ( SN - 1 );

canSend = True;

}

}

If Event( Time Out( ) ) {

Start Timer( );

Resend Frame( SN - 1 );

}

}

Stop-And-Wait ARQ

Event

Sequence Number

Frame Sn = 0

Rn = 0

Arrival Notification

Event

Sequence Number

Frame Sn = 0

Rn = 0

Arrival Notification

Rn = 1

Frame Ackn = 1Data

Frame Sn = 0

RN = 0;

While ( true ) {WaitForEvent( );

If Event( Arrival Notification ) { Receive Frame ( );

If ( Frame is Corrupted )

Sleep ( );

If ( Sn = Rn ) {

Extract Data ( );

Deliver Data ( );

Rn = (Rn + 1) mod 2

}

Send Acknowledgement ( Rn );

}

}

Stop-And-Wait ARQ

Drawback: Wastage of bandwidth.

At a given time there can only be One Frame on the communication line

Stop and Wait ARQ

Go-Back-N ARQIn this protocol we can send multiple frames without receiving

acknowledgement This protocol uses a logical concept called:

SLIDING WINDOW Collection of frames that can be transmitted without receiving

acknowledgement Unacknowledged frames which are transmitted i.e. the frames

present in the window are called Outstanding frames

This protocol also uses the concept of:CUMULATIVE ACKNOWLEDGEMENT A single acknowledgement frame which acknowledges multiple

frames

A single timer can run for all the framesOr separate timers can run for every frame

Go-Back-N ARQ

A window is divided into three parts

Frames that have already been acknowledged, sender ignores these frames completely

SENDER WINDOW

Outstanding frames with unknown status, i.e. their acknowledgement has not yet arrived (actual window)

Frames that cannot be transmitted. Every time ACK of outstanding frame arrives, the window slides to right

0 1 2 3 4 5 6 7 8 9 10 11

Receiver window contains only one frame

Go-Back-N ARQProcedure:

Suppose the sender window size is 3 frames

Sender transmits frame 0,1 and 2 without waiting for acknowledgement

After transmitting frame 0, it immediately starts the timer

Receiver sends an acknowledgement for every frame

Every time acknowledgment arrives, Sender window slides to the right, meaning one more frame enters the

window and the Acknowledged Frame exits the window

If the acknowledgment does not come, the sender goes back to the beginning of window and retransmits all frames

Hence the name Go-Back-N ARQ

0 1 2 3 4 5

Sender Window = 3 FRAMES

F0

F1

F2A1

A2

A3

TIM

E O

UT

0

F3

F4

F5A4

A5

A6

TIM

E O

UT

1 2 3 4 5

SENDER RECEIVER SENDER RECEIVER

Cumulative Acknowledgement

F0

F1

F2A1

A2

A3

TIM

E O

UT

SENDER RECEIVER

F3

A4

Acknowledgment 4 arrives before timeout

So in this case Ack-4 is the Accumulative Acknowledgement

Ack-4 will be accepted as the acknowledgement for F3, F2 and F1

F0

F1

F2

TIM

E O

UT

SENDER RECEIVER

F3

A1

Go-Back-N ARQ F2 arrives at the receiverWhere receiver is expecting F1An out-of-order frame So receiver discards itAnd also the frame after itUltimately timer times outSender goes back to the beginning of window (i.e. F1)Retransmits all the framesGo-Back-N ARQ

Size of Window:

How many frames can be sent without receiving acknowledgement? Or in other words

How many frames can be outstanding?

We know that m bits can count 2m frames

But

Go-Back-N ARQ

If m bits are used for sequence number field then:size of window <= 2m – 1

Go-Back-N ARQIf m bitsare used for sequence number field then:size of window <= 2m – 1

If We break this rule, receiver cannot detect duplicate frames, i.e. if keep the window size = 2m

Go-Back-N ARQSuppose m is 3 bits so it can count 2m = 23 = 8 frames

Frames are numbered as 0,1,2,3,4,5,6,7

The size of window should be 2m – 1 = 23 – 1 = 7

Now instead of 7 we choose window size = 23 = 8Entire window is transmitted i.e. frames from 0,1,….7 All Frames were received correctly but their acknowledgements were lost

Next expected frame by the receiver is frame-0.

Sender retransmits frame-0 but this is not the new frame, it’s the duplicate of first frame in window

But sender mistakenly accepts this frame as the new frame instead of discarding it

Go-Back-N ARQSuppose m is 3 bits so it can count 2m = 23 = 8 frames

Frames are numbered as 0,1,2,3,4,5,6,7

This time we choose size of window = 2m – 1 = 7Entire window is transmitted i.e. frames from 0,1,….6

All Frames were received correctly but their acknowledgements were lost

Next expected frame by the receiver is frame-7

Sender retransmits frame-0

Since receiver has already received frame-0 and is expecting frame-7

So receiver detects the duplicate frame and rightfully discards it

Go-Back-N ARQ

Event

Sender Window Size

Seq_No of First Outstanding Frame

SW = 2

SF = 0

RequestToSend

Seq_No of Next Frame to be transmitted

SN = 0

DataFrame Sn = 0

Frame Sn = 0

SN = 1

Frame Sn = 1

Frame Sn = 1

SN = 2

SW = 2m – 1

SF = 0

SN = 0

While ( true ) {

WaitForEvent( );

If Event ( RequestToSend )

{

If ( SN – SF >= SW )

Sleep ( )

Get Data ( );

Make Frame ( SN );

Store Frame ( SN );

Send Frame ( SN );

SN = SN + 1

If ( Timer Not Running )

Start Timer( )

}

Frame Ackn = 1

Sender Window Size

Seq_No of First Outstanding Frame

SW = 2

SF = 0

Seq_No of Next Frame to be transmitted

SN = 0SN = 1SN = 2

Frame Sn = 0

Frame Sn = 1

Event

Arrival Notification

Frame Sn = 0

Frame Sn = 1

SF = 1

If Event( Arrival Notification( ) )

{

Receive Frame ( AckN );If ( Corrupted Acknowledgement )

Sleep ( );

If ( Ack No > SF and Ack No <= SN )

While ( SF < Ack No )

{

Purge Frame(SF )

SF = SF + 1

}

Stop Timer ( )

}

Sender Window Size

Seq_No of First Outstanding Frame

SW = 2

SF = 0

Seq_No of Next Frame to be transmitted

SN = 0SN = 1SN = 2

Frame Sn = 0

Frame Sn = 1

Event

Time Out

Frame Sn = 0

Frame Sn = 1

Temp = 0Temp = 1Temp = 2

If Event( Time Out ) {

Start Timer( );

Temp = SF

While ( Temp < SN )

{

Send Frame( Temp )

Temp = Temp + 1

}

}

}

Go-Back-N ARQ

Event

Sequence Number

Frame Sn = 0

Rn = 0

Arrival Notification

Event

Sequence Number

Frame Sn = 0

Rn = 0

Arrival Notification

Rn = 1

Frame Ackn = 1Data

Frame Sn = 0

RN = 0;

While ( true ) {WaitForEvent( );

If Event( Arrival Notification ) {Receive Frame ( );

If ( Frame is Corrupted )

Sleep ( );

If ( Sn = Rn ) {

Extract Data ( );

Deliver Data ( );

Rn = Rn + 1

}

Send Acknowledgement ( Rn );

}

}

Selective Repeat ARQ

Assignment