Click “Read the original text” to access more VxWorks resources
Introduction
With the gradual improvement of the stability, anti-interference ability, and bandwidth issues of Ethernet, Ethernet is entering the industrial control field on a large scale. Networks used in industrial process control, communication, spacecraft, and navigation systems have extremely high requirements for reliability and rapid fault response. Currently, redundant design, as an effective method to improve equipment reliability, has been widely applied. For a single node in the network system, it is often necessary to have dual redundant backups for the network card, meaning each node uses two network cards (or two ports), interconnected by a hub or switch. When the network card or line that is normally communicating fails, the node can automatically switch to the backup network card for communication. Figure 1 shows a typical connection form of a redundant network.
Although a node with dual redundant network cards has two network cards and two channels, it still presents the characteristics of a single network card to higher-level application systems. Specifically, the two network cards share one physical address and one IP address. According to the TCP/IP reference model, the TCP/IP protocol suite can be divided into four layers: application layer, transport layer, network layer, and link layer, where redundant network card technology can be implemented at each layer.
VxWorks, MUX, and Network Card Driver
The network protocol stack of the embedded real-time operating system VxWorks has two types of interfaces with network device drivers: one is the standard BSD4.4 Driver, which tightly associates the driver and the protocol, making it unfavorable for multi-protocol support; the other standard is unique to VxWorks, which isolates the driver and the protocol stack, connecting them through a thin layer called MUX, allowing network services to be unaffected by specific network interface drivers, achieving driver independence from specific protocols, thus supporting multiple protocols. The relationship among the three is shown in Figure 2.
The current version of MUX supports two types of network driver interface modes: Enhanced Network Driver Interface (END) and Network Protocol Toolkit (NPT) driver interface. Taking the END-type network card driver as an example, this article introduces how to implement dual network card redundancy design in the NE2000 compatible network card driver under VxWorks 5.4. Normally, the protocol driver submits requests through the NIC handle provided by the MUX layer, which is obtained by calling EndLoaD(); then the MUX layer calls the interface function in the network card driver to fulfill the requests of the higher-level protocol driver.
Analysis of Implementing Dual Redundant Network Card Technology at the Application Layer
In the system, dual redundant backups for the network card are performed, meaning one network card is used during normal operation while the other serves as a backup. The backup network card remains in an active state. When the normally communicating network card fails or when the system requires it, the backup network card can switch to continue working in real-time and automatically. Clearly, this requires that the two network cards can only use the same physical address and the same IP address. From the perspective of the application program, only one network card is seen working, regardless of which network card is functioning and how the switch occurs.
Theoretically, redundant network card technology can be implemented at various layers of the OSI model, and the lower the implementation layer, the faster the detection and switching speed, and the better the effect should be. Other methods for implementing dual redundant network cards at the application layer mainly involve initiating tasks in the program to continuously query the working status of the currently active network card. When it is determined that the current network card is in an abnormal state, the routing of the current network card will be deleted, the current hostname will be removed from the host list, and the binding of the network card and the protocol will be released; then the backup network card will be configured: binding the protocol to the backup network card, setting the subnet mask and IP address. In practical tests using this method, the host with dual network cards continuously sent broadcast packets while using network analysis software to receive them. The measured average switching time between the two ports was 120ms, during which many broadcast packets were lost. It can be seen that implementing dual network card redundancy technology at the application layer leads to slow switching speeds, which is detrimental to network reliability and real-time performance.
Implementation in the Driver Program
In the VxWorks system, network cards of the same type use the same driver, and the network cards are distinguished by the handles provided by the driver. When the MUX calls the interface function of the NIC driver, the handle of the network card is passed into the function. This provides a basis for implementing dual network card redundancy in the driver program. Therefore, the ideal way to achieve dual redundancy for network cards is to implement it in the NIC driver program.
Data Structure
The most critical data structure in the network card driver program is the data structure related to the characteristics of the network card. Each network card has its own characteristics, including its unit number, interrupt vector, I/O base address, physical address, etc.
During system startup, in the loading function of the network card driver ne2000EndLoad(), a data structure is initialized for the device, and a pointer to this structure is allocated. At this time, two global pointers are defined:
NE2000END-DEVICE * pDrvCtrl-0;
NE2000END-DEVICE * pDrvCtrl-1;
During network card initialization, these two pointers are pointed to the data structures of the two network cards, and through the definitions of these two pointers, when the MUX calls the interface function of the NIC driver, it can choose pDrvCtrl-0 or pDrvCtrl-1 based on the condition of the network card or the needs of the system to adjust the active network card.
Sending and Receiving Processing
When the upper-level driver calls the sending function of the NIC driver through MUX, the handle of the network card is passed in to specify which network card to use. Normally, the driver sends instructions to the corresponding network card based on that handle to send the packets. In the dual network card redundancy backup driver program, the network card to be used for sending data is specified as needed, rather than necessarily using the network card specified by MUX. For example, first read the Link signal registers of the two network cards to determine the connectivity before deciding which network card to use for sending data.
When receiving packets, it is usually processed in an interrupt. Due to the characteristics of Ethernet at the physical layer, both network cards can receive packets, but only the network card bound to the higher-level protocol can pass the received data upwards. In the dual network card redundancy backup driver program, the data is not sent upwards based on the network card handle specified by MUX, but rather according to the working status of the current network card, sending data upwards even if the data is received from another network card or if another network card is not bound to the higher-level protocol.
Handling of Single Physical Address
Normally, each network card has a globally unique physical address stored in the network card’s PROM. During network card initialization, the physical address is read from the PROM and stored in the appropriate registers and data structures.
To enable the two network cards to back each other up, they must have the same physical address and IP address. In the dual network card redundancy backup driver program, one of the network cards’ physical addresses can be used. There are two methods: either read the physical address from the PROM of one network card during driver initialization; or modify the ne2000EnetAddrGet() function in the network card driver to set any physical address for the network card (as long as it avoids conflicts in the same network).
Handling of Single IP Address
As for the two network cards using the same IP address, this can be achieved by ensuring that only one network card has an IP address during installation, while the other network card does not have an IP address. Since binding an IP address to a network card is implemented at the network layer where the IP protocol resides, switching network cards below the network layer is completely transparent to the upper layer. The application program only sees one network card working throughout. Figure 3 is a schematic diagram of dual network card backup from the perspective of the application program.
Effect Analysis
Through comparative experiments, the average switching time for implementing dual network card redundancy at the application layer is 120ms, while the average switching time at the driver layer is 5ms. Compared to implementation at the application layer or other higher layers, the efficiency is significantly higher, greatly shortening the switching time of dual network cards, thereby reducing the probability of packet loss during switching.
Conclusion
This paper analyzes the network structure model of the VxWorks system, proposes the idea of implementing dual network card redundancy backup functionality in the system’s lower-level driver, and carries out design and implementation. It also compares the two methods of implementation in the driver program and at the application layer, proving that the dual network card redundancy backup functionality can be effectively implemented in the driver program, improving the real-time performance and reliability of Ethernet. This has practical significance in the context of the booming development of industrial Ethernet.