Скачать презентацию Chapter 3 Transport Layer last revised 23 03 04 Chapter Скачать презентацию Chapter 3 Transport Layer last revised 23 03 04 Chapter

4e1da9bd2c75f1385b19097354555c36.ppt

  • Количество слайдов: 125

Chapter 3: Transport Layer last revised 23/03/04 Chapter goals: Chapter Overview: r understand principles Chapter 3: Transport Layer last revised 23/03/04 Chapter goals: Chapter Overview: r understand principles r transport layer services behind transport layer services: r multiplexing/demultiplexing r connectionless transport: UDP multiplexing/demultiplex r principles of reliable data ing transfer m reliable data transfer r connection-oriented transport: m flow control TCP m congestion control m reliable transfer r instantiation and m flow control implementation in the m connection management Internet m r principles of congestion control r TCP congestion control Comp 361, Spring 2004 3: Transport Layer 1

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 2

Transport services and protocols r provide logical communication network data link physical al ic Transport services and protocols r provide logical communication network data link physical al ic d en d- en network data link physical po s an tr rt Comp 361, Spring 2004 network data link physical g lo between app processes running on different hosts r transport protocols run in end systems m send side: breaks app messages into segments, passes to network layer m rcv side: reassembles segments into messages, passes to app layer r more than one transport protocol available to apps m Internet: TCP and UDP application transport network data link physical 3: Transport Layer 3

Transport vs. network layer r network layer: logical communication between hosts r transport layer: Transport vs. network layer r network layer: logical communication between hosts r transport layer: logical communication between processes m relies on, enhances, network layer services Comp 361, Spring 2004 Household analogy: 12 kids sending letters to 12 kids r processes = kids r app messages = letters in envelopes r hosts = houses r transport protocol = Ann and Bill r network-layer protocol = postal service 3: Transport Layer 4

Transport-layer protocols Comp 361, Spring 2004 network data link physical rt m network data Transport-layer protocols Comp 361, Spring 2004 network data link physical rt m network data link physical po m real-time bandwidth guarantees reliable multicast s an m network data link physical tr unordered unicast or multicast delivery: UDP r services not available: d en d- r unreliable (“best-effort”), en m al m congestion flow control connection setup network data link physical ic m application transport network data link physical g lo Internet transport services: r reliable, in-order unicast delivery (TCP) application transport network data link physical 3: Transport Layer 5

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 6

Multiplexing/demultiplexing Multiplexing at send host: gathering data from multiple sockets, enveloping data with header Multiplexing/demultiplexing Multiplexing at send host: gathering data from multiple sockets, enveloping data with header (later used for demultiplexing) Demultiplexing at rcv host: delivering received segments to correct socket = socket application = process P 3 transport network link P 1 application transport network P 2 P 4 application transport network link physical host 1 Comp 361, Spring 2004 physical host 2 physical host 3 3: Transport Layer 7

Multiplexing/demultiplexing segment - unit of data exchanged between transport layer entities m aka TPDU: Multiplexing/demultiplexing segment - unit of data exchanged between transport layer entities m aka TPDU: transport protocol data unit application-layer data segment header segment Ht M Hn segment P 1 M application transport network Comp 361, Spring 2004 Demultiplexing: delivering received segments to correct app layer processes P 3 receiver M M application transport network P 4 M P 2 application transport network 3: Transport Layer 8

How demultiplexing works r host receives IP datagrams each datagram has source IP address, How demultiplexing works r host receives IP datagrams each datagram has source IP address, destination IP address m each datagram carries 1 transport-layer segment m each segment has source, destination port number (recall: well-known port numbers for specific applications) r host uses IP addresses & port numbers to direct segment to appropriate socket m Comp 361, Spring 2004 32 bits source port # dest port # other header fields application data (message) TCP/UDP segment format 3: Transport Layer 9

Connectionless demultiplexing r Create sockets with port numbers: Datagram. Socket my. Socket 1 = Connectionless demultiplexing r Create sockets with port numbers: Datagram. Socket my. Socket 1 = new Datagram. Socket(99111); Datagram. Socket my. Socket 2 = new Datagram. Socket(99222); r UDP socket identified by two-tuple: (dest IP address, dest port number) Comp 361, Spring 2004 r When host receives UDP segment: m m checks destination port number in segment directs UDP segment to socket with that port number r IP datagrams with different source IP addresses and/or source port numbers directed to same socket 3: Transport Layer 10

Connectionless demux (cont) Datagram. Socket server. Socket = new Datagram. Socket(6428); P 3 SP: Connectionless demux (cont) Datagram. Socket server. Socket = new Datagram. Socket(6428); P 3 SP: 6428 DP: 9157 SP: 6428 DP: 5775 SP: 9157 client IP: A P 1 P 3 DP: 6428 server IP: C SP: 5775 DP: 6428 Client IP: B SP provides “return address” Comp 361, Spring 2004 3: Transport Layer 11

Connection-oriented demux r TCP socket identified by 4 -tuple: m m source IP address Connection-oriented demux r TCP socket identified by 4 -tuple: m m source IP address source port number dest IP address dest port number r recv host uses all four values to direct segment to appropriate socket Comp 361, Spring 2004 r Server host may support many simultaneous TCP sockets: m each socket identified by its own 4 -tuple r Web servers have different sockets for each connecting client m non-persistent HTTP will have different socket for each request 3: Transport Layer 12

Connection-oriented demux (cont) P 3 SP: 80 DP: 9157 client IP: A SP: 9157 Connection-oriented demux (cont) P 3 SP: 80 DP: 9157 client IP: A SP: 9157 DP: 80 Comp 361, Spring 2004 P 1 P 4 SP: 80 DP: 5775 server IP: C SP: 5775 DP: 80 Client IP: B 3: Transport Layer 13

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 14

UDP: User Datagram Protocol r “no frills, ” “bare bones” Internet transport protocol r UDP: User Datagram Protocol r “no frills, ” “bare bones” Internet transport protocol r “best effort” service, UDP segments may be: m lost m delivered out of order to app r connectionless: m no handshaking between UDP sender, receiver m each UDP segment handled independently of others Comp 361, Spring 2004 [RFC 768] Why is there a UDP? r no connection establishment (which can add delay) r simple: no connection state at sender, receiver r small segment header (8 Bytes) r no congestion control: UDP can blast away as fast as desired 3: Transport Layer 15

UDP: more r often used for streaming multimedia apps m loss tolerant m rate UDP: more r often used for streaming multimedia apps m loss tolerant m rate sensitive Length, in bytes of UDP segment, r other UDP uses (why? ): including header m DNS: small delay SNMP: stressful cond. r reliable transfer over UDP: add reliability at application layer m application-specific error recover! m Comp 361, Spring 2004 32 bits source port # dest port # length checksum Application data (message) UDP segment format 3: Transport Layer 16

UDP checksum Goal: detect “errors” (e. g. , flipped bits) in transmitted segment Sender: UDP checksum Goal: detect “errors” (e. g. , flipped bits) in transmitted segment Sender: r treat segment contents as sequence of 16 -bit integers r checksum: addition (1’ s complement sum) of segment contents r sender puts checksum value into UDP checksum field Comp 361, Spring 2004 Receiver: r compute checksum of received segment r check if computed checksum equals checksum field value: m NO - error detected m YES - no error detected. But maybe errors nonetheless? More later. . r Receiver may choose to discard segment or send a warning to app in case error 3: Transport Layer 17

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 18

Principles of Reliable data transfer r important in app. , transport, link layers r Principles of Reliable data transfer r important in app. , transport, link layers r top-10 list of important networking topics! r characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt) Comp 361, Spring 2004 3: Transport Layer 19

Reliable data transfer: getting started rdt_send(): called from above, (e. g. , by app. Reliable data transfer: getting started rdt_send(): called from above, (e. g. , by app. ). Passed data to deliver to receiver upper layer send side udt_send(): called by rdt, to transfer packet over unreliable channel to receiver Comp 361, Spring 2004 deliver_data(): called by rdt to deliver data to upper receive side rdt_rcv(): called when packet arrives on rcv-side of channel 3: Transport Layer 20

Reliable data transfer: getting started We’ll: r incrementally develop sender, receiver sides of reliable Reliable data transfer: getting started We’ll: r incrementally develop sender, receiver sides of reliable data transfer protocol (rdt) r consider only unidirectional data transfer m but control info will flow on both directions! r use finite state machines (FSM) to specify sender, receiver state: when in this “state” next state uniquely determined by next event Comp 361, Spring 2004 state 1 event causing state transition actions taken on state transition event actions state 2 3: Transport Layer 21

Incremental Improvements r rdt 1. 0: assumes every packet sent arrives, and no errors Incremental Improvements r rdt 1. 0: assumes every packet sent arrives, and no errors introduced in transmission r rdt 2. 0: assumes every packet sent arrives, but some errors (bit flips) can occur within a packet. Introduces concept of ACK and NAK r rdt 2. 1: deals with corrupted ACKS/NAKS r rdt 2. 2: like rdt 2. 1 but does not need NAKs r Rdt 3. 0: Allows packets to be lost Comp 361, Spring 2004 3: Transport Layer 22

Rdt 1. 0: reliable transfer over a reliable channel r underlying channel perfectly reliable Rdt 1. 0: reliable transfer over a reliable channel r underlying channel perfectly reliable m no bit errors m no loss of packets r separate FSMs for sender, receiver: m sender sends data into underlying channel m receiver read data from underlying channel Wait for call from above rdt_send(data) packet = make_pkt(data) udt_send(packet) sender Comp 361, Spring 2004 Wait for call from below rdt_rcv(packet) extract (packet, data) deliver_data(data) receiver 3: Transport Layer 23

Rdt 2. 0: channel with bit errors r underlying channel may flip bits in Rdt 2. 0: channel with bit errors r underlying channel may flip bits in packet m recall: UDP checksum to detect bit errors r the question: how to recover from errors: m acknowledgements (ACKs): receiver explicitly tells sender that pkt received OK m negative acknowledgements (NAKs): receiver explicitly tells sender that pkt had errors m sender retransmits pkt on receipt of NAK m human scenarios using ACKs, NAKs? r new mechanisms in rdt 2. 0 (beyond rdt 1. 0): m m error detection receiver feedback: control msgs (ACK, NAK) rcvr->sender Comp 361, Spring 2004 3: Transport Layer 24

rdt 2. 0: FSM specification rdt_send(data) snkpkt = make_pkt(data, checksum) udt_send(sndpkt) rdt_rcv(rcvpkt) && is. rdt 2. 0: FSM specification rdt_send(data) snkpkt = make_pkt(data, checksum) udt_send(sndpkt) rdt_rcv(rcvpkt) && is. NAK(rcvpkt) Wait for call from ACK or udt_send(sndpkt) above NAK rdt_rcv(rcvpkt) && is. ACK(rcvpkt) L sender receiver rdt_rcv(rcvpkt) && corrupt(rcvpkt) udt_send(NAK) Wait for call from below rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) extract(rcvpkt, data) deliver_data(data) udt_send(ACK) Comp 361, Spring 2004 3: Transport Layer 25

rdt 2. 0: operation with no errors rdt_send(data) snkpkt = make_pkt(data, checksum) udt_send(sndpkt) rdt_rcv(rcvpkt) rdt 2. 0: operation with no errors rdt_send(data) snkpkt = make_pkt(data, checksum) udt_send(sndpkt) rdt_rcv(rcvpkt) && is. NAK(rcvpkt) Wait for call from ACK or udt_send(sndpkt) above NAK rdt_rcv(rcvpkt) && is. ACK(rcvpkt) L rdt_rcv(rcvpkt) && corrupt(rcvpkt) udt_send(NAK) Wait for call from below rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) extract(rcvpkt, data) deliver_data(data) udt_send(ACK) Comp 361, Spring 2004 3: Transport Layer 26

rdt 2. 0: error scenario rdt_send(data) snkpkt = make_pkt(data, checksum) udt_send(sndpkt) rdt_rcv(rcvpkt) && is. rdt 2. 0: error scenario rdt_send(data) snkpkt = make_pkt(data, checksum) udt_send(sndpkt) rdt_rcv(rcvpkt) && is. NAK(rcvpkt) Wait for call from ACK or udt_send(sndpkt) above NAK rdt_rcv(rcvpkt) && is. ACK(rcvpkt) L rdt_rcv(rcvpkt) && corrupt(rcvpkt) udt_send(NAK) Wait for call from below rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) extract(rcvpkt, data) deliver_data(data) udt_send(ACK) Comp 361, Spring 2004 3: Transport Layer 27

rdt 2. 0 has a fatal flaw! What happens if ACK/NAK corrupted? r sender rdt 2. 0 has a fatal flaw! What happens if ACK/NAK corrupted? r sender doesn’t know what happened at receiver! r can’t just retransmit: possible duplicate. But receiver waiting! What to do? r sender ACKs/NAKs receiver’s ACK/NAK? What if sender ACK/NAK corrupted? r retransmit, but this might cause retransmission of correctly received pkt! r Receiver won’t know about duplication! Comp 361, Spring 2004 Handling duplicates: r sender adds sequence number (0/1) to each pkt r sender retransmits current pkt if ACK/NAK garbled r receiver discards (doesn’t deliver up) duplicate pkt r Duplicate packet is one with same sequence # as previous packet stop and wait Sender sends one packet, then waits for receiver response 3: Transport Layer 28

r Sender: whenever sender receives control message it sends a packet to receiver. m r Sender: whenever sender receives control message it sends a packet to receiver. m A valid ACK: Sends next packet (if exists) with new sequence # m A NAK or corrupt response: resends old packet r Receiver: sends ACK/NAK to sender m If received packet is corrupt: send NAK m If received packet is valid and has different sequence # as prev packet: send ACK and deliver new data up. m If received packet is valid and has same sequence # as prev packet, i. e. , is a retransmission of duplicate: send ACK r Note: ACK/NAK do not contain sequence #. Comp 361, Spring 2004 3: Transport Layer 29

rdt 2. 1: sender, handles garbled ACK/NAKs rdt_send(data) sndpkt = make_pkt(0, data, checksum) udt_send(sndpkt) rdt 2. 1: sender, handles garbled ACK/NAKs rdt_send(data) sndpkt = make_pkt(0, data, checksum) udt_send(sndpkt) rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && is. ACK(rcvpkt) Wait for call 0 from above rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && is. ACK(rcvpkt) L rdt_rcv(rcvpkt) && ( corrupt(rcvpkt) || is. NAK(rcvpkt) ) udt_send(sndpkt) Comp 361, Spring 2004 ( corrupt(rcvpkt) || is. NAK(rcvpkt) ) udt_send(sndpkt) Wait for ACK or NAK 0 L Wait for ACK or NAK 1 Wait for call 1 from above rdt_send(data) sndpkt = make_pkt(1, data, checksum) udt_send(sndpkt) 3: Transport Layer 30

rdt 2. 1: receiver, handles garbled ACK/NAKs rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && has_seq 0(rcvpkt) rdt_rcv(rcvpkt) rdt 2. 1: receiver, handles garbled ACK/NAKs rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && has_seq 0(rcvpkt) rdt_rcv(rcvpkt) && (corrupt(rcvpkt) extract(rcvpkt, data) deliver_data(data) sndpkt = make_pkt(ACK, chksum) udt_send(sndpkt) rdt_rcv(rcvpkt) && (corrupt(rcvpkt) sndpkt = make_pkt(NAK, chksum) udt_send(sndpkt) rdt_rcv(rcvpkt) && not corrupt(rcvpkt) && has_seq 1(rcvpkt) sndpkt = make_pkt(ACK, chksum) udt_send(sndpkt) sndpkt = make_pkt(NAK, chksum) udt_send(sndpkt) Wait for 0 from below Wait for 1 from below rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && has_seq 1(rcvpkt) rdt_rcv(rcvpkt) && not corrupt(rcvpkt) && has_seq 0(rcvpkt) sndpkt = make_pkt(ACK, chksum) udt_send(sndpkt) extract(rcvpkt, data) deliver_data(data) sndpkt = make_pkt(ACK, chksum) udt_send(sndpkt) Comp 361, Spring 2004 3: Transport Layer 31

rdt 2. 1: discussion Sender: r seq # added to pkt r two seq. rdt 2. 1: discussion Sender: r seq # added to pkt r two seq. #’s (0, 1) will suffice. Why? r must check if received ACK/NAK corrupted r twice as many states m state must “remember” whether “current” pkt has 0 or 1 seq. # Comp 361, Spring 2004 Receiver: r must check if received packet is duplicate m state indicates whether 0 or 1 is expected pkt seq # r note: receiver can not know if its last ACK/NAK received OK at sender 3: Transport Layer 32

rdt 2. 2: a NAK-free protocol r same functionality as rdt 2. 1, using rdt 2. 2: a NAK-free protocol r same functionality as rdt 2. 1, using ACKs only r instead of NAK, receiver sends ACK for last pkt received OK m receiver must explicitly include seq # of pkt being ACKed r duplicate ACK at sender results in same action as NAK: retransmit current pkt Comp 361, Spring 2004 3: Transport Layer 33

rdt 2. 2: sender, receiver fragments rdt_send(data) sndpkt = make_pkt(0, data, checksum) udt_send(sndpkt) rdt_rcv(rcvpkt) rdt 2. 2: sender, receiver fragments rdt_send(data) sndpkt = make_pkt(0, data, checksum) udt_send(sndpkt) rdt_rcv(rcvpkt) && Wait for call 0 from above rdt_rcv(rcvpkt) && (corrupt(rcvpkt) || has_seq 1(rcvpkt)) udt_send(sndpkt) Wait for 0 from below ( corrupt(rcvpkt) || is. ACK(rcvpkt, 1) ) udt_send(sndpkt) Wait for ACK 0 sender FSM fragment rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && is. ACK(rcvpkt, 0) receiver FSM fragment L rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && has_seq 1(rcvpkt) Comp 361, Spring 2004 extract(rcvpkt, data) deliver_data(data) sndpkt = make_pkt(ACK 1, chksum) udt_send(sndpkt) 3: Transport Layer 34

rdt 3. 0: channels with errors and loss New assumption: underlying channel can also rdt 3. 0: channels with errors and loss New assumption: underlying channel can also lose packets (data or ACKs) m checksum, seq. #, ACKs, retransmissions will be of help, but not enough Q: how to deal with loss? m m sender waits until certain data or ACK lost, then retransmits yuck: drawbacks? Comp 361, Spring 2004 Approach: sender waits “reasonable” amount of time for ACK r retransmits if no ACK received in this time r if pkt (or ACK) just delayed (not lost): m retransmission will be duplicate, but use of seq. #’s already handles this m receiver must specify seq # of pkt being ACKed r requires countdown timer 3: Transport Layer 35

rdt 3. 0 sender rdt_send(data) sndpkt = make_pkt(0, data, checksum) udt_send(sndpkt) start_timer rdt_rcv(rcvpkt) L rdt 3. 0 sender rdt_send(data) sndpkt = make_pkt(0, data, checksum) udt_send(sndpkt) start_timer rdt_rcv(rcvpkt) L rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && is. ACK(rcvpkt, 1) rdt_rcv(rcvpkt) && ( corrupt(rcvpkt) || is. ACK(rcvpkt, 0) ) Comp 361, Spring 2004 timeout udt_send(sndpkt) start_timer rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) && is. ACK(rcvpkt, 0) stop_timer timeout udt_send(sndpkt) start_timer L Wait for ACK 0 Wait for call 0 from above L rdt_rcv(rcvpkt) && ( corrupt(rcvpkt) || is. ACK(rcvpkt, 1) ) Wait for ACK 1 Wait for call 1 from above rdt_send(data) rdt_rcv(rcvpkt) L sndpkt = make_pkt(1, data, checksum) udt_send(sndpkt) start_timer 3: Transport Layer 36

rdt 3. 0 in action Comp 361, Spring 2004 3: Transport Layer 37 rdt 3. 0 in action Comp 361, Spring 2004 3: Transport Layer 37

rdt 3. 0 in action Comp 361, Spring 2004 3: Transport Layer 38 rdt 3. 0 in action Comp 361, Spring 2004 3: Transport Layer 38

Performance of rdt 3. 0 r rdt 3. 0 works, but performance stinks r Performance of rdt 3. 0 r rdt 3. 0 works, but performance stinks r example: 1 Gbps link, 15 ms e-e prop. delay, 1 KB packet: Ttransmit = m m m L (packet length in bits) 8 kb/pkt = = 8 microsec R (transmission rate, bps) 10**9 b/sec U sender: utilization – fraction of time sender busy sending 1 KB pkt every 30 msec -> 33 k. B/sec thruput over 1 Gbps link network protocol limits use of physical resources! Comp 361, Spring 2004 3: Transport Layer 39

rdt 3. 0: stop-and-wait operation sender receiver first packet bit transmitted, t = 0 rdt 3. 0: stop-and-wait operation sender receiver first packet bit transmitted, t = 0 last packet bit transmitted, t = L / R RTT first packet bit arrives last packet bit arrives, send ACK arrives, send next packet, t = RTT + L / R Comp 361, Spring 2004 3: Transport Layer 40

Pipelined protocols Pipelining: sender allows multiple, “in-flight”, yet-to-be-acknowledged pkts m range of sequence numbers Pipelined protocols 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 Comp 361, Spring 2004 3: Transport Layer 41

Pipelined protocols r Advantage: much better bandwidth utilization than stop-and-wait r Disadvantage: More complicated Pipelined protocols r Advantage: much better bandwidth utilization than stop-and-wait r Disadvantage: More complicated to deal with reliability issues, e. g. , corrupted, lost, out of order data. m Two generic approaches to solving this • go-Back-N protocols • selective repeat protocols r Note: TCP is not exactly either Comp 361, Spring 2004 3: Transport Layer 42

Pipelining: increased utilization sender receiver first packet bit transmitted, t = 0 last bit Pipelining: increased utilization sender receiver first packet bit transmitted, t = 0 last bit transmitted, t = L / R RTT first packet bit arrives last packet bit arrives, send ACK last bit of 2 nd packet arrives, send ACK last bit of 3 rd packet arrives, send ACK arrives, send next packet, t = RTT + L / R Increase utilization by a factor of 3! Comp 361, Spring 2004 3: Transport Layer 43

Go-Back-N Sender: r k-bit seq # in pkt header r “window” of up to Go-Back-N Sender: r k-bit seq # in pkt header r “window” of up to N, consecutive unack’ed pkts allowed r ACK(n): ACKs all pkts up to, including seq # n - “cumulative ACK” may receive duplicate ACKs (see receiver) r Only one timer: for oldest unacknowledged pkt r timeout(n): retransmit pkt n and all higher seq # pkts in window r Called a sliding-window protocol m Comp 361, Spring 2004 3: Transport Layer 44

GBN: Sender r rdt_Send() called: checks to see if window is full. m No: GBN: Sender r rdt_Send() called: checks to see if window is full. m No: send out packet m Yes: return data to application level r Receipt of ACK(n): cumulative acknowledgement that all packets up to and including n have been received. Updates window accordingly. r Timeout: resends ALL packets that have been sent but not yet acknowledged. Comp 361, Spring 2004 3: Transport Layer 45

GBN: sender extended FSM rdt_send(data) L base=1 nextseqnum=1 if (nextseqnum < base+N) { sndpkt[nextseqnum] GBN: sender extended FSM rdt_send(data) L base=1 nextseqnum=1 if (nextseqnum < base+N) { sndpkt[nextseqnum] = make_pkt(nextseqnum, data, chksum) udt_send(sndpkt[nextseqnum]) if (base == nextseqnum) start_timer nextseqnum++ } else refuse_data(data) Wait rdt_rcv(rcvpkt) && corrupt(rcvpkt) timeout start_timer udt_send(sndpkt[base]) udt_send(sndpkt[base+1]) … udt_send(sndpkt[nextseqnum-1]) rdt_rcv(rcvpkt) && notcorrupt(rcvpkt) base = getacknum(rcvpkt)+1 If (base == nextseqnum) stop_timer else start_timer Comp 361, Spring 2004 3: Transport Layer 46

GBN: receiver extended FSM default udt_send(sndpkt) L expectedseqnum=1 sndpkt = make_pkt(0, ACK, chksum) Wait GBN: receiver extended FSM default udt_send(sndpkt) L expectedseqnum=1 sndpkt = make_pkt(0, ACK, chksum) Wait rdt_rcv(rcvpkt) && notcurrupt(rcvpkt) && hasseqnum(rcvpkt, expectedseqnum) extract(rcvpkt, data) deliver_data(data) sndpkt = make_pkt(expectedseqnum, ACK, chksum) udt_send(sndpkt) expectedseqnum++ r If expected packet received: m Send ACK and deliver packet upstairs r If out-of-order packet received: m discard (don’t buffer) -> no receiver buffering! m Re-ACK pkt with highest in-order seq # m may generate duplicate ACKs Comp 361, Spring 2004 3: Transport Layer 47

More on receiver r The receiver always sends ACK for last correctly received packet More on receiver r The receiver always sends ACK for last correctly received packet with highest inorder seq # r Receiver only sends ACKS (no NAKs) r Can generate duplicate ACKs r need only remember expectedseqnum Comp 361, Spring 2004 3: Transport Layer 48

GBN in action Comp 361, Spring 2004 3: Transport Layer 49 GBN in action Comp 361, Spring 2004 3: Transport Layer 49

GBN is easy to code but might have performance problems. In particular, if many GBN is easy to code but might have performance problems. In particular, if many packets are in pipeline at one time (bandwidth-delay product large) then one error can force retransmission of huge amounts of data! Selective Repeat protocol allows receiver to buffer data and only forces retransmission of required packets. Comp 361, Spring 2004 3: Transport Layer 50

Selective Repeat r receiver individually acknowledges all correctly received pkts m buffers pkts, as Selective Repeat r receiver individually acknowledges all correctly received pkts m buffers pkts, as needed, for eventual in-order delivery to upper layer r sender only resends pkts for which ACK not received m m sender timer for each un. ACKed pkt Compare to GBN which only had timer for base packet r sender window m N consecutive seq #’s m again limits seq #s of sent, un. ACKed pkts m Important: Window size < seq # range Comp 361, Spring 2004 3: Transport Layer 51

Selective repeat: sender, receiver windows Comp 361, Spring 2004 3: Transport Layer 52 Selective repeat: sender, receiver windows Comp 361, Spring 2004 3: Transport Layer 52

Selective repeat sender data from above : receiver pkt n in [rcvbase, rcvbase+N-1] r Selective repeat sender data from above : receiver pkt n in [rcvbase, rcvbase+N-1] r if next available seq # in r send ACK(n) timeout(n): r in-order: deliver (also window, send pkt r resend pkt n, restart timer ACK(n) in [sendbase, sendbase+N]: r mark pkt n as received r if n smallest un. ACKed pkt, advance window base to next un. ACKed seq # r out-of-order: buffer deliver buffered, in-order pkts), advance window to next not-yet-received pkt n in [rcvbase-N, rcvbase-1] r ACK(n) (note this is a re. ACK) otherwise: r ignore Comp 361, Spring 2004 3: Transport Layer 53

Selective repeat in action Comp 361, Spring 2004 3: Transport Layer 54 Selective repeat in action Comp 361, Spring 2004 3: Transport Layer 54

Selective repeat: dilemma Example: r seq #’s: 0, 1, 2, 3 r window size=3 Selective repeat: dilemma Example: r seq #’s: 0, 1, 2, 3 r window size=3 r receiver sees no difference in two scenarios! r incorrectly passes duplicate data as new in (a) Q: what is relationship between seq # size and window size? Comp 361, Spring 2004 3: Transport Layer 55

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 56

TCP: Overview r point-to-point: m one sender, one receiver r reliable, in-order byte steam: TCP: Overview r point-to-point: m one sender, one receiver r reliable, in-order byte steam: m no “message boundaries” r pipelined: m TCP congestion and flow control set window size r send & receive buffers Comp 361, Spring 2004 RFCs: 793, 1122, 1323, 2018, 2581 r full duplex data: m bi-directional data flow in same connection m MSS: maximum segment size r connection-oriented: m handshaking (exchange of control msgs) init’s sender, receiver state before data exchange r flow controlled: m sender will not overwhelm receiver 3: Transport Layer 57

More TCP Details r Maximum Segment Size (MSS) m Depends upon implementation (can often More TCP Details r Maximum Segment Size (MSS) m Depends upon implementation (can often be set) m The Max amount of application-layer data in segment r Application Data + TCP Header = TCP Segment r Three way Handshake m Client sends special TCP segment to server requesting connection. No payload (Application data) in this segment. m Server responds with second special TCP segment (again no payload) m Client responds with third special segment This can contain payload Comp 361, Spring 2004 3: Transport Layer 58

Even More TCP Details r A TCP connection between client and server creates, in Even More TCP Details r A TCP connection between client and server creates, in both client and server (i) buffers m (ii) variables and m (iii) a socket connection to process. m r TCP only exists in the two end machines. No buffers and variables allocated to the connection in any of the network elements between the host and server. Comp 361, Spring 2004 3: Transport Layer 59

TCP segment structure 32 bits URG: urgent data (generally not used) ACK: ACK # TCP segment structure 32 bits URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now (generally not used) RST, SYN, FIN: connection estab (setup, teardown commands) Internet checksum (as in UDP) Comp 361, Spring 2004 source port # dest port # sequence number acknowledgement number head not UA P R S F len used checksum Receive window Urg data pnter Options (variable length) counting by bytes of data (not segments!) # bytes rcvr willing to accept application data (variable length) 3: Transport Layer 60

TCP seq. #’s and ACKs Seq. #’s: m byte stream “number” of first byte 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 Q: how receiver handles out-of-order segments m A: TCP spec doesn’t say, - up to implementer Comp 361, Spring 2004 Host B Host A User types ‘C’ Seq=4 2, ACK = 79, da ta ta = 3, da 4 K= 9, AC eq=7 S host ACKs receipt of echoed ‘C’ = ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ Seq=4 3, ACK =80 simple telnet scenario time 3: Transport Layer 61

TCP Round Trip Time and Timeout Q: how to set TCP timeout value? r TCP Round Trip Time and Timeout Q: how to set TCP timeout value? r longer than RTT m but RTT varies r too short: premature timeout m unnecessary retransmissions r too long: slow reaction to segment loss Comp 361, Spring 2004 Q: how to estimate RTT? r Sample. RTT: measured time from segment transmission until ACK receipt m ignore retransmissions r Sample. RTT will vary, want estimated RTT “smoother” m average several recent measurements, not just current Sample. RTT 3: Transport Layer 62

TCP Round Trip Time and Timeout Estimated. RTT = (1 - )*Estimated. RTT + TCP Round Trip Time and Timeout Estimated. RTT = (1 - )*Estimated. RTT + *Sample. RTT r Exponential weighted moving average r influence of past sample decreases exponentially fast r typical value: = 0. 125 Comp 361, Spring 2004 3: Transport Layer 63

Example RTT estimation: Comp 361, Spring 2004 3: Transport Layer 64 Example RTT estimation: Comp 361, Spring 2004 3: Transport Layer 64

TCP Round Trip Time and Timeout Setting the timeout r Estimted. RTT plus “safety TCP Round Trip Time and Timeout Setting the timeout r Estimted. RTT plus “safety margin” m large variation in Estimated. RTT -> larger safety margin r first estimate of how much Sample. RTT deviates from Estimated. RTT: Dev. RTT = (1 - )*Dev. RTT + *|Sample. RTT-Estimated. RTT| (typically, = 0. 25) Then set timeout interval: Timeout. Interval = Estimated. RTT + 4*Dev. RTT Comp 361, Spring 2004 3: Transport Layer 65

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 66

TCP reliable data transfer r TCP creates rdt service on top of IP’s unreliable TCP reliable data transfer r TCP creates rdt service on top of IP’s unreliable service r Pipelined segments r Cumulative acks r TCP uses single retransmission timer Comp 361, Spring 2004 r Retransmissions are triggered by: m m timeout events duplicate acks r Initially consider simplified TCP sender: m m ignore duplicate acks ignore flow control, congestion control 3: Transport Layer 67

TCP sender events: data rcvd from app: r Create segment with seq # r TCP sender events: data rcvd from app: r Create segment with seq # r seq # is byte-stream number of first data byte in segment r start timer if not already running (think of timer as for oldest unacked segment) r expiration interval: Time. Out. Interval Comp 361, Spring 2004 timeout: r retransmit segment that caused timeout r restart timer Ack rcvd: r If acknowledges previously unacked segments m m update what is known to be acked start timer if there are outstanding segments 3: Transport Layer 68

Next. Seq. Num = Initial. Seq. Num Send. Base = Initial. Seq. Num loop Next. Seq. Num = Initial. Seq. Num Send. Base = Initial. Seq. Num loop (forever) { switch(event) event: data received from application above create TCP segment with sequence number Next. Seq. Num if (timer currently not running) start timer pass segment to IP Next. Seq. Num = Next. Seq. Num + length(data) event: timer timeout retransmit not-yet-acknowledged segment with smallest sequence number start timer event: ACK received, with ACK field value of y if (y > Send. Base) { Send. Base = y if (there are currently not-yet-acknowledged segments) start timer } TCP sender (simplified) Comment: • Send. Base-1: last cumulatively ack’ed byte Example: • Send. Base-1 = 71; y= 73, so the rcvr wants 73+ ; y > Send. Base, so that new data is acked } /* end of loop forever */ Comp 361, Spring 2004 3: Transport Layer 69

TCP: retransmission scenarios Host A 2, 8 by tes da t Seq=92 timeout a TCP: retransmission scenarios Host A 2, 8 by tes da t Seq=92 timeout a =100 X ACK loss Seq=9 2, 8 by tes da ta 100 Sendbase = 100 Send. Base = 120 = ACK Send. Base = 100 time Send. Base = 120 lost ACK scenario Comp 361, Spring 2004 Host B Seq=9 2, 8 by Seq= 100, 2 tes da ta 0 byte s data 00 =1 20 CK CK=1 A A Seq=92 timeout Seq=9 timeout Host A Host B time 2, 8 by tes da ta 20 K=1 AC premature timeout 3: Transport Layer 70

TCP retransmission scenarios (more) Host A Host B Seq=9 timeout 2, 8 by Seq=1 TCP retransmission scenarios (more) Host A Host B Seq=9 timeout 2, 8 by Seq=1 tes da ta 100 CK= A 00, 20 bytes data X loss 120 Send. Base = 120 = ACK time Cumulative ACK scenario Comp 361, Spring 2004 3: Transport Layer 71

TCP ACK generation [RFC 1122, RFC 2581] Event at Receiver TCP Receiver action Arrival TCP ACK generation [RFC 1122, RFC 2581] Event at Receiver TCP Receiver action Arrival of in-order segment with expected seq #. All data up to expected seq # already ACKed Delayed ACK. Wait up to 500 ms for next segment. If no next segment, send ACK Arrival of in-order segment with expected seq #. One other segment has ACK pending Immediately send single cumulative ACK, ACKing both in-order segments Arrival of out-of-order segment higher-than-expect seq. #. Gap detected Immediately send duplicate ACK, indicating seq. # of next expected byte Arrival of segment that partially or completely fills gap Immediate send ACK, provided that segment starts at lower end of gap Comp 361, Spring 2004 3: Transport Layer 72

More on Sender Policies r Doubling the Timeout Interval m Used by most TCP More on Sender Policies r Doubling the Timeout Interval m Used by most TCP implementations m If timeout occurs then, after retransmisison, Timeout Interval is doubled m Intervals grow exponentially with each consecutive timeout m When Timer restarted because of (i) new data from above or (ii) ACK received, then Timeout Interval is reset as described previously using Estimated RTT and Dev. RTT. m Limited form of Congestion Control Comp 361, Spring 2004 3: Transport Layer 73

Fast Retransmit r Time-out period often relatively long: m long delay before resending lost Fast Retransmit r Time-out period often relatively long: m long delay before resending lost packet r Detect lost segments via duplicate ACKs. m m Sender often sends many segments back-toback If segment is lost, there will likely be many duplicate ACKs. Comp 361, Spring 2004 r If sender receives 3 ACKs for the same data, it supposes that segment after ACKed data was lost: m fast retransmit: resend segment before timer expires 3: Transport Layer 74

Fast retransmit algorithm: event: ACK received, with ACK field value of y if (y Fast retransmit algorithm: event: ACK received, with ACK field value of y if (y > Send. Base) { Send. Base = 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 } a duplicate ACK for already ACKed segment Comp 361, Spring 2004 fast retransmit 3: Transport Layer 75

TCP: GBN or Selective Repeat? r Basic TCP looks a lot like GBN r TCP: GBN or Selective Repeat? r Basic TCP looks a lot like GBN r Many TCP implementations will buffer received out-of-order segments and then ACK them all after filling in the range m This looks a lot like Selective Repeat r TCP is a hybrid Comp 361, Spring 2004 3: Transport Layer 76

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 77

TCP Flow Control r Sender should not overwhelm receiver’s capacity to receive data r TCP Flow Control r Sender should not overwhelm receiver’s capacity to receive data r If necessary, sender should slow down transmission rate to accommodate receiver’s rate. r Different from Congestion Control whose purpose was to handle congestion in network. (But both congestion control and flow control work by slowing down data transmission) Comp 361, Spring 2004 3: Transport Layer 78

TCP Flow Control r receive side of TCP connection has a receive buffer: flow TCP Flow Control r receive side of TCP connection has a receive buffer: flow control sender won’t overflow receiver’s buffer by transmitting too much, too fast r speed-matching r app process may be service: matching the send rate to the receiving app’s drain rate slow at reading from buffer Comp 361, Spring 2004 3: Transport Layer 79

TCP segment structure 32 bits URG: urgent data (generally not used) ACK: ACK # TCP segment structure 32 bits URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now (generally not used) RST, SYN, FIN: connection estab (setup, teardown commands) Internet checksum (as in UDP) Comp 361, Spring 2004 source port # dest port # sequence number acknowledgement number head not UA P R S F len used checksum Receive window Urg data pnter Options (variable length) counting by bytes of data (not segments!) # bytes rcvr willing to accept application data (variable length) 3: Transport Layer 80

TCP Flow control: how it works r Rcvr advertises spare (Suppose TCP receiver discards TCP Flow control: how it works r Rcvr advertises spare (Suppose TCP receiver discards out-of-order segments) r spare room in buffer room by including value of Rcv. Window in segments r Sender limits un. ACKed data to Rcv. Window m guarantees receive buffer doesn’t overflow = Rcv. Window = Rcv. Buffer-[Last. Byte. Rcvd Last. Byte. Read] Comp 361, Spring 2004 3: Transport Layer 81

Technical Issue r Suppose Rcv. Window=0 and that receiver has already ACK’d ALL packets Technical Issue r Suppose Rcv. Window=0 and that receiver has already ACK’d ALL packets in buffer r Sender does not transmit new packets until it hears Rcv. Window>0. r Receiver never sends Rcv. Window>0 since it has no new ACKS to send to Sender r DEADLOCK r Solution: TCP specs require sender to continue sending packets with one data byte while Rcv. Window=0, just to keep receiving ACKS from B. At some point the receiver’s buffer will empty and Rcv. Window>0 will be transmitted back to sender. Comp 361, Spring 2004 3: Transport Layer 82

Note on UDP has no flow control! UDP appends packets to receiving socket’s buffer. Note on UDP has no flow control! UDP appends packets to receiving socket’s buffer. If buffer is full then packets are lost! Comp 361, Spring 2004 3: Transport Layer 83

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 84

TCP Connection Management Recall: TCP sender, receiver establish “connection” before exchanging data segments r TCP Connection Management Recall: TCP sender, receiver establish “connection” before exchanging data segments r initialize TCP variables: m seq. #s m buffers, flow control info (e. g. Rcv. Window) r client: connection initiator Socket client. Socket = new Socket("hostname", "port number"); r server: contacted by client Socket connection. Socket = welcome. Socket. accept(); Three way handshake: Step 1: client end system sends TCP SYN control segment to server m specifies client_isn, the initial seq # m No application data Step 2: server end system receives SYN, replies with SYNACK control segment m ACKs received SYN m allocates buffers m Replies with client_isn+1 in ACK field to signal synchronization m Specifies server_isn m Comp 361, Spring 2004 No application data 3: Transport Layer 85

TCP Connection Management (cont. ) Step 3: client end system receives SYNACK, replies with TCP Connection Management (cont. ) Step 3: client end system receives SYNACK, replies with SYN=0 and server_isn+1 m client server Conne ction r eques t (SYN =1 seq =c lient_is Allocate buffers m Can include application data isn, Allocates buffers m SYN=0 signals that connection established server_isn+1 signals that # is synchronized Comp 361, Spring 2004 n) ver_ , ser 1 YN= d (S rante ng n+1) nt_is clie ack= ctio onne C ACK ( SYN= 0, ack=s seq=c li erver_ is ent_is n+1) n+1 3: Transport Layer 86

TCP Connection Management (cont. ) Closing a connection: client closes socket: client. Socket. close(); TCP Connection Management (cont. ) Closing a connection: client closes socket: client. Socket. close(); client close Step 1: client end system Comp 361, Spring 2004 close FIN timed wait FIN, replies with ACK. Closes connection, sends FIN ACK sends TCP FIN control segment to server Step 2: server receives server ACK closed 3: Transport Layer 87

TCP Connection Management (cont. ) client Step 3: client receives FIN, m m Enters TCP Connection Management (cont. ) client Step 3: client receives FIN, m m Enters “timed wait” – during which will respond with ACK to received FINs (that might arrive if ACK gets lost). Closes down after timedwait Step 4: server, receives ACK. Connection closed. Note: with small modification, closing FIN ACK closing FIN timed wait replies with ACK. server ACK closed can handle simultaneous FINs. Comp 361, Spring 2004 3: Transport Layer 88

TCP Connection Management (cont) Example. TCP server lifecycle Example TCP client lifecycle Comp 361, TCP Connection Management (cont) Example. TCP server lifecycle Example TCP client lifecycle Comp 361, Spring 2004 3: Transport Layer 89

A few special cases r Have not discussed what happens if both client and A few special cases r Have not discussed what happens if both client and server decide to close down connection at same time. r It is possible that first ACK (from server) and second FIN (also from server) are sent in same segment Comp 361, Spring 2004 3: Transport Layer 90

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 91

Principles of Congestion Control Congestion: r informally: “too many sources sending too much data Principles of Congestion Control Congestion: r informally: “too many sources sending too much data too fast for network to handle” r different from flow control! r manifestations: m lost packets (buffer overflow at routers) m long delays (queuing in router buffers) r a top-10 problem! Comp 361, Spring 2004 3: Transport Layer 92

Causes/costs of congestion: scenario 1 r two senders, two receivers r one router, infinite Causes/costs of congestion: scenario 1 r two senders, two receivers r one router, infinite buffers r no retransmission r Send rate 0 -C/2 r large delays when congested r maximum achievable throughput Comp 361, Spring 2004 3: Transport Layer 93

Causes/costs of congestion: scenario 2 r one router, finite buffers r sender retransmission of Causes/costs of congestion: scenario 2 r one router, finite buffers r sender retransmission of lost packet Comp 361, Spring 2004 3: Transport Layer 94

r always: lin= lout (goodput) r Magic transmission; only send when there’s space in r always: lin= lout (goodput) r Magic transmission; only send when there’s space in buffer lin> lout retransmission of delayed (not lost) packet makes l larger (than in perfect case) for same lout r “perfect” retransmission only when loss: r “costs” of congestion: r more work (retrans) for given “goodput” r unneeded retransmissions: link carries multiple copies of pkt Comp 361, Spring 2004 3: Transport Layer 95

Causes/costs of congestion: scenario 3 r four senders r multihop paths r timeout/retransmit Comp Causes/costs of congestion: scenario 3 r four senders r multihop paths r timeout/retransmit Comp 361, Spring 2004 Q: what happens as l in and l increase ? in 3: Transport Layer 96

Causes/costs of congestion: scenario 3 Another “cost” of congestion: r when packet dropped, any Causes/costs of congestion: scenario 3 Another “cost” of congestion: r when packet dropped, any “upstream transmission capacity used for that packet wasted! Comp 361, Spring 2004 3: Transport Layer 97

Approaches towards congestion control Two broad approaches towards congestion control: End-end congestion control: r Approaches towards congestion control Two broad approaches towards congestion control: End-end congestion control: r no explicit feedback from network r congestion inferred from end-system observed loss, delay r approach taken by TCP Comp 361, Spring 2004 Network-assisted congestion control: r routers provide feedback to end systems m single bit indicating congestion (SNA, DECbit, TCP/IP ECN, ATM) m explicit rate sender should send at 3: Transport Layer 98

Case study: ATM ABR congestion control ABR: available bit rate: r “elastic service” r Case study: ATM ABR congestion control ABR: available bit rate: r “elastic service” r if sender’s path “underloaded”: m sender should use available bandwidth r if sender’s path congested: m sender throttled to minimum guaranteed rate RM (resource management) cells: r sent by sender, interspersed with data cells r bits in RM cell set by switches (“network-assisted”) m NI bit: no increase in rate (mild congestion) m CI bit: severe congestion indicator r RM cells returned to sender by receiver, with bits intact small exception – see next page Comp 361, Spring 2004 3: Transport Layer 99

Case study: ATM ABR congestion control r two-byte ER (explicit rate) field in RM Case study: ATM ABR congestion control r two-byte ER (explicit rate) field in RM cell m congested switch may lower ER value in cell m sender’s send rate thus minimum supportable rate on path r EFCI bit in data cells: set to 1 by congested switch m Signals congestion m if data cell preceding RM cell has EFCI=1, destination sets CI bit=1 before returning RM cell to source. Comp 361, Spring 2004 3: Transport Layer 100

Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing Chapter 3 outline r 3. 1 Transport-layer services r 3. 2 Multiplexing and demultiplexing r 3. 3 Connectionless transport: UDP r 3. 4 Principles of reliable data transfer Comp 361, Spring 2004 r 3. 5 Connection-oriented transport: TCP m m segment structure reliable data transfer flow control connection management r 3. 6 Principles of congestion control r 3. 7 TCP congestion control 3: Transport Layer 101

TCP Congestion Control r end-end control (no network assistance) r transmission rate limited by TCP Congestion Control r end-end control (no network assistance) r transmission rate limited by congestion window size, Congwin, over segments. Congwin dynamically modified to reflect perceived congestion. Congwin r w segments, each with MSS bytes sent in one RTT: throughput = Comp 361, Spring 2004 w * MSS Bytes/sec RTT 3: Transport Layer 102

r To simplify presentation we assume that Rcv. Buffer is large enough that it r To simplify presentation we assume that Rcv. Buffer is large enough that it will not overflow r Tools are “similar” to flow control. sender limits transmission using: Last. Byte. Sent-Last. Byte. Acked Cong. Win How does sender perceive congestion? r loss event = timeout or 3 duplicate acks r TCP sender reduces rate (Cong. Win) after loss event three mechanisms: m m m AIMD = Additive Increase Multiplicative Decrease slow start = Cong. Win set to 1 and then grows exponentially conservative after timeout events Comp 361, Spring 2004 3: Transport Layer 103

TCP AIMD multiplicative decrease: cut Cong. Win in half after loss event additive increase: TCP AIMD multiplicative decrease: cut Cong. Win in half after loss event additive increase: increase Cong. Win by 1 MSS every RTT in the absence of loss events: probing also known as congestion avoidance Long-lived TCP connection Comp 361, Spring 2004 3: Transport Layer 104

TCP Slow Start r When connection begins, Cong. Win = 1 MSS m m TCP Slow Start r When connection begins, Cong. Win = 1 MSS m m Example: MSS = 500 bytes & RTT = 200 msec initial rate = 20 kbps r When connection begins, increase rate exponentially fast until first loss event r available bandwidth may be >> MSS/RTT m desirable to quickly ramp up to respectable rate Comp 361, Spring 2004 3: Transport Layer 105

TCP Slow Start (more) r When connection m m double Cong. Win every RTT TCP Slow Start (more) r When connection m m double Cong. Win every RTT done by incrementing Cong. Win for every ACK received RTT begins, increase rate exponentially until first loss event: Host A Host B one segme nt two segme nts four segme nts r Summary: initial rate is slow but ramps up exponentially fast Comp 361, Spring 2004 time 3: Transport Layer 106

r So Far m Slow-Start: ramps up exponentially m Followed by AIMD: sawtooth pattern r So Far m Slow-Start: ramps up exponentially m Followed by AIMD: sawtooth pattern r Reality (TCP Reno) m Introduce new variable threshold m threshold initially very large m Slow-Start exponential growth stops when reaches threshold and then switches to AIMD m Two different types of loss events • 3 dup ACKS: cut Cong. Win in half and set threshold=Cong. Win (now in standard AIMD) • Timeout: set threshold=Cong. Win/2, Cong. Win=1 and switch to Slow-Start Comp 361, Spring 2004 3: Transport Layer 107

r Reason for treating 3 dup ACKS differently than timeout is that 3 dup r Reason for treating 3 dup ACKS differently than timeout is that 3 dup ACKs indicates network capable of delivering some segments while timeout before 3 dup ACKs is “more alarming”. r Note that older protocol, TCP Tahoe, treated both types of loss events the same and always goes to slowstart with Congwin=1 after a loss event. r TCP Reno’s skipping of the slow start for a 3 -DUP-ACK loss event is known as fast-recovery. Comp 361, Spring 2004 3: Transport Layer 108

Summary: TCP Congestion Control r When Cong. Win is below Threshold, sender in slow-start Summary: TCP Congestion Control r When Cong. Win is below Threshold, sender in slow-start phase, window grows exponentially. r When Cong. Win is above Threshold, sender is in congestion-avoidance phase, window grows linearly. r When a triple duplicate ACK occurs, Threshold set to Cong. Win/2 and Cong. Win set to Threshold. (only in TCP Reno) r When timeout occurs, Threshold set to Cong. Win/2 and Cong. Win is set to 1 MSS. (TCP Tahoe does this for 3 Dup Acks as well) Comp 361, Spring 2004 3: Transport Layer 109

The Big Picture Comp 361, Spring 2004 3: Transport Layer 110 The Big Picture Comp 361, Spring 2004 3: Transport Layer 110

TCP Fairness goal: if K TCP sessions share same bottleneck link of bandwidth R, TCP Fairness goal: if K TCP sessions share same bottleneck link of bandwidth R, each should have average rate of R/K TCP connection 1 TCP connection 2 Comp 361, Spring 2004 bottleneck router capacity R 3: Transport Layer 111

Why is TCP fair? Two competing sessions: r Additive increase gives slope of 1, Why is TCP fair? Two competing sessions: r Additive increase gives slope of 1, as throughout increases r multiplicative decreases throughput proportionally equal bandwidth share Connection 2 throughput R loss: decrease window by factor of 2 congestion avoidance: additive increase Connection 1 throughput R Comp 361, Spring 2004 3: Transport Layer 112

Fairness (more) Fairness and UDP r Multimedia apps often do not use TCP m Fairness (more) Fairness and UDP r Multimedia apps often do not use TCP m do not want rate throttled by congestion control r Instead use UDP: m pump audio/video at constant rate, tolerate packet loss r Current Research area: m How to keep UDP from congesting the internet. Comp 361, Spring 2004 Fairness and parallel TCP connections r nothing prevents app from opening parallel cnctions between 2 hosts. r Web browsers do this r Example: link of rate R supporting 9 cnctions; m m new app asks for 1 TCP, gets rate R/10 new app asks for 11 TCPs, gets R/2 ! 3: Transport Layer 113

TCP Latency Modeling Q: How long does it take to completely receive an object TCP Latency Modeling Q: How long does it take to completely receive an object from a Web server after sending a request? This is known as the latency of the (request for the) object. Ignoring congestion, delay is influenced by: r TCP connection establishment r data transmission delay r slow start Comp 361, Spring 2004 Notation, assumptions: r Assume one link between client and server of rate R r S: MSS (bits) r O: object size (bits) r no retransmissions (no loss, no corruption) Window size: r First assume: fixed congestion window, W segments r Then dynamic window, modeling slow start 3: Transport Layer 114

Fixed Congestion Window (W) Two cases 1. WS/R > RTT + S/R: ACK for Fixed Congestion Window (W) Two cases 1. WS/R > RTT + S/R: ACK for first segment in window returns before window’s worth of data sent Latency = 2 RTT + O/R 2. WS/R < RTT + S/R: ACK for first segment in window returns after window’s worth of data sent Latency = 2 RTT + O/R + (K-1)[S/R + RTT - WS/R] Comp 361, Spring 2004 3: Transport Layer 115

Fixed congestion window (1) First case: WS/R > RTT + S/R: ACK for first Fixed congestion window (1) First case: WS/R > RTT + S/R: ACK for first segment in window returns before window’s worth of data sent latency = 2 RTT + O/R Comp 361, Spring 2004 3: Transport Layer 116

Fixed congestion window (2) Second case: r WS/R < RTT + S/R: wait for Fixed congestion window (2) Second case: r WS/R < RTT + S/R: wait for ACK after sending window’s worth of data sent latency = 2 RTT + O/R + (K-1)[S/R + RTT - WS/R] Comp 361, Spring 2004 3: Transport Layer 117

TCP Latency Modeling: Slow Start (1) Now suppose window grows according to slow start TCP Latency Modeling: Slow Start (1) Now suppose window grows according to slow start (with no threshold and no loss events) Will show that the delay for one object is: where P is the number of times TCP idles at server: - where Q is the number of times the server idles if the object were of infinite size. - and K is the number of windows that cover the object. Comp 361, Spring 2004 3: Transport Layer 118

TCP Latency Modeling: Slow Start (2) Delay components: • 2 RTT for connection estab TCP Latency Modeling: Slow Start (2) Delay components: • 2 RTT for connection estab and request • O/R to transmit object • time server idles due to slow start Server idles: P = min{K-1, Q} times Example: • O/S = 15 segments • K = 4 windows • Q=2 • P = min{K-1, Q} = 2 Server idles P=2 times Comp 361, Spring 2004 3: Transport Layer 119

TCP Latency Modeling (3) Comp 361, Spring 2004 3: Transport Layer 120 TCP Latency Modeling (3) Comp 361, Spring 2004 3: Transport Layer 120

TCP Latency Modeling (4) Recall K = number of windows that cover object How TCP Latency Modeling (4) Recall K = number of windows that cover object How do we calculate K ? Calculation of Q, number of idles for infinite-size object, is similar. Comp 361, Spring 2004 3: Transport Layer 121

HTTP Modeling r Assume Web page consists of: 1 base HTML page (of size HTTP Modeling r Assume Web page consists of: 1 base HTML page (of size O bits) m M images (each of size O bits) r Non-persistent HTTP: m M+1 TCP connections in series m Response time = (M+1)O/R + (M+1)2 RTT + sum of idle times r Persistent HTTP: m 2 RTT to request and receive base HTML file m 1 RTT to request and receive M images m Response time = (M+1)O/R + 3 RTT + sum of idle times r Non-persistent HTTP with X parallel connections m Suppose M/X integer. m 1 TCP connection for base file m M/X sets of parallel connections for images. m Response time = (M+1)O/R + (M/X + 1)2 RTT + sum of idle times m Comp 361, Spring 2004 3: Transport Layer 122

HTTP Response time (in seconds) RTT = 100 msec, O = 5 Kbytes, M=10 HTTP Response time (in seconds) RTT = 100 msec, O = 5 Kbytes, M=10 and X=5 For low bandwidth, connection & response time dominated by transmission time. Persistent connections only give minor improvement over parallel connections. Comp 361, Spring 2004 3: Transport Layer 123

HTTP Response time (in seconds) RTT =1 sec, O = 5 Kbytes, M=10 and HTTP Response time (in seconds) RTT =1 sec, O = 5 Kbytes, M=10 and X=5 For larger RTT, response time dominated by TCP establishment & slow start delays. Persistent connections now give important improvement: particularly in high delay bandwidth networks. Comp 361, Spring 2004 3: Transport Layer 124

Chapter 3: Summary r principles behind transport layer services: m multiplexing, demultiplexing m reliable Chapter 3: Summary r principles behind transport layer services: m multiplexing, demultiplexing m reliable data transfer m flow control m congestion control r instantiation and implementation in the Internet m UDP m TCP Comp 361, Spring 2004 Next: r leaving the network “edge” (application, transport layers) r into the network “core” 3: Transport Layer 125