[go: up one dir, main page]

CN103997500A - Achieving method of light-weight real-time TCP/IP protocol stack - Google Patents

Achieving method of light-weight real-time TCP/IP protocol stack Download PDF

Info

Publication number
CN103997500A
CN103997500A CN201410244343.2A CN201410244343A CN103997500A CN 103997500 A CN103997500 A CN 103997500A CN 201410244343 A CN201410244343 A CN 201410244343A CN 103997500 A CN103997500 A CN 103997500A
Authority
CN
China
Prior art keywords
data
processing module
tcp
protocol
protocol stack
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201410244343.2A
Other languages
Chinese (zh)
Inventor
蒋泽军
杜承烈
陈进朝
黄云婷
侯亮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Northwestern Polytechnical University
Original Assignee
Northwestern Polytechnical University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Northwestern Polytechnical University filed Critical Northwestern Polytechnical University
Priority to CN201410244343.2A priority Critical patent/CN103997500A/en
Publication of CN103997500A publication Critical patent/CN103997500A/en
Pending legal-status Critical Current

Links

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The invention provides an achieving method of a light-weight real-time TCP/IP protocol stack. A standard TCP/IP protocol stack is improved through protocol stack initialization, a socket interface module processing state, a transmission layer processing stage, a network layer processing stage, a media access control layer processing stage and a network card abstraction layer processing stage, system expandability is enhanced, system real-time performance is improved, and system overhead and communication delay are lowered.

Description

一种轻量级实时TCP/IP协议栈的实现方法A Realization Method of Lightweight Real-time TCP/IP Protocol Stack

技术领域technical field

本发明属于计算机网络和数据通信技术领域,具体为一种轻量级实时TCP/IP协议栈的实现方法。The invention belongs to the technical field of computer network and data communication, and specifically relates to a realization method of a lightweight real-time TCP/IP protocol stack.

背景技术Background technique

目前标准TCP/IP协议栈其实现复杂,且不能满足特定应用对实时性的要求,而为保证通信实时性的解决方案,大多是对数据链路层进行更改和扩展,诸如以下三种方案:The implementation of the current standard TCP/IP protocol stack is complex and cannot meet the real-time requirements of specific applications. To ensure real-time communication solutions, most of the solutions are to modify and expand the data link layer, such as the following three solutions:

1.由奥地利贝加莱公司提出的Ethernet Powerlink,引入了SCNM(时间槽通信网络管理)算法来保证实时以太网通信的确定性。1. The Ethernet Powerlink proposed by B&R Austria introduced the SCNM (Time Slot Communication Network Management) algorithm to ensure the determinism of real-time Ethernet communication.

2.由德国倍福公司提出的EtherCAT(Ethernet for Control Automation Technology),其采用IEEE1588标准中定义的精确时钟同步机制,引入了时间戳数据类型座位扩展。2. EtherCAT (Ethernet for Control Automation Technology) proposed by Beckhoff, Germany, adopts the precise clock synchronization mechanism defined in the IEEE1588 standard, and introduces the seat extension of the timestamp data type.

3.我国第一个拥有自主知识产权的现场总线国家标准:《EPA通信标准》对ISO/IEC8802.3协议规定的数据链路层进行扩展,增加了通信调度管理实体(Communication Scheduling Management Entity,CSME)。3. my country's first fieldbus national standard with independent intellectual property rights: "EPA Communication Standard" expands the data link layer specified in the ISO/IEC8802.3 protocol, and adds the Communication Scheduling Management Entity (CSME) ).

但这些方案仅为了保证通信实时性,而对于协议栈实现复杂的缺点仍未得到解决,因此提出一种轻量级实时对TCP/IP协议栈的实现方法具有重要意义。But these schemes are only to ensure the real-time communication, and the disadvantages of complex implementation of the protocol stack have not been solved, so it is of great significance to propose a lightweight real-time implementation method for the TCP/IP protocol stack.

发明内容Contents of the invention

本发明旨在实现一种轻量级实时TCP/IP协议栈,使之不仅实现简单,使用方便,减少系统开销和通信延迟,且能满足特定应用对实时性能的要求。The invention aims at realizing a light-weight real-time TCP/IP protocol stack, which is not only simple to implement, convenient to use, reduces system overhead and communication delay, but also can meet the requirements of specific applications for real-time performance.

本发明的技术方案为:Technical scheme of the present invention is:

所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:包括以下步骤:The realization method of described a kind of lightweight real-time TCP/IP protocol stack, is characterized in that: comprise the following steps:

步骤1:初始化协议栈;Step 1: Initialize the protocol stack;

步骤2:完成socket接口优先级、实时指标、阻塞方式、最大发送和接收缓冲区池大小的设置操作;完成socket接口的创建、绑定、监听、关闭以及数据收发接口实现;通过socket接口接收应用程序请求,并对不兼容的应用程序请求进行格式转换;Step 2: Complete the setting operation of socket interface priority, real-time indicators, blocking mode, maximum sending and receiving buffer pool size; complete the creation, binding, monitoring, closing and data sending and receiving interface implementation of socket interface; receive applications through socket interface Program requests, and format conversions for incompatible application requests;

步骤3:采用TCP协议处理模块或UDP协议处理模块对网络数据包进行处理;Step 3: using the TCP protocol processing module or the UDP protocol processing module to process the network data packets;

步骤4:采用IP协议处理模块对网络数据包进行封包和拆包;Step 4: Packing and unpacking the network data packets by using the IP protocol processing module;

步骤5:在介质访问控制模块中采用基于TDMA的介质访问机制和令牌环方式得到所需的网络实时性;Step 5: In the medium access control module, adopt the medium access mechanism based on TDMA and the token ring mode to obtain the required network real-time performance;

步骤6:在网卡驱动抽象层对网卡驱动进行统一的数据抽象;当网卡设备启用时,向该网卡驱动的数据抽象进行注册,并完成网卡驱动数据抽象与网卡驱动的连接;当需要发送的数据到达网卡驱动数据抽象层时,通过本地维护的路由表选择具体使用的网卡设备从而完成数据的发送。Step 6: Perform unified data abstraction on the network card driver at the network card driver abstraction layer; when the network card device is enabled, register with the data abstraction of the network card driver, and complete the connection between the network card driver data abstraction and the network card driver; when the data to be sent When reaching the data abstraction layer of the network card driver, the specific network card device to be used is selected through the locally maintained routing table to complete the data transmission.

进一步的优选方案,所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:初始化协议栈包括:完成网卡服务句柄的打开、网卡设备的绑定、打开操作;分配全局重发缓冲区池和全局发送缓冲区池;设置发送、接收线程优先级;增加系统服务表项;设置本机IP地址和MAC地址,并通过内存映射到用户空间。A further preferred solution, the implementation method of a lightweight real-time TCP/IP protocol stack is characterized in that: initializing the protocol stack includes: completing the opening of the network card service handle, the binding and opening of the network card device; Send buffer pool and global send buffer pool; set sending and receiving thread priority; add system service table items; set local IP address and MAC address, and map to user space through memory.

进一步的优选方案,所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:创建socket接口时,设置socket接口的类型,在内核中为每个socket接口分配接收缓冲区池,并将之映射到用户空间;绑定socket接口时,完成socket接口、端口号和目的主机的绑定操作,在内核下向目的主机发送ARP请求以获得目的主机MAC地址,协议栈中采用静态ARP机制,完成地址解析。Further preferred scheme, described a kind of realization method of lightweight real-time TCP/IP protocol stack, is characterized in that: when creating socket interface, the type of socket interface is set, in kernel, allocates receiving buffer pool for each socket interface , and map it to the user space; when binding the socket interface, complete the binding operation of the socket interface, port number and destination host, send an ARP request to the destination host under the kernel to obtain the destination host MAC address, the protocol stack adopts static ARP mechanism to complete address resolution.

进一步的优选方案,所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:socket接口接收数据直接从缓冲区池中取出数据;socket接口发送数据,直接写入到协议栈初始化时分配的全局发送缓冲区池中。Further preferred scheme, described a kind of implementation method of lightweight real-time TCP/IP protocol stack, is characterized in that: socket interface receives data and directly takes out data from buffer pool; Socket interface sends data, directly writes into protocol stack In the global send buffer pool allocated at initialization.

进一步的优选方案,所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:当网络采用TCP传输方式,socket接口调用TCP协议处理模块进行数据包处理,所述TCP协议处理模块实现正常的TCP流程的状态机、对大数据包进行拆分,屏蔽IP分片功能、通过窗口大小完成流量和拥塞控制功能;当网络采用UDP传输方式,socket接口调用UDP协议处理模块进行数据包处理,所述UDP协议处理模块完成数据包的UDP协议封装、通过对大数据包进行拆分,屏蔽IP分片功能,省略UDP校验和计算功能。Further preferred scheme, described a kind of implementation method of lightweight real-time TCP/IP protocol stack, is characterized in that: when network adopts TCP transmission mode, socket interface transfers TCP protocol processing module to carry out packet processing, and described TCP protocol processing The module implements the state machine of the normal TCP process, splits large data packets, shields the function of IP fragmentation, and completes the flow and congestion control functions through the window size; when the network adopts UDP transmission mode, the socket interface calls the UDP protocol processing module to process data Packet processing, the UDP protocol processing module completes the UDP protocol encapsulation of the data packet, splits the large data packet, shields the IP fragmentation function, and omits the UDP checksum calculation function.

进一步的优选方案,所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:IP协议处理模块实现IP数据包的封包和拆包,屏蔽IP分片,将TOS字段和分片偏移字段作为预留字段;其中IP协议处理模块包括ARP协议处理模块和ICMP协议处理模块,所述ARP协议处理模块将IP地址映射为MAC地址;所述ICMP协议处理模块对网络控制报文进行发送和解析。Further preferred scheme, described a kind of implementation method of lightweight real-time TCP/IP protocol stack, is characterized in that: IP protocol processing module realizes the encapsulation and unpacking of IP data packet, shields IP fragmentation, TOS field and fragmentation The slice offset field is used as a reserved field; wherein the IP protocol processing module includes an ARP protocol processing module and an ICMP protocol processing module, and the ARP protocol processing module maps the IP address to a MAC address; the ICMP protocol processing module is used for network control messages for sending and parsing.

进一步的优选方案,所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:基于TDMA的介质访问机制对各个节点的数据帧发送时刻进行控制;采用令牌环方式发送数据,任意终端站在传输之前能够计算出最大等待时间。Further preferred scheme, described a kind of implementation method of lightweight real-time TCP/IP protocol stack, is characterized in that: the medium access mechanism based on TDMA controls the data frame transmission time of each node; Adopt token ring mode to send data , any terminal station can calculate the maximum waiting time before transmitting.

有益效果Beneficial effect

本发明的创新点和优点如下:Innovation point and advantage of the present invention are as follows:

1)在基于介质访问控制模块中,采用两种方式来解决通信延迟:基于TDMA的介质访问机制对各个节点的数据帧发送时刻进行控制;采用令牌环方式发送数据,任意终端站在传输之前可以计算出最大等待时间。通过这两种方式,来得到所需的网络实时性。1) In the medium access control module, two methods are used to solve the communication delay: the TDMA-based medium access mechanism controls the sending time of each node's data frame; The maximum waiting time can be calculated. Through these two methods, to get the required real-time network.

2)设置线程和数据包优先级:协议栈初始化阶段,设置发送和接收线程优先级,使协议栈能够高效地发送和接收数据,避免了其他线程的抢占,影响发送和接收数据的速率;socket接口模块设置数据包的优先级,保证优先级高的数据能够优先发送。2) Set thread and data packet priority: In the initial stage of the protocol stack, set the priority of sending and receiving threads, so that the protocol stack can efficiently send and receive data, avoiding the preemption of other threads, affecting the rate of sending and receiving data; socket The interface module sets the priority of data packets to ensure that data with high priority can be sent first.

3)整个数据发送和接收的过程,通过内存映射技术,将内核空间映射到用户空间,同时采用零拷贝技术减少数据包穿越TCP/IP协议栈时的复制次数,以提高以太网的实时性能。3) During the entire data sending and receiving process, the kernel space is mapped to the user space through the memory mapping technology, and the zero-copy technology is used to reduce the number of copies when the data packet passes through the TCP/IP protocol stack, so as to improve the real-time performance of Ethernet.

4)通过对标准TCP/IP协议栈进行裁剪和优化,使TCP/IP协议栈实现简单,使用方便,减少系统开销和网络延迟。TCP协议处理模块,对大数据包进行拆分,屏蔽IP分片功能、通过窗口大小来完成流量和拥塞控制;IP协议处理模块屏蔽IP分片,将TOS字段和分片偏移字段作为预留字段。ARP协议模块将IP地址映射为MAC地址,采用静态ARP机制,在网络初始化时完成地址解析。4) By tailoring and optimizing the standard TCP/IP protocol stack, the TCP/IP protocol stack is simple to implement, easy to use, and reduces system overhead and network delay. The TCP protocol processing module splits large data packets, shields the IP fragmentation function, and completes flow and congestion control through the window size; the IP protocol processing module shields IP fragmentation, and uses the TOS field and the fragmentation offset field as reserved field. The ARP protocol module maps the IP address to the MAC address, adopts the static ARP mechanism, and completes address resolution when the network is initialized.

5)提供不同协议栈之间的兼容性,以提供一套统一的API接口给应用层。5) Provide compatibility between different protocol stacks to provide a unified set of API interfaces to the application layer.

附图说明Description of drawings

图1为本发明实时TCP/IP协议栈的实现方法流程图;Fig. 1 is the realization method flowchart of real-time TCP/IP protocol stack of the present invention;

图2为本发明协议组织架构示意图。Fig. 2 is a schematic diagram of the protocol organization structure of the present invention.

具体实施方式Detailed ways

下面结合具体实施例描述本发明:Describe the present invention below in conjunction with specific embodiment:

本发明的实时TCP/IP协议栈的实现方法对标准TCP/IP协议栈进行改进,增强了系统的可扩展性,提高了系统的实时性能,减少了系统开销和通信延迟。The implementation method of the real-time TCP/IP protocol stack of the present invention improves the standard TCP/IP protocol stack, enhances the scalability of the system, improves the real-time performance of the system, and reduces system overhead and communication delay.

在本实施方式中,首先本发明的实时TCP/IP协议栈包括IP协议,TCP协议,UDP协议,ICMP协议和ARP协议;其次,为了增强实时性能,增加了介质访问控制模块;最后,为了增强可扩展性和应用程序的兼容性,增加了socket接口模块和网卡驱动抽象层;其中介质访问控制模块是为了满足网络通信的实时要求;socket接口模块是为了符合通用的网络socket编程接口,兼容大多数的网络应用程序;网卡驱动抽象层是对网卡驱动的统一管理层,在实时TCP/IP协议栈中进行处理后的数据将通过网卡驱动抽象层发送到具体的网卡设备上,具体步骤如下:In this embodiment, at first the real-time TCP/IP protocol stack of the present invention includes IP protocol, TCP protocol, UDP protocol, ICMP protocol and ARP protocol; secondly, in order to enhance real-time performance, a media access control module is added; finally, in order to enhance Scalability and compatibility of application programs, the socket interface module and network card driver abstraction layer have been added; the media access control module is to meet the real-time requirements of network communication; the socket interface module is to meet the general network socket programming interface, compatible with large Most network applications; the network card driver abstraction layer is a unified management layer for the network card driver, and the data processed in the real-time TCP/IP protocol stack will be sent to the specific network card device through the network card driver abstraction layer. The specific steps are as follows:

步骤1:初始化协议栈:完成网卡服务句柄的打开、网卡设备的绑定、打开操作;分配全局重发缓冲区池和全局发送缓冲区池,使得数据发送过程中无需进行内存分配;设置发送、接收线程优先级,使协议栈能够高效地发送和接收数据,进而避免其他线程的抢占;增加系统服务表项,以完成系统服务函数的添加;设置本机IP地址和MAC地址,并通过内存映射到用户空间;用户发送数据时,可以将数据直接写入该缓冲区池,从而省略了用户到内核的数据拷贝过程。Step 1: Initialize the protocol stack: complete the opening of the network card service handle, the binding and opening of the network card device; allocate the global retransmission buffer pool and the global transmission buffer pool, so that no memory allocation is required during data transmission; set the transmission, Receive thread priority, so that the protocol stack can efficiently send and receive data, thereby avoiding the preemption of other threads; add system service table items to complete the addition of system service functions; set the local IP address and MAC address, and through memory mapping to the user space; when the user sends data, the data can be directly written into the buffer pool, thereby omitting the data copy process from the user to the kernel.

步骤2:socket接口模块处理阶段:完成socket接口优先级、实时指标、阻塞方式、最大发送和接收缓冲区池大小的设置操作;并对不兼容的应用请求进行格式转换,保证优先级高的数据优先发送,提高以太网的实时性能;完成socket的创建、绑定、监听、关闭以及数据收发接口实现。Step 2: socket interface module processing stage: complete the setting operation of socket interface priority, real-time indicators, blocking mode, maximum sending and receiving buffer pool size; and perform format conversion on incompatible application requests to ensure high priority data Prioritize transmission to improve the real-time performance of Ethernet; complete socket creation, binding, monitoring, closing, and data sending and receiving interface implementation.

其中创建socket时,设置socket的类型,在内核中为每个socket分配接收缓冲区池,并将之映射到用户空间;绑定socket时,完成socket、端口号和目的主机的绑定操作,在内核下向目的主机发送ARP请求以获得目的主机MAC地址,协议栈中采用静态ARP机制,完成地址解析,使得数据发送过程中无需再次发送ARP请求。When creating a socket, set the type of the socket, allocate a receiving buffer pool for each socket in the kernel, and map it to the user space; when binding the socket, complete the binding operation of the socket, port number and destination host, in The kernel sends an ARP request to the destination host to obtain the MAC address of the destination host. The static ARP mechanism is used in the protocol stack to complete address resolution, so that there is no need to send the ARP request again during the data transmission process.

收发数据,通过内存映射和零拷贝技术,使之具有更高的效率,其中,接收数据直接从缓冲区池中取出数据,减少了内核到用户的数据拷贝过程;发送数据,直接写入到协议栈初始化时分配的全局发送缓冲区池中,减少了用户到内核的数据拷贝操作。具体实施过程中,应用程序通过调用socket接口完成网络编程,socket接口模块根据应用程序调用的socket接口函数完成具体的操作。在本实施方案中,socket接口模块只处理TCP/IP协议族的请求,其他协议族的请求不支持,且只支持以SOCK_DGREAM和SOCK_STREAM为参数的套接字传输类型。Sending and receiving data, through memory mapping and zero-copy technology, makes it more efficient. Among them, receiving data is directly taken out of the buffer pool, reducing the data copy process from the kernel to the user; sending data is directly written to the protocol In the global send buffer pool allocated when the stack is initialized, the data copy operation from the user to the kernel is reduced. In the specific implementation process, the application program completes network programming by calling the socket interface, and the socket interface module completes specific operations according to the socket interface function called by the application program. In this embodiment, the socket interface module only handles the requests of the TCP/IP protocol family, and does not support the requests of other protocol families, and only supports the socket transmission type with SOCK_DGREAM and SOCK_STREAM as parameters.

步骤3:传输层处理阶段:采用TCP协议处理模块或UDP协议处理模块对网络数据包进行处理;当网络采用TCP传输方式后,socket将调用TCP协议处理模块进行数据包处理,所述TCP协议处理模块会实现正常的TCP流程的状态机、对大数据包进行拆分,屏蔽IP分片功能、通过窗口大小来完成流量和拥塞控制等功能;当网络采用UDP传输方式后,socket将调用UDP协议处理模块进行数据包处理,所述UDP协议处理模块会完成数据包的UDP协议封装、通过对大数据包进行拆分,屏蔽IP分片功能,省略UDP校验和的计算等功能。Step 3: transport layer processing stage: adopt TCP protocol processing module or UDP protocol processing module to process network packet; after network adopts TCP transmission mode, socket will call TCP protocol processing module to carry out data packet processing, described TCP protocol processing The module will implement the state machine of the normal TCP process, split large data packets, shield the IP fragmentation function, and complete the flow and congestion control functions through the window size; when the network adopts UDP transmission mode, the socket will call the UDP protocol The processing module performs data packet processing, and the UDP protocol processing module can complete the UDP protocol encapsulation of the data packet, split the large data packet, shield the IP fragmentation function, and omit functions such as the calculation of the UDP checksum.

步骤4:网络层处理阶段:采用IP协议处理模块对网络数据包进行封包和拆包;IP协议处理模块实现了IP数据包的封包和拆包,屏蔽IP分片,将TOS字段和分片偏移字段作为预留字段。IP协议处理模块包括ARP协议处理模块和ICMP协议处理模块,所述ARP协议处理模块将IP地址映射为MAC地址;所述ICMP协议处理模块对网络控制报文进行发送和解析。Step 4: Network layer processing stage: use the IP protocol processing module to pack and unpack network data packets; the IP protocol processing module realizes the packaging and unpacking of IP data packets, shields IP fragments, and separates TOS fields and fragments shift field as a reserved field. The IP protocol processing module includes an ARP protocol processing module and an ICMP protocol processing module. The ARP protocol processing module maps an IP address to a MAC address; the ICMP protocol processing module sends and analyzes network control messages.

步骤5:介质访问控制层处理阶段:采用两种方式来解决通信延迟:采用基于TDMA的介质访问机制对各个节点的数据帧发送时刻进行控制;采用令牌环方式发送数据,任意终端站在传输之前可以计算出最大等待时间。通过这两种方式,来得到所需的网络实时性。Step 5: Media access control layer processing stage: use two methods to solve communication delay: use TDMA-based media access mechanism to control the sending time of data frames of each node; use token ring to send data, any terminal station transmits The maximum waiting time can be calculated before. Through these two methods, to get the required real-time network.

步骤6:网卡抽象层处理阶段:在网卡驱动抽象层对网卡驱动进行统一的数据抽象,由于网络设备所采用的网卡多且网卡驱动差异很大,所以通过驱动的数据抽象来规范网卡驱动的统一化管理。Step 6: Network card abstraction layer processing stage: Perform unified data abstraction on the network card driver at the network card driver abstraction layer. Since there are many network cards used in network devices and the network card drivers are very different, the unification of the network card driver is standardized through the data abstraction of the driver management.

这一步主要维护当前可用网卡设备,当网卡设备启用时,向该网卡驱动的数据抽象进行注册,并完成网卡驱动数据抽象与网卡驱动的连接;当需要发送的数据到达网卡驱动数据抽象层时,通过本地维护的路由表选择具体使用的网卡设备从而完成数据的发送。This step mainly maintains the currently available network card device. When the network card device is enabled, it registers with the data abstraction of the network card driver, and completes the connection between the network card driver data abstraction and the network card driver; when the data to be sent reaches the network card driver data abstraction layer, The specific network card device to be used is selected through the locally maintained routing table to complete the data transmission.

本发明的实时TCP/IP协议栈的实现方法对标准TCP/IP协议栈进行改进,增强了系统的可扩展性,提高了系统的实时性能,减少了系统开销和通信延迟。The implementation method of the real-time TCP/IP protocol stack of the present invention improves the standard TCP/IP protocol stack, enhances the scalability of the system, improves the real-time performance of the system, and reduces system overhead and communication delay.

最后应说明的是:以上实施例是仅用以说明而非限制本发明的技术方案,尽管参照上述实施例对本发明进行了详细说明,本领域的技术人员应当理解:您依然可以对本发明进行修改或者等同替换,并且不脱离本发明的精神和范围的任何修改或局部替换,其均应涵盖在本发明的权利要求范围当中。Finally, it should be noted that: the above embodiments are only used to illustrate and not limit the technical solutions of the present invention. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that: you can still modify the present invention Or an equivalent replacement, and any modification or partial replacement that does not depart from the spirit and scope of the present invention shall fall within the scope of the claims of the present invention.

Claims (7)

1.一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:包括以下步骤:1. a kind of implementation method of lightweight real-time TCP/IP protocol stack, is characterized in that: comprise the following steps: 步骤1:初始化协议栈;Step 1: Initialize the protocol stack; 步骤2:完成socket接口优先级、实时指标、阻塞方式、最大发送和接收缓冲区池大小的设置操作;完成socket接口的创建、绑定、监听、关闭以及数据收发接口实现;通过socket接口接收应用程序请求,并对不兼容的应用程序请求进行格式转换;Step 2: Complete the setting operation of socket interface priority, real-time indicators, blocking mode, maximum sending and receiving buffer pool size; complete the creation, binding, monitoring, closing and data sending and receiving interface implementation of socket interface; receive applications through socket interface Program requests, and format conversions for incompatible application requests; 步骤3:采用TCP协议处理模块或UDP协议处理模块对网络数据包进行处理;Step 3: using the TCP protocol processing module or the UDP protocol processing module to process the network data packets; 步骤4:采用IP协议处理模块对网络数据包进行封包和拆包;Step 4: Packing and unpacking the network data packets by using the IP protocol processing module; 步骤5:在介质访问控制模块中采用基于TDMA的介质访问机制和令牌环方式得到所需的网络实时性;Step 5: In the medium access control module, adopt the medium access mechanism based on TDMA and the token ring mode to obtain the required network real-time performance; 步骤6:在网卡驱动抽象层对网卡驱动进行统一的数据抽象;当网卡设备启用时,向该网卡驱动的数据抽象进行注册,并完成网卡驱动数据抽象与网卡驱动的连接;当需要发送的数据到达网卡驱动数据抽象层时,通过本地维护的路由表选择具体使用的网卡设备从而完成数据的发送。Step 6: Perform unified data abstraction on the network card driver at the network card driver abstraction layer; when the network card device is enabled, register with the data abstraction of the network card driver, and complete the connection between the network card driver data abstraction and the network card driver; when the data to be sent When reaching the data abstraction layer of the network card driver, the specific network card device to be used is selected through the locally maintained routing table to complete the data transmission. 2.根据权利要求1所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:初始化协议栈包括:完成网卡服务句柄的打开、网卡设备的绑定、打开操作;分配全局重发缓冲区池和全局发送缓冲区池;设置发送、接收线程优先级;增加系统服务表项;设置本机IP地址和MAC地址,并通过内存映射到用户空间。2. according to the realization method of a kind of lightweight real-time TCP/IP protocol stack described in claim 1, it is characterized in that: initialization protocol stack comprises: finish the opening of network card service handle, the binding of network card equipment, open operation; Retransmit buffer pool and global send buffer pool; set sending and receiving thread priority; add system service table items; set local IP address and MAC address, and map to user space through memory. 3.根据权利要求1或2所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:创建socket接口时,设置socket接口的类型,在内核中为每个socket接口分配接收缓冲区池,并将之映射到用户空间;绑定socket接口时,完成socket接口、端口号和目的主机的绑定操作,在内核下向目的主机发送ARP请求以获得目的主机MAC地址,协议栈中采用静态ARP机制,完成地址解析。3. according to the realization method of a kind of lightweight real-time TCP/IP protocol stack described in claim 1 or 2, it is characterized in that: when creating socket interface, the type of socket interface is set, in kernel, for each socket interface distribution receiving Buffer pool, and map it to user space; when binding the socket interface, complete the binding operation of the socket interface, port number and destination host, send an ARP request to the destination host under the kernel to obtain the destination host MAC address, protocol stack The static ARP mechanism is adopted to complete address resolution. 4.根据权利要求3所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:socket接口接收数据直接从缓冲区池中取出数据;socket接口发送数据,直接写入到协议栈初始化时分配的全局发送缓冲区池中。4. according to the realization method of a kind of lightweight real-time TCP/IP protocol stack described in claim 3, it is characterized in that: socket interface receives data and directly takes out data from the buffer pool; socket interface sends data, directly writes into protocol In the global send buffer pool allocated when the stack is initialized. 5.根据权利要求4所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:当网络采用TCP传输方式,socket接口调用TCP协议处理模块进行数据包处理,所述TCP协议处理模块实现正常的TCP流程的状态机、对大数据包进行拆分,屏蔽IP分片功能、通过窗口大小完成流量和拥塞控制功能;当网络采用UDP传输方式,socket接口调用UDP协议处理模块进行数据包处理,所述UDP协议处理模块完成数据包的UDP协议封装、通过对大数据包进行拆分,屏蔽IP分片功能,省略UDP校验和计算功能。5. according to the realization method of a kind of lightweight real-time TCP/IP protocol stack described in claim 4, it is characterized in that: when network adopts TCP transmission mode, socket interface transfers TCP protocol processing module to carry out packet processing, and described TCP protocol The processing module implements the state machine of the normal TCP process, splits large data packets, shields the function of IP fragmentation, and completes the flow and congestion control functions through the window size; when the network adopts UDP transmission mode, the socket interface calls the UDP protocol processing module to perform Data packet processing, the UDP protocol processing module completes the UDP protocol encapsulation of the data packet, splits the large data packet, shields the IP fragmentation function, and omits the UDP checksum calculation function. 6.根据权利要求5所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:IP协议处理模块实现IP数据包的封包和拆包,屏蔽IP分片,将TOS字段和分片偏移字段作为预留字段;其中IP协议处理模块包括ARP协议处理模块和ICMP协议处理模块,所述ARP协议处理模块将IP地址映射为MAC地址;所述ICMP协议处理模块对网络控制报文进行发送和解析。6. according to the realization method of a kind of lightweight real-time TCP/IP protocol stack described in claim 5, it is characterized in that: IP protocol processing module realizes the packet and the unpacking of IP packet, shields IP fragmentation, TOS field and Fragment offset field is as reserved field; Wherein IP protocol processing module comprises ARP protocol processing module and ICMP protocol processing module, described ARP protocol processing module maps IP address to MAC address; Described ICMP protocol processing module is to network control report The text is sent and parsed. 7.根据权利要求6所述一种轻量级实时TCP/IP协议栈的实现方法,其特征在于:基于TDMA的介质访问机制对各个节点的数据帧发送时刻进行控制;采用令牌环方式发送数据,任意终端站在传输之前能够计算出最大等待时间。7. according to the realization method of a kind of lightweight real-time TCP/IP protocol stack described in claim 6, it is characterized in that: the medium access mechanism based on TDMA controls the data frame sending moment of each node; Adopt token ring mode to send data, any terminal station can calculate the maximum waiting time before transmission.
CN201410244343.2A 2014-06-04 2014-06-04 Achieving method of light-weight real-time TCP/IP protocol stack Pending CN103997500A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410244343.2A CN103997500A (en) 2014-06-04 2014-06-04 Achieving method of light-weight real-time TCP/IP protocol stack

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410244343.2A CN103997500A (en) 2014-06-04 2014-06-04 Achieving method of light-weight real-time TCP/IP protocol stack

Publications (1)

Publication Number Publication Date
CN103997500A true CN103997500A (en) 2014-08-20

Family

ID=51311507

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410244343.2A Pending CN103997500A (en) 2014-06-04 2014-06-04 Achieving method of light-weight real-time TCP/IP protocol stack

Country Status (1)

Country Link
CN (1) CN103997500A (en)

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104580491A (en) * 2015-01-21 2015-04-29 郑州大学 End system protocol stack construction method and method for accessing end system to service carrying network
CN107147655A (en) * 2017-05-25 2017-09-08 北京中电普华信息技术有限公司 A network dual protocol stack parallel processing model and its processing method
CN109218271A (en) * 2017-07-07 2019-01-15 中兴通讯股份有限公司 Drive implementation method, device, equipment and computer readable storage medium
CN109361723A (en) * 2018-04-18 2019-02-19 上海锐智集数电子有限公司 A kind of effective message transmission timing control method of UDP
CN109413106A (en) * 2018-12-12 2019-03-01 中国航空工业集团公司西安航空计算技术研究所 A kind of ICP/IP protocol stack implementation method
CN109684232A (en) * 2018-10-23 2019-04-26 许继集团有限公司 A kind of Embedded Protocol Stack EMS memory management process
CN109842567A (en) * 2017-11-24 2019-06-04 华为技术有限公司 Data distributing method and the distribution server
CN110535813A (en) * 2018-05-25 2019-12-03 网宿科技股份有限公司 Kernel state protocol stack and User space protocol stack simultaneously deposit treating method and apparatus
CN115665267A (en) * 2022-10-20 2023-01-31 广东核电合营有限公司 A method and device for implementing a lightweight network protocol stack
CN116055578A (en) * 2023-03-06 2023-05-02 北京朝歌数码科技股份有限公司 Lightweight AT protocol stack, communication method and system
CN118488021A (en) * 2024-07-15 2024-08-13 浙江禾川科技股份有限公司 Industrial Ethernet message transmission optimization method, device, equipment and medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020099827A1 (en) * 2001-01-22 2002-07-25 Shah Hemal V. Filtering calls in system area networks
CN101163143A (en) * 2006-08-18 2008-04-16 通用汽车公司 Lightweight protocol for use in a TCP/IP communications network
CN102685243A (en) * 2012-05-22 2012-09-19 清华大学 Realizing method of light-weight TCP (Transmission Control Protocol)/IP (Internet Protocol) stack

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020099827A1 (en) * 2001-01-22 2002-07-25 Shah Hemal V. Filtering calls in system area networks
CN101163143A (en) * 2006-08-18 2008-04-16 通用汽车公司 Lightweight protocol for use in a TCP/IP communications network
CN102685243A (en) * 2012-05-22 2012-09-19 清华大学 Realizing method of light-weight TCP (Transmission Control Protocol)/IP (Internet Protocol) stack

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
夏仲平: "对WindowsTCP_IP协议栈的一种简化设计", 《现代电子技术》 *
张明虎: "轻量级实时通信关键技术的研究", 《中国博士学位论文全文数据库信息科技辑》 *
陈进朝: "Xenomai平台下基于以太网的实时通信方案", 《计算机工程》 *

Cited By (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104580491A (en) * 2015-01-21 2015-04-29 郑州大学 End system protocol stack construction method and method for accessing end system to service carrying network
CN107147655A (en) * 2017-05-25 2017-09-08 北京中电普华信息技术有限公司 A network dual protocol stack parallel processing model and its processing method
CN109218271A (en) * 2017-07-07 2019-01-15 中兴通讯股份有限公司 Drive implementation method, device, equipment and computer readable storage medium
CN109842567B (en) * 2017-11-24 2020-12-25 华为技术有限公司 Data distribution method and distribution server
US11134001B2 (en) 2017-11-24 2021-09-28 Huawei Technologies Co., Ltd. Data distribution method and distribution server
CN109842567A (en) * 2017-11-24 2019-06-04 华为技术有限公司 Data distributing method and the distribution server
CN109361723A (en) * 2018-04-18 2019-02-19 上海锐智集数电子有限公司 A kind of effective message transmission timing control method of UDP
CN109361723B (en) * 2018-04-18 2021-08-31 上海锐智集数电子有限公司 UDP (user Datagram protocol) effective message sending time sequence control method
CN110535813B (en) * 2018-05-25 2022-04-22 网宿科技股份有限公司 Method and device for processing coexistence of kernel mode protocol stack and user mode protocol stack
CN110535813A (en) * 2018-05-25 2019-12-03 网宿科技股份有限公司 Kernel state protocol stack and User space protocol stack simultaneously deposit treating method and apparatus
CN109684232B (en) * 2018-10-23 2021-09-14 许继集团有限公司 Embedded protocol stack memory management method
CN109684232A (en) * 2018-10-23 2019-04-26 许继集团有限公司 A kind of Embedded Protocol Stack EMS memory management process
CN109413106A (en) * 2018-12-12 2019-03-01 中国航空工业集团公司西安航空计算技术研究所 A kind of ICP/IP protocol stack implementation method
CN115665267A (en) * 2022-10-20 2023-01-31 广东核电合营有限公司 A method and device for implementing a lightweight network protocol stack
CN116055578A (en) * 2023-03-06 2023-05-02 北京朝歌数码科技股份有限公司 Lightweight AT protocol stack, communication method and system
CN118488021A (en) * 2024-07-15 2024-08-13 浙江禾川科技股份有限公司 Industrial Ethernet message transmission optimization method, device, equipment and medium

Similar Documents

Publication Publication Date Title
CN103997500A (en) Achieving method of light-weight real-time TCP/IP protocol stack
US10372637B2 (en) Methods and apparatus for aggregating packet transfer over a virtual bus interface
US11178259B2 (en) Methods and apparatus for regulating networking traffic in bursty system conditions
US11023411B2 (en) Programmed input/output mode
JP6188093B2 (en) Communication traffic processing architecture and method
US10057387B2 (en) Communication traffic processing architectures and methods
US7586936B2 (en) Host Ethernet adapter for networking offload in server environment
US7996569B2 (en) Method and system for zero copy in a virtualized network environment
US10609125B2 (en) Method and system for transmitting communication data
CN107483370A (en) A method of transmitting IP and CAN services on FC network
US11347567B2 (en) Methods and apparatus for multiplexing data flows via a single data structure
US9515963B2 (en) Universal network interface controller
US20160128079A1 (en) Mapping data traffic throughout protocol layers based on priority information
US11570120B2 (en) Methods and systems for data transmission
US9274586B2 (en) Intelligent memory interface
CN107708153A (en) A kind of radio modem ascending packet data processing method
CN111586040A (en) High-performance network data receiving method and system
CN118972354A (en) Telecommunication network element real-time processing method, device, equipment, medium and program product

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20140820