The protocollayer just above the Internet Layer is the Host-to-HostTransport Layer. This name is usually shortened toTransport Layer. The two most importantprotocols in the Transport Layer are Transmission ControlProtocol (TCP) and User Datagram Protocol(UDP). TCP provides reliable data delivery service withend-to-end error detection and correction. UDP provides low-overhead,connectionless datagram delivery service. Both protocols deliver databetween the Application Layer and the Internet Layer. Applicationsprogrammers can choose whichever service is more appropriate fortheir specific applications.
The UserDatagram Protocol gives application programs direct access to adatagram delivery service, like the delivery service that IPprovides. This allows applications to exchange messages over thenetwork with a minimum of protocol overhead.
UDPis an unreliable, connectionless datagram protocol. As notedpreviously, unreliable merely means that there are no techniques inthe protocol for verifying that the data reached the other end of thenetwork correctly. Within your computer, UDP will deliver datacorrectly. UDP uses 16-bit Source Port andDestination Port numbers in word 1 of themessage header, to deliver data to the correct applications process.Figure 1-8 shows the UDP message format.
Why do applications programmers choose UDP as a data transportservice? There are a number of good reasons. If the amount of databeing transmitted is small, the overhead of creating connections andensuring reliable delivery may be greater than the work ofre-transmitting the entire data set. In this case, UDP is the mostefficient choice for a Transport Layer protocol. Applications thatfit a query-response model are also excellentcandidates for using UDP. The response can be used as a positiveacknowledgment to the query. If a response isn’t receivedwithin a certain time period, the application just sends anotherquery. Still other applications provide their own techniques forreliable data delivery, and don’t require that service from thetransport layer protocol. Imposing another layer of acknowledgment onany of these types of applications is inefficient.
Many important Windows NT services rely on UDP. A prime example isthe Microsoft DHCP Server. The client queries the Dynamic HostConfiguration Protocol (DHCP) server for configuration information.The server responds with the requested information. This vitalquery/response protocol runs efficiently over UDP.
Applications that require thetransport protocol to provide reliable data delivery use TCP becauseit verifies that data is delivered across the network accurately andin the proper sequence. TCP is a reliable,connection-oriented,byte-stream protocol. Let’s look at eachof the terms—reliable, connection-oriented, andbyte-stream—in more detail.
TCP provides reliability with amechanism called Positive Acknowledgment withRe-transmission (PAR). Simply stated, a system using PARsends the data again, unless it hears from the remote system that thedata arrived successfully. The unit of data exchanged betweencooperating TCP modules is called a segment (seeFigure 1-9). Each segment contains a checksum that the recipient usesto verify that the data is undamaged. If the data segment is receivedundamaged, the receiver sends a positiveacknowledgment back to the sender. If the data segment isdamaged, the receiver discards it. After an appropriate time-outperiod, the sending TCP module re-transmits any segment for which nopositive acknowledgment has been received.
TCP is connection-oriented. Itestablishes a logical end-to-end connection between the twocommunicating hosts. Control information, called ahandshake, is exchanged between the twoendpoints to establish a dialogue before data is transmitted. TCPindicates the control function of a segment by setting theappropriate bit in the Flags field in word 4 of thesegment header.
Thetype of handshake used by TCP is called a three-wayhandshake because three segments are exchanged. Figure 1-10 show the simplest form of the three-way handshake. HostA begins the connection by sending hostB a segment with the Synchronize sequencenumbers (SYN) bit set. This segment tells host Bthat A wishes to set up a connection, and ittells B what sequence number hostA will use as a starting number for itssegments. (Sequence numbers are used to keep data in the properorder.) Host B responds toA with a segment that has theAcknowledgment(ACK) and SYN bits set. B’s segmentacknowledges the receipt of A’s segment,and informs A which Sequence Number hostB will start with. Finally, hostA sends a segment that acknowledges receipt ofB’s segment, and transfers the firstactual data.
After this exchange, hostA’s TCP has positive evidence that theremote TCP is alive and ready to receive data. As soon as theconnection is established, data can be transferred. When thecooperating modules have concluded the data transfers, they willexchange a three-way handshake with segments containing theNo more data from sender bit (called theFIN bit) to close the connection. It is theend-to-end exchange of data that provides the logical connectionbetween the two systems.
TCP views the data it sends as acontinuous stream of bytes, not as independent packets. Therefore,TCP takes care to maintain the sequence in which bytes are sent andreceived. The Sequence Number and Acknowledgment Number fields in theTCP segment header keep track of the bytes.
The TCP standard does not require thateach system start numbering bytes with any specific number; eachsystem chooses the number it will use as a starting point. To keeptrack of the data stream correctly, each end of the connection mustknow the other end’s initial number. The two ends of theconnection synchronize byte-numbering systems by exchanging SYNsegments during the handshake. The Sequence Number field in the SYNsegment contains the Initial Sequence Number(ISN), which is the starting point for the byte-numbering system. Forsecurity reasons the ISN should be a random number, though it isoften 0.
Each byte of data is numbered sequentially from the ISN, so the firstreal byte of data sent has a sequence number of ISN+1. The SequenceNumber in the header of a data segment identifies the sequentialposition in the data stream of the first data byte in the segment.For example, if the first byte in the data stream was sequence number1 (ISN=0) and 4000 bytes of data have already been transferred, thenthe first byte of data in the current segment is byte 4001, and theSequence Number would be 4001.
TheAcknowledgment Segment (ACK) performs twofunctions—positive acknowledgment andflow control. The acknowledgment tells thesender how much data has been received, and how much more thereceiver can accept. The Acknowledgment Number is the sequence numberof the next byte the receiver expects to receive. The standard doesnot require an individual acknowledgment for every packet. Theacknowledgment number is a positive acknowledgment of all bytes up tothat number. For example, if the first byte sent was numbered 1 and2000 bytes have been successfully received, the Acknowledgment Numberwould be 2001.
The Windowfield contains the window, or the number ofbytes the remote end is able to accept. If the receiver is capable ofaccepting 6000 more bytes, the window would be 6000. The windowindicates to the sender that it can continue sending segments as longas the total number of bytes that it sends is smaller than the windowof bytes that the receiver can accept. The receiver controls the flowof bytes from the sender by changing the size of the window. A zerowindow tells the sender to cease transmission until it receives anon-zero window value.
Figure 1-11 shows a TCP data stream that starts with an InitialSequence Number of 0. The receiving system has received andacknowledged 2000 bytes, so the current Acknowledgment Number is2001. The receiver also has enough buffer space for another 6000bytes, so it has advertised a window of 6000. The sender is currentlysending a segment of 1000 bytes starting with Sequence Number 4001.The sender has received no acknowledgment for the bytes from 2001 on,but continues sending data as long as it is within the window. If thesender fills the window and receives no acknowledgment of the datapreviously sent, it will, after an appropriate time-out, send thedata again starting from the first unacknowledged byte. In Figure 1-11, re-transmission would start from byte 2001 if no furtheracknowledgments are received. This procedure ensures that data isreliably received at the far end of the network.
TCP is also responsible for delivering data received from IP to thecorrect application. The application that the data is bound for isidentified by a 16-bit number called the portnumber.The Source Port andDestination Portare contained in the first word of the segment header. Correctlypassing data to and from the Application Layer is an important partof what the Transport Layer services do.