Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Instructions for redundant backup of SylixOS dual network cards

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Work preparation

The development board needs to have dual network cards and be able to communicate normally.

If the interrupt mechanism is selected, the hardware PHY needs to have interrupt pins and be able to output normally.

An overview of the principle of environmental preparation

In the dual network card redundant backup scheme, multiple physical network cards are bound by the "primary-backup" network card strategy. after binding, the two network cards have only one physical address and IP address, and only one network card works at the same time. When the main network card or line fails, it can automatically switch to the backup network card.

The dual network card redundancy backup scheme adopts polling mechanism detection, that is, PHY connection status detection is carried out every once in a while, and when the primary network card connection is disconnected and the backup network card connection is normal, switch to the backup network card.

The dual network card redundancy backup scheme adopts interrupt mechanism detection, that is, the interrupt signal caused by the change of PHY connection status is detected immediately, and when the main network card connection is disconnected and the backup network card connection is normal, switch to the backup network card.

The response time of interrupt mechanism detection is faster than that of polling mechanism, but it needs hardware support.

Overview of interrupt Mechanism Overview of polling Mechanism Overview of implementation steps

Call the ifconfig command to view the current network card information and get the names of the two network cards that need to be bound, as shown in figure 4.1.

Figure 4.1 obtaining Nic information

Jump to the / etc/ directory and add a configuration file bonding.ini that binds dual network cards, as shown in listing 4.1 of the program.

Listing 4.1 bonding.ini configuration file

[bonding] ipaddr=192.168.2.220netmask=255.255.255.0gateway=192.168.2.1mac=80:46:38:78:28:39en1name=en1en2name=en2mode=1* mode=0 (if default 100ms is not configured) * miimon=100* mode=1 (if default falling edge trigger is not configured) * gpiotype=1gpiolevel=0

The master-slave policy is adopted in this configuration, which is described as follows:

Basic configuration

Ipaddr: configure the bound IP address

Netmask: configure the bound subnet mask

Gateway: configure the bound default gateway

Mac: configure the bound physical address

En1name: configure the name of the primary network card to be bound

En2name: configure the name of the backup network card to be bound

Mode: configure working mode (0: polling mechanism, 1: interrupt mechanism). If you select polling mechanism, you need to configure miimon entry; if you select interrupt mechanism, configure en1gpio, en2gpio, gpiotype and gpiolevel entries.

Miimon: configure polling detection time (milliseconds), usually set to 100ms

Gpiotype: configure trigger mode (0: level trigger, 1: edge trigger)

Gpiolevel: configure the trigger condition (if it is level trigger, 1 means high level trigger, 0 means low level trigger; if edge trigger, 1 means rising edge trigger, 0 means falling edge trigger, 2 means double edge trigger).

Ioctl function implementation

The dual Nic redundant backup module needs to call the ioctl function in the Nic driver and set the physical Nic hardware address, requiring the underlying Nic driver to have functions such as Table 4.1:

Table 4.1 ioctl function cmd command

Cmd command

Parameter type

Function

SIOCSIFHWADDR

Struct ifreq

Set hardware address

GET_LINK_STATE

Struct ifreq

Get PHY status

SET_PHY_MICR

NULL

Set PHY interrupt

CLEAR_PHY_MISR

NULL

Clear PHY interrupt statu

GET_MAC_IRQ

ULONG

Get the interrupt number of the network card

GET_PHY_GPIO

UINT8

Get PHY interrupt output GPIO pin number

If the ioctl function in the Nic driver is not implemented, you need to modify the Nic driver. The details are as follows:

Add the ioctl function to the Nic driver function, as shown in listing 4.2.

Listing 4.2 Modification of the network card driver function

Static struct netdev_funcs net0_drv = {ioctl = _ _ enetCoreIoctl,}

Write the ioctl function, as shown in listing 4.3.

Listing 4.3 adds the ioctl function

Static INT _ enetCoreIoctl (struct netdev * pNetDev, int iCmd, void * pArg) {struct ifreq * pifreq; switch (iCmd) {case XXX: break; default: break;} return (ERROR_NONE);}

In the ioctl function, add the SIOCSIFHWADDR command, as shown in listing 4.4 of the program.

Listing 4.4 adds the SIOCSIFHWADDR command

# define SIOCSIFHWADDR _ IOW (55, struct ifreq) case GET_LINK_STATE: pifreq = (struct ifreq *) pArg; / * TODO: set MAC address * / break

In the ioctl function, add the GET_MAC_IRQ command, as shown in listing 4.5.

Listing 4.5 adds the GET_MAC_IRQ command

# define GET_MAC_IRQ _ IOWR (260,260, struct ifreq) case GET_MAC_IRQ: / * TODO: get MAC interrupt number * / break; polling mechanism implementation

The polling mechanism needs to call the ioctl function in the Nic driver and read the connection status of the hardware device PHY. You need to modify the Nic driver ioctl function. Details are as follows:

In the ioctl function, add the GET_LINK_STATE command, as shown in listing 4.6 of the program.

Listing 4.6 add the GET_LINK_STATE command

# define GET_LINK_STATE _ IOWR (struct ifreq, 257, struct ifreq) case GET_LINK_STATE: pifreq = (struct ifreq *) pArg; / * TODO: read the connection status of hardware device PHY * / / * if connected: pifreq- > ifr_flags | = IFF_RUNNING; * / / * not connected: pifreq- > ifr_flags & = ~ IFF_RUNNING; * / break; interrupt mechanism implementation

The interrupt mechanism needs to call the ioctl function in the Nic driver, clear the interrupt status register of PHY, and modify the Nic driver ioctl function. The details are as follows:

Add the SET_PHY_MICR command, as shown in listing 4.7.

Listing 4.7 adds the SET_PHY_MICR command

# define SET_PHY_MICR _ IOWR (PHY, 258, struct ifreq) case SET_PHY_MICR: / * TODO: set the PHY interrupt control register to enable link state change interrupt * / / * set the interrupt pin on the hardware PHY to output * / break

Add the CLEAR_PHY_MISR command, as shown in listing 4.8 of the program.

Listing 4.8 adds the CLEAR_PHY_MISR command

# define CLEAR_PHY_MISR _ IOWR (PHY, 259, struct ifreq) case CLEAR_PHY_MISR: / * TODO: clear PHY interrupt status * / break

Note: to apply for GPIO pin number, you need to add the corresponding GPIO configuration in the BSP adaptation file of the development board.

Add the GET_PHY_GPIO command, as shown in listing 4.9.

Listing 4.9 adds the GET_PHY_GPIO command

# define GET_PHY_GPIO _ IOWR (261, struct ifreq) case GET_PHY_GPIO: / * TODO: get the PHY GPIO pin number * / break; instructions

Load the module and turn on the redundant backup of double network cards.

Uninstall the module and turn off the redundant backup of the dual network card.

Test method for turning function off and function on

Host ping development board, manually unplug a network cable, observe whether automatically switch to another network card, whether the network is still connected; and then unplug another network cable to observe network connectivity again.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report