Download presentation
Presentation is loading. Please wait.
Published byGertrude Cunningham Modified over 8 years ago
1
Network Transport Layer: Transport Reliability: Sliding Windows; Connection Management; TCP Y. Richard Yang http://zoo.cs.yale.edu/classes/cs433/ 3/9/2016
2
Admin.: PS4 proj-sol: 129 400 3045 FishThread.java 388 1457 12873 Node.java 51 167 1145 PingRequest.java 83 250 2106 SimpleTCPSockSpace.java 181 605 5248 TCPManager.java 889 3088 26381 TCPSock.java 60 149 1316 TCPSockID.java 123 382 3866 TransferClient.java 147 500 5059 TransferServer.java 2051 6998 61039 total 2 proj: 129 400 3045 FishThread.java 341 1301 11313 Node.java 51 167 1145 PingRequest.java 50 128 909 TCPManager.java 132 460 3146 TCPSock.java 123 382 3866 TransferClient.java 147 500 5059 TransferServer.java 973 3338 28483 total
3
3 Recap: Reliable Data Transfer send side receive side rdt_send(): called from above, (e.g., by app.) udt_send(): called by rdt, to transfer packet over unreliable channel to receiver rdt_rcv(): called from below; when packet arrives on rcv-side of channel deliver_data(): called by rdt to deliver data to upper
4
4 Recap: Potential Channel Errors r bit errors r loss (drop) of packets r reordering or duplication Characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt).
5
5 Recap: rdt3.0 Sender (Bit Error/Loss) sndpkt = make_pkt(0, data, checksum) udt_send(sndpkt) start_timer rdt_send(data) Wait for ACK0 rdt_rcv(rcvpkt) && ( corrupt(rcvpkt) || isACK(rcvpkt,1) ) Wait for call 1 from above sndpkt = make_pkt(1, data, checksum) udt_send(sndpkt) start_timer rdt_send(data) rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && isACK(rcvpkt,0) rdt_rcv(rcvpkt) && ( corrupt(rcvpkt) || isACK(rcvpkt,0) ) rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && isACK(rcvpkt,1) stop_timer udt_send(sndpkt) start_timer timeout udt_send(sndpkt) start_timer timeout rdt_rcv(rcvpkt) Wait for call 0 from above Wait for ACK1 rdt_rcv(rcvpkt)
6
6 rdt3.0 in Action Question to think about: What is a good timeout value?
7
7 rdt3.0 in Action
8
rdt3.0 sender data 0 (n-1) receiver data 0 (n-1) ACK for 0 (n-1) data 1 (n) waiting for 0 (n-1) sending 0 (n-1) waiting for 1 (n) sending 1 (n) waiting for 0 (n+1) ACK for 0 (n-1) State consistency: When receiver’s state is waiting n, the state of the sender is either sending for n-1 or sending for n When sender’s state is sending for n, receiver’s state is waiting for n or n + 1
9
rdt3.0: Stop-and-Wait Performance first packet bit transmitted, t = 0 senderreceiver RTT last packet bit transmitted, t = L / R first packet bit arrives last packet bit arrives, send ACK ACK arrives, send next packet, t = RTT + L / R What is U sender : utilization – fraction of time sender busy sending? Assume: 1 Gbps link, 15 ms e-e prop. delay, 1KB packet
10
10 Performance of rdt3.0 r rdt3.0 works, but performance stinks r Example: 1 Gbps link, 15 ms e-e prop. delay, 1KB packet: T transmit = 8kb/pkt 10**9 b/sec = 8 microsec m 1KB pkt every 30 msec -> 33kB/sec thruput over 1 Gbps link m network protocol limits use of physical resources ! L (packet length in bits) R (transmission rate, bps) =
11
A Summary of Questions How to improve the performance of rdt3.0? r What if there are reordering and duplication? r How to determine the “right” timeout value?
12
Sliding Window Protocols: Pipelining Pipelining: sender allows multiple, “in-flight”, yet-to-be- acknowledged pkts m range of sequence numbers must be increased m buffering at sender and/or receiver r Two generic forms of pipelined protocols: go-Back-N, selective repeat
13
13 Pipelining: Increased Utilization first packet bit transmitted, t = 0 senderreceiver RTT last bit transmitted, t = L / R first packet bit arrives last packet bit arrives, send ACK ACK arrives, send next packet, t = RTT + L / R last bit of 2 nd packet arrives, send ACK last bit of 3 rd packet arrives, send ACK increase utilization by a factor of 3! Question: a rule-of-thumb window size?
14
14 Go-Back-n Sender: r k-bit seq # in pkt header r “window” of up to W, consecutive unack’ed pkts allowed r ACK(n): ACKs all pkts up to, including seq # n - “cumulative ACK” m note: ACK(n) could mean two things: I have received upto and include n, or I am waiting for n r timer for the packet at base r timeout(n): retransmit pkt n and all higher seq # pkts in window W
15
15 GBN: Sender FSM Wait start_timer udt_send(sndpkt[base]) udt_send(sndpkt[base+1]) … udt_send(sndpkt[nextseqnum-1]) timeout rdt_send(data) if (nextseqnum < base+W) { sndpkt[nextseqnum] = make_pkt(nextseqnum,data,chksum) udt_send(sndpkt[nextseqnum]) if (base == nextseqnum) start_timer nextseqnum++ } else block sender if (new packets ACKed) { advance base; if (more packets waiting) send more packets } if (base == nextseqnum) stop_timer else start_timer for the packet at new base rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) base=1 nextseqnum=1 rdt_rcv(rcvpkt) && corrupt(rcvpkt)
16
16 GBN: Receiver FSM Only state: expectedseqnum r out-of-order pkt: m discard (don’t buffer) -> no receiver buffering! m re-ACK pkt with highest in-order seq # m may generate duplicate ACKs Wait udt_send(sndpkt) default rdt_rcv(rcvpkt) && notcurrupt(rcvpkt) && hasseqnum(rcvpkt,expectedseqnum) extract(rcvpkt,data) deliver_data(data) sndpkt = make_pkt(expectedseqnum,ACK,chksum) udt_send(sndpkt) expectedseqnum++ expectedseqnum=1 sndpkt = make_pkt(expectedseqnum,ACK,chksum)
17
17 GBN in Action window size = 4
18
18 Analysis: Efficiency of Go-Back-n r Assume window size W r Assume each packet is lost with probability p r On average, how many packets do we send for each data packet received?
19
19 Selective Repeat r Sender window m Window size W: W consecutive unACKed seq #’s r Receiver individually acknowledges correctly received pkts m buffers out-of-order pkts, for eventual in-order delivery to upper layer m ACK(n) means received packet with seq# n only m buffer size at receiver: window size r Sender only resends pkts for which ACK not received o sender timer for each unACKed pkt
20
20 Selective Repeat: Sender, Receiver Windows W W
21
21 Selective Repeat data from above : r unACKed packets is less than window size W, send; otherwise block app. timeout(n): r resend pkt n, restart timer ACK(n) in [sendbase,sendbase+W-1]: r mark pkt n as received r update sendbase to the first packet unACKed sender pkt n in [rcvbase, rcvbase+W-1] r send ACK(n) r if (out-of-order) mark and buffer pkt n else /*in-order*/ deliver any in-order packets otherwise: r ignore receiver
22
22 Selective Repeat in Action
23
23 Discussion: Efficiency of Selective Repeat r Assume window size W r Assume each packet is lost with probability p r On average, how many packets do we send for each data packet received?
24
24 State Invariant: Window Location m Go-back-n (GBN) m Selective repeat (SR) sender window receiver window sender window receiver window
25
25 Window Location m Go-back-n (GBN) m Selective repeat (SR) sender window receiver window sender window receiver window Q: what relationship between seq # size and window size?
26
26 Selective Repeat: Seq# Ambiguity Example: r seq #’s: 0, 1, 2, 3 r window size=3 r incorrectly passes duplicate data as new in (a)
27
27 Sliding Window Protocols: Go-back-n and Selective Repeat Go-back-nSelective Repeat data bandwidth: sender to receiver (avg. number of times a pkt is transmitted) ACK bandwidth (receiver to sender) Relationship between M (the number of seq#) and W (window size) Buffer size at receiver Complexity p: the loss rate of a packet; M: number of seq# (e.g., 3 bit M = 8); W: window size More efficient Less efficient M > W M ≥ 2W 1 W Simpler More complex Less efficientMore efficient
28
28 Question: What is Initial Seq#? sender receiver ACK for 0 accept data 0
29
29 Question: What is Initial Seq#? sender receiver ACK for 0 (n) accept data 0 (transfer $1000 to B) accept?
30
30 Outline r Review Reliable data transfer o perfect channel o channel with bit errors o channel with bit errors and losses o sliding window: reliability with throughput connection management
31
31 Three Way Handshake (TWH) [Tomlinson 1975] Host A SYN(seq=x) Host B ACK(seq=x), SYN(seq=y) ACK(seq=y) DATA(seq=x+1) SYN: indicates connection setup accept data only after verified y is bounced back x is the init. seq notify initial seq#. Accept? think of y as a challenge
32
32 Scenarios with Duplicate Request/SYN Attack Host A Host B ACK(seq=x), SYN(seq=y) REJECT(seq=y) SYN(seq=x) accept? no such request reject
33
33 Scenarios with Duplicate Request/SYN Attack Host A Host B ACK(seq=x), SYN(seq=y) REJECT(seq=y) SYN(seq=x) accept? no such request reject ACK(seq=z)
34
34 Make “Challenge y” Robust r To avoid that “SYNC ACK y” comes from reordering and duplication m for each connection (sender-receiver pair), ensuring that two identically numbered packets are never outstanding at the same time network bounds the life time of each packet a sender will not reuse a seq# before it is sure that all packets with the seq# are purged from the network seq. number space should be large enough to not limit transmission rate
35
35 Connection Close r Why connection close? m so that each side can release resource and remove state about the connection (do not want dangling socket) client server I am done. Are you done too? I am done too. Goodbye! init. close close release resource? release resource? release resource?
36
36 General Case: The Two-Army Problem The gray (blue) armies need to agree on whether or not they will attack the white army. They achieve agreement by sending messengers to the other side. If they both agree, attack; otherwise, no. Note that a messenger can be captured!
37
37 Four Way Teardown Host A FIN Host B ACK FIN close closed all states removed timed wait - can retransmit the ACKif its ACK is lost closed A->B closed all states removed propose close A->B propose close B->A
38
38 A Summary of Questions How to improve the performance of rdt3.0? ü sliding window protocols r What if there are duplication and reordering? ü network guarantee: max packet life time ü transport guarantee: not reuse a seq# before life time ü seq# management and connection management r How to determine the “right” parameters?
39
39 Outline r Recap r Reliable data transfer TCP reliability
40
40 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r Point-to-point reliability: one sender, one receiver r Flow controlled and congestion controlled
41
41 Evolution of TCP Source: http://webcourse.cs.technion.ac.il/236341/Winter2015-2016/ho/WCFiles/Tutorial10.pdf
42
42 Evolution of TCP Source: http://webcourse.cs.technion.ac.il/236341/Winter2015-2016/ho/WCFiles/Tutorial10.pdf multiple versions
43
43 TCP Reliable Data Transfer r Connection-oriented: m connection management setup (exchange of control msgs) init’s sender, receiver state before data exchange close r Full duplex data: m bi-directional data flow in same connection r A sliding window protocol m a combination of go-back-n and selective repeat: send & receive buffers cumulative acks TCP uses a single retransmission timer do not retransmit all packets upon timeout
44
44 TCP Segment Structure source port # dest port # 32 bits application data (variable length) sequence number acknowledgement number rcvr window size ptr urgent data checksum F SR PAU head len not used Options (variable length) RST, SYN, FIN: connection management (reset, setup teardown commands) flow control ACK: ACK # valid counting by bytes of data (not segments!) Also in UDP URG: urgent data (generally not used) PSH: push data now (generally not used)
45
45 Flow Control r receive side of a connection has a receive buffer: r speed-matching service: matching the send rate to the receiving app’s drain rate r app process may be slow at reading from buffer sender won’t overflow receiver’s buffer by transmitting too much, too fast flow control
46
46 TCP Flow Control: How it Works spare room in buffer = RcvWindow source port # dest port # application data (variable length) sequence number acknowledgement number rcvr window size ptr urgent data checksum F SR PAU head len not used Options (variable length)
47
47 TCP Seq. #’s and ACKs Seq. #’s: m byte stream “number” of first byte in segment’s data ACKs: m seq # of next byte expected from other side m cumulative ACK Host A Host B Seq=42, ACK=79, data = ‘C’ Seq=79, ACK=43, data = ‘C’ Seq=42, ACK=80 User types ‘C’ host ACKs receipt of echoed ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ time simple telnet scenario
48
48 Fast Retransmit r Problem: Timeout period often relatively long: m long delay before resending lost packet r If sender receives 3 ACKs for the same data, it supposes that segment after ACKed data was lost: m resend segment before timer expires r Detect lost segments via duplicate ACKs m sender often sends many segments back-to-back m if segment is lost, there will likely be many duplicate ACKs
49
49 Triple Duplicate Ack 1 23456 Packets Acknowledgements (waiting seq#) 7 2344 4 4
50
50 event: ACK received, with ACK field value of y if (y > SendBase) { … SendBase = y if (there are currently not-yet-acknowledged segments) start timer … } else { increment count of dup ACKs received for y if (count of dup ACKs received for y = 3) { resend segment with sequence number y … Fast Retransmit: a duplicate ACK for already ACKed segment fast retransmit
51
51 TCP: reliable data transfer 00 sendbase = initial_sequence number agreed by TWH 01 nextseqnum = initial_sequence number by TWH 02 loop (forever) { 03 switch(event) 04 event: data received from application above 05 if (window allows send) 06 create TCP segment with sequence number nextseqnum 06 if (no timer) start timer 07 pass segment to IP 08 nextseqnum = nextseqnum + length(data) else put packet in buffer 09 event: timer timeout for sendbase 10 retransmit segment 11 compute new timeout interval 12 restart timer 13 event: ACK received, with ACK field value of y 14 if (y > sendbase) { /* cumulative ACK of all data up to y */ 15 cancel the timer for sendbase 16 sendbase = y 17 if (no timer and packet pending) start timer for new sendbase 17 while (there are segments and window allow) 18 sent a segment; 18 } 19 else { /* y==sendbase, duplicate ACK for already ACKed segment */ 20 increment number of duplicate ACKs received for y 21 if (number of duplicate ACKS received for y == 3) { 22 /* TCP fast retransmit */ 23 resend segment with sequence number y 24 restart timer for segment y 25 } 26 } /* end of loop forever */ Simplified TCP sender
52
52 TCP Receiver ACK Generation [RFC 1122, RFC 2581] Event at Receiver Arrival of in-order segment with expected seq #. All data up to expected seq # already ACKed Arrival of in-order segment with expected seq #. One other segment has ACK pending Arrival of out-of-order segment higher-than-expect seq. #. Gap detected Arrival of segment that partially or completely fills gap TCP Receiver Action Delayed ACK. Wait up to 500ms for next segment. If no next segment, send ACK Immediately send single cumulative ACK, ACKing both in-order segments Immediately send duplicate ACK, indicating seq. # of next expected byte Immediate send ACK, provided that segment starts at lower end of gap
53
53 %netstat -t -a CLOSED LISTEN SYN RCVD SYN SYN/ACK ACK CLOSED SYN SENT ESTABLSIHED FIN ACK FIN WAIT 1 ESTABLSIHED CLOSE WAIT FIN LAST ACK FIN WAIT 2 TIME WAIT
54
54 TCP Connection Management TCP lifecycle: init SYN/FIN CLOSED SYN RCVD SYN SYN/ACK ACK CLOSED SYN SENT ESTABLSIHED FIN ACK FIN WAIT 1 ESTABLSIHED CLOSE WAIT FIN LAST ACK FIN WAIT 2 TIME WAIT http://dsd.lbl.gov/TCP-tuning/ip-sysctl-2.6.txt
55
55 TCP Connection Management TCP lifecycle: wait for SYN/FIN CLOSED SYN RCVD SYN SYN/ACK ACK CLOSED SYN SENT ESTABLSIHED FIN ACK FIN WAIT 1 ESTABLSIHED CLOSE WAIT FIN LAST ACK FIN WAIT 2 TIME WAIT
56
56 A Summary of Questions How to improve the performance of rdt3.0? ü sliding window protocols r What if there are duplication and reordering? ü network guarantee: max packet life time ü transport guarantee: not reuse a seq# before life time ü seq# management and connection management r How to determine the “right” parameters?
57
57
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.