Lwip protocol stack extension and multi-network card implementation method for space real-time network communication

By introducing the LWIP_vlan protocol stack and extending its functionality, the problem of poor compatibility between the traditional LWIP protocol stack and extended network cards is solved, enabling flexible configuration and independent operation of different network cards in a multi-NIC system, thereby improving network reliability and maintainability.

CN121367744BActive Publication Date: 2026-07-07BEIJING INST OF CONTROL ENG

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING INST OF CONTROL ENG
Filing Date
2025-09-24
Publication Date
2026-07-07

AI Technical Summary

Technical Problem

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.

Method used

It introduces the LWIP protocol stack that supports VLAN tagless mode and the LWIP_vlan protocol stack that supports VLAN tag mode. By modifying symbols, expanding functions and integrating the two protocol stacks, it enables flexible switching of multiple network cards and protocol compatibility, and supports VLAN tagging and spatial real-time network functions.

Benefits of technology

It enables flexible configuration and independent operation of different network cards in a multi-NIC system, reduces code complexity, improves network reliability and maintainability, and supports data exchange between various devices and systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121367744B_ABST
    Figure CN121367744B_ABST
Patent Text Reader

Abstract

The application relates to a LWIP protocol stack expansion and multi-network card implementation method for spatial real-time network communication, and introduces a LWIP protocol stack and a LWIP_vlan protocol stack, 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 LWIP protocol stack into the LWIP_vlan protocol stack, and then expanding the function of the LWIP_vlan protocol stack to support a VLAN label and a spatial real-time network function; 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 under the two protocol stack modes; for the LWIP_vlan protocol stack, a spatial real-time network function module is initialized, and the function of a low_level_output_vlan function is expanded, so that the two protocol stacks are simultaneously supported by the multi-network card. The application supports flexible switching modes, protocols and standards of the multi-network card, ensures accurate data transmission and reception, simultaneously supports various network cards and device types, and realizes more extensive data exchange and integration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of multi-NIC application technology in aerospace and industrial control computers, and relates to the LWIP protocol stack extension and multi-NIC implementation method for real-time space network communication. Background Technology

[0002] In aerospace and industrial control computers, extreme operating conditions such as temperature variations and electromagnetic interference often lead to communication delays or even interruptions. Therefore, redundant networks with multiple network interface cards (NICs) are required to support long-term, trouble-free operation for critical missions. Multi-port designs support various network protocols and standards, allowing the control computer to connect to different networks simultaneously, supporting a wider range of devices and systems, and enabling broader data exchange and integration. Furthermore, by distributing traffic across multiple NIC interfaces, network load can be effectively reduced, preventing a single network channel from becoming a bottleneck, thereby improving overall network performance and response speed. This is particularly important for applications requiring real-time processing of large amounts of data. To achieve these functionalities, a communication method needs to be designed that, on top of traditional Ethernet, simultaneously supports high-precision time synchronization, flow scheduling, and priority management.

[0003] LWIP, a widely used TCP / IP protocol stack, is specifically designed for resource-constrained embedded systems, offering flexibility and configurability to adapt to various hardware platforms. However, traditional LWIP protocol stacks have limitations. Their multi-NIC mechanism requires all NICs to use the same hardware mode, Ethernet controller mode, and VLAN protocol support mode. This limitation results in poor compatibility between traditional LWIP protocol stacks and extended NICs, failing to meet the application requirements of multiple network ports simultaneously supporting multiple network protocols and standards, and making it difficult to cope with the complex and ever-changing network environments in aerospace and industrial fields. Therefore, it is necessary to develop a multi-NIC and multi-protocol stack based on the traditional LWIP protocol stack.

[0004] The space real-time network achieves nanosecond-level clock synchronization via the IEEE 1588 protocol, ensuring multi-system collaboration and meeting the high-precision timing requirements of aerospace missions. Its flow scheduling and shaping technologies guarantee low-latency and deterministic transmission of critical data, making it suitable for real-time scenarios such as attitude control and scientific data transmission. The space real-time network supports redundant paths and rapid fault recovery, improving system reliability and adapting to harsh environments. Compared to traditional Ethernet, the space real-time network provides an efficient and predictable communication foundation through hardware-level time awareness and priority management. Therefore, combining the space real-time network with the LWIP protocol stack is a feasible approach for development with multiple network cards and protocol stacks. However, this process faces challenges such as complex program porting, difficult hardware adaptation, and protocol stack expansion compatibility, necessitating research into porting methods between the space real-time network and the LWIP protocol stack. Summary of the Invention

[0005] The technical problem solved by this invention is: This invention proposes an LWIP protocol stack extension and multi-NIC implementation method for real-time space network communication, which solves the problem of poor compatibility between the LWIP protocol stack and the extended NIC, supports flexible switching of modes, protocols and standards of multiple NICs, ensures accurate data transmission and reception, and supports multiple NICs and device types to achieve broader data exchange and integration.

[0006] The solution to the technical problem of this invention is: a method for extending the LWIP protocol stack and implementing multiple network cards for real-time space network communication, comprising the following steps:

[0007] Two LWIP protocol stacks are introduced: one supporting LWIP protocol stack without VLAN tags and the other supporting LWIP_vlan protocol stack with VLAN tags. The LWIP_vlan protocol stack with VLAN tags is created by adding the suffix "vlan" to all symbols in the LWIP protocol stack source code, changing them to LWIP_vlan. The functionality of the LWIP_vlan protocol stack is then extended, including adding VLAN tag frame header processing logic, modifying the network card driver to support VLAN tag recognition and filtering, and implementing a flow control mechanism based on VLAN ID and priority in the protocol stack to support VLAN tags and real-time spatial network functions.

[0008] The LWIP protocol stack and the LWIP_vlan protocol stack are integrated into the same software project. Tasks are created, network interface cards are added, threads for receiving and processing network packets are created, and socket threads for providing network programming interfaces are created in both protocol stack modes. For the LWIP_vlan protocol stack, the initialization of the space real-time network function module and the extension of the low_level_output_vlan function are also executed, so that multiple network cards can simultaneously support the LWIP protocol stack for Ethernet communication and the LWIP_vlan protocol stack for handling space real-time network functions.

[0009] Furthermore, for the LWIP_vlan protocol stack, symbols with the suffix "vlan" are uniformly added to the LWIP protocol stack source code, including function names, variable names, macro definitions, enumeration types, and structures.

[0010] Furthermore, the functional 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 extended by modifying the macro definition PBUF_LINK_HLEN_vlan from 14 bytes to 18 bytes.

[0012] Enable the macro definition ETHARP_SUPPORT_VLAN_vlan to 1 to indicate support for VLAN functionality, and create the macro definition VLAN_SET_ENABLE_vlan to 1 to control the on / off state of VLAN functionality;

[0013] Define a structure struct s_VLAN_vlan to store VLAN tag information, including a 2-byte VLAN protocol identifier, a 1-byte canonical format indicator, a 1-byte priority identifier, and a 2-byte VLAN ID;

[0014] The structure definition struct LWIP_sock_vlan introduces the member struct s_VLAN_vlan VLAN_user_vlan to store VLAN information;

[0015] The structure definition struct pbuf_vlan introduces the member struct s_VLAN_vlan VLAN_user_vlan to store VLAN information;

[0016] Modify the ethernet_output_vlan function to add logic for processing VLAN tags;

[0017] The function LWIP_sendto_vlan adds a VLAN enable check, retrieves VLAN information from the socket, and passes this information to the data to be sent, pbuf_vlan.

[0018] The functions raw_sendto_if_src_vlan, udp_sendto_if_src_vlan, and tcp_sendto_if_src_vlan require VLAN information from pbuf_vlan;

[0019] The function LWIP_setsockopt_impl_vlan adds the setting of VLAN priority. By judging the SO_PRIORITY_vlan setting option, the priority is bound to the socket.

[0020] Furthermore, for the LWIP_vlan protocol stack, adding a network interface card refers to adding an EP network interface card, and the steps are as follows:

[0021] Configure the IP address, subnet mask, and gateway for the end node EP;

[0022] Add the end node EP to the system network interface card and perform initial configuration, including setting the MAC address of the end node EP, initializing the MAC controller, and configuring DMA;

[0023] Assign a unique name to the EP network card, associate the generated network card name with the network card instance netif structure, and register it in the system; the network card name is a prerequisite for implementing the SO_BINDTODEVICE network card binding function.

[0024] Create a task network_input_thread to add support for the ETHTYPE_VLAN protocol for receiving and processing network packets;

[0025] Create two socket threads for the network interface card of the end node EP, corresponding to the TEMAC0 and TEMAC1 controllers respectively.

[0026] Furthermore, for the LWIP_vlan protocol stack, the steps for creating a socket thread to provide a network programming interface are as follows:

[0027] Create a new socket, bind it to the local IP address and port number using bind, and establish a connection with the destination IP address and port using connect.

[0028] Set the SO_RCVTIMEO option for the socket to make it work in non-blocking mode;

[0029] Set the SO_BINDTODEVICE option for the socket, parse the incoming network interface name parameter, and select the specified network interface based on this parameter when sending or receiving data;

[0030] The SO_PRIORITY option can be set for sockets to support different VLANs and priority bindings. When sending data packets, VLAN tags are added according to the set priority, and these tags are correctly parsed when receiving data packets.

[0031] After completing the above settings, use the recv and send functions to test whether UDP communication is normal.

[0032] Furthermore, the initialization of the spatial real-time network function module includes the following steps:

[0033] Perform hardware and software initialization configuration on the switch to ensure it can properly handle time-sensitive network traffic;

[0034] Clear all TADMA-related configurations and data;

[0035] Add a new flow to the hash table of the TADMA system. The relevant attributes of the flow include trigger time, trigger count, flow ID, MAC address and VLAN information.

[0036] Iterate through all stream 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;

[0037] Configure the switch's CAM to ensure that the switch can quickly look up and forward data packets based on the entries in the CAM table;

[0038] Configure the Spanning Tree Protocol (STP) state of the switch to ensure that there are no loops in the network and that packets are forwarded along the optimal path.

[0039] Furthermore, the clearing of all TADMA-related configurations and data includes: setting the configuration completion flag to 0, clearing register values ​​at specific offsets, and clearing the linked list nodes associated with each stream in the hash table, ensuring that the system is in a clean state when reconfigured or initialized.

[0040] Furthermore, the steps for extending the functionality of the low_level_output_vlan function are as follows:

[0041] Obtain the VLAN tag from the data to be sent, pbuf_vlan, and further extract the TCI field containing priority information and the VLAN protocol field;

[0042] Determine if it is an 802.1Q VLAN format. If it is VLAN format, select the DMA transmission channel according to the priority information. High priority data is sent through the ST channel of TADMA, and low priority data is sent through the BE or RES channel of MCDMA. If it is not VLAN format, the BE channel of MCDMA is used by default.

[0043] For data pbuf_vlan with a total length less than 64 bytes, pad with bytes 0 to 64; at the same time, calculate its FCS checksum and append the FCS checksum to the end of the data pbuf_vlan to be sent, and send them together.

[0044] If the transmission channel is an ST channel, the TADMA transmission function is called to send the data; if the transmission channel is not an ST channel, the MCDMA transmission function is called to send the data.

[0045] The beneficial effects of this invention compared to the prior art are:

[0046] The method of this invention extends and optimizes the traditional LWIP protocol stack. By introducing the LWIP_vlan protocol stack and adjusting the relevant code logic, it realizes flexible configuration based on different network interface instances (netif). Specifically, it supports configuring different network cards with parameters such as DMA mode, Ethernet controller hardware, PHY chip, FCS verification, VLAN enable, and interrupt handling functions, thereby enabling the collaborative operation of traditional Ethernet and real-time space network functions.

[0047] This approach makes the two protocol stacks almost completely independent; any changes to one stack will not affect the other. Because the two versions use different namespaces (by adding suffixes), they are logically completely separated and will not conflict even if coexisting in the same project. When adding new features to a protocol stack, there is no need to add numerous conditional statements throughout the codebase to differentiate processing logic under different conditions. For example, to add new features to the LWIP Ethernet protocol stack to support VLAN-untagged protocols, development can be done directly within that stack without considering how to prevent these changes from affecting the LWIP_vlan protocol stack. This approach reduces code complexity, lowers the risk of errors due to frequent modifications, and facilitates subsequent testing and maintenance. Attached Figure Description

[0048] Figure 1 Flowchart for implementing multi-NIC functionality;

[0049] Figure 2 Flowchart for adding an EP network card interface;

[0050] Figure 3 Flowchart for UDP socket network programming interface;

[0051] Figure 4 The flowchart for the low_level_output_vlan function. Detailed Implementation

[0052] This invention extends the LWIP protocol stack by adding support for the LWIP_vlan protocol stack with VLAN tagging mode. It also ensures compatibility between multiple network cards and both the LWIP and LWIP_vlan protocol stacks through top-level and bottom-level configurations. The main methods are as follows:

[0053] Two LWIP protocol stacks are introduced: one supporting VLAN-untagged mode and the other supporting VLAN-tagged mode (LWIP_vlan). This approach uses specific tools to uniformly modify all symbols in the LWIP protocol stack source code by adding the suffix "vlan," thus changing them to LWIP_vlan. Furthermore, the LWIP_vlan protocol stack is further developed and its functionality extended to support VLAN tagging and spatial real-time network functions. Integrating the LWIP and LWIP_vlan protocol stacks into the same software project allows multiple network cards to simultaneously support both standard Ethernet and spatial real-time network functions by modifying necessary logic. This approach reduces the coupling between the two protocol stacks, enhancing the stability and maintainability of the codebase. Each protocol stack can be optimized for its specific application scenario. For example, the LWIP protocol stack provides efficient, lightweight standard Ethernet communication, while the LWIP_vlan protocol stack handles spatial real-time network functions, ensuring the accuracy and timeliness of data transmission. By adding an EP network card interface, initializing the spatial real-time network function module, and expanding the functionality of the low_level_output_vlan function, the extended network card is made to support the LWIP_vlan protocol stack.

[0054] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0055] Example 1

[0056] The method for LWIP protocol stack extension and multi-NIC implementation for real-time space network communication in this embodiment includes the following steps:

[0057] 1. Extension and optimization of the LWIP_vlan protocol stack

[0058] 1.1 Symbol Renaming Using Specific Tools: A specific code processing tool is used to perform a comprehensive scan of the LWIP protocol stack source code, and all symbols (including but not limited to function names, variable names, macro definitions, enumeration types, structures, etc.) are uniformly appended with the suffix "vlan". 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". These changes ensure that there are no naming conflicts 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: Extend the functionality of the LWIP_vlan protocol stack to support VLAN tagging and real-time spatial networking. This includes adding VLAN tag frame header processing logic, modifying the network card driver to support VLAN tag recognition and filtering, and implementing a flow control mechanism based on VLAN ID and priority within the protocol stack. The specific steps are as follows:

[0060] 1.2.1 The VLAN tag occupies 4 bytes (TPID + TCI), therefore 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 support for VLAN functionality. Create the macro definition VLAN_SET_ENABLE_vlan to 1 to control the on / off state of VLAN functionality.

[0062] 1.2.3 Define a structure `struct s_VLAN_vlan` to store VLAN tag information. It includes 2 bytes of tpid, 1 byte of cif, 1 byte of pri, and 2 bytes of vid.

[0063]

[0064]

[0065] 1.2.4 The structure definition introduces the member struct s_VLAN_vlanVLAN_user_vlan in struct LWIP_sock_vlan to store VLAN information.

[0066] 1.2.5 The structure definition introduces the member struct s_VLAN_vlan VLAN_user_vlan in struct pbuf_vlan to store VLAN information.

[0067] 1.2.6 Modify the ethernet_output_vlan function to add logic for processing VLAN tags.

[0068] The function LWIP_sendto_vlan in section 1.2.7 adds a VLAN enable check, retrieves VLAN information from the socket, and passes this information to the data to be sent, pbuf_vlan.

[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] The function LWIP_setsockopt_impl_vlan in 1.2.9 adds the setting of VLAN priority. By judging the SO_PRIORITY_vlan setting option, the priority is bound to the socket.

[0071] 1.3 Protocol Stack Integration and Deployment: The original LWIP protocol stack and the renamed LWIP_vlan protocol stack folder, along with all its contained .c and .h files, are added to the project. This step ensures that the code for both protocol stacks can be compiled correctly and will not interfere with each other by configuring compiler options and linker scripts.

[0072] 2. Detailed Implementation of Multi-NIC Functionality

[0073] The flowchart of the specific implementation of the multi-NIC function is as follows: Figure 1 As shown, this invention extends and optimizes the LWIP protocol stack and the LWIP_vlan protocol stack, creating tasks, adding network interface cards, and receiving and processing data packets in both protocol stack modes.

[0074] 2.1 Implementation of Multi-NIC Functionality in LWIP_vlan Protocol Stack

[0075] This invention focuses on the addition of EP network card interfaces and the configuration of TEMAC0 and TEMAC1 Ethernet MAC hardware instances, the initialization of the spatial real-time network function module, and the functional expansion of the low_level_output_vlan function.

[0076] 2.1.1 Add EP network card interface

[0077] As an end node, the EP is responsible for the generation, reception, and management of time-sensitive data streams. The EP connects to the network through the network interface card and uses spatial real-time network protocols (such as clock synchronization and traffic scheduling) to ensure that its data packets arrive at their destination on time.

[0078] TEMAC is a three-mode Ethernet MAC IP core that can be configured in GMII / RMII, SGMII, or RGMII mode. TEMAC0 and TEMAC1 can each serve as Ethernet MAC hardware instances, 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] The flowchart describes the creation of a socket thread for the EP's network interface card, taking the implementation of a UDP socket that supports multiple network cards, VLANs, and priority settings as an example. Figure 3 As shown, the specific steps are as follows:

[0088] (1) Create a new socket, bind it to the local IP address and port number using bind, and establish a connection with the destination IP address and port using connect.

[0089] (2) Set the SO_RCVTIMEO option for the socket to make it work in non-blocking mode.

[0090] (3) Set the SO_BINDTODEVICE option for the socket, parse the incoming network interface name parameter, and select the specified network interface according to the parameter when sending or receiving data.

[0091] (4) Set the SO_PRIORITY option for the socket to support different VLANs and priority bindings. When sending data packets, add appropriate VLAN tags according to the set priority and correctly parse these tags when receiving data packets.

[0092] (5) After completing the above settings, use the recv and send functions to test whether UDP communication is normal.

[0093] 2.1.2 Initialize the spatial real-time network function module

[0094] The specific steps for initializing a space real-time network switch are as follows:

[0095] (1) Initialize the hardware and software configuration of the switch to ensure that it can correctly handle time-sensitive network traffic.

[0096] (2) Clear all configurations and data related to TADMA, including setting the configuration completion flag to 0, clearing register values ​​at specific offsets, and clearing the linked list nodes associated with each stream in the hash table to ensure that the system is in a clean state when reconfigured or initialized.

[0097] (3) Add a new flow to the hash table of the TADMA system. The relevant attributes of the flow include trigger time, trigger count, flow ID, MAC address, VLAN information, etc.

[0098] (4) Traverse all stream entries and program the hardware according to the information of each entry to ensure that the DMA operation is scheduled to be executed according to the preset time slot.

[0099] (5) Configure the switch's CAM to ensure that the switch can quickly look up and forward data packets based on the entries in the CAM table. Configure the switch's Spanning Tree Protocol (STP) state to ensure that there are no loops in the network and that data packets can be forwarded along the optimal path.

[0100] 2.1.3 Extension of the low_level_output_vlan function

[0101] To support VLAN functionality and address the specific issues related to hardware and IP cores, the following modifications are needed to the low_level_output_vlan function:

[0102] (1) Obtain the VLAN tag (4 bytes) from the data to be sent pbuf_vlan, and further extract the TCI field (containing priority information) and the VLAN protocol field.

[0103] (2) Determine if it is an 802.1Q VLAN (TPID is 0x8100). If it conforms to the VLAN format, select the DMA transmission 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 does not conform to the VLAN format, the BE channel of MCDMA is used by default.

[0104] (3) Due to the special nature of the hardware and IP core, when the total length of the data pbuf_vlan to be sent is less than 64 bytes, the MAC controller will automatically pad it to 64 bytes. Furthermore, this MAC controller will not automatically calculate the FCS checksum, causing the data to fail verification. To solve this problem, the software is specially designed to pad data pbuf_vlan with a total length less than 64 bytes with bytes from 0 to 64; simultaneously, the software calculates its FCS checksum (4 bytes) and appends it to the end of the data pbuf_vlan to be sent (bytes 65 to 68) before sending it.

[0105] (4) If the transmission channel is an ST (Time-Sensitive) channel, the TADMA transmission function is called to transmit. If the transmission channel is a non-ST channel (such as BE or RES), the MCDMA transmission function is called to transmit.

[0106] The low_level_output_vlan function implements the following functionality: Figure 4 As shown.

[0107] This invention can be widely applied in fields with complex and ever-changing network environments, such as aerospace and industrial control, to improve network reliability, facilitate network management and maintenance, enhance fault tolerance, and ensure security.

[0108] Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make possible changes and modifications to the technical solutions of the present invention by utilizing the methods and techniques disclosed above without departing from the spirit and scope of the present invention. Therefore, any simple modifications, equivalent changes and alterations made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solutions of the present invention shall fall within the protection scope of the technical solutions of the present invention.

[0109] The contents not described in detail in this specification are common knowledge to those skilled in the art.

Claims

1. A method for extending the LWIP protocol stack and implementing multiple network interface cards (NICs) for real-time space network communication, characterized in that, Includes the following steps: Two LWIP protocol stacks are introduced: one supporting LWIP protocol stack without VLAN tags and the other supporting LWIP_vlan protocol stack with VLAN tags. The LWIP_vlan protocol stack with VLAN tags is created by adding the suffix "vlan" to all symbols in the LWIP protocol stack source code, changing them to LWIP_vlan. The functionality of the LWIP_vlan protocol stack is then extended, including adding VLAN tag frame header processing logic, modifying the network card driver to support VLAN tag recognition and filtering, and implementing a flow control mechanism based on VLAN ID and priority in the protocol stack to support VLAN tags and real-time spatial network functions. The LWIP protocol stack and the LWIP_vlan protocol stack are integrated into the same software project. Tasks are created, network interface cards are added, threads for receiving and processing network packets are created, and socket threads for providing network programming interfaces are created in both protocol stack modes. For the LWIP_vlan protocol stack, the initialization of the space real-time network function module and the extension of the low_level_output_vlan function are also executed, so that multiple network cards can simultaneously support the LWIP protocol stack for Ethernet communication and the LWIP_vlan protocol stack for handling space real-time network functions.

2. The method for LWIP protocol stack extension and multi-NIC implementation for real-time space network communication according to claim 1, characterized in that, For the LWIP_vlan protocol stack, symbols with the suffix "vlan" are uniformly added to the LWIP protocol stack source code, including function names, variable names, macro definitions, enumeration types, and structures.

3. The method for LWIP protocol stack extension and multi-NIC implementation for real-time space network communication according to claim 1, characterized in that, The functional expansion of the LWIP_vlan protocol stack includes: The VLAN tag occupies 4 bytes: TPID+TCI, so the length of the link layer header needs to be extended by modifying the macro definition PBUF_LINK_HLEN_vlan from 14 bytes to 18 bytes. Enable the macro definition ETHARP_SUPPORT_VLAN_vlan to 1 to indicate support for VLAN functionality, and create the macro definition VLAN_SET_ENABLE_vlan to 1 to control the on / off state of VLAN functionality; Define a structure struct s_VLAN_vlan to store VLAN tag information, including a 2-byte VLAN protocol identifier, a 1-byte canonical format indicator, a 1-byte priority identifier, and a 2-byte VLAN ID; The structure definition struct LWIP_sock_vlan introduces the member struct s_VLAN_vlan VLAN_user_vlan to store VLAN information; The structure definition struct pbuf_vlan introduces the member struct s_VLAN_vlan VLAN_user_vlan to store VLAN information; Modify the ethernet_output_vlan function to add logic for processing VLAN tags; The function LWIP_sendto_vlan adds a VLAN enable check, retrieves VLAN information from the socket, and passes this information to the data to be sent, pbuf_vlan. The functions raw_sendto_if_src_vlan, udp_sendto_if_src_vlan, and tcp_sendto_if_src_vlan require VLAN information from pbuf_vlan; The function LWIP_setsockopt_impl_vlan adds the setting of VLAN priority. By judging the SO_PRIORITY_vlan setting option, the priority is bound to the socket.

4. The method for LWIP protocol stack extension and multi-NIC implementation for real-time space network communication according to claim 1, characterized in that, For the LWIP_vlan protocol stack, adding a network interface card refers to adding an EP network interface card, and the steps are as follows: Configure the IP address, subnet mask, and gateway for the end node EP; Add the end node EP to the system network interface card and perform initial configuration, including setting the MAC address of the end node EP, initializing the MAC controller, and configuring DMA; Assign a unique name to the EP network card, associate the generated network card name with the network card instance netif structure, and register it in the system; the network card name is a prerequisite for implementing the SO_BINDTODEVICE network card binding function. Create a task network_input_thread to add support for the ETHTYPE_VLAN protocol for receiving and processing network packets; Create two socket threads for the network interface card of the end node EP, corresponding to the TEMAC0 and TEMAC1 controllers respectively.

5. The method for LWIP protocol stack extension and multi-NIC implementation for real-time space network communication according to claim 4, characterized in that, For the LWIP_vlan protocol stack, the steps for creating a socket thread to provide a network programming interface are as follows: Create a new socket, bind it to the local IP address and port number using bind, and establish a connection with the destination IP address and port using connect. Set the SO_RCVTIMEO option for the socket to make it work in non-blocking mode; Set the SO_BINDTODEVICE option for the socket, parse the incoming network interface name parameter, and select the specified network interface based on this parameter when sending or receiving data; The SO_PRIORITY option can be set for sockets to support different VLANs and priority bindings. When sending data packets, VLAN tags are added according to the set priority, and these tags are correctly parsed when receiving data packets. After completing the above settings, use the recv and send functions to test whether UDP communication is normal.

6. The method for LWIP protocol stack extension and multi-NIC implementation for real-time space network communication according to claim 1, characterized in that, The steps for initializing the real-time spatial network function module are as follows: Perform hardware and software initialization configuration on the switch to ensure it can properly handle time-sensitive network traffic; Clear all TADMA-related configurations and data; Add a new flow to the hash table of the TADMA system. The relevant attributes of the flow include trigger time, trigger count, flow ID, MAC address and VLAN information. Iterate through all stream 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; Configure the switch's CAM to ensure that the switch can quickly look up and forward data packets based on the entries in the CAM table; Configure the Spanning Tree Protocol (STP) state of the switch to ensure that there are no loops in the network and that packets can be forwarded along the optimal path.

7. The method for LWIP protocol stack extension and multi-NIC implementation for real-time space network communication according to claim 6, characterized in that, The process of clearing all configurations and data related to TADMA includes: setting the configuration completion flag to 0, clearing the register values ​​at specific offsets, and clearing the linked list nodes associated with each stream in the hash table to ensure that the system is in a clean state when reconfigured or initialized.

8. The method for LWIP protocol stack extension and multi-NIC implementation for real-time space network communication according to claim 3, characterized in that, The steps to extend the functionality of the low_level_output_vlan function are as follows: Obtain the VLAN tag from the data to be sent, pbuf_vlan, and further extract the TCI field containing priority information and the VLAN protocol field; Determine if it is an 802.1Q VLAN format. If it is VLAN format, select the DMA transmission channel according to the priority information. High priority data is sent through the ST channel of TADMA, and low priority data is sent through the BE or RES channel of MCDMA. If it is not VLAN format, the BE channel of MCDMA is used by default. For data pbuf_vlan with a total length less than 64 bytes, pad with bytes 0 to 64; at the same time, calculate its FCS checksum and append the FCS checksum to the end of the data pbuf_vlan to be sent, and send them together. If the transmission channel is an ST channel, the TADMA transmission function is called to send the data; if the transmission channel is not an ST channel, the MCDMA transmission function is called to send the data.