Lecture 4: Transport Layer Literature: Forouzan: ch 11-12 2004 Image Coding Group, Linköpings Universitet
Lecture 4: Outline Transport layer responsibilities UDP TCP 2
Transport layer in OSI model Figure from Forouzan 3
Lower layer responsibilities The physical layer transmits signals representing individual bits on a channel The link layer provides reliable link communication through framing, physical addressing, flow- error- and access control The network layer provides end to end delivery of individual packets through logical addressing and routing support 4
End to end delivery of a packet Figure from Forouzan 5
The Transport Layer The transport layer is responsible for end to end delivery of messages. This is achieved through Service point addressing Segmentation and reassembly Connection control Flow control Error control 6
End to end delivery of a message Figure from Forouzan 7
Addressing - Protocol Ports Port numbers are used as a process identifier. They are needed since computers can run multiple programs at the same time. IP addresses identify computers Port numbers identify processes An (IP address, port number) pair is called a socket. Messages must define source and destination sockets 8
Port Numbers The IANA has divided the port numbers into three ranges: Well known ports (0-1023) Assigned and controlled by IANA Registered ports (1024-49151) Ports in this range can be registered with IANA to prevent duplication. Dynamic ports (49152-65535) The ephemeral ports can be used by any process. 9
Some Well Known Ports Port number Application 20 FTP 23 Telnet 25 SNMP 80 HTTP 10
Transport layer protocols There are two transport layer protocols in the TCP/IP stack: UDP - User Datagram Protocol Connectionless unreliable service TCP - Transmission Control Protocol Connection- oriented reliable stream service TCP UDP IGMP ICMP IP ARP RARP Underlying networks 11
User Datagram Protocol UDP is a connectionless, unreliable transport protocol UDP provides process to process communication limited error checking UDP does not provide acknowledgement for recieved packets segmentation and reassembly flow control 12
User Datagram Protocol Why use UDP? 13
User Datagram Protocol UDP is suitable for processes that provide internal flow and error control mechanisms, eg TFTP multicasting and broadcasting management processes, eg SNMP some route updating protocols, eg RIP processes that only send short messages 14
User Datagram UDP packets (datagrams): 8 byte header max 65507 bytes of data 16 bits 16 bits Source port address UDP total length Destination port address UDP Checksum Data... 15
UDP Checksum The UDP checksum includes pseudoheader UDP header data from the application layer pad byte (if needed) 8 bits 8 bits Protocol All 0s (17) Source port address Source IP address... 8 bits 8 bits Destination IP address UDP total length Data Header checksum Destination port address UDP Checksum 16
Checksum example Figure from Forouzan 17
UDP Operation Messages are encapsulated in UDP datagrams Usually each port is associated with one or two queues UDP handles multiplexing and demultiplexing of messages. 18
Encapsulation Figure from Forouzan 19
Incoming and outgoing queues Figure from Forouzan 20
Multiplexing Figure from Forouzan 21
UDP Package Figure from Forouzan 22
Transmission Control Protocol TCP is a connection- oriented transport protocol TCP provides full duplex connections reliable stream service flow control error control 23
Buffers Sending and receiving buffers are used for storage. This makes it possible to handle differences in speed between the sending and receiving processes. Buffers are also used in flow and error control mechanisms. 24
Buffers Figure from Forouzan 25
Reliable Service TCP provides reliable service by breaking application data into suitable sized blocks called segments using an acknowledgement mechanism retransmission when errors occur providing flow control checksum control of header and data 26
TCP Segment 8 bits 8 bits 8 bits 8 bits Source port address Destination port address Sequence Number Acknowledgement Number hlen 6 bits reserved flags Window Size TCP Checksum... Options (if any) Urgent Pointer Data (if any) 27
Sequence number All bytes transmitted in a connection are numbered, starting from a random position 32 bits are used for numbering The value in the header is the number of the first byte of data contained in the segment. 28
Acknowledgement number This number is used to announce the sequence number of the next expected segment and thus acknowledging that all prior segments (with lower sequence numbers) have been received. 29
TCP Flags 6 flags can be used to determine the purpose of the segment (more than one can be set) URG - urgent pointer valid (set when sender wants the receiver to read a piece of data urgently and possibly out of order) ACK - acknowledgement number valid PSH - push data, receiver should immediately pass the data to the application (buffers should be emtied!) RST - reset the connection SYN - synchronize sequence numbers to initiate connection FIN - terminate the connection 30
TCP Handshake A three- way handshake is used to establish a connection Client Server Negotiation on initial sequence numbers Initial segment number (ISN) chosen so that each active connection has its own ISN Normally initiation is made by the client SYN, seq=x ACK, seq=x+1, SYN, seq=y ACK, seq=y+1 31
Connection Termination 4 segments needed to close a connection Client Server FIN ACK of FIN FIN ACK of FIN 32
Maximum Segment Size MSS is the largest block of data TCP will send to the other side. MSS can be announced in the options field during connection establishment. Default MSS is 536 The larger the better (until fragmentation occurs) 33
TCP Options Up to 40 bytes of optional informationcan be included in the TCP header Used to convey additional information or to align other options Options Single- byte End of option No operation Maximum segment size Multiple- byte Window scale factor Timestamp 34
Flow Control How much can a source send without receiving an ACK? The sliding window protocol is used in TCP offered window usable window 35
Senders window Figure from Forouzan 36
Sliding window 37
Silly window syndrome Sender sends 1- byte segments because the application produces data slowly. Solution - Nagle's algorithm After sending one segment, wait until either an ack is received or a full window can be transmitted. 1- byte windows are announced by the receiver because the application consumes data slowly. Solution - Clark's Announce zero window size until a maximum size segment fits into the buffer Solution - delayed ack Wait with acknowledgments until there is room in the buffer 38
Error control Figure from Forouzan 39
Congestion Control Handles bottlenecks in the network Without congestion control the network will collaps! Solution: Congestion window (CWND) slow start Additive increase of CWND Multiplicative decrease of CWND Fast retransmit and Fast recovery 40
Congestion window size Figure from Forouzan 41
TCP Timers Retransmission timer how long should sender wait for an ACK? Persistence timer how long should sender wait if window size = 0? Keepalive timer Prevents connections to live forever Time- Waited timer Each connection held in limbo before actually closed 42
State transistions Figure from Forouzan 43
TCP packet Figure from Forouzan 44
Summary Transport layer basics UDP - a fairly simple connectionless protocol TCP - a very complex protocol Reliability Connection management Flow control Congestion avoidance Timers 45