LWIP protocol stack extension and multi-network card implementation method oriented to space real-time network communication
By introducing the LWIP_vlan protocol stack that supports VLAN tags and integrating it into the traditional LWIP protocol stack, the problem of poor compatibility between the traditional LWIP protocol stack and extended network cards is solved, enabling flexible configuration and efficient data exchange of multi-NIC systems, and improving the reliability and stability of aerospace and industrial networks.
Patent Information
- Application Number
- CN202511371914.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-24
- Publication Date
- 2026-01-20
- Estimated Expiration
- 2045-09-24
AI Technical Summary
The traditional LWIP protocol stack has poor compatibility with extended network cards, and cannot meet the needs of multiple network ports to support multiple network protocols and standards at the same time, making it difficult to cope with the complex and ever-changing network environments in the aerospace and industrial fields.
We introduce the LWIP protocol stack that supports VLAN tagless mode and the LWIP_vlan protocol stack that supports VLAN tag mode. By modifying the symbol suffix, extending the VLAN tag processing logic, and implementing the flow control mechanism, we integrate the two protocol stacks in the same software project to support flexible switching between multiple network cards and various device types.
It enables flexible configuration and independent operation of different network cards in a multi-NIC system, reduces code complexity, improves network performance and reliability, and facilitates maintenance and management.
Smart Images

Figure CN121367744A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of multi-network card application in space and industrial control computers, and relates to a LWIP protocol stack expansion and multi-network card implementation method for space real-time network communication. BACKGROUND
[0002] In the control computers in the field of space and industry, extreme working conditions such as temperature change, electromagnetic interference, etc. are usually faced, which leads to communication delay or even interruption. Therefore, a multi-network card redundant network needs to be used to support the long-time fault-free operation of key tasks. The multi-network port design supports multiple different network protocols and standards, the control computer is connected to different networks at the same time, supports more kinds of devices and systems, and realizes more extensive data exchange and integration. In addition, by distributing the traffic to multiple network card interfaces, the network load can be effectively shared, avoiding the single network channel from becoming a bottleneck, and thus improving the overall network performance and response speed, which is particularly important for applications that need to process a large amount of data in real time. In order to realize the above functions, a communication method needs to be designed, which supports high-precision time synchronization, flow scheduling, priority management, etc. on the basis of traditional Ethernet.
[0003] LWIP is a widely used TCP / IP protocol stack, which is specially designed for resource-constrained embedded systems, and has flexibility and configurability, which can adapt to various hardware platforms. However, the traditional LWIP protocol stack has limitations, and its multi-network card mechanism requires all network cards to use the same hardware mode, Ethernet controller mode and VLAN protocol support mode. This limitation leads to poor compatibility of the traditional LWIP protocol stack with extended network cards, which cannot meet the application requirements of multi-network port supporting multiple network protocols and standards at the same time, and is difficult to cope with the complex and variable network environment in the field of space and industry. Therefore, development needs to be carried out on the basis of the traditional LWIP protocol stack, which is oriented to multi-network cards and multi-protocol stacks.
[0004] Space real-time network realizes nanosecond-level clock synchronization through IEEE 1588 protocol, ensures multi-system cooperation, and meets the high-precision timing requirements of space missions. Its flow scheduling and shaping technology guarantees the low delay and deterministic transmission of key data, which is suitable for real-time scenarios such as attitude control and scientific data transmission. Space real-time network supports redundant paths and fast fault recovery, improves system reliability, and adapts to harsh environments. Compared with traditional Ethernet, space real-time network provides efficient and predictable communication foundation through hardware-level time perception and priority management. Therefore, combining space real-time network with LWIP protocol stack is a feasible way to realize the development of multi-network cards and multi-protocol stacks, but this process faces problems such as complex program transplantation, difficult hardware adaptation, and compatibility of protocol stack expansion, and research on the transplantation method of space real-time network and LWIP protocol stack needs to be carried out. SUMMARY
[0005] The technical problem solved by the present application is that the present application proposes a LWIP protocol stack expansion and multi-network card implementation method for space real-time network communication, solves the poor compatibility of the LWIP protocol stack and the expansion network card, supports a multi-network card flexible switching mode, protocols and standards, ensures accurate data transmission and reception, simultaneously supports various network cards and device types, and realizes more extensive data exchange and integration.
[0006] The technical problem solved by the present application is that the present application proposes a LWIP protocol stack expansion and multi-network card implementation method for space real-time network communication, solves the poor compatibility of the LWIP protocol stack and the expansion network card, supports a multi-network card flexible switching mode, protocols and standards, ensures accurate data transmission and reception, simultaneously supports various network cards and device types, and realizes more extensive data exchange and integration.
[0007] Two LWIP protocol stacks are introduced, which are an LWIP protocol stack supporting a VLAN tag-free mode and an LWIP_vlan protocol stack supporting a VLAN tag mode, wherein the LWIP_vlan protocol stack supporting the VLAN tag mode is that all symbols in the LWIP protocol stack source code are uniformly added with a suffix vlan and are modified to LWIP_vlan, and then the LWIP_vlan protocol stack is functionally expanded, including adding processing logic of a VLAN tag frame header, modifying a network card driver program to support identification and filtering of the VLAN tag, and implementing a flow control mechanism based on a VLAN ID and a priority in the protocol stack, so that the VLAN tag and the space real-time network function are supported.
[0008] The LWIP protocol stack and the LWIP_vlan protocol stack are integrated into the same software engineering, tasks are created, network card interfaces are added, threads for receiving and processing network data packets are created, and socket threads for providing network programming interfaces are created in the two protocol stack modes; for the LWIP_vlan protocol stack, a space real-time network function module is initialized and the low_level_output_vlan function is expanded, so that the multi-network card simultaneously supports the LWIP protocol stack for Ethernet communication and the LWIP_vlan protocol stack for processing the space real-time network function.
[0009] Further, for the LWIP_vlan protocol stack, the symbols including function names, variable names, macro definitions, enumeration types and structure bodies in the LWIP protocol stack source code are uniformly added with the suffix vlan.
[0010] Further, the function expansion of the LWIP_vlan protocol stack includes:
[0011] The VLAN tag occupies 4 bytes: TPID+TCI, so the length of the link layer header needs to be expanded, and the macro definition PBUF_LINK_HLEN_vlan is modified from 14 bytes to 18 bytes.
[0012] Enable macro definition ETHARP_SUPPORT_VLAN_vlan as 1, indicating support of VLAN function, create macro definition VLAN_SET_ENABLE_vlan as 1, used for controlling switch of VLAN function;
[0013] Define structure body struct s_VLAN_vlan, used for storing VLAN tag information, including 2 bytes VLAN protocol identifier, 1 byte standard format indicator, 1 byte priority identifier and 2 bytes VLAN ID;
[0014] Introduce member struct s_VLAN_vlan VLAN_user_vlan, used for storing VLAN information, in structure body definition struct LWIP_sock_vlan;
[0015] Introduce member struct s_VLAN_vlan VLAN_user_vlan, used for storing VLAN information, in structure body definition struct pbuf_vlan;
[0016] Modify function ethernet_output_vlan, and increase processing logic of VLAN tag;
[0017] Function LWIP_sendto_vlan increases judgment of VLAN enable, obtains VLAN information from socket socket, and passes the information to pbuf_vlan to be sent;
[0018] Function raw_sendto_if_src_vlan, function udp_sendto_if_src_vlan and function tcp_sendto_if_src_vlan need to obtain VLAN information in pbuf_vlan;
[0019] Function LWIP_setsockopt_impl_vlan increases setting of VLAN priority, and through judgment of SO_PRIORITY_vlan setting option, binds priority to socket socket.
[0020] Further, for LWIP_vlan protocol stack, the added network card interface is EP network card interface, and the steps are as follows:
[0021] Set ip address, subnet mask and gateway for end node EP;
[0022] Add end node EP to system network card interface, and perform initialization configuration, including setting mac address of end node EP, initializing mac controller and configuring dma;
[0023] A unique name is assigned to the EP network card, the generated network card name is associated with the network card instance netif structure, and is registered in the system; the network card name is the premise of realizing the SO_BINDTODEVICE network card binding function;
[0024] A task network_input_thread is created to increase support for the ETHTYPE_VLAN protocol, which is used to receive and process network packets;
[0025] Two socket threads are created for the network card interface of the end node EP, corresponding to TEMAC0 and TEMAC1 controllers respectively.
[0026] Further, for the LWIP_vlan protocol stack, the socket thread for providing a network programming interface is created as follows:
[0027] A new socket socket is created, which is bound to the local IP address and port number by bind, and a connection is established with the destination IP address and port by connect;
[0028] The SO_RCVTIMEO option is set for the socket, so that it works in non-blocking mode;
[0029] The SO_BINDTODEVICE option is set for the socket, the incoming network card interface name parameter is parsed, and the specified network card interface is selected according to the parameter when sending or receiving data;
[0030] The SO_PRIORITY option is set for the socket, which supports different VLAN and priority bindings, adds VLAN tags according to the set priority when sending data packets, and correctly parses these tags when receiving data packets;
[0031] After the above settings are completed, the recv and send functions are used to test whether the udp communication is normal.
[0032] Further, the space real-time network function module is initialized as follows:
[0033] The hardware and software of the switch are initialized and configured to ensure that time-sensitive network traffic can be correctly processed;
[0034] All TADMA-related configurations and data are cleared;
[0035] A new flow is added to the hash table of the TADMA system, and the related attributes of the flow include trigger time, trigger count, flow ID, MAC address and VLAN information;
[0036] Traverse all flow entries, and program hardware according to the information of each entry to ensure that DMA operation is executed according to preset time slot scheduling;
[0037] Configure CAM of the switch to ensure that the switch can quickly find and forward data packets according to entries of the CAM table;
[0038] Configure STP state of the switch to ensure that there is no loop in the network, and data packets can be forwarded according to an optimal path.
[0039] Further, the clearing all TADMA-related configurations and data includes: setting a configuration completion flag bit to 0, clearing register values at specific offsets, and emptying a linked list node related to each flow in a hash table, to ensure that the system is in a clean state when being reconfigured or initialized.
[0040] Further, the function of the low_level_output_vlan function is expanded, and the steps are as follows:
[0041] The VLAN tag is obtained from the to-be-sent data pbuf_vlan, and a TCI field containing priority information and a protocol field of the VLAN are further extracted;
[0042] It is judged whether it is an 802.1Q VLAN format, if it is the VLAN format, a DMA sending channel is selected according to the priority information, high-priority data is sent through an ST channel of the TADMA, low-priority data is sent through a BE or RES channel of the MCDMA, and if it is not the VLAN format, a BE channel of the MCDMA is used by default;
[0043] For to-be-sent data pbuf_vlan with a total length less than 64 bytes, 0 is filled to 64 bytes; meanwhile, an fcs check value is calculated, and the fcs check value is attached to the end of the to-be-sent data pbuf_vlan, and is sent together;
[0044] If the sending channel is the ST channel, a sending function of the TADMA is called to send, and if the sending channel is a non-ST channel, a sending function of the MCDMA is called to send.
[0045] Compared with the prior art, the present application has the beneficial effects that:
[0046] The method of the application is extended and optimized on the basis of the traditional LWIP protocol stack, and the flexible configuration based on different netif of network card interface instances is realized by introducing the LWIP_vlan protocol stack and adjusting the related code logic, specifically, the parameters such as DMA mode, Ethernet controller hardware, PHY chip, FCS check, VLAN enablement, and interrupt processing function of different network cards are configured respectively, and then the collaborative work of the traditional Ethernet and the spatial real-time network function is realized.
[0047] This way makes the two protocol stacks almost completely independent, and any change in one protocol stack will not affect the other protocol stack. Since the two versions use different namespaces (by adding a suffix), they are completely logically separated and will not conflict even if they coexist in the same project. When adding new features to a protocol stack, there is no need to add a large number of conditional judgment statements in the entire code library to distinguish the processing logic under different conditions. For example, to add new features to the Ethernet protocol stack LWIP without VLAN tags, you only need to develop directly within the protocol stack, without considering how to avoid these changes affecting the LWIP_vlan protocol stack. This way reduces code complexity, reduces the risk of errors caused by frequent modifications, and facilitates subsequent testing and maintenance. BRIEF DESCRIPTION OF DRAWINGS
[0048] Figure 1 Flowchart for multi-network card function implementation
[0049] Figure 2 Flowchart for adding EP network card interface
[0050] Figure 3 Flowchart for udp socket network programming interface
[0051] Figure 4 Flowchart for low_level_output_vlan function. DETAILED DESCRIPTION
[0052] The application extends the LWIP protocol stack, adds the LWIP_vlan protocol stack supporting the VLAN tag mode on the basis of the original LWIP protocol stack, and meets the compatibility of the multi-network card with the LWIP protocol stack and the LWIP_vlan protocol stack through the top-level and bottom-level configuration, and the main way is:
[0053] Two LWIP protocol stacks are introduced, one for supporting LWIP protocol stack without VLAN tag mode and the other for supporting LWIP_vlan protocol stack with VLAN tag mode. This method uses a specific tool to modify all symbols in the LWIP protocol stack source code to add a suffix vlan, i.e., change to LWIP_vlan. Further, the LWIP_vlan protocol stack is developed and functionally extended to support VLAN tags and spatial real-time network functions. The LWIP protocol stack and the LWIP_vlan protocol stack are integrated into the same software project, and by modifying the necessary logic, the multi-network card can support ordinary Ethernet and spatial real-time network at the same time. This method reduces the coupling between the two protocol stacks, enhances the stability and maintainability of the code library. Each protocol stack can be optimized according to its specific application scenario. For example, the LWIP protocol stack is used to provide efficient and lightweight ordinary Ethernet communication, while the LWIP_vlan protocol stack is used to handle spatial real-time network functions to ensure the accuracy and timeliness of data transmission. By adding the EP network card interface, initializing the spatial real-time network function module, and extending the low_level_output_vlan function, the extended network card supports the LWIP_vlan protocol stack.
[0054] The application will be further described in conjunction with the accompanying drawings and examples.
[0055] Example 1
[0056] The LWIP protocol stack expansion and multi-network card implementation method for spatial real-time network communication in this embodiment includes the following steps:
[0057] 1. Extension and optimization of LWIP_vlan protocol stack
[0058] 1.1 Symbol renaming using a specific tool: Use a specific code processing tool to comprehensively scan the source code of the LWIP protocol stack, and add a suffix vlan to all symbols (including but not limited to function names, variable names, macro definitions, enumeration types, structures, etc.). For example, the function originally named tcp_connect() is renamed to tcp_connect_vlan() after processing; the configuration macro originally named ETH_PAD_SIZE is renamed to ETH_PAD_SIZE_vlan after processing. These changes ensure that there is no naming conflict between the newly generated LWIP_vlan protocol stack and the original LWIP protocol stack, allowing the two protocol stacks to coexist in the same software project.
[0059] 1.2 Modify the LWIP_vlan protocol stack: Function extension is made to the LWIP_vlan protocol stack to support VLAN tags and spatial real-time network functions, including adding processing logic for VLAN tag frame headers, modifying network card drivers to support VLAN tag identification and filtering, and implementing traffic control mechanisms based on VLAN ID and priority in the protocol stack. The specific steps are as follows:
[0060] 1.2.1 The VLAN tag occupies 4 bytes (TPID + TCI), so the length of the link layer header needs to be extended. Modify the macro definition PBUF_LINK_HLEN_vlan (Ethernet frame header length) from 14 bytes to 18 bytes.
[0061] 1.2.2 Enable the macro definition ETHARP_SUPPORT_VLAN_vlan to 1, indicating that VLAN function is supported. Create the macro definition VLAN_SET_ENABLE_vlan to 1, which is used to control the switch of VLAN function.
[0062] 1.2.3 Define the structure struct s_VLAN_vlan, which is used to store VLAN tag information. It includes 2 bytes tpid, 1 byte cif, 1 byte pri, and 2 bytes vid.
[0063]
[0064]
[0065] 1.2.4 Introduce the member struct s_VLAN_vlan VLAN_user_vlan in the structure definition struct LWIP_sock_vlan to store VLAN information.
[0066] 1.2.5 Introduce the member struct s_VLAN_vlan VLAN_user_vlan in the structure definition struct pbuf_vlan to store VLAN information.
[0067] 1.2.6 Modify the function ethernet_output_vlan to add processing logic for VLAN tags.
[0068] 1.2.7 The function LWIP_sendto_vlan adds judgment for VLAN enable, obtains VLAN information from the socket socket, and passes the information to the pbuf_vlan to be sent.
[0069] 1.2.8 Similarly, the functions raw_sendto_if_src_vlan, udp_sendto_if_src_vlan and tcp_sendto_if_src_vlan also need to obtain the VLAN information in pbuf_vlan.
[0070] 1.2.9 The function LWIP_setsockopt_impl_vlan adds the setting of VLAN priority by judging the SO_PRIORITY_vlan setting option to bind the priority to the socket socket.
[0071] 1.3 Protocol stack integration and deployment: The original LWIP protocol stack and the LWIP_vlan protocol stack folder after renaming processing and all.c and.h files contained therein are added to the project. This step ensures that the codes of the two protocol stacks can be compiled correctly and will not interfere with each other by configuring the compiler options and linker scripts.
[0072] 2. Specific implementation of multi-network card function
[0073] The specific implementation flowchart of the multi-network card function is shown in Figure 1 The expansion and optimization of the LWIP protocol stack and the LWIP_vlan protocol stack are respectively used to create tasks, add network card interfaces, receive and process data packets in the two protocol stack modes.
[0074] 2.1 Implementation of multi-network card function of LWIP_vlan protocol stack
[0075] The application focuses on the addition of EP network card interface, the configuration of TEMAC0 and TEMAC1 Ethernet MAC hardware instances, the initialization of spatial real-time network function modules, the function expansion of low_level_output_vlan function, etc.
[0076] 2.1.1 Add EP network card interface
[0077] EP, as an end node, is responsible for generating, receiving and managing time-sensitive data streams. EP is connected to the network through the network card interface, and uses spatial real-time network protocols (such as clock synchronization, flow scheduling, etc.) to ensure that its data packets arrive at the destination on time.
[0078] TEMAC is a three-mode Ethernet MAC IP core, which can be configured as GMII / RMII, SGMII or RGMII mode. TEMAC0 and TEMAC1 can be used as Ethernet MAC hardware instances respectively, responsible for sending and receiving Ethernet frames.
[0079] In the LWIP protocol stack, the netif structure corresponds to the actual network interface card (NIC) and contains all relevant information about that interface, such as IP address, MAC address, and status. The LWIP protocol stack uses the netif interface to ensure that data packets are sent or processed in the correct order and within the correct time window. In the space real-time network system, to manage and configure the corresponding NIC interfaces, the netif is associated with the EP (Electronic Interface Device), a corresponding netif instance is created for the EP, an IP address is assigned to it, and it is registered in the LWIP protocol stack. Simultaneously, the TEMAC0 and TEMAC1 instances are initialized and configured to support space real-time network functions. By creating sockets for TEMAC0 and TEMAC1 respectively and binding them to the EP's netif instance, the physical layer and data link layer functions of network communication are facilitated.
[0080] EP manages data exchange with TEMAC, ensuring that data frames are correctly encapsulated and parsed according to the space real-time network standard. When EP prepares to send a time-sensitive data packet, it first processes the packet according to the requirements of the space real-time network protocol stack (such as adding a timestamp, setting priority, etc.), and then hands the packet over to the underlying hardware for transmission through the corresponding TEMAC instance. Similarly, when a data packet with a VLAN tag or other space real-time network-specific fields is received, TEMAC first verifies the packet and then passes it to the corresponding netif processing in the LWIP protocol stack.
[0081] 2.1.1.1 Figure 2 The diagram shows the flowchart for adding an EP network card interface. The specific steps are as follows:
[0082] (1) Configure the IP address, subnet mask, gateway, etc. for the end node EP;
[0083] (2) Add the end node EP to the system network card interface and initialize its configuration, including setting the MAC address of the end node EP, initializing the MAC controller, configuring DMA, etc.
[0084] (3) Assign a unique name to the EP network card, associate the generated network card name with the netif structure of the network card instance, and register it in the system. This network card name is a prerequisite for implementing the SO_BINDTODEVICE network card binding function.
[0085] (4) Create a task network_input_thread to add support for the ETHTYPE_VLAN protocol for receiving and processing network packets.
[0086] (5) Create two socket threads for the network interface of the end node EP, corresponding to the TEMAC0 and TEMAC1 controllers respectively.
[0087] A socket thread is created for the EP's network card interface to implement a udp socket supporting multiple network cards, VLANs, and priority settings, as shown in the flowchart Figure 3 , and the specific steps are as follows:
[0088] (1) A new socket is created, which is bound to the local IP address and port number through bind, and a connection is established with the destination IP address and port through connect.
[0089] (2) The SO_RCVTIMEO option is set for the socket to work in non-blocking mode.
[0090] (3) The SO_BINDTODEVICE option is set for the socket, the incoming network card interface name parameter is parsed, and the specified network card interface is selected when sending or receiving data according to the parameter.
[0091] (4) The SO_PRIORITY option is set for the socket to support different VLAN and priority bindings, add appropriate VLAN tags according to the set priority when sending data packets, and correctly parse these tags when receiving data packets.
[0092] (5) After the above settings, use the recv and send functions to test whether the udp communication is normal.
[0093] 2.1.2 Initialize the space real-time network function module
[0094] The specific steps for initializing the space real-time network switch are as follows:
[0095] (1) Perform hardware and software initialization configuration of the switch to ensure that it can correctly handle time-sensitive network traffic.
[0096] (2) Clear all TADMA-related configurations and data, including setting the configuration completion flag to 0, clearing the register values at specific offsets, and emptying the hash table of each flow-related linked list nodes, to ensure that the system is in a clean state when reconfiguring or initializing.
[0097] (3) Add a new flow to the TADMA system's hash table, including trigger time, trigger count, flow ID, MAC address, VLAN information, etc.
[0098] (4) Traverse all flow entries and program the hardware according to the information of each entry to ensure that DMA operations are executed according to the preset time slot schedule.
[0099] (5) Configure the CAM of the switch to ensure that the switch can quickly find and forward the data packet according to the entries of the CAM table. Configure the spanning tree protocol (STP) state of the switch to ensure that there is no loop in the network and the data packet can be forwarded according to the optimal path.
[0100] 2.1.3 Function extension of low_level_output_vlan function
[0101] In order to support the VLAN function and solve the special problems of hardware and IP core, the following changes need to be made to the low_level_output_vlan function:
[0102] (1) Get the VLAN tag (4 bytes) from the to-be-sent data pbuf_vlan, and further extract the TCI field (containing priority information) and the protocol field of the VLAN.
[0103] (2) Determine whether it is an 802.1Q VLAN format (TPID is 0x8100). If it is a VLAN format, select the DMA sending channel according to the priority information, high-priority data is sent through the ST (time-sensitive) channel of TADMA, and low-priority data is sent through the BE (best effort) or RES (reserved) channel of MCDMA. If it is not a VLAN format, use the BE channel of MCDMA by default.
[0104] (3) Due to the particularity of hardware and IP core, when the total length of the to-be-sent data pbuf_vlan is less than 64 bytes, the mac controller will automatically pad it to 64 bytes. And this mac controller will not automatically calculate the fcs checksum, resulting in a failed to-be-sent data check. In order to solve the above problems, the software is specially designed to pad the to-be-sent data pbuf_vlan with a total length of less than 64 bytes to 64 bytes; at the same time, the software calculates its fcs checksum (4 bytes) and appends it to the end of the to-be-sent data pbuf_vlan (65 to 68 bytes) for transmission.
[0105] (4) If the sending channel is the ST (time-sensitive) channel, call the sending function of TADMA for sending. If the sending channel is not the ST channel (such as BE or RES), call the sending function of MCDMA for sending.
[0106] The function implementation of the low_level_output_vlan function is as shown in Figure 4 .
[0107] The application can be widely applied in fields such as aerospace and industrial control with complex and variable network environment, improve the reliability of the network, facilitate network management and maintenance, enhance fault tolerance, and ensure security.
[0108] Although the present application has been disclosed with reference to the preferred embodiments, it is not intended to limit the present application to the preferred embodiments, and any person skilled in the art can make possible changes and modifications to the technical solutions of the present application without departing from the spirit and scope of the present application by using the disclosed methods and technical contents. Therefore, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present application without departing from the technical solutions of the present application shall fall within the protection scope of the present application.
[0109] The contents not described in detail in the specification of the present application are the known technologies of the person skilled in the art.
Claims
1. The method for extending LWIP protocol stack and implementing multi-network card for space real-time network communication, characterized in that, The method comprises the following steps: Two LWIP protocol stacks are introduced, i.e., an LWIP protocol stack supporting a VLAN tag-free mode and an LWIP_vlan protocol stack supporting a VLAN tag mode, wherein the LWIP_vlan protocol stack is obtained by adding a suffix "vlan" to all symbols in the source code of the LWIP protocol stack, modifying the symbols to "LWIP_vlan", and then extending the functions of the LWIP_vlan protocol stack, including adding processing logic of a VLAN tag frame header, modifying a network card driver to support identification and filtering of a VLAN tag, and implementing a flow control mechanism based on a VLAN ID and a priority in the protocol stack to support a VLAN tag and spatial real-time network functions; The LWIP protocol stack and the LWIP_vlan protocol stack are integrated into the same software project, tasks are created, network card interfaces are added, threads for receiving and processing network data packets are created, and socket threads for providing network programming interfaces are created in the two protocol stack modes; for the LWIP_vlan protocol stack, a spatial real-time network function module is initialized, and the function of the low_level_output_vlan function is extended to realize that multiple network cards simultaneously support the LWIP protocol stack for Ethernet communication and the LWIP_vlan protocol stack for processing spatial real-time network functions.
2. The LWIP protocol stack extension and multi-network card implementation method for space-oriented real-time network communication according to claim 1, characterized in that, For the LWIP_vlan protocol stack, the symbols including function names, variable names, macro definitions, enumeration types and structure bodies in the source code of the LWIP protocol stack are uniformly added with the suffix "vlan".
3. The LWIP protocol stack extension and multi-network card implementation method for space-oriented real-time network communication according to claim 1, characterized in that, The function extension of the LWIP_vlan protocol stack comprises: The VLAN tag occupies 4 bytes: TPID+TCI, so the length of the link layer header needs to be extended, and the macro definition PBUF_LINK_HLEN_vlan is modified from 14 bytes to 18 bytes; The macro definition ETHARP_SUPPORT_VLAN_vlan is enabled to be 1, indicating that the VLAN function is supported, and the macro definition VLAN_SET_ENABLE_vlan is created to be 1, which is used to control the switch of the VLAN function; A structure body struct s_VLAN_vlan is defined to store VLAN tag information, including a 2-byte VLAN protocol identifier, a 1-byte specification format indicator, a 1-byte priority identifier and a 2-byte VLAN ID; In the structure body definition struct LWIP_sock_vlan, a member struct s_VLAN_vlan VLAN_user_vlan is introduced to store VLAN information; In the structure body definition struct pbuf_vlan, a member struct s_VLAN_vlan VLAN_user_vlan is introduced to store VLAN information; The function ethernet_output_vlan is modified to add processing logic of the VLAN tag. The function LWIP_sendto_vlan adds the judgment of VLAN enable, gets the VLAN information from the socket socket, and passes the information to the pbuf_vlan to be sent; The functions raw_sendto_if_src_vlan, udp_sendto_if_src_vlan and tcp_sendto_if_src_vlan need to get the VLAN information in the pbuf_vlan; The function LWIP_setsockopt_impl_vlan adds the setting of VLAN priority, and binds the priority to the socket socket by judging the SO_PRIORITY_vlan setting option.
4. The LWIP protocol stack extension and multi-network card implementation method for space-oriented real-time network communication according to claim 1, characterized in that, For the LWIP_vlan protocol stack, the added network card interface is the EP network card interface, and the steps are as follows: Set the IP address, subnet mask and gateway for the end node EP; Add the end node EP to the system network card interface and perform initialization configuration, including setting the mac address of the end node EP, initializing the mac controller, and configuring the dma; Allocate a unique name for the EP network card, associate the generated network card name with the netif structure body of the network card instance, and register it in the system; the network card name is a prerequisite for realizing the SO_BINDTODEVICE network card binding function; Create a task network_input_thread and add support for the ETHTYPE_VLAN protocol to receive and process network packets; Create two socket threads for the network card interface of the end node EP, respectively corresponding to TEMAC0 and TEMAC1 controllers.
5. The LWIP protocol stack extension and multi-network card implementation method for space-oriented real-time network communication according to claim 4, characterized in that, For the LWIP_vlan protocol stack, the steps of creating a socket thread for providing a network programming interface are as follows: New socket socket, bind it to the local IP address and port number through bind, and establish a connection with the destination IP address and port through connect; Set the SO_RCVTIMEO option for the socket to work in non-blocking mode; Set the SO_BINDTODEVICE option for the socket, parse the incoming network card interface name parameter, and select the specified network card interface when sending or receiving data according to the parameter; Set the SO_PRIORITY option for the socket to support different VLAN and priority bindings, add VLAN tags according to the set priority when sending data packets, and correctly parse these tags when receiving data packets; After the above settings are completed, use the recv and send functions to test whether the udp communication is normal.
6. The LWIP protocol stack extension and multi-network card implementation method for space-oriented real-time network communication according to claim 1, characterized in that, The steps of initializing the spatial real-time network function module are as follows: Perform hardware and software initialization configuration on the switch to ensure that it can correctly process time-sensitive network traffic; Clear all TADMA-related configurations and data; Add a new flow to the hash table of the TADMA system, and the related attributes of the flow include trigger time, trigger count, flow ID, MAC address and VLAN information; All flow entries are traversed, and the hardware is programmed according to the information of each entry to ensure that the DMA operation is executed according to the preset time slot scheduling; The CAM of the switch is configured to ensure that the switch can quickly find and forward the data packet according to the entries of the CAM table; The spanning tree protocol (STP) state of the switch is configured to ensure that there is no loop in the network, and the data packet can be forwarded according to the optimal path.
7. The LWIP protocol stack extension and multi-network card implementation method for space-oriented real-time network communication according to claim 6, characterized in that, The configuration and data related to TADMA are cleared, including setting the configuration completion flag bit to 0, clearing the register value at a specific offset, and emptying the linked list node related to each flow in the hash table, to ensure that the system is in a clean state during reconfiguration or initialization.
8. The LWIP protocol stack extension and multi-network card implementation method for space-oriented real-time network communication according to claim 3, characterized in that, The function of low_level_output_vlan is expanded, and the steps are as follows: The VLAN tag is obtained from the to-be-sent data pbuf_vlan, and the TCI field containing the priority information and the protocol field of the VLAN are further extracted; It is judged whether it is the VLAN format of 802.1Q, if it is the VLAN format, the DMA sending channel is selected according to the priority information, the high-priority data is sent through the ST channel of TADMA, and the low-priority data is sent through the BE or RES channel of MCDMA, if it is not the VLAN format, the BE channel of MCDMA is used by default; For the to-be-sent data pbuf_vlan with a total length less than 64 bytes, 0 is filled to 64 bytes; at the same time, the fcs check value is calculated, and the fcs check value is appended to the end of the to-be-sent data pbuf_vlan for transmission together; If the sending channel is the ST channel, the sending function of TADMA is called for sending, if the sending channel is not the ST channel, the sending function of MCDMA is called for sending.
Citation Information
Patent Citations
Embedded wireless network system and method thereof for accessing wireless network
CN106060901A
Data processing method and device, nonvolatile storage medium and computer equipment
CN115665057A
Network proxy access processing method and device and readable storage medium thereof
CN117336361A
Creation and migration of distributed streams in clusters of networked computers
US6047323A