CS 4470 Computer Networking Protocols 15 TCP 2

  • Slides: 28
Download presentation
CS 4470 Computer Networking Protocols 15. TCP 2 Huiping Guo Department of Computer Science

CS 4470 Computer Networking Protocols 15. TCP 2 Huiping Guo Department of Computer Science California State University, Los Angeles

Outline r Principles of reliable transfer r Stop and wait r Go back N

Outline r Principles of reliable transfer r Stop and wait r Go back N 15. TCP 2 CS 4470 15 -2

Principles of reliable transfer r Errors m m A segment is corrupted A segment

Principles of reliable transfer r Errors m m A segment is corrupted A segment is lost r Automatic retransmission request (ARQ) m When errors occur, the receiver sends a message to the sender asking for retransmission r Types of ARQ m m Stop and wait Sliding window (Go back N) 15. TCP 2 CS 4470 15 -3

A trivial reliable transfer protocol r Assumption m A segment may be corrupted. m

A trivial reliable transfer protocol r Assumption m A segment may be corrupted. m NO segment gets lost r Sender m Sends a segment m Waits for the acknowledgement for the segment m If the acknowledgement is positive • Sends the next segment m If the acknowledgement is negative • Resends the segment 15. TCP 2 CS 4470 15 -4

A trivial reliable transfer protocol r Receiver m Receives a segment m Is the

A trivial reliable transfer protocol r Receiver m Receives a segment m Is the segment corrupted? • Yes. Sends a negative acknowledgement (NAK) asking for retransmission • No. Sends a positive acknowledgement (ACK). Waits for the next segment 15. TCP 2 CS 4470 15 -5

Problems with this protocol What happens if ACK/NAK is corrupted? r sender doesn’t know

Problems with this protocol What happens if ACK/NAK is corrupted? r sender doesn’t know what happened at receiver! r A possible approach m m m The sender just simply resends the segment. This causes possible duplicate segments • The receiver cannot tell whether the received segment is the re-transmitted segment or a new segment A solution to this problem • Add a field sequence number(1 bit) to the segment header • The receiver only need to check the sequence number to determine whether or not the received segment is a retransmission. 15. TCP 2 CS 4470 15 -6

Stop-and-Wait Protocol v 1 r Characteristics m Use 1 bit sequence number m A

Stop-and-Wait Protocol v 1 r Characteristics m Use 1 bit sequence number m A NAK free protocol • The receiver always sends positive acknowledgements • ACK 0: Seg 1 is correctly received, waiting for seg 0 • ACK 1: Seg 0 is correctly received, waiting for seg 1 15. TCP 2 CS 4470 15 -7

Stop-and-Wait Protocol v 1(cont. ) Sender: Sender keeps track of the sequence number k

Stop-and-Wait Protocol v 1(cont. ) Sender: Sender keeps track of the sequence number k (0, 1) of the current segment being sent out 1. 2. 3. Sender sends out a segment k If the sender receives ACK k, go to step 1 If the sender receives ACK k+1 , k=k+1 mod 2, go to step 1 15. TCP 2 CS 4470 15 -8

Stop-and-Wait Protocol v 1 (cont. ) Receiver: keeps track of the sequence number of(0,

Stop-and-Wait Protocol v 1 (cont. ) Receiver: keeps track of the sequence number of(0, 1) of the next expected segment 1. Receiver is expecting segment k 2. Receiver receives a segment. 3. If the sequence number of the segment is not k, discards the segment , sends ack k, go to step 1 4. If sequence number is k and the segment is OK, sends ACK k=k+1 mod 2 to the sender, go to step 1 5. If segment k is corrupted, sends ACK k 6. Go to step 1 15. TCP 2 CS 4470 15 -9

Stop-and-Wait v 1 Examples Receiver Sends seg 0 ACK 1 Receives ack 1 Sends

Stop-and-Wait v 1 Examples Receiver Sends seg 0 ACK 1 Receives ack 1 Sends seg 1 Receives seg 0 Sends ack 1 Sends seg 0 Receives seg 1 Sends ack 0 Receives ack 1 Sends seg 1 seg 0 ACK 1 ACK 0 Receives ack 0 Sends seg 0 Receiver Sender seg 1 ACK 1 seg 0 Receives ack 1 resends seg 1 Receives seg 1 Seg 1 has errors Sends ack 1 seg 1 b. With a seg corrupted a. Without erros 15. TCP 2 Receives seg 0 Sends ack 1 CS 4470 15 -10

Stop-and-Wait v 1 Examples (cont. ) Receiver Sender seg 0 Sends seg 0 ACK

Stop-and-Wait v 1 Examples (cont. ) Receiver Sender seg 0 Sends seg 0 ACK 1 Receives ack 1 Sends seg 1 Receives seg 0 Sends ack 1 Receives seg 1 Sends ack 0 ACK 0 Ack 0 is corrupted resends seg 1 ACK 0 Receives seg 1, discards it Sends ack 0 c. With an ack corrupted 15. TCP 2 CS 4470 15 -11

Stop-and-Wait Protocol v 2 r Stop-and-wait protocol v 1 only works if there is

Stop-and-Wait Protocol v 2 r Stop-and-wait protocol v 1 only works if there is no data loss. r What if there is data loss? m m A segment may be lost An ACK may be lost r Stop-and-wait protocol v 2 m Works with data errors AND data loss 15. TCP 2 CS 4470 15 -12

Stop-and-Wait Protocol v 2 (cont. ) Approach: sender waits “reasonable” amount of time for

Stop-and-Wait Protocol v 2 (cont. ) Approach: sender waits “reasonable” amount of time for ACK r retransmits if no ACK received in this time r if segments(or ACKs) are just delayed (not lost): m m retransmission will be duplicate, but use of seq. #’s already handles this receiver must specify seq # of seg being ACKed r requires countdown timer 15. TCP 2 CS 4470 15 -13

Stop-and-Wait examples Sender Sends seg 0 ACK 1 Receives ack 1 Sends seg 1

Stop-and-Wait examples Sender Sends seg 0 ACK 1 Receives ack 1 Sends seg 1 Receives seg 0 Sends ack 1 Receives seg 1 Sends ack 0 Receiver Sender Receiver Sends seg 0 ACK 1 Receives ack 1 Sends seg 1 Receives seg 0 Sends ack 1 seg 1 X loss ACK 0 Receives ack 0 Sends seg 0 timeout resends seg 1 a. Without errors 15. TCP 2 seg 1 Receives seg 1 Sends ack 0 b. segment loss CS 4470 15 -14

Stop-and-Wait examples Sender Receiver Sender seg 0 Sends seg 0 Receives seg 0 Sends

Stop-and-Wait examples Sender Receiver Sender seg 0 Sends seg 0 Receives seg 0 Sends ack 1 ACK 1 Receives ack 1 Sends seg 1 ACK 0 c. Ack loss seg 0 ACK 1 Receives ack 1 Sends seg 1 Receives seg 1 Sends ack 0 ACK 0 lost timeout Resends seg 1 Sends seg 0 Receiver seg 1 Receives seg 1 Sends ack 0 ACK 0 Timeout Resends seg 1 Receives ack 0 seg 0 Sends seg 0 Receives ack 0 ACK 0 Receives seg 1 Resends seg 0 ACK 1 Sends ack 0 seg 0 Receives ack 1 seg 1 Sends seg 1 15. TCP 2 Receives seg 0 Sends ack 1 Receives seg 1 Discards it Sends ack 0 Receives seg 0 Sends ack 1 d. Premature timeout CS 4470 15 -15

Pros and Cons of Stop-and-wait r Pros m m Stop-and-wait is a complete reliable

Pros and Cons of Stop-and-wait r Pros m m Stop-and-wait is a complete reliable transfer protocol It’s very simple r Cons m m Inefficient While the sender is waiting for an ACK, it doesn’t do anything. r Why not the sender sends multiple segments at a time? m Need more than 1 bits for the sequence number. 15. TCP 2 CS 4470 15 -16

RTT and transmission delay r Definition of RTT: m time to send a small

RTT and transmission delay r Definition of RTT: m time to send a small segment to travel from sender to receiver and back. r Transmission delay m m m R=link bandwidth (bps) L=segment length (bits) time to send bits into link = L/R r Total delay m RTT+L/R 15. TCP 2 CS 4470 15 -17

RTT and transmission delay first segment bit transmitted, t = 0 first segment bit

RTT and transmission delay first segment bit transmitted, t = 0 first segment bit arrives RTT ACK arrives, send next segment, t = RTT + L / R 15. TCP 2 CS 4470 15 -18

Performance of stop-and-wait sender receiver first segment bit transmitted, t = 0 last packet

Performance of stop-and-wait sender receiver first segment bit transmitted, t = 0 last packet bit transmitted, t = L / R first segment bit arrives last packet bit arrives, send ACK RTT ACK arrives, send next segment, t = RTT + L / R 15. TCP 2 CS 4470 15 -19

Increased utilization sender receiver first segment bit transmitted, t = last bit transmitted, t

Increased utilization sender receiver first segment bit transmitted, t = last bit transmitted, t = L / R 0 first segment bit arrives last segment bit arrives, send ACK last bit of 2 nd segment arrives, send ACK last bit of 3 rd frame arrives, send ACK RTT ACK arrives, send next segment, t = RTT + L / R Increase utilization by a factor of 3! 15. TCP 2 CS 4470 15 -20

Go-Back-N r Based on a sliding window r Use window to control number of

Go-Back-N r Based on a sliding window r Use window to control number of segments to send m Number of segments that the sender can send • N-(nextseqnum – send_base) 15. TCP 2 CS 4470 15 -21

Go-Back-N r Cumulative ACKs m ACK (n): ACKs all segments up to, including seq

Go-Back-N r Cumulative ACKs m ACK (n): ACKs all segments up to, including seq # n - 1 r Timer m m Only one timer is used. The timer is for the oldest transmitted, yet un-acked segment 15. TCP 2 CS 4470 15 -22

Go-back-N: sender r Needs to send segments m m If the window is full,

Go-back-N: sender r Needs to send segments m m If the window is full, wait until it’s not full If the window is not full, sends out as many segment as allowed, adjusts nextsegnum r Receive an ACK for un-acked segments m m m Slide the window forward by the number of acked segments Start the timer Adjust send_base r Timerout m m Re-transmit all un-acked segments in the window Start the timer 15. TCP 2 CS 4470 15 -23

Go-back-N: receiver r Waits for seg k m Receives seg k, sends ack k+1

Go-back-N: receiver r Waits for seg k m Receives seg k, sends ack k+1 m Receives, seg k+1, discards it and sends ack k m Receives seg k-1, discards it and sends ack k 15. TCP 2 CS 4470 15 -24

ACK 1 Go-back-N example ACK 2 ACK 1 ACK 2 The window size is

ACK 1 Go-back-N example ACK 2 ACK 1 ACK 2 The window size is 4 ACK 2 ACK 3 ACK 4 15. TCP 2 CS 4470 15 -25

Exercise r Consider a sender sends 7 segments to a receiver. The RTT between

Exercise r Consider a sender sends 7 segments to a receiver. The RTT between the sender and the receiver is 2 ms. m m The transmission time of each segment is 0. 2 ms. The timeout value is 3 ms. r In each of the following cases, how long does it take for sender to transfer the 7 segments? (time between sending out the first segment and receiving the ack of the last segment). a) Stop-and-wait protocol is used. b) Go-Back-N protocol is used. The window size is 4. The 2 nd and the 5 th segment are lost during the first transmission. r For each case, draw a diagram that shows the interaction between the sender and receiver. You also need to provide the information about which segment is sent and the ACK number. 15. TCP 2 CS 4470 15 -26

For each segment, it takes 2+0. 2=2. 2 to send and receive the ack,

For each segment, it takes 2+0. 2=2. 2 to send and receive the ack, so the total time is 7 x 2. 2 =15. 4 ms 15. TCP 2 CS 4470 7 -27

15. TCP 2 CS 4470 8 -28

15. TCP 2 CS 4470 8 -28