3.2 – Multiplexing and Demultiplexing
- Extending the host-to-host delivery service provided by the network layer to a process-to-process deliver service.
- Example:
- Suppose you are sitting in front of your computer, and you are downloading web pages while running one FTP session and two telnet sessions. You therefore have four network application processes running. When the transport layer in your computer receives data from the network layer below, it needs to direct the received data to one of these four processes.
- A process can have one or more socket, doors through which data passes from the network to the process and through which data passes from the process to the network. The transport layer in the receiving host does not actually deliver data directly to a process, but instead to an intermediary socket. Each socket has a unique identifier (format depends on TCP or UDP)
- Each transport-layer segment has a set of fields in the segment. At the receiving end, the transport layer examines these fields to identify the receiving socket and then directs the segment to that 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 to create segments, and passing the segments to the network layer is called multiplexing.
- The special fields in the header are the source port number field and the destination port number field. Each port number is a 16-bit number (0-65535).
- The ports ranging from 0-1023 are called well-known port numbers and are restricted/reserved for use by well-known application protocols such as HTTP (80) and FTP (21)
- Connectionless multiplexing and demultiplexing:
- When creating a UDP socket it gets assigned a port number, but you can bind it to a specific port afterwards.
- Lets see how UDP multiplexing/demultiplexing works:
- Suppose a process in Host A, with UDP port 19157, wants to send a chunk of application data to a process with UDP port 46428 in Host B.
- The transport layer in Host A creates a transport-layer segment that includes the application data, the source port, the destination port number, and two other values.
- The transport layer then passes the resulting segment to the network layer who encapsulates it in an IP datagram and makes a best effort delivery.
- If the segment arrives at the receiving host B, the transport layer at the receiving host examines the destination port number in the segment and delivers the segment to its socket identified by port 46428.
- Note that Host B could be running multiple processes, each with its own UDP socket and associated port number. As UDP segments arrive from the network, host B directs (demultiplexing) each segment to the appropriate socket by examining the segments destination port number.
- If two segment has different source IP address and or source port, but the same destination IP address and port then both will go to the same socket.
- The source port and IP address is used as a return address if the server were to send/respond back to the client.
- Connection-Oriented Multiplexing and Demultiplexing:
- The TCP socket is identified by a four-touple:
- Source IP address
- Source port number
- Destination IP address
- Destination port number
- Two arriving segments with different source IP addresses or source port number will be directed to two different sockets.
- Look at the example of where we coded a TCP socket to see how it works.
- A connection-established request is nothing more than a TCP segment with destination port number and a special connection-establishment bit set in the TCP header (it also contains the source port number)
- Consider a host running a Web server, such as an apache Web server on port 80. When clients send segments to the server, all segments will have destination port 80. In particular, both the initial connection establishment segments and the segments carrying HTTP request messages will have destination port 80. As we have just described, the server distinguishes the segments form the different clients using source IP addresses and source port numbers.
- There is not always a one-to-one correspondence between connection sockets and processes. In fact, todays web servers often us only one process and create a new thread with a new connection socket for each new client connection.
- If the connection to the server is persistent then it uses the same socket during the whole connection. If it is a non-persistent connection then a new TCP connection is created and closed for every request/response.