Transport Layer - Ports and Multiplexing
In questa pagina 6
Role
The network layer (Network Layer and IPv4 AddressingThe network layer delivers datagrams host to host through routers (encapsulation, routing, forwarding); an IPv4 address is 32 bits split into a network prefix and a host suffix, and modern classless addressing (CIDR) gives a block of 2^(32-n) addresses from a.b.c.d/n, with network and broadcast addresses computed through the netmask.Network Layer and IPv4 Addressing →) brings a datagram to the right computer; many programs run on the same computer, and the datagram must reach the right program. That second step is done by transport.
Definition. The transport layer provides logical end-to-end communication between application processes on different hosts. The sender splits application messages into segments and passes them to the network layer; the receiver reassembles them into messages.
The communication is logical: the two application layers behave as if directly connected, whereas in reality many routers and links lie in between. Hence transport protocols are implemented in end systems and not in routers.
Analogy. Twelve children in Ann's house write letters to twelve children in Bill's house: houses are hosts, children processes, letters application messages, Ann and Bill the transport protocol, the postal service the network protocol. The postal service brings the envelope to the right house; Bill then needs the name on the envelope: the port number.
| service | what it does |
|---|---|
| process-to-process communication | delivers to the destination process, not just the computer |
| addressing | identifies processes by port numbers (client-server paradigm) |
| encapsulation / decapsulation | adds and removes the transport header |
| multiplexing / demultiplexing | many processes share one transport protocol on a host |
| error control | only for reliable protocols (TCP) |
| flow control | only for reliable protocols (TCP) |
| congestion control | only for reliable protocols (TCP) |
Port numbers
Hosts are identified by IP addresses, processes by port numbers.
Definition. A port number is a 16-bit integer, from to . The destination IP chooses the host; the destination port chooses the process on it.
The server must be findable, so its port is a well-known port; the client picks a temporary ephemeral port (above 1023). Exceptions exist (the DHCP client uses 68: DHCP - Dynamic Host ConfigurationBOOTP (obsolete) statically maps MAC addresses to IP addresses, while DHCP assigns addresses dynamically on lease, even after the operating system has started; the client-server dialogue runs over UDP (server port 67, client port 68) with DHCPDISCOVER, DHCPOFFER, DHCPREQUEST and DHCPACK (plus DHCPRELEASE), and the ACK delivers IP address, netmask, default gateway and DNS server, with lease renewal at 50 percent and rebinding at 87.5 percent of the lease.DHCP - Dynamic Host Configuration →).
| range | name | managed by |
|---|---|---|
| - | well-known | assigned by ICANN |
| - | registered | not controlled, can be registered |
| - | dynamic | free temporary or private use |
Counts: well-known ; registered ; dynamic . A browser might use ephemeral source port and destination port (HTTP) or (HTTPS). On Unix well-known ports are listed in /etc/services, and only privileged processes can use them.
| port | application | transport |
|---|---|---|
| 7 | Echo | UDP, TCP |
| 20, 21 | FTP (data, control) | TCP |
| 22 | SSH | TCP |
| 23 | Telnet | TCP |
| 25 | SMTP | TCP |
| 53 | DNS | UDP (TCP for large answers) |
| 67, 68 | DHCP (server, client) | UDP |
| 80 | HTTP | TCP |
| 110 | POP3 | TCP |
| 143 | IMAP | TCP |
| 161 | SNMP | UDP |
| 179 | BGP | TCP |
| 443 | HTTPS | TCP |
| 520 | RIP | UDP |
Sockets and connection identification
Definition (socket). The pair ; it selects a host and a process on it.
Property. A connection is uniquely identified by the four-tuple (source port, destination port, source IP, destination IP).
Example. Students and open the same page on server : and are different connections (different IPs). A second tab of gets another ephemeral port, e.g. . The server uses only port 80 for all of them; the four-tuple tells them apart.
Encapsulation: the transport header (PCI) is added to the message; transport packets are called user datagrams (UDP) or segments (TCP). The segment becomes the payload of an IP datagram, whose Protocol field says who gets it ( TCP, UDP).
Multiplexing and demultiplexing
A host has one UDP and one TCP, used by many processes. Multiplexing (sender) gathers messages of many processes into one stream of segments, each with its source port; demultiplexing (receiver) delivers incoming segments to the right process by looking at ports.
- UDP: socket identified by (destination IP, destination port); segments from different sources with the same destination end in the same socket.
- TCP: socket identified by the whole four-tuple, so a server on one port can serve many clients, one socket per connection.
Example. On , port 80 has connections , , . A TCP segment with source port 51234, destination port 80, source IP goes to the process of the second connection. NAT with port translation uses the same idea (NAT and Private AddressesPrivate networks (intranets) use TCP/IP with private address blocks (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) that may be reused by different intranets but are never routed in the public Internet; to reach the Internet an intranet needs an application proxy or NAT, a router that translates private to public addresses using a NAT table and per-session mappings: Basic NAT translates only the IP address one to one, NAPT also translates the port so many sessions share one public IP, and Twice NAT adds DNS support and static mappings so sessions can also start from outside.NAT and Private Addresses →).
Flow, error and congestion control
| service | depends on | involves |
|---|---|---|
| error | loss or corruption of packets | only the transport layers of sender and receiver |
| flow | capacity of the receiver (and sender) | sender and receiver |
| congestion | the channel and context (the network) | the sender, according to the network |
Flow. If the producer pushes items faster than the consumer consumes them the consumer is overwhelmed: buffers help (if the sender's buffer is full, transport tells the application to stop; if the receiver's is full it tells the sender to stop).
Error. IP is unreliable; a reliable transport detects and discards corrupted packets, tracks and resends lost ones, removes duplicates and keeps out-of-order packets until the missing one arrives, using a sequence number. With bits sequence numbers go from to (3 bits: ; TCP uses 32 bits). Numbers wrap around (modulo ), so the ARQ window cannot cover all numbers; TCP uses a modification or combination of stop-and-wait, Go-Back-N and Selective Repeat (ARQ Protocols - Stop-and-Wait, Go-Back-N and Selective RepeatARQ (Automatic Repeat reQuest) makes an error-prone link reliable: the receiver acknowledges (ACK) frames received correctly and the sender retransmits when the timeout expires. Timeouts (against deadlock) and sequence numbers (against duplicates) are needed. With t_G = t_F + 2 tau_p + t_A and error probability p: Stop-and-Wait rho = t_F(1-p)/t_G; Go-Back-N with window N >= t_G/t_F rho = (1-p)/(1+(N-1)p); Selective Repeat rho = 1-p. Efficiency eta = rho I/F. The optimal window is the pipe capacity in packets. For Selective Repeat there is also an optimal frame length: with overhead o and bit error probability P_b, x_opt is about o/2 + sqrt(o/P_b) (shorter frames when the channel errs more).ARQ Protocols - Stop-and-Wait, Go-Back-N and Selective Repeat →).
Congestion. Congestion exists when load exceeds network capacity and router queues overflow: TCP Congestion ControlCongestion arises when fast links feed a slow one, router queues fill and packets are lost or delayed, possibly up to network collapse; TCP controls its congestion window cwnd using loss feedback (timeout or three duplicate ACKs): slow start doubles cwnd every RTT up to the threshold ssthresh, then congestion avoidance adds 1 MSS per RTT, and on a loss ssthresh becomes W/2; variants differ in reaction to three dupACKs: Tahoe restarts from cwnd=1, Reno uses fast recovery (ssthresh=cwnd/2, cwnd=ssthresh+3, +1 per further dupACK), NewReno handles partial ACKs and recovers several losses in one window, SACK acknowledges received blocks and resends only what is missing.TCP Congestion Control →.
Protocols
- UDP: connectionless, unreliable, simple: UDP - User Datagram ProtocolUDP is the connectionless, unreliable transport protocol that adds to IP only process-to-process communication through ports and an optional checksum; its header is 8 bytes (source port, destination port, length, checksum), the checksum covers a pseudo-header (IP addresses, protocol 17, length), the UDP header and the data as a one's complement sum (0 means not computed and a computed 0 is sent as 0xFFFF), and UDP has no connection setup, sequence numbers, flow, error or congestion control, which makes it suitable for short messages (DNS, DHCP, RIP, SNMP) and real-time applications.UDP - User Datagram Protocol →.
- TCP: connection-oriented, reliable: TCP - Connection, Reliability and Flow ControlTCP is the connection-oriented, reliable transport protocol that turns IP's unreliable service into an ordered byte stream without errors or duplicates; the connection opens with a three-way handshake (SYN, SYN+ACK, ACK) and closes with FIN segments, bytes are numbered (sequence number = first byte of the segment, cumulative ACK = next byte expected), the sender may transmit min(rwnd, cwnd) unacknowledged bytes (rwnd, the receiver window in a 16-bit field, is flow control), errors are handled with checksum, ACKs, retransmission timeout and fast retransmit after three duplicate ACKs, and to fill the pipe the window must reach the bandwidth-delay product, with maximum throughput MSS times Wmax over RTT.TCP - Connection, Reliability and Flow Control →.
- SCTP: newer, combines features of both.
HTTP, SMTP, FTP, SSH and BGP use TCP; DNS, DHCP, RIP, SNMP and real-time interactive applications use UDP.
Versione ripasso
- Transport gives logical end-to-end communication between processes; implemented only in end hosts. Network layer: to the computer (IP); transport: to the process (port).
- Services: process-to-process, addressing, (de)encapsulation, multiplexing/demultiplexing; error, flow, congestion control only if reliable (TCP).
- Port: 16 bits, to . Well-known - (ICANN), registered -, dynamic -. Servers use well-known ports, clients ephemeral ones.
- Common ports: FTP 20/21, SSH 22, Telnet 23, SMTP 25, DNS 53 (UDP), DHCP 67/68 (UDP), HTTP 80, POP3 110, IMAP 143, BGP 179, HTTPS 443, RIP 520 (UDP).
- Socket . Connection four-tuple (source port, destination port, source IP, destination IP). and differ.
- Demultiplexing: UDP by (destination IP, destination port); TCP by the whole four-tuple.
- Sequence numbers of bits: to (TCP: 32 bits). IP Protocol field: 6 TCP, 17 UDP.
- Flow control (receiver capacity), error control (loss), congestion control (network) are different things.
- Protocols: UDP - User Datagram ProtocolUDP is the connectionless, unreliable transport protocol that adds to IP only process-to-process communication through ports and an optional checksum; its header is 8 bytes (source port, destination port, length, checksum), the checksum covers a pseudo-header (IP addresses, protocol 17, length), the UDP header and the data as a one's complement sum (0 means not computed and a computed 0 is sent as 0xFFFF), and UDP has no connection setup, sequence numbers, flow, error or congestion control, which makes it suitable for short messages (DNS, DHCP, RIP, SNMP) and real-time applications.UDP - User Datagram Protocol →, TCP - Connection, Reliability and Flow ControlTCP is the connection-oriented, reliable transport protocol that turns IP's unreliable service into an ordered byte stream without errors or duplicates; the connection opens with a three-way handshake (SYN, SYN+ACK, ACK) and closes with FIN segments, bytes are numbered (sequence number = first byte of the segment, cumulative ACK = next byte expected), the sender may transmit min(rwnd, cwnd) unacknowledged bytes (rwnd, the receiver window in a 16-bit field, is flow control), errors are handled with checksum, ACKs, retransmission timeout and fast retransmit after three duplicate ACKs, and to fill the pipe the window must reach the bandwidth-delay product, with maximum throughput MSS times Wmax over RTT.TCP - Connection, Reliability and Flow Control →, SCTP.