|CITS3002 Computer Networks|
Internet Transport Layer ProtocolsTo date, we've compared the 7-layered OSI/ISO model to the 4-layered TCP/IP protocol suite. We've recently focused on how TCP/IP delivers its packets - using 32-bit IPv4 addresses to deliver data, first to the correct network, and then to the correct host on that network. We've also focused on how the protocols are embedded, or encapsulated, within each other:
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p1, 29th April 2020.
Port numbersIP addresses, alone, are not enough as they only address hosts, and not individual operating system processes on those hosts. From the perspective of any transport protocol, such as TCP (next), each arriving frame is further identified by a 16-bit positive port number that identifies the 'software end-point' to receive the payload. One role of TCP is to demultiplexed each arriving segment to its corresponding communication end-point, using a port as an index. Port numbers below 1024 are described as reserved ports, and on operating systems with distinct users and privilege levels, elevated privilege ('root' or 'administrator' access) is required to create a 'software end-point' bound to such ports. The Unix/Linux file /etc/services lists common ports:
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p2, 29th April 2020.
The Transmission Control Protocol (TCP)
The Transmission Control Protocol (TCP) transforms the 'raw' IP into a full-duplex reliable character stream [Ref:RFC 793].
TCP uses a 'well-understood' sliding window with selective-repeat protocol, and conveys a number of important fields in its TCP frame header:
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p3, 29th April 2020.
What TCP/IP Provides to Applications
TCP/IP provides 6 major features:
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p4, 29th April 2020.
TCP/IP 3-way connection establishment and teardown
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p5, 29th April 2020.
TCP/IP is employed between processes physically tens of centimetres (i.e. nano-seconds) apart, as well as processes tens of thousands of kilometres (near a second) apart.
As TCP/IP uses a sliding window protocol, timeouts are employed to force re-transmissions. As there are so many destination hosts, what should be the timeout value?
To cope with the widely varying network delays, TCP maintains a dynamic estimate of the current round trip time (RTT) for each connection. Because the RTTs vary tremendously, TCP averages RTTs into a smoothed round trip time (SRTT) that minimizes the effects of unusually short or long RTTs.
where α is a smoothing factor that determines how much weight the new values are given. When α=1, the new value of RTT is ignored, when α=0 all previous values are ignored. Typically α is between 0.8 and 0.9.
The SRTT estimates the average round trip time. To also allow for queuing and transmission delays, TCP also calculates the mean deviation (MDEV) of the RTT from the measured value.
This is also smoothed:
RTO = SRTT + 2 x SMDEV
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p6, 29th April 2020.
TCP/IP Congestion Control
Perhaps the most important, and certainly the most studied and 'tinkered with' aspect of TCP/IP is its congestion control.
TCP attempts to avoid congestion collapse by using end-to-end packet loss as the metric of congestion.
In combination with its closely related slow-start algorithm for new connections, TCP is capable of both avoiding and recovering from most congestion.
Ref: RFC 2001.
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p7, 29th April 2020.
Network Application Program Interfaces (APIs)
Dating back to early operating system implementations, applications attempted to provide a common framework to access both files and devices.
Calls to Unix open() return a file descriptor which is then used in calls to read() and write().
It is preferable if the application program interfaces (API) to network I/O exhibit the same semantics as file, or stream, I/O, but this is difficult for a number of reasons:
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p8, 29th April 2020.
An Example Network API - Berkeley Sockets
Sockets are a generalization of the Unix file system I/O model. The most important difference is that the operating system binds file descriptors to files and devices when they are opened. With sockets, applications can specify the destination each time they use the socket.
When sockets were first proposed (1982 in 4.1cBSD), it was unclear how significant TCP/IP would become. As a (beneficial) consequence, sockets have been designed to use many different protocols.
The current (kernel) socket implementation consists of three parts :
A Guide to Network Programming using Internet sockets, by Brian "Beej" Hall.
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p9, 29th April 2020.
Legal combinations of protocols and drivers are specified when the kernel is configured.
For example, sockets that share common communication properties, such as naming conventions and protocol address formats, are grouped into address families.
The Linux file /usr/include/bits/socket.h lists all supported address families.
Processes communicate using the client-server paradigm.
A server process listens to a socket, one end of a bidirectional communication path and the client processes communicate with the server over another socket, the other end of the communication path.
The kernel maintains internal connections and routes data from client to server.
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p10, 29th April 2020.
Establishing Sockets With OS System Calls
The socket mechanism requires several Unix system calls. The socket() call establishes an end point of a communications link.
protocol is usually 0 to indicate the default for the family/type combination. The socket() system call returns a small integer, termed a socket descriptor, (akin to a file descriptor). The call may fail due to a request for an unknown protocol or when a request is made for a type without a supporting protocol.
The socket() system call only instantiates protocol from the 5-tuple association.
Depending on whether the socket is being used in the client or server of either a connection-oriented or connectionless communication, different programs do different things next:
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p11, 29th April 2020.
When initially created a socket is unbound (it has no addresses associated with it).
Communication cannot occur on an unbound socket - without a name for the process owning the socket, the kernel cannot demultiplex packets to the correct socket. The bind() routine provides an address (a name) to the local end of the socket.
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p12, 29th April 2020.
Naming Sockets, continued
The related call connect() takes the same arguments but binds an address to the remote end of the socket.
For connectionless protocols, such as UDP/IP, the kernel caches the destination address associated with the socket.
Server processes bind address to sockets and 'advertise' their names to identify themselves to clients.
Servers accept connections from remote clients and cannot use connect() because they do not (usually) know the address of the remote client until the client has initiated a connection.
Applications use listen() and accept() to perform passive opens.
When a server arranges to accept data over a virtual circuit, the kernel must arrange to queue requests until they can be serviced.
When accept() returns, from contains the network address of the remote end of the socket, and new_socket is in a connected state.
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p13, 29th April 2020.
System Call Sequences for Connection-oriented and Connectionless I/O
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p14, 29th April 2020.
A Client Process in the Unix Domain (in C)
Consider a simple client process wishing to establish a connection with a server process in the Unix domain. When communicating within the Unix domain, the data frames never leave the single computer, and never get lost (other than on an extremely busy machine).
In this example, the client program sends commands to a 3D printer which is directly connected to the same computer. The client process simply connects to the server process and then writes the bytes to be printed to the socket (note that this example is far from how print spooling works in practice!)
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p15, 29th April 2020.
A Server Process in the Unix Domain (in C)
Now consider our server process which accepts streams of bytes (commands and contents) to be printed on our 3D-printer.
To avoid contention for the printer, and to possibly screen the requests, a single server performs the printing.
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p16, 29th April 2020.
A Remote Login Client (Internet Domain, in C)
Most operating systems, supporting internetworking using the Berkeley sockets API, also provide many functions to facilitate access to many commonly required resources - such as hostnames, protocol numbers, service numbers, etc. In an environment where many computers require access to consistent data, these API functions, themselves, may be configured to seek their information via the Internet.
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p17, 29th April 2020.
Establishing TCP/IP Servers With Java Classes
Java provides two classes in its java.net package to establish stream-based input and output between server and client processes.
A ServerSocket object provides the Java representation of a TCP/IP connection on the server-side. When a ServerSocket is created, the calling thread blocks awaiting new connection requests.
There are four constructors for ServerSocket (since Java v1.2); the most popular simply accepts the required (integer) port to use. Specifying a port of 0 creates a socket on any free (non-reserved) port at the operating system's discretion.
When an instance of a ServerSocket is created it automatically listens for connection requests; by default with a queue length of 50.
When a connection request arrives the method blocking accept returns a new Socket for future data transfers between client and server.
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p18, 29th April 2020.
Establishing TCP/IP Clients With Java Classes
A Socket object provides the Java representation of a TCP/IP connection on the client-side.
There are eight constructors for Socket (since Java v1.2); the most popular accepts the remote host name and its server's port number.
The following simple (truncated) example connects to a server's port, and prints whatever output the server produces.
Once a connection is established between client and server, methods in the standard Stream classes in the java.io package send and receive data.
CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p19, 29th April 2020.