Presentation is loading. Please wait.

Presentation is loading. Please wait.

Instructor: Christopher Cole Some slides taken from Kurose & Ross book IT 347: Chapter 3 Transport Layer.

Similar presentations


Presentation on theme: "Instructor: Christopher Cole Some slides taken from Kurose & Ross book IT 347: Chapter 3 Transport Layer."— Presentation transcript:

1 Instructor: Christopher Cole Some slides taken from Kurose & Ross book IT 347: Chapter 3 Transport Layer

2 Network layer: logical communication between hosts Transport layer: logical communication between processes – end-to-end only – Routers, etc. don’t read segments Weird analogy of 2 families with Bill and Ann IP provides a best-effort delivery service – No guarantees! – unreliable Most fundamentally: extend host-to-host delivery to process-to-process delivery

3 Transport Layer3-3 Internet transport-layer protocols reliable, in-order delivery (TCP) – congestion control – flow control – connection setup unreliable, unordered delivery: UDP – no-frills extension of “best- effort” IP services not available: – delay guarantees – bandwidth guarantees application transport network data link physical network data link physical network data link physical network data link physical network data link physical network data link physical network data link physical application transport network data link physical logical end-end transport

4 Multiplexing Everybody is on sockets – Multiplexing: passing segments to network layer – Demultiplexing: taking network layer and distributing to sockets – How is it done? What are the 2 things that applications need to talk to each other? Source port/IP and destination port/IP – Server side usually specifically names a port – Client side lets the transport layer automatically assign a port

5 More multiplexing UDP: two-tuple – Identified by destination IP address and port number – If two UDP segments have difference source IP addresses and/or port numbers, but the same destination IP and port number, they will be directed to the same destination process via the same socket

6 TCP: four-tuple – Identified by source IP/port and destination IP/port – Two segments with difference source info, but the same destination info, will be directed to different sockets – TCP keeps the port open as a “welcoming socket” Server process creates new socket when connection is created One server can have many sockets open at a time Web server – Spawns a new thread for each connection (How does it know which collection belongs to who? Source port & IP) – Threads are like lightweight subprocesses – Many threads for one process

7 UDP A transport layer protocol must: provide multiplexing/demultiplexing – That’s all UDP does besides some light error checking – You’re practically talking directly to IP UDP process – Take the message from the application – Add source and destination port number fields – Add length & checksum fields – Send the segment to layer 3 Connectionless (no handshaking) – Why is DNS using UDP?

8 Advantages of UDP Finer application control – Just spit the bits onto the wire. No congestion control, flow control, etc. Connectionless – No extra RTT delay – Doesn’t create buffers, so a UDP server can take more clients than a TCP server Small packet overhead – TCP overhead = 20 bytes – UDP overhead = 8 bytes

9 The UDP Controversy UDP doesn’t play nice – No congestion control Say UDP packets flood the lines… – Causes routers to get more congested – TCP sees this, and slows down packet sending – UDP doesn’t Only UDP packets end up getting sent

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

11 Transport Layer3-11 UDP: more often used for streaming multimedia apps – loss tolerant – rate sensitive other UDP uses – DNS – SNMP reliable transfer over UDP: add reliability at application layer – application-specific error recovery! source port #dest port # 32 bits Application data (message) UDP segment format length checksum Length, in bytes of UDP segment, including header

12 Transport Layer3-12 UDP checksum Sender: treat segment contents as sequence of 16-bit integers checksum: addition (1’s complement sum) of segment contents sender puts checksum value into UDP checksum field Receiver: compute checksum of received segment check if computed checksum equals checksum field value: – NO - error detected – YES - no error detected. Throw the bit away OR Pass it on with a warning Goal: detect “errors” (e.g., flipped bits) in transmitted segment

13 Transport Layer3-13 Internet Checksum Example Note – When adding numbers, a carryout from the most significant bit needs to be added to the result Example: add two 16-bit integers 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1 wraparound sum checksum

14 Reliable Data Transfer See book for state machines and full explanations Case 1: underlying channel completely reliable – Just have a sender and receiver.

15 Case 2: bit errors (but no packet loss) – How do you know? Receiver has to acknowledge (ACK) or negative (NAK) A NAK makes the sender resend the packet NAK based on UDP checksum (talk about timers later) – Reliable transfer based on retransmission = ARQ (Automatic Repeat reQuest) protocol – 3 capabilities: Error detection, receiver feedback, retransmission – Stop and wait protocol

16 What if the ACK or NAK packet is corrupted? – Just resend the old packet. Duplicate packets: But how does the receiver know it is the same packet and not the next one? Add a sequence number! Do we really need a NAK? – Just ACK the last packet that was received.

17 Case 3: bit errors and packet loss – What if a packet gets lost? Set a timer on each packet sent. When the timer runs out, send the packet again. Can we handle duplicate packets? – How long? At least as long as a RTT

18 Transport Layer3-18 Performance of rdt3.0 rdt3.0 works, but performance stinks ex: 1 Gbps link, 15 ms prop. delay, 8000 bit packet: m U sender : utilization – fraction of time sender busy sending m 1KB pkt every 30 msec -> 33kB/sec (264 kbps) thruput over 1 Gbps link m network protocol limits use of physical resources!

19 Pipelining will fix it! – Make sure your sequence numbers are large enough – Buffering packets Sender buffers packets that have been transmitted but not yet acknowledged Receiver buffers correctly received packets Two basic approaches: Go-Back-N and selective repeat

20 Transport Layer3-20 Pipelined protocols Pipelining: sender allows multiple, “in-flight”, yet-to-be- acknowledged pkts – range of sequence numbers must be increased – buffering at sender and/or receiver Two generic forms of pipelined protocols: go-Back-N, selective repeat

21 Go-Back-N (sliding window) Sender: k-bit seq # in pkt header “window” of up to N, consecutive unACKed pkts allowed Transport Layer3-21 r ACK(n): ACKs all pkts up to, including seq # n - “cumulative ACK” m may receive duplicate ACKs (see receiver) r timer for each in-flight pkt r timeout(n): retransmit pkt n and all higher seq # pkts in window

22 ACK-only: always send ACK for correctly-received pkt with highest in-order seq # – may generate duplicate ACKs – need only remember expectedseqnum out-of-order pkt: – discard (don’t buffer) -> no receiver buffering! – Re-ACK pkt with highest in-order seq # Problems with GBN? – It can spit out a lot of needless packets onto the wire. A single error will really do some damage. A wire with lots of errors? Lots of needless duplicate packets

23 Transport Layer3-23 Selective Repeat receiver individually acknowledges all correctly received pkts – buffers pkts, as needed, for eventual in-order delivery to upper layer sender only resends pkts for which ACK not received – sender timer for each unACKed pkt sender window – N consecutive seq #’s – again limits seq #s of sent, unACKed pkts – The sender and receiver window will not always coincide! If your sequence numbers aren’t big enough, you won’t know which is which

24 Transport Layer3-24 Selective repeat: sender, receiver windows

25 Transport Layer3-25 Selective repeat data from above : if next available seq # in window, send pkt timeout(n): resend pkt n, restart timer ACK(n) in [sendbase,sendbase+N]: mark pkt n as received if n smallest unACKed pkt, advance window base to next unACKed seq # sender pkt n in [rcvbase, rcvbase+N-1] r send ACK(n) r out-of-order: buffer r in-order: deliver (also deliver buffered, in-order pkts), advance window to next not- yet-received pkt pkt n in [rcvbase-N,rcvbase-1] r ACK(n) otherwise: r ignore receiver

26 Transport Layer3-26 Pipelining Protocols - Summary Go-back-N: overview sender: up to N unACKed pkts in pipeline receiver: only sends cumulative ACKs – doesn’t ACK pkt if there’s a gap sender: has timer for oldest unACKed pkt – if timer expires: retransmit all unACKed packets Selective Repeat: overview sender: up to N unACKed packets in pipeline receiver: ACKs individual pkts sender: maintains timer for each unACKed pkt – if timer expires: retransmit only unACKed packet

27 Reliable Data Transfer Mechanisms See table p. 242 – Checksum – Timer – Sequence number – Acknowledgement – Negative acknowledgement – Window, pipelining

28 TCP Read 3.5 to the end Point to point – Single sender, single receiver – Multicasting (4.7) will not work with TCP 3 way handshake – SYN – SYN-ACK – ACK TCP sets aside a send buffer – where the application message data gets put TCP takes chunks of data from this buffer and sends segments

29 Vocabulary RTT = Round Trip Time MSS = Maximum segment size – Maximum amount of data that TCP can grab and place into a segment – This is application layer data – does not include TCP headers, etc. MTU = Maximum transmission unit – The largest link-layer frame that can be sent by the local sending host – This will have a lot of bearing on the MSS – Common values: 1,460, 536, and 512 bytes

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

31 Transport Layer3-31 TCP segment structure source port # dest port # 32 bits application data (variable length) sequence number acknowledgement number Receive window Urg data pointer checksum F SR PAU head len not used Options (variable length) URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now (generally not used) RST, SYN, FIN: connection estab (setup, teardown commands) # bytes rcvr willing to accept counting by bytes of data (not segments!) Internet checksum (as in UDP)

32 Transport Layer3-32 TCP seq. #’s and ACKs Seq. #’s: – byte stream “number” of first byte in segment’s data ACKs: – seq # of next byte expected from other side – cumulative ACK Q: how receiver handles out- of-order segments – A: TCP spec doesn’t say, - up to implementer Host A Host B Seq=42, ACK=79, data = ‘C’ Seq=79, ACK=43, data = ‘C’ Seq=43, ACK=80 User types ‘C’ host ACKs receipt of echoed ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ time simple telnet scenario

33 Transport Layer3-33 TCP Round Trip Time and Timeout Q: how to set TCP timeout value? longer than RTT – but RTT varies too short: premature timeout – unnecessary retransmissions too long: slow reaction to segment loss Q: how to estimate RTT? SampleRTT : measured time from segment transmission until ACK receipt – ignore retransmissions SampleRTT will vary, want estimated RTT “smoother” – average several recent measurements, not just current SampleRTT

34 Transport Layer3-34 TCP Round Trip Time and Timeout EstimatedRTT = (1-  )*EstimatedRTT +  *SampleRTT r Exponential weighted moving average r influence of past sample decreases exponentially fast  typical value:  = 0.125

35 Transport Layer3-35 Example RTT estimation:

36 Transport Layer3-36 TCP Round Trip Time and Timeout Setting the timeout EstimtedRTT plus “safety margin” – large variation in EstimatedRTT -> larger safety margin first estimate of how much SampleRTT deviates from EstimatedRTT: TimeoutInterval = EstimatedRTT + 4*DevRTT DevRTT = (1-  )*DevRTT +  *|SampleRTT-EstimatedRTT| (typically,  = 0.25) Then set timeout interval:

37 Transport Layer3-37 TCP reliable data transfer TCP creates rdt service on top of IP’s unreliable service pipelined segments cumulative ACKs TCP uses single retransmission timer retransmissions are triggered by: – timeout events – duplicate ACKs initially consider simplified TCP sender: – ignore duplicate ACKs – ignore flow control, congestion control

38 Transport Layer3-38 TCP sender events: data rcvd from app: create segment with seq # seq # is byte-stream number of first data byte in segment start timer if not already running (think of timer as for oldest unACKed segment) expiration interval: TimeOutInterval timeout: retransmit segment that caused timeout restart timer ACK rcvd: if acknowledges previously unACKed segments – update what is known to be ACKed – start timer if there are outstanding segments

39 Transport Layer3-39 TCP sender (simplified) NextSeqNum = InitialSeqNum SendBase = InitialSeqNum loop (forever) { switch(event) event: data received from application above create TCP segment with sequence number NextSeqNum if (timer currently not running) start timer pass segment to IP NextSeqNum = NextSeqNum + 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 > SendBase) { SendBase = y if (there are currently not-yet-acknowledged segments) start timer } } /* end of loop forever */ Comment: SendBase-1: last cumulatively ACKed byte Example: SendBase-1 = 71; y= 73, so the rcvr wants 73+ ; y > SendBase, so that new data is ACKed

40 Transport Layer3-40 TCP 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

41 Transport Layer3-41 Fast Retransmit time-out period often relatively long: – long delay before resending lost packet detect lost segments via duplicate ACKs. – sender often sends many segments back-to-back – if segment is lost, there will likely be many duplicate ACKs for that segment If sender receives 3 ACKs for same data, it assumes that segment after ACKed data was lost: – fast retransmit: resend segment before timer expires

42 Transport Layer3-42 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 algorithm: a duplicate ACK for already ACKed segment fast retransmit

43 Go-Back-N or Selective Repeat? The book says it’s sorta both. To me it mostly looks like GBN – Out of order segments not individually ACKed However – Many TCP implementations will buffer out of order segments – TCP will also usually only retransmit a single segment rather than all of them

44 Flow Control (NOT congestion control) TCP creates a receive buffer – Data is put into the receive buffer once it has been received correctly and in order – The application reads from the receive buffer Sometimes not right away. Flow control tries not to overflow this receive buffer Each sender maintains a variable called the receive window – What if the receive window goes to 0? – In this case, the sending host is required to send segments with 1 data byte What happens in UDP when the UDP receive buffer overflows?

45 Transport Layer3-45 TCP Flow Control receive side of TCP connection has a receive buffer: speed-matching service: matching send rate to receiving application’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 IP datagrams TCP data (in buffer) (currently) unused buffer space application process

46 Transport Layer3-46 TCP Connection Management Recall: TCP sender, receiver establish “connection” before exchanging data segments initialize TCP variables: – seq. #s – buffers, flow control info (e.g. RcvWindow ) client: connection initiator Socket clientSocket = new Socket("hostname","port number"); server: contacted by client Socket connectionSocket = welcomeSocket.accept(); Three way handshake: Step 1: client host sends TCP SYN segment to server – specifies initial seq # – no data Step 2: server host receives SYN, replies with SYNACK segment – server allocates buffers – specifies server initial seq. # Step 3: client receives SYNACK, replies with ACK segment, which may contain data

47 Transport Layer3-47 TCP Connection Management (cont.) Closing a connection: client closes socket: clientSocket.close(); Step 1: client end system sends TCP FIN control segment to server Step 2: server receives FIN, replies with ACK. Closes connection, sends FIN. client FIN server ACK FIN close closed timed wait

48 Transport Layer3-48 TCP Connection Management (cont.) Step 3: client receives FIN, replies with ACK. – Enters “timed wait” - will respond with ACK to received FINs Step 4: server, receives ACK. Connection closed. Note: with small modification, can handle simultaneous FINs. client FIN server ACK FIN closing closed timed wait closed

49 Transport Layer3-49 TCP Connection Management (cont) TCP client lifecycle TCP server lifecycle

50 SYN Flood Attack Bad guy sends a bunch of TCP SYN segments Server opens up buffers to create this segment Resources all become allocated to half open TCP connections – This is called a SYN flood attack SYN Cookies – The server allocates on the resources upon receipt of a ACK (third part of handshake) segment rather than a SYN segment – It knows because the sequence field the server sent out was a special number (complex hash function of source and destination IP and port plus the server’s secret number) – P. 269s

51 How does nmap work? To find out what is on a port, nmap sends a TCP SYN segment to that port – If the port responds with a SYNACK, it labels the port open – If the response is a TCP RST segment, it means the port is not blocked, but it is closed – If the response is nothing, the port is blocked by a firewall

52 Congestion Control Principles Typical cause of congestion: – Overflowing of router buffers as the network becomes congested.

53 Scenario 1 Scenario 1: two senders, a router with infinite buffers – Always maximizing throughput looks good with throughput alone. (left) – Maximizing throughput is bad when looking at delays (right)

54 Scenario 2 Scenario 2: Routers with finite buffers & retransmission – If you are constantly resending packets, throughput is even lower since a % of the packets are retransmissions – Creating these large delays, you may send needless retransmissions, wasting precious router resources

55 Scenario 3 Scenario 3: multiple hops – When a packet is dropped along a path, the transmission capacity at each of the upstream links ends up being wasted

56 Transport Layer3-56 Approaches towards congestion control end-end congestion control: no explicit feedback from network congestion inferred from end- system observed loss, delay approach taken by TCP network-assisted congestion control: routers provide feedback to end systems – single bit indicating congestion (SNA, DECbit, TCP/IP ECN, ATM) – explicit rate sender should send at two broad approaches towards congestion control:

57 Transport Layer3-57 TCP congestion control: r goal: TCP sender should transmit as fast as possible, but without congesting network m Q: how to find rate just below congestion level r decentralized: each TCP sender sets its own rate, based on implicit feedback: m ACK: segment received (a good thing!), network not congested, so increase sending rate m lost segment: assume loss due to congested network, so decrease sending rate

58 Transport Layer3-58 TCP congestion control: bandwidth probing r “probing for bandwidth”: increase transmission rate on receipt of ACK, until eventually loss occurs, then decrease transmission rate m continue to increase on ACK, decrease on loss (since available bandwidth is changing, depending on other connections in network) ACKs being received, so increase rate X X X X X loss, so decrease rate sending rate time r Q: how fast to increase/decrease? m details to follow TCP’s “sawtooth” behavior

59 Transport Layer3-59 TCP Congestion Control: details sender limits rate by limiting number of unACKed bytes “in pipeline”: – cwnd: differs from rwnd (how, why?) – sender limited by min(cwnd,rwnd) roughly, cwnd is dynamic, function of perceived network congestion rate = cwnd RTT bytes/sec LastByteSent-LastByteAcked  cwnd cwnd bytes RTT ACK(s)

60 Transport Layer3-60 TCP Congestion Control: more details segment loss event: reducing cwnd timeout: no response from receiver – cut cwnd to 1 3 duplicate ACKs: at least some segments getting through (recall fast retransmit) – cut cwnd in half, less aggressively than on timeout ACK received: increase cwnd r slowstart phase: m increase exponentially fast (despite name) at connection start, or following timeout r congestion avoidance: m increase linearly

61 Transport Layer3-61 TCP Slow Start when connection begins, cwnd = 1 MSS – example: MSS = 500 bytes & RTT = 200 msec – initial rate = 20 kbps available bandwidth may be >> MSS/RTT – desirable to quickly ramp up to respectable rate increase rate exponentially until first loss event or when threshold reached – double cwnd every RTT – done by incrementing cwnd by 1 for every ACK received Host A one segment RTT Host B time two segments four segments

62 Transport Layer3-62 Transitioning into/out of slowstart ssthresh: cwnd threshold maintained by TCP on loss event: set ssthresh to cwnd/2 – remember (half of) TCP rate when congestion last occurred when cwnd >= ssthresh : transition from slowstart to congestion avoidance phase slow start timeout ssthresh = cwnd/2 cwnd = 1 MSS dupACKcount = 0 retransmit missing segment timeout ssthresh = cwnd/2 cwnd = 1 MSS dupACKcount = 0 retransmit missing segment  cwnd > ssthresh cwnd = cwnd+MSS dupACKcount = 0 transmit new segment(s),as allowed new ACK dupACKcount++ duplicate ACK  cwnd = 1 MSS ssthresh = 64 KB dupACKcount = 0 congestion avoidance

63 Transport Layer3-63 TCP: congestion avoidance when cwnd > ssthresh grow cwnd linearly – increase cwnd by 1 MSS per RTT – approach possible congestion slower than in slowstart – implementation: cwnd = cwnd + MSS/cwnd for each ACK received  ACKs: increase cwnd by 1 MSS per RTT: additive increase  loss: cut cwnd in half (non-timeout-detected loss ): multiplicative decrease AIMD AIMD: Additive Increase Multiplicative Decrease

64 Transport Layer3-64 Popular “flavors” of TCP ssthresh TCP Tahoe TCP Reno Transmission round cwnd window size (in segments)

65 Transport Layer3-65 Summary: TCP Congestion Control when cwnd < ssthresh, sender in slow-start phase, window grows exponentially. when cwnd >= ssthresh, sender is in congestion- avoidance phase, window grows linearly. when triple duplicate ACK occurs, ssthresh set to cwnd/2, cwnd set to ~ ssthresh when timeout occurs, ssthresh set to cwnd/2, cwnd set to 1 MSS.

66 Transport Layer3-66 Fairness (more) Fairness and UDP multimedia apps often do not use TCP – do not want rate throttled by congestion control instead use UDP: – pump audio/video at constant rate, tolerate packet loss Fairness and parallel TCP connections nothing prevents app from opening parallel connections between 2 hosts. web browsers do this example: link of rate R supporting 9 connections; – new app asks for 1 TCP, gets rate R/10 – new app asks for 11 TCPs, gets R/2 !


Download ppt "Instructor: Christopher Cole Some slides taken from Kurose & Ross book IT 347: Chapter 3 Transport Layer."

Similar presentations


Ads by Google