3. Design and Implementation of SX52 ICMP protocol
To allow routers on the Internet to report or provide unexpected information, in the TCP/IP Protocol series, an Internet Control Packet Protocol (ICMPInternet Control Message Protocol) is added for sending error messages ). ICMP is part of an IP address and must be used in each IP address implementation. Like all other communication services, ICMP packets are transmitted in the data part of an IP datagram. The ultimate goal of an ICMP packet is not the application or the user on the target machine, but the Internet protocol software module that processes it on the machine. That is to say, the Internet Control Packet protocol allows routers to send error or control packets to other routers or hosts. ICMP provides communication between the Internet protocol software of the two hosts.
Each ICMP message starts with the same 3 bytes: 1 8-bit integer Message TYPE). The field is used to identify the packet, with an 8-bit CODE) field provides further information about the message type, one 16-bit checksum field. In addition, ICMP packets always contain the problematic datagram header and the 64-bit data starting with it.
ICMP uses IP addresses to send each error message. When a router has an ICMP packet to be transmitted, it creates an IP datagram and encapsulates the ICMP packet. That is, the ICMP packet is placed in the IP datagram data zone, then the datagram is forwarded as usual. That is, the entire datagram is encapsulated in the frame for transmission.
The generation of each ICMP packet always corresponds to a datagram. The router returns an ICMP packet to the host that generates the datagram. Here, only the ICMP Response Request/response service is implemented. It is mainly used to PING the program to test the smoothness of the communication link. That is, it only processes ICMP frames of the received packet type 0x08, the ICMP packet sent is 0x00. It does not have its own proprietary variables and involves only ICMPGenCheckSum and ICMPProcPktIn () functions ().
4. Design and Implementation of SX52 UDP protocol
UDP is a simple datagram-oriented transport layer protocol. Each output operation of a process generates a UDP datagram and assembles it into an IP datagram to be sent. UDP does not provide reliability. It sends data from applications to the IP layer, but it does not guarantee that the data can reach the destination. Due to the lack of reliability, we seem to consider using UDP instead of a reliable protocol, such as TCP. However, the analysis shows that UDP has many advantages in our interconnect design: first, UDP has high transmission efficiency and does not require connection overhead before TCP communication. Second, UDP is simple, without complex state machine transmission mechanisms, the SX52 gateway cannot communicate normally due to inconsistent statuses after a reset, and the upper layer protocol is difficult to detect. Therefore, UDP can be used for communication to avoid the overhead of TCP connections), and many required features such as dynamic supertransmission and retransmission, congestion avoidance, and error checking are placed at the application layer for design and implementation. The variables used include:
Source Port {udpRxSrcPortMSB, udpRxSrcPortLSB };
Destination Port for UDP to receive the datagram {udpRxDestPortMSB, udpRxDestPortLSB };
Length of the UDP received datagram {udpRxDataLenMSB, udpRxDataLenLSB };
Source Port {udpTxSrcPortMSB, udpTxSrcPortLSB };
Destination Port for UDP to send the datagram {udpTxDestPortMSB, udpTxDestPortLSB };
The length of the datagram sent by UDP is {udpTxDataLenMSB, udpTxDataLenLSB }.
UDPAppInit (),
DPGenCheckSum (),
UDPStartPktOut (),
UDPProcPktIn (),
UDPEndPktOut (),
UDPAppProcPktIn (),
UDPAppProcPktOut.
5. Design and Implementation of SX52 TCP protocol
Transport Control Protocol (TCPTransmission Control Protocol) is an important Protocol in the transport layer. It provides a completely reliable, connection-oriented, full-duplex stream transmission service without data duplication or loss. In this design, the complex TCP protocol is reasonably simplified:
① Because the CAN network transmission speed is fast, Ethernet transmission with a small data volume and 10 Mbps will not be blocked, and hosts on the Ethernet will have sufficient capabilities to process communication data in a timely manner, therefore, the timeout and retransmission time can be fixed to 5 s.
② There are two 1500-byte receiving buffers on RTL8019AS, And the CAN network is a control network with a small amount of information. Therefore, the fixed receiving window is 1400 bytes.
③ Because we can use a common TCP service to satisfy the application, we can ignore emergency pointers and options and fill field values.
Through the above three simplification, the realization of TCP is actually greatly simplified.
Because TCP timeout and retransmission time determination and Window Size Control have complicated algorithms and implementation mechanisms. Its implementation variables include:
TcpState, {tcpTmpSeq4, tcpTmpSeq3, tcpTmpSeq2, tcpTmpSeq1 }, {TcpTmpAck4, tcpTmpAck3, tcpTmpAck2, tcpTmpAck1 }, {TcpUnAckMSB, tcpUnAckLSB }, TcpRxFlags, {tcpCheckSumMSB, tcpCheckSumLSB }, {TcpLengthMSB, tcpLengthLSB }, {TcpTmpMSB, TcpTmpLSB }, {TcbLocalPortMSB, tcbLocalPortLSB }, {TcbRemotePortMSB, tcbRemotePortLSB }, {TcbSndUna4, tcbSndUna3, tcbSndUna2, tcbSndUnal }, {TcbRcvNxt4, tcbRcvNxt3, tcbRcvNxt2, tcbRcvNxt1 }, TcbOffset, TcbFlags, {tcbSendWinMSB, tcbSendWinLSB }, {TcpTimerMSB, tcpTimerLSB}, etc. Related functions include: TCPIPInit (), TCPRxHeader (), TCPProcPktIn (), TCPTransmit (), TCPReTransmit (), TCPAppPassiveOpen (), TCPAppActiveOpen (), CPAppClose (), TCPAddRcvNxt (), TCPIncRcvNxt (), TCPIncSndUna (), TCPCopySeqToNxt (), TCPAckUpdate (), TCPUpdateSeq (), TCPChkSeq (), TCPRestorePrev (), TCPCmpNxtSeq (), TCPSendEmptyPkt (), TCPSendReset (), TCPSendSyn (), TCPSendISN (), TCPSendSynAck (), TCPSendAck (), TCPSendFin (), TCPCheckSuminit (), CPCheckSumAcc (), TCPCheckSumAddHdr (), CPTxByte (), TCPStartPktOut (), TCPAppInit (), TCPAppTxBytes (), TCPAppTxData (), TCPAppTxDone (), TCPAppRxBytes (), TCPAppRxData. |
6. Selection of TCP/IP Transport Layer Protocol
It is critical to apply the TCP/IP protocol to the control network and select the transport layer protocol type. To communicate with an existing application, the same protocol type must be used. In actual applications, TCP provides reliable data connections in terms of reliability. UDP and some protocols that directly access IP addresses are unreliable, and the datagram may be lost, damaged, or duplicated; in terms of performance, UDP delivers the fastest performance. Additional overhead such as reliability, traffic control reorganization package, and connection maintenance reduce TCP performance.
For low-speed systems, such as temperature and humidity sensors, it doesn't matter if you select TCP or UDP. For less important sensors, you can choose UDP. For sensors with high reliability requirements, TCP protocol should be used; for network devices with high real-time requirements, such as network conferencing systems, IP audios, and TVs with real-time playback, UDP protocol should be used for high data transmission rates; some synchronization systems with strict requirements should adopt UDP; data monitoring systems have high reliability requirements and should adopt TCP; Web and Email should also adopt TCP. In short, determine the protocol to be selected based on the actual situation.
Iv. Conclusion
For the embedded heterogeneous network interconnection scheme, the SX52 CAN bus and Ethernet Interconnection scheme are simplified for the TCP/IP protocol stack, it meets the high real-time performance, reliability and embedded design requirements of the measurement and control communication system. The interconnection scheme ensures the connection between the management and monitoring layer and the production measurement and control layer, facilitates the information exchange between the upper and lower layers, and meets the application requirements of industrial applications such as factories and substations.
Related Articles]
- Use Ethereal to learn TCP/IP protocol
- Microsoft Windows TCP/IP protocol stack IP header option Verification Vulnerability (MS05-019)
- TELNET TCP/IP terminal simulation Protocol