Chapter 5 Transport layer With special emphasis on Transmission Control Protocol (TCP) Contents • Need for TCP • TCP functions – Segmentation – Reliability – Flow-control – Multiplexing – Connection establishment • TCP Header • UDP 2 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment The need for a Transport layer • The network layer (IP) sends packets of data to their correct destinations with best effort – Packets may get lost in transit • The maximum packet size in IP is 65,536 bytes – What happens if the application wants to send a file of size 5,000,000 bytes? • Port addressing – Distinguish between applications on computers 3 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment The Transport layer in the stack http smtp sip Other application protocols Application layer Transport layer Transport layer IP Network layer Local network Data Link layer Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Transport Control Protocol (TCP) • These (and other related jobs) are performed by the Transport layer • TCP is a highly reliable host-to-host transport layer protocol over packet switched networks – Defined in RFC 793 (Sep 1981) 5 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Transport layer - reference • TCP – RFC 793 (Sep 1981) • UDP – RFC 768 (Aug 1980) 6 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP – Overview of operation • At the sending end, the application creates the data to be sent and passes it to its TCP module for transmission • At the receiving end, TCP collects all fragments from IP, reassembles them into the original data and passes it to the receiving application 7 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions • TCP provides a reliable application-toapplication communication service over a network of arbitrary complexity and unreliability – Applications (such as browsers and email) simply pass the data to be transferred to TCP and leave all communication complexities to TCP 8 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions • TCP corrects for all possible imperfections of IP • Therefore TCP has to perform many tasks – Segmentation – Reliability – Multiplexing – Flow-control – Connection establishment 9 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions - segmentation • TCP allows IP to transfer arbitrarily large data blocks – Accomplished by breaking data into segments – A sequence number is assigned to each datagram – Sequence numbers help receiver order datagrams even when received out of order 10 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Sequence numbers Application layer data Data length = 930 Bytes To transport layer Segmentation by transport layer Sequence number = 1 Length = 300 Sequence number = 301 Length = 320 Sequence number = 621 Length = 310 Sequence number of a TCP segment = To IP for transmission TCP segment 3 To IP for transmission TCP segment 2 To IP for transmission TCP segment 1 sequence number of the previous segment + length of previous segment 11 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions - segmentation • Advantages – Errors are less likely in smaller segments – Less retransmission if error is introduced in a segment – Easier for routers to hold segments in memory if onward route is busy • Disadvantages 12 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions - reliability • TCP recovers from network damage to data • Basic mechanism • Datagrams may also get duplicated – Sequence numbers help identify these duplicates 13 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Sequence numbers and reliability Sender Receiver TCP segment 1 TCP segment 1 Sequence number = 1 Length = 300 Sequence number = 1 Length = 300 ACK 301 TCP segment 2 TCP segment 2 Sequence number = 301 Length = 320 ACK 622 Sequence number = 301 Length = 320 Sender times out TCP segment 2 TCP segment 2 Sequence number = 301 Length = 320 ACK 622 Sequence number = 301 Length = 320 14 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions - reliability • Datagrams may get seriously damaged during transmission – If datagrams are further fragmented by IP, some IP fragments may get lost during transmission – Such damage is corrected by adding a checksum to each datagram and comparing it at the receiver 15 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions - multiplexing • Modern computers are capable of multitasking • TCP supports multiplexing by providing multiple port addresses within each host • A network address and port address together is called a socket 16 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Port addresses and multiplexing Windows file share 131.247.95.252 Port 445 (smb) Port 56244 Port 52279 Quicken application server 12.149.160.223 Port 443 (https) Port 52336 Port 52277 Yahoo web server 68.142.213.132 Port 80 (http) Client PC Port 131.247.95.132 61331 USF file server 131.247.100.8 Port 21 (ftp) College of Business DNS server 131.247.92.208 Port 53 (dns) 17 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP ports and airport gates ru n wa y Gate B25 to Lansing, MI Airport code GSO Gate B26 to Phoenix, AZ Data packets Port 1856 Web to yahoo cable Computer address: 216.149.56.68 Port 1857 IM to MSN 18 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP port assignment • On the sender side, the operating system assigns one of the free ports to an application that requires network connectivity • How do you know what port to connect to on the receiver side? 19 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Standard ports • Standard ports – Assigned by IANA: Internet Assigned Numbers Authority • To see list – In Windows: • C:/Windows/System32/drivers/etc/services – In UNIX/ Linux • /etc/services • Used ports displayed by netstat utility 20 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Standard ports • Typically ports 1 – 1023 are reserved for defined services – Applications may use the remaining port numbers 1024 – 65535 • Common ports – 80 : web (http) – 25 : email (smtp) – 443: SSL (https) – 445: microsoft-ds (smb) 21 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment etc\services file 22 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Viewing ports usage with netstat Ports on local desktop Ports on remote servers 23 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Viewing ports usage with netstat Invoking application Invoked port 24 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions – flow control • If the receiver is slow, it will not be able to process the packets reaching it • Therefore, TCP enables the receiver to limit the sender’s data rate • If sender is slow, it only tests the patience of receivers 25 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment V. simple flow control mechanism Sender Receiver TCP segment 1 TCP segment 1 Sequence number = 0 Length = 300 ACK 301 Sequence number = 0 Length = 300 TCP segment 2 TCP segment 2 Sequence number = 301 Length = 320 ACK 621 Sequence number = 301 Length = 320 26 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions – flow control • Flow control mechanism shown earlier is called stop-and-wait – Sender waits for ACK before sending next datagram • TCP flow control is accomplished by returning a “window” with every ACK • “Window” indicates how many bytes of data the sender may transmit before receiving any more ACK 27 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP flow control with window size Sender Receiver ize Window S 700 TCP segment 1 TCP segment 1 Sequence number = 1 Length = 300 Sequence number = 1 Length = 300 TCP segment 2 TCP segment 2 Sequence number = 301 Length = 320 ACK 621 Sequence number = 301 Length = 320 28 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Sliding window • Flow control is the regulation by the receiver of the amount of data the sender may send • Creates a “sliding window” at the sender • Packets that have received permission for transmission are within the window • Window slides as receiver acknowledges packets or modifies window size 29 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Sliding window Sender Receiver Window Size 700 Seg 1 SN = 1 Len = 300 Seg 2 SN = 301 Len = 300 Seg 3 SN = 601 Len = 300 Segments permitted for transmission “SENT window” Seg 4 SN = 901 Len = 300 Segments waiting for permission Seg 1 SN = 1 Len = 300 Seg 2 SN = 301 Len = 300 Seg 6 SN = 1501 More data Len = 300 Segments waiting for permission Seg 3 Seg 4 SN = 601 SN = 901 Len = 300 Len = 300 Seg 5 SN = 1201 Len = 300 ACK 601; Window Size 900 Seg 13 SN = 1 Len = 300 Seg 2 SN = 301 Len = 300 Segments successfully transmitted Seg 3 SN = 601 Len = 300 Seg 4 SN = 901 Len = 300 More data Seg 5 SN = 1201 Len = 300 Segments permitted for transmission “SENT window” 30 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP functions – connection establishment • Sequence numbers are core part of TCP • It is not a good idea to reuse the same sequence numbers in succession • Hence, before communication starts, sender and receiver negotiate a set of sequence numbers to use in TCP – Called 3-way handshake 31 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment Using an initial sequence number Sender Receiver TCP segment 1 TCP segment 1 Seq no = 1620789 Length = 300 ACK 162 789 + 300 1090 (1620 + 1) Seq no = 1620789 Length = 300 TCP segment 2 TCP segment 2 Seq no = 1621090 Length = 320 ACK 621090 + 1621411 (1 320 + 1 ) Seq no = 1621090 Length = 320 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment 3-way handshake Sender Receiver SYN Flag = 1, ACK Flag = 0 Sequence number = 83441 Acknowledgment number = 0 Relative sequence number = 0 Length = 0 1 SYN Flag = 1, ACK Flag = 0 Sequence number = 83441 Acknowledgment number = 0 Relative sequence number = 0 Length = 0; SYN = 1; ACK = 0 SYN Flag = 1, ACK Flag = 1 SYN Flag = 1, ACK Flag = 1 Sender knows that receiver has copied the correct starting sequence number 2 Sequence number = 2713867 Acknowledgment number = 83442 Relative sequence number = 0 Length = 0; SYN = 1; ACK = 1 Sequence number = 2713867 Acknowledgment number = 83442 Relative sequence number = 0 Length = 0 SYN Flag = 0, ACK Flag = 1 Sequence number = 83442 Acknowledgment number = 2713868 Relative sequence number = 1 Length = 0 3 SYN Flag = 0, ACK Flag = 1 Sequence number = 83442 Acknowledgment number = 2713868 Relative sequence number = 1 Length = 0 Receiver knows that sender has copied the correct starting acknowledgment number 33 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP Header 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Source port 20 21 22 23 24 25 26 27 28 29 Destination port Sequence number Acknowledgment number Data offset U R G Reserved A C K P S H Checksum R S T S Y N F I N Window Urgent pointer Options Padding Note: Each tick mark represents a bit position 34 30 31 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP header fields • Port addresses have 16 bits – 216 possible ports – 216 = 65,536 ports possible per host – If computing resources are available, a single computer running TCP can support 65,536 simultaneous network connections • Compare to telephone – no concept of port – only one network connection possible at a time 35 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP header fields • Sequence and acknowledgment numbers have 32 bits – Sequence number is the sequence number of the first data byte in the datagram – Acknowledgments are cumulative • ACK 1079 implies that all data till byte number 1078 have been received correctly • Initial sequence number for connection is chosen from an ascending clock 36 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP header fields • Data offset is the number of 32-bit words in the TCP header • Control fields – ACK: 1 implies that the value of the acknowledgment field is meaningful – RST: Reset the connection – SYN: 1 implies that the segment is trying to synchronize sequence numbers – FIN: Sender has no more data to send 37 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment TCP header fields • Window size – Number of data octets the sender of this information is willing to accept, beginning with the acknowledged segment • Checksum – Verification of TCP header, IP header and TCP data 38 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment User Datagram Protocol (UDP) • Defined in RFC 768 (1980) • Many applications do not need TCP, e.g.. – When applications send very small amounts of data (DNS), – Prefer speed to reliability (voice) • In these cases, if we can avoid TCP, we eliminate the overhead of keeping track of sequence numbers, window sizes etc. 39 Overview Segmentation Reliability Flow Connection Multiplexing Header UDP control establishment UDP Header 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Source port Destination port Length Checksum 27 28 29 Note: Each tick mark represents a bit position 40 30 31 Summary • • • • • • Why segmentation Why sequence numbers Why sliding window Why port numbers Why three-way handshake Why UDP Case study – the financial industry • Most financial transactions occur on computer networks – Securities markets, credit cards, bank transfers • In securities markets, low latency is considered very important – The delays from TCP handshaking and flow control are unacceptable • Alternate transport protocols are used Hands-on exercise • netstat • In Windows – netstat /? Displays help – netstat –n – netstat –f – netstat –b • Requires administrative privileges Network design exercise • Data rate from database transactions – Conversion from bytes to bits • Data rate from phone calls
© Copyright 2026 Paperzz