TCPとIPの基本
informationnetworksundergraduatelecture
data/lecture/information/networks/computer-network-basics.lecture.n.md
1導入
この講義では、IPによるデータグラム転送と、TCPによるバイトストリーム転送の責務を区別する。IPが提供するサービスの限界を確認したうえで、TCPが順序制御と再送によってどのような信頼性を付加するかを説明する。
2ネットワーク層とトランスポート層
IPはネットワーク層のプロトコルである。IPアドレスはネットワーク層のインタフェースを識別し、ルータは宛先IPアドレスのプレフィックスに基づいてデータグラムを次ホップへ転送する。経路情報を形成することをルーティング、その情報に従って個々のデータグラムを転送することをフォワーディングという。
TCPはトランスポート層のプロトコルであり、IPの上に構成される。TCPは後述するポート番号とIPアドレスを組み合わせて通信端点を識別し、アプリケーション間のデータ転送を支援する。
3IPのベストエフォート転送
IPは、上位層から受け取ったデータをIPデータグラムとして宛先へ転送する。ただし、IPが提供するサービスはベストエフォートである。ネットワークの混雑や機器の障害などにより、データグラムが欠落することも、送信順序と異なる順序で到着することも、重複して到着することもある。IPは、到達、到着順序、重複排除を保証しない。
4TCPの信頼性のあるバイトストリーム
TCPは、接続の両端に順序付きバイトストリームを提供する。TCPはデータへ通し番号を付与し、受信側からの確認応答によって受信状況を確認する。確認応答が得られないデータを再送し、順序が入れ替わったデータを整列することにより、アプリケーションへ順序付きのデータ列を渡す。
TCPは全二重通信を支援するため、両方向へ同時にバイトストリームを転送できる。ただし、TCPはアプリケーションが送信した個々のメッセージの境界を保存しない。アプリケーションは、データの長さや区切りを独自のプロトコルで表現する必要がある。
5ポート番号とTCP接続
IPアドレスがネットワーク層のインタフェースを識別するのに対し、ポート番号はTCPなどの特定のトランスポートプロトコルとIPアドレスの文脈で通信端点を識別する。TCP接続は、送信元IPアドレス、送信元ポート番号、宛先IPアドレス、宛先ポート番号の組みによって概念的に識別できる。
クライアントは一般に一時的なポート番号を使用し、サーバは提供するサービスに対応するポート番号で接続を待つ。ポート番号があるため、同一のIPアドレスを持つ計算機で複数のアプリケーションが通信できる。
6カプセル化と通信手順
アプリケーションのデータはTCPセグメントに格納され、TCPセグメントはIPデータグラムのペイロードに格納される。このように、上位層のデータへ下位層の制御情報を付加することをカプセル化という。
\text{アプリケーションデータ}
\longrightarrow \text{TCPセグメント}
\longrightarrow \text{IPデータグラム}
たとえば、HTTP/1.1またはHTTP/2の通信では、HTTPのデータをTCPがバイトストリームとして転送し、そのTCPセグメントをIPがデータグラムとして宛先へ転送する。
7保証範囲
TCPの信頼性は、接続が維持されている間に、送信側のバイト列を順序どおりに受信側へ提供することを対象とする。障害によって接続が失敗した場合の最終的な配送や、受信側のアプリケーションがデータを処理したことまでは保証しない。「TCPは常にデータを配送する」と解釈してはならない。
8要点
- IPはデータグラムをベストエフォートで転送し、到達や順序を保証しない。
- TCPはIPの上に順序付きで信頼性のある全二重バイトストリームを構成する。
- IPアドレスはネットワーク層のインタフェースを識別し、ポート番号はトランスポートプロトコルとIPアドレスの文脈で通信端点を識別する。
- TCPの保証は、アプリケーションによる処理完了の保証とは異なる。
9次に進む講義
data/lecture/information/networks/dns-basics.lecture.n.md
TCP and IP Fundamentals
data/lecture/information/networks/computer-network-basics.lecture.n.md
1Introduction
This lecture distinguishes datagram forwarding by IP from byte-stream transport by TCP. After establishing the limits of the service that IP provides, it explains how TCP adds reliability through sequencing and retransmission.
2Network and Transport Layers
IP is a network-layer protocol. An IP address identifies a network-layer interface, and routers use a destination IP-address prefix to forward a datagram to its next hop. Routing constructs route information, whereas forwarding transfers each datagram according to that information.
TCP is a transport-layer protocol built on IP. It identifies communication endpoints by combining IP addresses with the port numbers introduced below and supports data transfer between applications.
3IP Best-Effort Forwarding
IP carries data received from an upper layer toward a destination as an IP datagram. IP provides a best-effort service. Network congestion, device failure, and other conditions can cause datagrams to be lost, arrive in a different order from the sending order, or arrive more than once. IP does not guarantee delivery, arrival order, or duplicate suppression.
4TCP Reliable Byte Streams
TCP provides an ordered byte stream between the two endpoints of a connection. TCP assigns sequence numbers to data and uses acknowledgments from the receiver to determine reception status. It retransmits data that has not been acknowledged and reorders data that arrives out of order, thereby delivering an ordered sequence of bytes to the application.
TCP supports full-duplex communication, so byte streams can be carried simultaneously in both directions. TCP does not, however, preserve the boundaries of individual messages sent by an application. An application protocol must represent its own lengths or delimiters.
5Port Numbers and TCP Connections
An IP address identifies a network-layer interface. In the context of a particular transport protocol such as TCP, a port number combines with an IP address to identify a communication endpoint. Conceptually, a TCP connection can be identified by the combination of source IP address, source port number, destination IP address, and destination port number.
A client generally uses a temporary port number, while a server waits for connections on a port number associated with the service that it provides. Port numbers allow multiple applications on a computer with the same IP address to communicate concurrently.
6Encapsulation and Communication Sequence
Application data is placed in a TCP segment, and the TCP segment is placed in the payload of an IP datagram. Adding lower-layer control information to upper-layer data in this manner is called encapsulation.
\text{application data}
\longrightarrow \text{TCP segment}
\longrightarrow \text{IP datagram}
For example, in HTTP/1.1 or HTTP/2 communication, TCP carries HTTP data as a byte stream, and IP forwards the TCP segments toward the destination as datagrams.
7Scope of Guarantees
TCP reliability concerns providing the receiver with the sender's bytes in order while the connection remains viable. It does not guarantee eventual delivery after a connection fails, nor does it guarantee that the receiving application has processed the data. TCP must not be interpreted as always delivering data.
8Key Points
- IP forwards datagrams on a best-effort basis and does not guarantee delivery or order.
- TCP builds an ordered, reliable, full-duplex byte stream on IP.
- An IP address identifies a network-layer interface, while a port number identifies an endpoint in the context of a transport protocol and an IP address.
- TCP's guarantees differ from a guarantee that an application has completed processing.
9Next Lecture
data/lecture/information/networks/dns-basics.lecture.n.md