Quick viewing(Text Mode)

INTRODUCTION to the TRANSMISSION CONTROL PROTOCOL How Does TCP and UDP Impact Control Networks? by George Thomas, Contemporary Controls

INTRODUCTION to the TRANSMISSION CONTROL PROTOCOL How Does TCP and UDP Impact Control Networks? by George Thomas, Contemporary Controls

Volume 1 • Issue 5 March–April 2000

Introduction to Industrial , Part 3. Part 2 was featured in Issue 4, the Winter 1999. If you would like a copy, please send your request to EXTENSION [email protected] A Technical Supplement to control NETWORK

INTRODUCTION TO THE TRANSMISSION CONTROL PROTOCOL How does TCP and UDP impact control networks? By George Thomas, Contemporary Controls

INTRODUCTION USER The UDP is short and PROTOCOL simple. Only eight bytes are In the last EXTENSION issue required in the header. Source and (Volume 1 Issue 4) we discussed UDP provides a connectionless destination ports are each 16-bits the impact of the Protocol and unreliable transport service long and, therefore, require four (IP) on control networks. IP since it does not issue bytes. The message length of 16- resides at the of the acknowledgements to the sender bits indicates the length of the OSI communications model and upon receipt of data nor does it header and attached data. A 16-bit provides the basic unit of data inform the sender that data was checksum is used to check the transfer, which includes addressing, lost. Data integrity can suffer by validity of the header and data. , and fragmentation. The dropped packets, missequenced The UDP header and attached of this same model packets or by the receipt of data, which comes from the resides above the network layer duplicate packets. Any of these , are encapsulated and provides station-to-station situations can occur without the into the IP data field. An IP communication and a common knowledge of the sender. It header, which provides station interface to the application layer. appears that UDP is no better than addressing, precedes the UDP This implies reliable the IP protocol but there is one datagram and the complete IP communication, which is either big difference. UDP introduces the datagram is encapsulated into the accomplished at the transport layer concept of port numbers, which frame of the data or at the application layer. With are used by the application layer technology used, such as Ethernet, control networks this is usually that resides above UDP. Port and sent to the desired station accomplished at the application numbers have significance in where the complete process is layer since many control networks terms of actions requested by the reversed. Notice that the only were designed before the application itself that require a contribution UDP provided was popularity of TCP/IP took hold. particular response by the the assignment of port numbers Still there are some control receiving station. network protocols, such as MODBUS/TCP, which do rely upon Source port Destination port the guaranteed delivery mechanism Message Length Checksum of TCP and there may be more in the future. Actually, at the transport Data layer of the TCP/IP stack there are Data two transport protocols, each of which find service in control networks. The User Datagram Type IP SADA UDP Header and Data CRC Protocol (UDP) and the 0800 Header Transmission Control Protocol (TCP) will both be discussed in Figure 1. The UDP header is quite short and, along with its data, this article. it is encapsulated into an IP datagram.

1 for use by the application layer. If quickly making it attractive for insert a 69 (a well-known port UDP is to be used, the application control networks. assignment indicating TFTP layer must worry about services) into its destination port. acknowledging message receipt, A dynamic (random but non- correctly ordering received packets PORT NUMBERS conflicting) number will be put in into meaningful messages, UDP introduces the port number its source port and the request will discarding duplicate packets and concept. When a station receives a be sent to station B. Station B requesting retransmission of faulty UDP datagram, it serves up the would receive the request and packets since UDP does not port number to the application recognize it is a TFTP request from provide this service. However, if layer, which then allocates a buffer station A since port number 69 the application layer was originally area for the attached data. The was used. Station B would then designed to provide this reliability port number has significance begin executing the process. But it of service there is no reason to since it identifies a particular would insert a 69 in its source have the transport layer duplicate application. Since there are many port, and the dynamic number that effort so UDP makes sense. UDP port number possibilities, several was generated by station A in its has low overhead and executes different applications can be destination port, and send the simultaneously supported on response to station A. Station B the same station. knows how to handle this particular application since it Port Number Assignments recognizes both the source and Port numbers are 16-bits long and destination port numbers. The use are classified as being assigned, Both UDP and TCP use port numbers and, of port numbers along with the IP registered or dynamic. Assigned if possible, the same assignment is used address creates what is called a port numbers in the range of zero socket, which can be represented for both. The 16-bit numbers are to 1023 have been defined by the as . As long classified as either assigned (well- Internet Assigned Numbers as there is structure to the known), registered or dynamic (private). Authority (IANA) for various assignment of ports, the socket Port number assignments are maintained applications that are considered assignment becomes a unique part of the TCP/IP protocol suite. by the Internet Assigned Numbers representation of a particular These applications include Authority (IANA) and the complete list application on the complete IP , FTP, and other popular network. can be found at ftp://ftp.isi.edu/in- Internet applications. These port notes/iana/ under port numbers. numbers are termed “well known” Numbers in the range of zero to 1023 and cannot be used by other TRANSMISSION CONTROL are classified as well-known and are applications. The remainder of the PROTOCOL port assignments is classified as used by common processes. However, The second transport layer being either registered or dynamic. individual organizations can register protocol is TCP which provides for Registered means that an a connection-based reliable numbers in the range of 1024 to 49151 organization wants to define some message delivery service for for proprietary purposes and will not be level of functionality and has processes. This relieves the used by other organizations. Looking at registered a unique port number application layer the responsibility the list, we find some companies in our with the IANA. Other organizations of guaranteed message delivery. are to respect this assignment and industry. Opto22 has registered 22000 Besides reliable connections, TCP not use either assigned or and 22001 for their SNAP I/O and Opto provides flow control to ensure registered port numbers. Finally, stations are not flooded with data. Control products. The BACnet building the dynamic port numbers are automation protocol has registered used in a random manner by a 47808. DeviceNet and ControlNet requesting station to signify the Data transmitted between stations intend to use 44818. Interestingly, the source port of an application is sent as a series of packets. request. These packets are reassembled at MODBUS/TCP specification calls for port the receiving end in the proper 502, which is in the well-known port order to recreate the data stream group. Port numbers 49152 to 65535 For example, if station A requests that was transmitted. Along the are considered as either private or a trivial way packets can be corrupted, (TFTP) service (TFTP happens to dynamic and can be used by anyone. lost, duplicated or received out of use UDP) from station B, it would

2 order. In order to make sense of scheme described above. Instead to station A’s request for data, that all this, sequence numbers are of sequencing each packet, TCP data can be sent along with an applied to each packet sequences each byte in the packet. acknowledgement of station A’s transmission. A sequence number Assigning a sequence number to requesting message. This speeds is assigned to the first packet of a indicate the first byte in a multi- up processing. message. It does not matter what byte packet does this. The second is the initial value of the sequence packet will have a sequence number only that the second number equal to the first sequence TCP’s header is larger than that of packet has been assigned the number plus the number of bytes UDP but uses the same port initial sequence number plus one. in the first packet. The receiver assignment scheme as UDP does. The rule is that successive packets expects the same. The receiver Unlike UDP, a 32-bit sequence of a data stream have ascending acknowledges receipt of good number and acknowledgement sequence numbers each packets by transmitting an number are included in the header incremented by one. After all the acknowledgement that includes as well as several flag bits. Only a packets are received, sequence the value of the next expected few of the flag bits will be numbers are used to order the sequence number. In this case, it discussed here. Since the TCP packets. Missing sequence is the sequence number of the last header can be of varying length numbers indicate the packet was byte in the last received packet depending upon the content of the lost. Duplicate packet numbers plus one. Upon receipt of this options field, a data offset field indicate duplicate packets were acknowledgement, the sender can has been provided in order to received allowing them to be assume that previous bytes up determine the actual beginning of discarded. If all the packets are until the indicated sequence the data. The padding field has received in tact then the data number were received properly. been provided so that the options stream was received properly and Before a sender can discard the field along with the padding field the receiving station could packets being sent it must wait will end on a 32-bit boundary. acknowledge receipt to the sender. until this acknowledgement has This is typically done with all the If not, a request for retransmission been received because it may be headers within the TCP/IP stack. A of the missing packet can be called upon to resend some of the window field in the header made. There is no need to resend data. Acknowledgements need not indicates to the sender how much the entire data stream. require a separate transmission data the receiver is willing to and each packet need not be accept. This feature is used for acknowledged. For efficiency, TCP flow control, which attempts to TCP provides a byte-oriented allows an acknowledgement field prevent buffer overflow in the sequencing protocol that is more to be sent along with data. For receiver. Finally, data follows the robust than the packet sequence example, if station B is responding TCP header. The header can be up to 40 bytes in length and the header with its appended data is

Source port Destination port called a segment. A checksum field ensures the integrity of the Sequence number header and its associated data.

Acknowledgment number

Data U A P R S F USING CONNECTIONS Reserved R C S S Y I Window offset G K H T N N When using the TCP protocol with Checksum Urgent pointer processes a connection must be Options Padding first established and maintained in order to provide for the flow of Data data. By establishing a connection between two stations, the proper buffer area is provided for the impending data. When station A wants to communicate to station B it must first establish a connection Type IP DA SA TCP Header and Data CRC 0800 Header which allows for the synchronization of sequence Figure 2. The TCP header is much more complex than UDP and its length can vary. numbers and acknowledgements.

3 This process is shown in figure 3. One of the flags within the TCP header is the SYN bit, which is used to indicate the initial sequence number when a connection is established. This informs the receiver to synchronize its error checking means to this sequence number. Therefore, station A sends a TCP segment with SYN set and its sequence number, which in this case is 10, to station B. Station B responds by sending an acknowledgement with the value 11 to indicate that is the value of the sequence number it expects to receive next. Station B has its own sequence number that it sends to station A. In this case it is 30 which station A acknowledges by sending out a 31. This establishes Figure 3. A full-duplex connection must first be established before two connections. Once the data can be transferred using TCP. connections are established, data is sent from station A to station B FLOW CONTROL flag set along with a sequence with station A incrementing number in the urgent pointer field sequence numbers and station B Flow control is the management of that indicates the first byte of data acknowledging them. This is what data transfer between two stations. following the urgent data. The is called a full duplex connection Depending upon the role of the receiver should always allow since two connections were station, be it client or server, or its room for urgent data. established; one from A to B and processing power, a station may another from B to A. These not be able to keep up with the connections remain established network traffic. In order to slow SUMMARY until terminated. down events the TCP header has a Although TCP is more reliable field called window. The receiving than UDP, UDP can be quite station sets a value in the window effective if the application layer Once the required data transfer has field informing the sender how been completed, the two can handle error checking and many bytes of data it will accept. retransmission. For applications connections should be terminated in The window is dynamic and the order to up buffer space in the that require secure window can be increased as buffer communication, TCP is the best two stations. There is a flag called space in the receiver becomes FIN, which is used to terminate the choice. Both TCP and UDP use available. The window can also be port numbers and when used with connection. Station A sends a TCP zero halting transmission. If the segment with FIN flag set along IP addresses create unique socket sender still needs to communicate definitions across the network. with a sequence number. Station B important information while in this acknowledges the request and once These socket definitions facilitate condition it can send out a the processes between the stations the acknowledgement is received at segment with the URG (urgent) Station A the connection from A to on the control network. B is terminated. This does not mean that the connection from B to A is terminated. This must be done in a REFERENCES like fashion in order to terminate Illustrated TCP/IP, Matthew Naugle, 1998, Wiley Computer Publishing the full duplex connection. TCP/IP Clearly Explained, Pete Loshin, 1997, Academic Press

www.ccontrols.com

4