Transport layer provides communication services directly to the application processes running on different hosts.

3.1 Introduction and Transport-Layer Services

  • logical communication
    A transport-layer protocol provides for logical communication between application processes running on different hosts.
    Application processes use the logical communication provided by the transport layer to send messages to each other, free from the worry of the details of the physical infrastructure used to carry these messages.

    Transport-layer protocols are implemented in the end systems but not in network routers.

3.1.1 Relationship Between Transport and Network Layers

Recall that the transport layer lies just above the network layer in the protocol stack.
Whereas a transport-layer protocol provides logical communication between processes running on different hosts, a network-layer protocol provides logical- communication between hosts.
Transport-layer protocols live in the end systems.
Within an end system, a transport protocol moves messages from application processes to the network edge (that is, the network layer) and vice versa, but it doesn’t have any say about how the messages are moved within the network core.
Intermediate routers neither act on, nor recognize, any information that the transport
layer may have added to the application messages.
The services that a transport protocol can provide are often constrained by the service model of the underlying network-layer protocol.

3.1.2 Overview of the Transport Layer in the Internet

UDP (User Datagram Protocol), which provides an unreliable, connectionless service to the invoking application.
TCP (Transmission Control Protocol) provides a reliable, connection-oriented service to the invoking application.

  • segment:transport-layer packet
  • IP
    The Internet’s network-layer protocol has a name—IP, for Internet Protocol.
    IP provides logical communication between hosts.
    The IP service model is a best-effort delivery service.

The most fundamental responsibility of UDP and TCP is to extend IP’s delivery service between two end systems to a delivery service between two processes running on the end systems.
Extending host-to-host delivery to process-to-process delivery is called transport-layer multiplexing and demultiplexing.
Process-to-process data delivery and error checking—are the only two services that UDP provides.

3.2 Multiplexing(复用) and Demultiplexing(解复用)

A multiplexing/demultiplexing service is needed for all computer networks.
The transport layer in the receiving host does not actually deliver data directly to a process, but instead to an intermediary socket.

This job of delivering the data in a transport-layer segment to the correct socket is called demultiplexing.
The job of gathering data chunks at the source host from different sockets, encapsulating each data chunk with header information (that will later be used in demultiplexing) to create segments, and passing the segments to the network layer is called multiplexing.
Transport-layer multiplexing requires:

  1. sockets have unique identifiers
  2. each segment have special fields that indicate the socket to which the segment is to be delivered.

Connectionless Multiplexing and Demultiplexing

The Python program running in a host can create a UDP socket with the line

1
clientSocket = socket(AF_INET, SOCK_DGRAM)

When a UDP socket is created in this manner, the transport layer automatically assigns a port number to the socket.
In particular, the transport layer assigns a port number in the range 1024 to 65535 that is currently not being used by any other UDP port in the host. Alternatively, we can add a line into our Python program after we create the socket to associate a specific port number (say, 19157) to this UDP socket via the socket bind() method:

1
clientSocket.bind((’’, 19157))

If the application developer writing the code were implementing the server side of a “well-known protocol,” then the developer would have to assign the corresponding well-known port number.
Typically, the client side of the application lets the transport layer automatically (and transparently) assign the port number, whereas the server side of the application assigns a specific port number.
UDP socket is fully identified by a two-tuple consisting of a destination IP address and a destination port number.

  • source port number(源端口号)

    In UDPServer.py, the server uses the recvfrom() method to extract the client-side (source) port number from the segment it receives from the client; it then sends a new segment to the client, with the extracted source port number serving as the destination port number in this new segment.
    In particular, and in contrast with UDP, two arriving TCP segments with different source IP addresses or source port numbers will (with the exception of a TCP segment carrying the original connection-establishment request) be directed to two different sockets.
    To gain further insight, let’s reconsider the TCP client-server programming example :
  1. The TCP server application has a “welcoming socket,” that waits for connection-establishment requests from TCP clients on port number 12000.
  2. The TCP client creates a socket and sends a connection establishment request segment with the lines:
    1
    2
    clientSocket = socket(AF_INET, SOCK_STREAM)  
    clientSocket.connect((serverName,12000))
  3. A connection-establishment request is nothing more than a TCP segment with destination port number 12000 and a special connection-establishment bit set in the TCP header. The segment also includes a source port number that was chosen by the client.
  4. When the host operating system of the computer running the server process receives the incoming connection-request segment with destination port 12000, it locates the server process that is waiting to accept a connection on port number. The server process then creates a new socket:
    1
    connectionSocket, addr = serverSocket.accept()
  5. Also, the transport layer at the server notes the following four values in the connection-request segment:
    (1) the source port number in the segment
    (2) the IP address of the source host
    (3) the destination port number in the segment
    (4) its own IP address. The newly created connection socket is identified by these four values;
    all subsequently arriving segments whose source port, source IP address, destination port, and destination IP address match these four values will be demultiplexed to this socket. With the TCP connection now in place, the client and server can now send data to each other.

The server host may support many simultaneous TCP connection sockets, with each socket attached to a process, and with each socket identified by its own four-tuple.

Web Servers and TCP

There is not always a one-to-one correspondence between connection sockets and processes.

3.3 Connectionless Transport: UDP

At the very least, the transport layer has to provide a multiplexing/demultiplexing service in order to pass data between the network layer and the correct application-level process.
Aside from the multiplexing/demultiplexing function and some light error checking, UDP adds nothing to IP.