Software upgrading method, network equipment and related device
By selecting the appropriate network card in the U-Boot state to receive and send data packets, the upgrade failure problem caused by lack of protocol stack support during the router U-Boot upgrade process is solved, and the upgrade efficiency is improved.
Patent Information
- Application Number
- CN202411071917.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2025-10-03
AI Technical Summary
During the U-boot upgrade process of the router, due to the lack of protocol stack support, the forwarding path cannot be found through the protocol stack process, resulting in the upgrade data packet being unable to be sent to the corresponding network card, which may cause the upgrade to fail and affect the upgrade efficiency.
In the U-Boot state, by obtaining the physical status, data packet detection results and server address detection results of at least two network cards, the target network card is selected to receive and send data packets to ensure the smooth progress of the upgrade process.
It improves the software upgrade efficiency of the router, avoids upgrade failures caused by network card failures, and ensures the normal progress of the data interaction process.
Smart Images

Figure CN120750758A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of electronic technology, and in particular to a software upgrading method, network equipment and related devices. Background Art
[0002] A router is a network device whose main function is to act as a gateway between networks, connecting two or more networks to receive and send data.
[0003] With the continuous advancement of technology, router upgrades have become a fundamental feature to enhance network performance. Generally speaking, router upgrades are categorized as kernel upgrades and U-boot upgrades. Kernel upgrades include web page upgrades, while U-boot upgrades are primarily used for R&D phase upgrades. During the upgrade process, the server sends an upgrade packet to the router. Upon receiving the packet, the router writes it to memory, completing the upgrade.
[0004] Because routers are configured with two or more network cards (NICs), the upgrade process requires the protocol stack to find a forwarding path and then send the upgrade packets to the corresponding NICs to ensure that the upgrade packets are correctly received. However, upgrades using U-Boot lack protocol stack support, so the protocol stack's processing flow cannot find a forwarding path and send the upgrade packets to the corresponding NICs. This can cause upgrade failures and affect upgrade efficiency. Summary of the Invention
[0005] An embodiment of the present application provides a software upgrade method, network device, and related apparatus. The network device includes at least two network cards. During the upgrade process, when a default network card fails and cannot send / receive data packets, other network cards can be selected to send / receive data packets, thereby ensuring that the upgrade can be completed based on the data packets and improving upgrade efficiency.
[0006] In a first aspect, an embodiment of the present application provides a software upgrade method, which is applied to a network device, wherein the network device includes at least two network cards, and the method includes:
[0007] In the U-Boot state, obtaining physical states respectively corresponding to the at least two network cards; when the physical states respectively corresponding to the at least two network cards are connected states, obtaining one or more of data packet detection results and server address detection results respectively corresponding to the at least two network cards, wherein the data packet detection result is used to indicate whether the network card has received an upgrade data packet from a server, and the server address detection result is used to indicate a connection state between the network card and the address of the server; and determining a target network card from the at least two network cards based on one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards, wherein the target network card is used to perform software upgrades by receiving and sending data packets.
[0008] In an embodiment of the present application, when a network device has at least two network cards, in the U-Boot state, since the kernel is not started, if the protocol stack process cannot be passed, the three dimensions of physical status, whether the upgrade data packet is received, and whether the address of the server is connected can be used to select the packet sending and receiving interface during the upgrade process, which can be more flexibly adapted to different scenarios. During the upgrade process, if the default network card fails and cannot send / receive data packets, other interfaces can be selected to send / receive data packets, thereby ensuring the completion of the upgrade, improving the upgrade efficiency, and preventing upgrade failures due to the network card not being connected as configured.
[0009] In a possible implementation of the first aspect, obtaining one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards includes:
[0010] The first network card detects whether the upgrade data packet can be received by detecting the first network card to determine the data packet detection result of the first network card, where the first network card is any one of the at least two network cards; wherein, if the upgrade data packet is detected, the data packet detection result of the first network card is a detection success; if the upgrade data packet is not detected, the data packet detection result to the first network card is a detection failure.
[0011] In an embodiment of the present application, if the physical status of at least two network cards in a network device indicates that both are connected, the upgrade data packet can be detected to obtain a data packet detection result, and then the target network card can be determined based on the data packet detection result, or the server address can be detected based on the data packet detection result to determine whether to obtain a server address detection result. The target network card serves as the network card that receives / sends data packets, and the packet receiving and sending interfaces during the upgrade process can be selected from multiple dimensions to improve upgrade efficiency.
[0012] In a possible implementation of the first aspect, determining the target network card from the at least two network cards based on one or more of the data packet detection results and the server address detection results corresponding to the at least two network cards includes: taking the network card among the at least two network cards whose data packet detection result is a successful detection as the target network card.
[0013] It can be understood that when the physical status of at least two network cards of the network device indicates that both network cards are in a connected state, if one of the network cards can detect the upgrade data packet, it means that the network card has established a connection with the server and can correctly receive the data packet and the data packet can be used for upgrading. Therefore, using this network card as the target network card can ensure that in the subsequent upgrade process, the network card can receive data packets from the server and send information to the server, thereby ensuring the data interaction process during the upgrade process and improving the upgrade efficiency.
[0014] In a possible implementation manner of the first aspect, the selecting, as the target network card, the network card with the data packet detection result indicating successful detection among the at least two network cards includes:
[0015] Determining whether a first network card receives a data packet, wherein the first network card is any one of the at least two network cards;
[0016] When the first network card receives the data packet, determining whether the data packet is a multicast data packet;
[0017] In the case where the data packet is the multicast data packet, determining whether the characteristic field position of the data packet is a characteristic field, wherein the characteristic field is used to indicate that the data packet is an upgrade data packet;
[0018] When the characteristic field position of the data packet is a characteristic field, the first network card is used as the target network card.
[0019] It can be seen that in order to ensure the correctness of the network card, the embodiment of the present application judges the data packet received by the network card through a series of judgment methods. When it is judged that the data packet received by the network card is an upgrade data packet, it means that the network card can receive the correct data packet (i.e., the upgrade data packet). Furthermore, it can be said that when the network card is used as a network card for receiving / sending data packets, the correct data packet (i.e., the upgrade data packet) can be received, thereby ensuring the data interaction process during the upgrade process and improving the upgrade efficiency.
[0020] In a possible implementation of the first aspect, obtaining one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards includes:
[0021] In a case where the data packet detection result in the at least two network cards is a detection failure, an Internet packet explorer ping request is sent to the server through the second network card to determine the server address detection result of the second network card, where the second network card is any one of the at least two network cards; wherein, in a case where the second network card receives a ping response to the ping request, the server address detection result of the second network card is that the second network card is connected to the address of the server; in a case where the second network card does not receive a ping response to the ping request, the server address detection result of the second network card is that the second network card is not connected to the address of the server.
[0022] In an embodiment of the present application, when the physical status of at least two network cards of the network device indicates that the network cards are both in a connected state, and the data packet detection results of at least two network cards of the network device indicate that the detection has failed, it is reasonable to suspect whether the server has not yet started sending data packets. At this time, in order to ensure that the correct data packet can be received by the target network card when the server sends the data packet, the server address detection result can be obtained by first detecting the server address, and then the target network card can be determined based on the server address detection result, or the target network card needs to be reselected based on the server address detection result. The target network card serves as the network card for receiving / sending data packets, and then the packet receiving and sending interface during the upgrade process can be selected from multiple dimensions to improve the upgrade efficiency.
[0023] In a possible implementation of the first aspect, determining the target network card from the at least two network cards according to one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards includes:
[0024] When the data packet detection results in the at least two network cards are detection failures, the network card among the at least two network cards whose server detection result is that the network card is connected to the address of the server is used as the target network card.
[0025] It can be understood that, when the physical status of at least two network cards of the network device indicates that both network cards are in a connected state and each network card has not received the upgrade data packet, if one of the network cards can be connected to the server's address, it means that when the server sends the upgrade data packet, the network card can correctly receive the upgrade data packet. Therefore, using this network card as the target network card can ensure that in the subsequent upgrade process, the network card can receive data packets from the server and send information to the server, thereby ensuring the data interaction process during the upgrade process and improving the upgrade efficiency.
[0026] In a possible implementation of the first aspect, the ping request carries a first message header and a destination address, and the step of using, as the target network card, a network card among the at least two network cards that has a server detection result indicating that the network card is connected to the server address, includes:
[0027] If the second message header parsed from the data received by the second network card is consistent with the message type of the first message header, and the source address of the data received by the second network card is consistent with the target address, the second network card is used as the target network card, wherein the second network card is any one of the at least two network cards, and the data received by the second network card is a ping response to the ping request.
[0028] It can be seen that in order to ensure the correctness of the network card, the embodiment of the present application uses a series of judgment methods to determine whether the network card has established a connection with the server address. When it is determined that the network card ping is successful, it can be said that when the network card is used as a network card for receiving / sending data packets, the correct data packet (i.e., upgrade data packet) can be received, thereby ensuring the data interaction process during the upgrade process and improving the upgrade efficiency.
[0029] In a second aspect, an embodiment of the present application provides a network device, comprising: one or more processors; a memory; and a communication interface; wherein the communication interface is configured to receive signals / data from a server and transmit them to the memory, and the communication interface is further configured to send signals / data from the processor or the memory to the server;
[0030] The memory is coupled to the one or more processors, and the memory is used to store computer program code, wherein the computer program code includes computer instructions, and the one or more processors call the computer instructions to enable the electronic device to execute the software upgrade method described in the first aspect or any possible implementation of the first aspect.
[0031] In a third aspect, the present application provides a chip or chip system, comprising at least one processor and a communication interface, wherein the communication interface and the at least one processor are interconnected via a line, and the at least one processor is configured to execute a computer program or instruction to perform the software upgrade method described in the first aspect or any possible implementation of the first aspect. The communication interface in the chip may be an input / output interface, a pin, or a circuit.
[0032] In one possible implementation, the chip or chip system described above in the embodiments of the present application further includes at least one memory, in which instructions are stored. The memory may be a storage unit within the chip, such as a register, a cache, etc., or a storage unit of the chip (e.g., a read-only memory, a random access memory, etc.).
[0033] In a fourth aspect, an embodiment of the present application provides a computer storage medium, which stores a computer program. When the computer program is executed by a processor, the computer executes the software upgrade method described in the first aspect or any possible implementation of the first aspect.
[0034] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when running on a communication device, enables the communication device to execute the software upgrade method described in the first aspect or any possible implementation of the first aspect.
[0035] It should be understood that the description of technical features, technical solutions, beneficial effects or similar language in this application does not imply that all features and advantages can be realized in any single embodiment. On the contrary, it is understood that the description of a feature or beneficial effect means that a specific technical feature, technical solution or beneficial effect is included in at least one embodiment. Therefore, the description of a technical feature, technical solution or beneficial effect in this specification does not necessarily refer to the same embodiment. Furthermore, the technical features, technical solutions and beneficial effects described in the present embodiment can also be combined in any appropriate manner. Those skilled in the art will understand that the embodiment can be implemented without one or more specific technical features, technical solutions or beneficial effects of a specific embodiment. In other embodiments, additional technical features and beneficial effects can also be identified in specific embodiments that do not embody all embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The following is an introduction to the drawings used in the embodiments of this application.
[0037] Figure 1A This is a schematic diagram of the architecture of a network device provided in an embodiment of the present application;
[0038] Figure 1B This is a schematic diagram of a process flow of a network device forwarding a data packet provided by an embodiment of the present application;
[0039] Figure 2 This is a schematic diagram of an interactive process of a software upgrade method provided in an embodiment of the present application;
[0040] Figure 3 This is a flow chart of setting a target network card provided by an embodiment of the present application;
[0041] Figure 4 This is a schematic diagram of a process for determining a target network card provided by an embodiment of the present application;
[0042] Figure 5 This is a schematic diagram of a process for determining a target network card from a first network card and a second network card provided by the present application;
[0043] Figure 6 This is a flow chart of detecting a physical state provided by an embodiment of the present application;
[0044] Figure 7 This is a schematic diagram of a process for detecting an upgrade data packet provided by an embodiment of the present application;
[0045] Figure 8 This is a flow chart of detecting a server address provided by an embodiment of the present application;
[0046] Figure 9 This is a hardware structure diagram of a network device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0047] The terms used in the following examples of the present application are for the purpose of describing specific embodiments only and are not intended to limit the present application. As used in the specification and appended claims of the present application, the singular expressions "a," "an," "said," "above," "the," and "this" are intended to include plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used in the present application refers to and encompasses any or all possible combinations of one or more of the listed items.
[0048] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood to imply or suggest relative importance or implicitly indicate the number of the technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of this application, unless otherwise specified, "plurality" means two or more.
[0049] First, some terms used in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.
[0050] The network devices involved in the embodiments of the present application may be devices for connecting and managing data transmission between different networks, such as routers. Routers are used to connect two or more networks, process data packets received from a receiving interface, and forward them to an appropriate sending interface.
[0051] The server involved in the embodiment of the present application can be a server for providing cloud computing services, that is, a server that provides corresponding resources to network devices. For example, the resources provided by the server to the network device can be an upgrade data packet, which is used to upgrade the routing software of the network device.
[0052] The operating system (OS) involved in the embodiments of the present application is the most basic system software running on the server. For example, the operating system can be a Windows operating system, a Linux operating system, or a VMware operating system, etc., without limitation.
[0053] The logical name involved in the embodiments of the present application is the name given to each network card of the network device by the operating system according to the preset naming rules after it is recognized by the operating system through the driver and corresponding software processing. For example, in the WMware operating system, the logical name of each network card is in the vmnic* format, such as vmnic0 or vmnic1; in the Windows operating system, the logical name of each network card is in the Ethernet* format, such as Ethernet0 or Ethernet1; in the Linux operating system, the logical name of each network card is in the eth* format, such as eth0 or eth1. It should be noted that the same network card of the same network device has different logical names in different operating systems, and the same network card has different logical names in different releases of the same operating system. Examples are not given here one by one. Logical names are generally sorted by standard protocols (such as the system management basic input and output system (SMBIOS)) or physical information of the network card (such as peripheral component interconnect bus (PCI Bus) information).
[0054] U-Boot, as described in the embodiments of this application, is an open-source embedded boot loader used in various network devices and embedded systems. It can boot the operating system or firmware and provide basic hardware abstraction layer functionality. For example, flashing U-Boot on a router can perform a variety of operations, including restoring factory settings, updating firmware, and updating software.
[0055] Among them, for external devices, "network card" can also be called "physical network port"; for internal systems, "network card" can be called "interface".
[0056] The following is an introduction to the network equipment involved in this application.
[0057] See Figure 1A , Figure 1A This is a schematic diagram of the architecture of a network device provided in an embodiment of the present application. Figure 1A It can be seen that the network device 100 includes a network card 110 and a switch structure 120. It is understandable that Figure 1A The structure of the network device shown does not constitute a limitation on the network device. The network device provided in the embodiment of the present application may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0058] The network card 110 is used to realize the physical connection between other physical devices. The network card 110 has at least one physical network port and at least one virtual network port. Figure 1A In the embodiment, the network card 110 includes at least a first network card 111 and a second network card 112. The first network card 111 corresponds to a first network port 113, and the second network card 112 corresponds to a second network port 114. The at least one network port is connected to the communication interface of other devices via a cable to enable data transmission between the network device 100 and other devices. Optionally, the network card 110 can be integrated onboard or inserted through a high-speed serial computer expansion bus standard (Peripheral Component Interconnect Express, PCIE) slot or PCI slot in the network device 100, without limitation herein.
[0059] In one implementation, the first network card 111 is a physical layer (PHY) chip that can support multiple rates, including 1 Gigabit per second (Gbps), 2.5G, 5G, and 10G multi-rate Ethernet. The second network card 112 is a switch, which is a multi-port network bridging device used to implement port storage and directional forwarding. Each network card of the network device 100 has a unique logical name (for example, the logical name of the first network card 111 is eth0, and the logical name of the second network card 112 is eth1) and network port information such as a media access control (MAC) address in the system of the network device 100 (for example, a Linux system).
[0060] The switching fabric 120 is used to forward data packets received from an input port to the next-hop network from an output port of the router according to the destination address of the data packet. The switching fabric 120 includes a protocol stack 121 and a packet switching engine (PSE) 122. The protocol stack 121 stores a routing table and a Layer 2 forwarding database (FDB). For example, the routing table, also known as the Routing Information Base (RIB), is primarily used to store path information for the network device 100, including path information to a specific network address. Each route entry in the routing table typically includes one or more of the following information: the destination network address, subnet mask, next-hop Internet Protocol (IP) address, output port, and routing priority. The FDB table primarily records the mapping between physical addresses or hardware addresses (e.g., MAC addresses) and ports. For example, the stored information may include one or more of the following: the MAC address, port number, and some flag fields. The FDB table can be statically configured or dynamically learned. The PSE is a data fast forwarding module, which can achieve the purpose of fast forwarding of data packets without passing through the protocol stack 121 by learning the forwarding process of the protocol stack 121 .
[0061] For example, after the data packet is transmitted from the network card 110 to the protocol stack 121 or the data packet switching engine 122, the forwarding path is searched according to the routing table and the FDB table, and then the data packet is sent to the corresponding eth device (for example, eth1), and the driver packet sending function of the eth device is called to send it to the corresponding network card (for example, the second network card 112), and then sent out of the route through the second network card 112.
[0062] See Figure 1B , Figure 1B This is a flow chart of a network device forwarding a data packet provided by an embodiment of the present application. Generally speaking, after a device under a bridge (e.g., a first network card) receives a data packet, it is generally processed by a Layer 2 bridge (i.e., the second layer data link layer) and then, based on the protocol stack (e.g., FBD), decides whether to send the packet to the host or forward it directly to another interface.
[0063] Take the example of a network device forwarding data packets. Figure 1BAs shown in the receiving end on the left side, the first network card is the default network card of the system, so the network device 100 receives the first data packet through the first network card, that is, the first data packet is transmitted to the network device 100 via the first network card. Among them, the driver packet receiving function of the first network card passes the first data packet to the entry of the protocol stack (for example, netif_receive_skb_core). At this time, the first data packet is received by the bridge. The bridge checks the FDB table entry and determines that the device corresponding to the destination address of the first data packet is the first network card or the second network card. Because the target device sent by the first network card or the second network card is not a local device, it is determined that the first data packet is forwarded to other devices. Then the first data packet enters the br_forward forwarding process. When the first data packet reaches hard_start_xmit, the packet sending function ndo_start_xmit of the corresponding device will be called to send it to the corresponding interface. Table 1 is an example of an FDB table entry.
[0064] Table 1 FDB table entries
[0065]
[0066] As can be seen from Table 1, by querying the destination MAC address and the corresponding FDB table entry in the first data packet, we can know whether the corresponding interface is eth0 (i.e., the first network card) or eth1 (i.e., the second network card). Then, when sending the packet, we select the packet sending function of the corresponding device and send the data to the corresponding network card.
[0067] Take the data packets sent out by network devices as an example, Figure 1B As shown in the sending end on the right side of the figure, after the network device completes the encapsulation of the local data packet, it determines that the transport layer protocol of the local data packet is the User Datagram Protocol (UDP), searches for the route in the routing table of the network protocol stack of the network layer, and determines the interface for sending the local data packet based on the destination IP address of the local data packet. As shown in the routing table in Table 2, the destination address of the local data packet is data in the 192.168.3.x network segment. After searching the routing table, it is sent to Interfacebr0 for processing. Among them, br0 is the local bridge, a virtual network device. After the local data packet arrives at the bridge, it actually still goes through the Layer 2 forwarding process, searches for the local FDB table entry, sends it from br0 to the corresponding eth device, and then calls the packet sending function of the eth device to send the data to the physical network card.
[0068] Table 2 Routing table
[0069]
[0070]
[0071] comprehensive Figure 1A and Figure 1B As can be seen, the network device 100 relies on the protocol stack 121 or packet switching engine 122 in the switching fabric 120 to forward / send data packets. These protocol stack 121 and packet switching engine 122 can only be used after the network device 100 boots the kernel. When upgrading the network device 100 in the U-Boot stage, if the network device 100 includes at least two network cards, since the kernel is not booted in the U-Boot stage, the forwarding path cannot be found through the processing flow in the switching fabric 120, and therefore data packets cannot be sent to the corresponding network card. Upgrading in the U-Boot stage can only be done by configuring one of the at least two network cards as the data transceiver, thereby performing the version upgrade using this card to send and receive data. However, if a problem occurs with this configured network card, the upgrade cannot be performed via U-Boot, significantly impacting development and production efficiency and making daily debugging inefficient and inefficient.
[0072] In addition, the network card that is detected in a connected state for the first time can be used as the transceiver interface. However, during actual use or development, when at least two network cards are connected by mistake, the network card that is detected in a connected state for the first time may not be the network card that needs to be upgraded. Therefore, if this network card is used as the transceiver interface, the upgrade service may not be possible.
[0073] Based on this, the present application provides a software upgrade method, which is applied to a network device, wherein the network device includes at least two network cards. After the network device is powered on, kernel startup is interrupted, so that the network device is in a U-Boot state. In the U-Boot state, the network device selects the network card that sends and receives data during the upgrade process based on one or more of the physical state of the network card, the data packet detection result, and the server address detection result. The data packet detection result is used to indicate whether the network card has received an upgrade data packet from the server, and the server address detection result is used to indicate whether the network card is connected to the server.
[0074] Exemplarily, when the physical states corresponding to at least two network cards are used to respectively indicate that the at least two network cards are in a connected state, the network device determines a target network card from the at least two network cards based on one or more of the data packet detection results and the server address detection results corresponding to the at least two network cards, wherein the target network card is used to perform software upgrades by receiving and sending data packets.
[0075] In one implementation, the network card that can receive the upgrade data packet among the at least two network cards is used as the target network card.
[0076] In one implementation, the network card that establishes a connection with the upgrade server among the at least two network cards is used as the target network card.
[0077] Therefore, when a network device has at least two network cards, in U-Boot mode, the interface for sending and receiving packets during the upgrade process can be selected based on three criteria: physical status, whether the upgrade packet has been received, and whether the upgrade packet is connected to the server address. This allows for greater flexibility in adapting to different scenarios. During the upgrade process, if the default network card fails and cannot send or receive packets, another interface can be selected to send or receive packets, ensuring the upgrade is complete and improving upgrade efficiency. This prevents upgrade failures due to network cards not being connected as configured.
[0078] See Figure 2 , Figure 2 This is a schematic diagram of an interactive process of a software upgrade method provided in an embodiment of the present application, which includes but is not limited to the following steps:
[0079] For example, in Figure 2 In the interaction flow shown, the server's address is 192.168.1.111, and the network device's address is 192.168.1.1. In one implementation, the server, acting as a multicast source, sends a multicast packet to multicast group 224.0.0.199. The address 192.168.1.1 belongs to multicast group 224.0.0.199. Therefore, upon receiving the multicast packet, the network device triggers the multicast processing flow.
[0080] S1. Set the target network card in the network device.
[0081] The network device includes at least two network cards. In the Uboot state, the network device needs to determine a target network card from at least two network cards as the default network card (eth_current), so that data packets can be received and sent through the target network card. For a detailed description of "Network device setting target network card", please refer to the following Figure 3 The content will not be repeated here.
[0082] S2. The network device monitors the data packets through the target network card.
[0083] Specifically, after powering on the network device, it is interrupted during the U-Boot phase and enters the U-Boot state. In the U-Boot state, the network device maintains a state machine that monitors whether data packets are received through the configured target network card. It is understood that the server sends data packets in the form of a data stream.
[0084] S3. The network device sends local information to the server.
[0085] Specifically, after receiving the first data packet through the target network card, after entering an intermediate state in the initialization process (for example, the UPG_STATE_INIT state), after determining that the data packet is a valid multicast data packet, the network device can send the local MAC address and barcode to the server.
[0086] In one implementation, after receiving the first multicast packet, the network device can parse the MAC address of the multicast packet and use the least significant bit of the first byte of the MAC address to distinguish whether the source address of the multicast packet is a unicast address or a multicast address. If the MAC address begins with 01, the received packet is determined to be a valid multicast packet; if the MAC address does not begin with 01, the received packet is determined to be an invalid multicast packet.
[0087] In another implementation, the data packet is a UDP data packet. The UDP message field in the data packet is parsed to determine whether the characteristic field position is a characteristic field. If it is a characteristic field, the received data packet is determined to be a valid multicast data packet; if it is not a characteristic field, the received data packet is determined to be not a valid multicast data packet. The characteristic field is a field pre-set by the network device when it leaves the factory. For example, the 20th byte of the UDP message field can be pre-configured as the characteristic field position.
[0088] S4. The server saves the local information.
[0089] Specifically, after receiving the MAC address and barcode sent from the network device, the server can save the information.
[0090] S5. The network device saves the multicast data packet.
[0091] Specifically, the server sends a data packet to the network device in the form of a UDP data stream. When the network device determines that the data packet received through the target network card is a valid multicast data packet, the network device can save the received data stream, which includes one or more multicast data packets.
[0092] S6. The network device parses the multicast data packet to determine if the version check passes.
[0093] Specifically, after the network device stores the received multicast stream, it can parse and verify the version of the multicast stream. After the version verification passes, step S7 can be executed.
[0094] S7. The network device sends an upgrade request to the server.
[0095] Specifically, after the version verification passes, the network device sends an upgrade request to the server.
[0096] S8. The server determines whether to allow the upgrade based on the upgrade request.
[0097] Specifically, after receiving the upgrade request, the server checks whether the upgrade request is legal, for example, whether the MAC address and barcode carried in the upgrade request have been recorded on the server side. If the record exists on the server side, the verification is successful and step S9 is executed.
[0098] S9. The server sends an upgrade permission instruction to the network device.
[0099] S10. The network device receives the upgrade permission instruction through the target network card, and determines that the upgrade is possible by parsing the upgrade permission message.
[0100] Specifically, in step S1, the target network card is configured as an interface for sending and receiving. Therefore, the network device can receive the upgrade permission instruction from the server through the target network card and analyze whether the MAC address and barcode carried in the upgrade permission instruction are the same as those of the local device. If they are the same, it means that the upgrade permission instruction is sent to the network device, and then execute S11.
[0101] S11. The network device is upgraded by writing an upgrade data packet into storage.
[0102] Specifically, when the network device determines that the received data packet is an upgrade data packet, it starts to erase the flash memory to perform software upgrade of the network device, such as software upgrade of the network card, system upgrade, etc.
[0103] S12. The network device sends an upgrade success message to the server.
[0104] Specifically, after the network device upgrade is completed, an upgrade success message is sent to the server.
[0105] S13. The server records a successful upgrade message.
[0106] Specifically, after receiving the upgrade success message, the server records the upgrade success message of the network device.
[0107] S14. The server sends a recording success message to the network device.
[0108] Specifically, after the server completes recording, it returns a recording success message to the network device.
[0109] S15. The network device prompts that the upgrade is complete.
[0110] Specifically, after the network device receives the record success message returned by the server, it completes the verification based on the MAC address and barcode carried in the record success message, ends the upgrade process, and turns on the green light to indicate that the upgrade is successful.
[0111] It should be noted that this application describes the data packet as a User Datagram Protocol (UDP) data packet as an example, but this application does not impose any restrictions on the protocol of the data packet. The protocol of the data packet can also be a Transmission Control Protocol (TCP) and the like.
[0112] See Figure 3 , Figure 3 This is a flow chart of setting a target network card provided by an embodiment of the present application, which includes but is not limited to the following steps:
[0113] Step S301: The network device executes U-Boot.
[0114] Among them, U-Boot is an open source boot loader, which is mainly used to boot the operating system kernel and provide some basic hardware initialization and configuration functions.
[0115] Specifically, after the network device is powered on, U-Boot is started, and a series of hardware initialization operations are performed through U-Boot. After completing hardware initialization, the network device starts the main function (main function), which is the main program of U-Boot. Furthermore, the network device can use the main function to complete one or more operations such as system memory, stack, global structure, and peripheral initialization, and then enter the loop processing flow atp_main_loop. The loop processing flow, also known as the main loop, is mainly used to process incoming data packets and poll the network interface to maintain activity. In the main loop, the program first calls the do_receive() function to receive data packets, and then calls the do_poll() function to keep the network driver active.
[0116] In summary, the U-Boot state of a network device is a key step in the embedded system's boot process. It is used to load and initialize hardware devices and prepare for the booting of the operating system kernel. The U-Boot state of a network device mainly includes the following stages: In the first stage of U-Boot, hardware device initialization is performed; in the second stage of U-Boot, U-Boot initializes the network interface and configures the IP address and other network parameters; in the third stage of U-Boot, U-Boot loads the operating system kernel image, environment variables, and other system service-related content from the storage medium. Finally, after the network device completes U-Boot, it can boot the operating system kernel.
[0117] Step S302: The network device determines whether a key event is detected.
[0118] Specifically, the network device listens for key events in the main loop. These key events are used to interrupt the network device from booting the operating system kernel, placing the network device in the U-Boot state. That is, if the network device detects a key event while executing U-Boot, the network device can interrupt U-Boot execution, placing the network device in the U-Boot state. Because the network device has not completed U-Boot, it cannot boot the operating system kernel, thus placing the network device in the U-Boot state.
[0119] Exemplarily, the key event includes but is not limited to: pressing the ctrl key or the HI key. If the network device detects the key event, the network device is in the U-Boot state and executes step S303; if the network device does not detect the key event, the network device enters the system boot node to start the system kernel.
[0120] Step S303: In the U-Boot state, determine the target network card from the at least two network cards by judging one or more of the physical states, data packet detection results, and server address detection results corresponding to the at least two network cards.
[0121] It is understandable that the network device includes at least two network cards, and a network card is pre-configured for sending and receiving data. However, when the network card fails, the network device cannot switch to other network cards to send and receive data packets in the U-Boot state, so it may cause the upgrade to fail. Therefore, in the present application, the network device determines the target network card from at least two network cards in the U-Boot state by judging one or more of the physical states, data packet detection results, and server address detection results corresponding to the at least two network cards. The target network card may be a pre-configured network card or may not be a pre-configured network card. This ensures that in the event of a failure of the pre-configured network card, data packets can be received and sent through other network cards.
[0122] Exemplarily, the network device includes a decision module, which can be used to determine the target network card from at least two network cards by judging one or more of the physical states, data packet detection results and server address detection results corresponding to the at least two network cards respectively.
[0123] For a detailed description of step S303, please refer to the following Figure 4 The content shown will not be repeated here.
[0124] S304. Configure the target network card as an interface for sending data packets and an interface for receiving data packets.
[0125] Specifically, for the upper layer, the packet receiving and sending interface is represented by a global variable, eth_current. This global variable can be configured as the target network card, meaning that the current packet receiving and sending interface uses the target network card. The network device then uses the packet receiving interface (NetLoop) to set the driver's processing function upon receiving the packet based on the parameters passed in. In one implementation, if the parameter passed in is MULTI_UPGRADE, the driver enters the atp_multicast_start multicast program entry point. If the parameter passed in the NetLoop is PING, the data received by the driver is processed by the PING service program, ping_start. After the driver is configured, the network device sets the packet receiving and sending interface to the multicast program processing interface. When receiving packets through the NetLoop loop, it calls a function (such as atpMcastUpgradeHandler) to enter the multicast upgrade process, configure the multicast program's packet sending interface to the target network card, and send the packet through the target network card. The network device then configures the interface for sending and receiving packets to the target network card and assigns the global variable eth_current to the value corresponding to the target network card (for example, eth0). Therefore, the upper-layer multicast program can call the send function and recv function of eth_current to direct the send function and recv function of the target network card.
[0126] Therefore, the multicast upgrade data packet sent by the server can complete the upgrade service through the sending interface (Transmit, TX) and receiving interface (Receive, RX) of the configured target network card driver to send and receive data, complete the image download, message interaction and other processes.
[0127] Figure 4 : This is a schematic diagram of a process for determining a target network card provided by an embodiment of the present application, which process includes but is not limited to the following steps:
[0128] S401. In the U-Boot state, obtain the physical states corresponding to at least two network cards.
[0129] The network device includes multiple network cards, each corresponding to a network card. Specifically, if the network card is connected to the communication interface of the other device via a cable, the physical state of the network card is connected; if the communication interface of the network card is not connected to the other device via a cable, the physical state of the network card is disconnected.
[0130] In one implementation, in the U-Boot state, the network device may obtain the physical state of each network card by reading a register of each network card.
[0131] In one implementation, during the network device initialization process, if one of the at least two network cards is in a connected state and the other network cards are in a disconnected state, the connected network card is used as the target network card, and the global variable eth_current can be configured as the target network card.
[0132] S402. When the physical states corresponding to the at least two network cards are connected, obtain one or more of the data packet detection results and the server address detection results corresponding to the at least two network cards.
[0133] The packet detection result indicates whether the network card has received the upgrade packet from the server. "Whether the upgrade packet has been received from the server" indicates whether the network card is connected to the server. If the network card can receive the upgrade packet from the server, it indicates that the network card is connected to the server. If the network card does not receive the upgrade packet from the server, it indicates that the network card is not connected to the server. The server address detection result indicates the address connection status between the network card and the server. The address connection status includes whether the network card is connected to the server address.
[0134] Specifically, if the physical statuses of at least two network cards in the network device indicate that both network cards are connected, this simply means that the network card is connected to the communication interface of the other device via a cable. Not all network cards corresponding to each network card may require an upgrade. Therefore, the network card corresponding to the network card that actually requires an upgrade must be selected from the at least two network cards as the network card for receiving / sending data packets. Therefore, the network device can obtain one or more of the data packet detection results and the server address detection results corresponding to each network card, and then proceed to step S403.
[0135] In one implementation, in the U-Boot state, the network device detects whether it can receive the upgrade data packet through any one of the at least two network cards (for example, the first network card), thereby determining the data packet detection result of any one of the at least two network cards. If one of the at least two network cards (for example, the first network card) detects the upgrade data packet, it means that the data packet detection result corresponding to the network card is a detection success; if one of the at least two network cards (for example, the first network card) does not detect the upgrade data packet, it means that the data packet detection result of the network card is a detection failure. Exemplarily, the data packet detection result corresponding to each network in the network device can be obtained by "detecting the upgrade data packet".
[0136] In one implementation, if the data packet detection result corresponding to each network card of the network device is that no upgrade data packet is detected, it means that each network card of the network device has failed to detect, which means that the server may not have started sending the upgrade data packet. The network device can detect the network connection status of the server to obtain the server address detection result.
[0137] Exemplarily, the network device can determine the server address detection result of the network card by sending an Internet Packet Groper (Ping) request to the server through any one of the at least two network cards (for example, the second network card). Ping is a program used to confirm whether a host (for example, a server) on the Internet is reachable. It detects whether the network of the target host (for example, the server in this application) is online by sending a data packet to a specified IP address or host name and waiting for an echo response. If one of the at least two network cards (for example, the second network card) receives a Ping response to the Ping request, the server address detection result corresponding to the network card is that the network card is connected to the server address; if one of the at least two network cards (for example, the second network card) does not receive a Ping response to the Ping request, the server address detection result corresponding to the network card is that the network card is not connected to the server address.
[0138] S403: Determine a target network card from the at least two network cards according to one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards.
[0139] In one implementation, if one of the at least two network cards detects the update packet, the packet detection result for that network card is successful. Therefore, the network device can select that network card as the target network card and configure the global variable eth_current to be that network card. The update packet has the following characteristics: it is a multicast packet and carries a characteristic field.
[0140] Exemplarily, taking the first network card of the at least two network cards as an example, the network device determines whether the first network card receives a data packet. If the data packet is not received, it indicates that the first network card is not the target network card.
[0141] When the first network interface card receives a data packet, it determines whether the data packet is a multicast data packet. If it is not a multicast data packet, it indicates that the first network interface card is not the target network interface card. The least significant bit of the MAC address of the data packet is used to distinguish between unicast addresses and multicast addresses. The destination MAC address of a multicast message begins with 01. For example, the first 6 bits of the data packet represent the destination MAC address. If the first bit of the MAC address of the data packet begins with 01, it indicates that the destination MAC address of the data packet is a multicast address.
[0142] If the packet is determined to be a multicast packet, the packet's signature field is determined to be a signature field. If not, the first network interface card is not the target network interface card. The signature field indicates that the packet is an upgrade packet and is pre-set when the network device leaves the factory. For example, the 20th byte of the message field can be pre-configured as the signature field.
[0143] When it is determined that the characteristic field position of the data packet is a characteristic field, the first network card is used as the target network card.
[0144] In one implementation, if at least two network cards fail to detect the upgrade data packet, it indicates that the data packet detection result of the network card is a detection failure. Therefore, the network device needs to use the network card connected to the server address in the server address detection results of the at least two network cards as the target network card.
[0145] For example, taking the second network card of at least two network cards as an example, a ping request sent by the network device through the second network card carries a first message header and a destination address. If the second message header obtained by parsing the data received by the second network card is consistent with the message type of the first message header, and the source address of the data received by the second network card is consistent with the destination address, the second network card is used as the target network card, wherein the data received by the second network card is a ping response to the ping request. If the second message header obtained by parsing the data received by the second network card is inconsistent with the message type of the first message header, or the source address of the data received by the second network card is inconsistent with the destination address, it indicates that the second network card is not the target network card.
[0146] Next, we take a network device including a first network card and a second network card as an example to explain how the network device determines the target network card for receiving / sending data packets from the first network card and the second network card. The first network card is a switch network card, and the second network card is a 2.5GPHY network card. Figure 5 , Figure 5 This is a schematic diagram of a process for determining a target network card from a first network card and a second network card provided by the present application. The process includes but is not limited to the following steps:
[0147] S501. Detect whether the first network card and the second network card are connected.
[0148] Specifically, the network device first obtains the physical status of the first network card and the second network card, and determines whether the first network card and the second network card are connected based on their respective physical status. In one implementation, the network device can obtain the actual connection status of the physical network cards (such as the first network card and the second network card) by reading the values in the relevant registers, thereby determining whether the first network card and the second network card are connected.
[0149] For example, assume that the first network card is a Switch network card and the second network card is a 2.5GPHY network card. Figure 6 , Figure 6 This is a flow chart of detecting a physical state provided by an embodiment of the present application. Figure 6 As shown, the register address corresponding to the first network card is GSW_PHYADDR, and the register address corresponding to the second network card is AN8811H_PHYADDR. The network device obtains the status register of the first network card by reading the register address GSW_PHYADDR, and obtains the status register of the second network card by reading the register address AN8811H_PHYADDR. For example, the status register of the first network card (value1) = MiiStationRead (GSW_PHYADDR, PHY_STATUS_REG), and the status register of the second network card (value2 = MiiStationRead (AN8811H_PHYADDR, PHY_STATUS_REG). Then The network device obtains a first register value from the status register of the first network card, and obtains a second register value from the status register of the second network card. For example, value1 & = first register value (BIT_PHY_LINK_STATUS), value2 & = second register value (BIT_PHY_LINK_STATUS), where BIT_PHY_LINK_STATUS is bit 2. Finally, the network device determines whether the first register value (i.e., bit 2) is 1, and determines whether the second register value (i.e., bit 2) is 1. If the first register value (i.e., bit 2) is 1, it indicates that the first network card is in a connected state (link up); otherwise, the first network card is in a disconnected state (link down). If the second register value (i.e., bit 2) is 1, it indicates that the second network card is in a connected state (link up); otherwise, the second network card is in a disconnected state (link down).
[0150] Exemplarily, it is assumed that the first network card is the default interface pre-configured for the network device, that is, after the network device is powered on and U-Boot is loaded, the default global variable eth_current is configured to the first network card. In one implementation, the network device first detects the physical state of the first network card, and then detects the physical state of the second network card. When it is detected that the first network card is in a connected state and the second network card is in an unconnected state, the current configuration (i.e., the pre-set configuration) is maintained, that is, the first network card is used as the network card for receiving / sending data packets; when it is detected that the first network card is in an unconnected state and the second network card is in a connected state, the configuration of the second network card is switched to, that is, the global variable eth_current is configured to the second network card, that is, the second network card is used as the network card for receiving / sending data packets.
[0151] Exemplarily, when it is detected that the first network card and the second network card are connected, step S502 is executed.
[0152] S502: Detect whether the first network card can receive the upgrade data packet.
[0153] Specifically, when both the first network card and the second network card are in a connected state, the network device needs to detect the upgrade data packet through the network card. It is understandable that because the first network card is a pre-configured default network card, that is, the global variable eth_current is configured as the first network card, in order to improve the detection efficiency, it is possible to first detect whether the first network card can receive the upgrade data packet. If the network card driver of the current network device is selected correctly and the server is sending a data packet, if the multicast data packet sent by the server can be correctly received through the first network card, and the multicast data packet carries a characteristic field, indicating that the first network card can receive the upgrade data packet, then the first network card can be used as the network card for receiving / sending data packets. Among them, the characteristic field can be a pre-set field used to indicate that the data packet is an upgrade data packet.
[0154] See Figure 7 , Figure 7 This is a flow chart of a detection upgrade data packet provided by an embodiment of the present application. Figure 7 The left half is the process of the first network card detecting the upgrade data packet. Figure 7As shown, since the first network card is a pre-configured default network card, the network device directly determines whether the first network card can receive the data packet. If the first network card does not receive the data packet, the detection fails, and the first network card cannot be used as a network card for receiving / sending data packets. If the first network card can receive the data packet, it is determined whether the data packet received by the first network card is a multicast packet. Among them, the least significant bit of the MAC address of the data packet is used to distinguish between unicast addresses and multicast addresses, and the destination MAC address of the multicast message starts with 01. For example, the first 6 bits of the data packet represent the destination MAC address. It is determined whether the first bit of the MAC address of the data packet starts with 01, that is, rxPacket[0]==01? If the first bit of the MAC address of the data packet does not start with 01, it means that the detection fails, and the first network card cannot be used as a network card for receiving / sending data packets; if the first bit of the MAC address of the data packet starts with 01, it means that the destination MAC address of the data packet is a multicast address, and the data packet is a multicast data packet. When it is determined that the data packet is a multicast data packet, it is determined whether the data packet contains a characteristic field. For example, assuming that the data packet (rxPacket) uses the UDP protocol, the network device parses the data packet to obtain UDP data (rxUdpData), MAC header (EPKT_EHE_HEAD_LEN), IP header (IP_HEAD_LEN), and UDP header (UDP_HEAD_LEN) offsets, adds the MAC header, IP header, and UDP header to the original data, and points to the UDP data area, that is, rxUdpData = rxPacket + EPKT_EHE_HEAD_LEN + IP_HEAD_LEN + UDP_HEAD_LEN. Among them, the characteristic field is stored at the position offset 20 bits from the UDP data, and then determines whether the data at the position of rxUdpData+20 bits is the same as the characteristic field. If they are not the same, it means that the data packet is not an upgrade data packet and the first network card detection fails; if they are the same, it means that the data packet is an upgrade data packet and the first network detection succeeds, and the first network card is used as the network card for receiving / sending data packets.
[0155] S503: Check whether the second network card can receive the upgrade data packet.
[0156] Specifically, if the first network card fails to detect the upgrade packet, the global variable eth_current is configured to the second network card, allowing the second network card to detect whether it can receive the upgrade packet. If the driver of the current network device is correctly selected and the server is sending data packets, if the second network card can correctly receive the multicast data packet sent by the server, and the multicast data packet carries a characteristic field, it indicates that the second network card can receive the upgrade data packet, and the second network card can be used as the network card for receiving / sending data packets. The characteristic field can be a pre-set field used to indicate that the data packet is an upgrade data packet.
[0157] See Figure 7 , Figure 7 This is a flow chart of a detection upgrade data packet provided by an embodiment of the present application. Figure 7 The right half of the figure shows the process of the second network card detecting the upgrade data packet. Figure 7 As shown, because the second network card is used to detect the upgrade data packet when the first network card fails to detect, it is necessary to first modify the global variable eth_current and configure the global variable eth_current to the second network card. Then the network device determines whether the second network card can receive the data packet. If the second network card does not receive the data packet, the detection fails and the second network card cannot be used as a network card for receiving / sending data packets. If the second network card can receive the data packet, it is determined whether the data packet received by the second network card is a multicast packet. Among them, the least significant bit of the MAC address of the data packet is used to distinguish between unicast addresses and multicast addresses, and the destination MAC address of the multicast message starts with 01. For example, the first 6 bits of the data packet represent the destination MAC address. It is determined whether the first bit of the MAC address of the data packet starts with 01, that is, rxPacket[0]==01? If the first bit of the MAC address of the data packet does not start with 01, it means that the detection failed and the second network card cannot be used as a network card for receiving / sending data packets; if the first bit of the MAC address of the data packet starts with 01, it means that the destination MAC address of the data packet is a multicast address and the data packet is a multicast data packet. When it is determined that the data packet is a multicast data packet, it is determined whether the data packet contains a characteristic field. For example, assuming that the data packet (rxPacket) adopts the UDP protocol, the network device parses the data packet to obtain UDP data (rxUdpData), MAC header (EPKT_EHE_HEAD_LEN), IP header (IP_HEAD_LEN) and UDP header (UDP_HEAD_LEN) and other offsets, adds the MAC header, IP header, and UDP header to the original data, and points to the UDP data area, that is, rxUdpData = rxPacket + EPKT_EHE_HEAD_LEN + IP_HEAD_LEN + UDP_HEAD_LEN. Among them, the characteristic field is stored at the position of 20 bits offset of the UDP data, and then it is determined whether the data at the position of rxUdpData+20 bits is the same as the characteristic field. If they are not the same, it means that the data packet is not an upgrade data packet and the second network card detection fails; if they are the same, it means that the data packet is an upgrade data packet, the first network detection is successful, and the second network card is used as the network card for receiving / sending data packets.
[0158] S504: Detect whether the second network card can receive a ping response to the incoming server ping request.
[0159] Specifically, if neither the first network card nor the second network card receives the upgrade data packet, it is possible that the server has not yet started to send the upgrade data packet. In this case, the connection status with the server address can be detected first.
[0160] It can be understood that in step S504, the switch has been made to the second network card to detect the upgrade data packet. This time, the second network card can continue to try to ping the server address (for example, 192.168.1.111) (for example, a ping request is sent to the server address 192.168.1.111). If the ping is successful, that is, the second network card can receive the ping response of the ping request, then the current configuration is maintained, that is, the global variable eth_current is kept configured as the second network card, and the second network card is used as the network card for receiving / sending data packets; if the ping fails, that is, the second network card does not receive the ping response of the ping request, and step S505 is executed.
[0161] Please refer to Figure 8 , Figure 8 This is a flow chart of detecting a server address provided by an embodiment of the present application. Figure 8 The right half of the figure shows the process of the second network card detecting the upgrade data packet. Figure 8 As shown, the network device configures the global variable eth_current to the second network card, so the driver layer can use the second network card as the data packet receiving and sending interface. Then, the network device generates a ping request, wherein the message header of the ping request is an ICMP message header constructed according to the ICMP message format, and the message type of the ping request is ICMP_ECHO_REQUEST, which is used to indicate that the ping request is an ICMP request message. Next, the network device sets the IP header of the ping request and configures the destination address to the server address (for example, 192.168.1.111). The destination address is used to indicate that the ping request is sent to the server. Finally, the bottom layer of the network device calls the send function of the second interface to send the ping request. After sending the ping request, the network device waits for the pingreply data (i.e., the ping response to the ping request) to be returned through the ping_receive function. If the returned data can be received correctly, the ICMP message header and IP header of the returned data are parsed. If the message type of the ICMP message header is ICMP_ECHO_REPLY and the source address in the IP header is 192.168.1.111, it means that the second network card is connected to the server address and the pingreply data returned by the server is received correctly. This indicates that the second network card detection is successful and the second network card can be used as the network card for receiving / sending data packets; otherwise, it indicates that the second network card detection has failed and step S506 is executed.
[0162] S505: Detect whether the first network card can receive a ping response to the ping request from the server.
[0163] It can be understood that in step S505, the switch has been made to the first network card to detect the upgrade data packet. This time, the switch can be made to the first network card to try to ping the server address (for example, 192.168.1.111) (for example, a ping request is sent to the server address 192.168.1.111). If the ping is successful, that is, the first network card can receive a ping response to the ping request, then the current configuration is maintained, that is, the global variable eth_current is kept configured as the first network card, and the first network card is used as the network card for receiving / sending data packets; if the ping fails, that is, the first network card does not receive a ping response to the ping request, and step S505 is executed.
[0164] Please refer to Figure 8 , Figure 8 This is a flow chart of detecting a server address provided by an embodiment of the present application. Figure 8 The left half is the process of the first network card detecting the upgrade data packet. Figure 8 As shown, the network device configures the global variable eth_current to the first network card, so the driver layer can use the first network card as the data packet receiving and sending interface. Then, the network device generates a ping request, wherein the message header of the ping request is an ICMP message header constructed according to the ICMP message format, and the message type of the ping request is ICMP_ECHO_REQUEST, which is used to indicate that the ping request is an ICMP request message. Next, the network device sets the IP header of the ping request and configures the destination address to the server address (for example, 192.168.1.111). The destination address is used to indicate that the ping request is sent to the server. Finally, the bottom layer of the network device calls the send function of the second interface to send the ping request. After sending the ping request, the network device waits for the pingreply data (i.e., the ping response to the ping request) to return through the ping_receive function. If the returned data can be received correctly, the ICMP header and IP header of the returned data are parsed. If the message type of the ICMP header is ICMP_ECHO_REPLY and the source address in the IP header is 192.168.1.111, it means that the first network card and the server address are connected, and the pingreply data returned by the server is received correctly, which means that the detection of the first network card is successful, and the first network card can be used as the network card for receiving / sending data packets; otherwise, it means that the detection of the first network card has failed, and steps S501-S505 are executed again until the upgrade data packet is detected or the detection times out and exits the detection.
[0165] It should be noted that the embodiment of the present application is described using the "server multicast data packet" method as an example. It can be understood that the embodiment of the present application is not limited to the "server multicast data packet" method, but is also applicable to the "server unicast data packet" method. This application does not impose any restrictions on this.
[0166] Figure 9 Schematic diagram of the hardware structure of the network device provided in the embodiment of this application. Figure 9 As shown, the network device may include at least one processor 901 , a communication bus 902 , a memory 903 and at least one communication interface 904 .
[0167] The processor 901 may be a general-purpose central processing unit (CPU), a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of the program of the present application.
[0168] The communication bus 902 may include a path for transmitting information between the processor 901 , the memory 903 , and the communication interface 904 .
[0169] The communication interface 904 uses any transceiver or other device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), or wireless local area network (WLAN). In this embodiment of the application, the communication interface 904 is mainly used to communicate with other devices and servers.
[0170] The memory 903 may be a read-only memory (ROM) or other static storage device capable of storing static information and instructions, a random access memory (RAM) or other dynamic storage device capable of storing information and instructions, an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, an optical disc storage (including a compact disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and capable of being accessed by a computer, but is not limited thereto. Among them, EEPROM may also be referred to as "flash memory" or non-volatile memory (flash).
[0171] The memory can be independent and connected to the processor via a bus, or it can be integrated with the processor.
[0172] The memory 903 is used to store and execute application code, such as a main program and an upgrade program, and is controlled by the processor 901. The processor 901 is used to execute the application code stored in the memory 903, thereby implementing the software upgrade method in the above embodiment. In this embodiment of the present application, the memory can also be used to store a target directory or target file, which is parsed from an upgrade data packet from a server, and the target directory or target file stores version information of the version software / upgrade package.
[0173] As an embodiment, the processor 901 may include one or more CPUs.
[0174] As an embodiment, the network device may include multiple processors, such as Figure 9 The two processors 901 in FIG. Each processor can be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor.
[0175] As an embodiment, the network device may further include an output device 905 and an input device 906. The output device 905 communicates with the processor 901 and can display information in various ways, such as displaying the interface of the main program and software test results. The output device 905 may be an LCD display device, an LED display device, a cathode ray tube (CRT) display device, or a projector.
[0176] The input device 906 communicates with the processor 901 and can receive user input in various ways, such as receiving input / operation input by a developer or tester to trigger the execution of the main program. The input device 906 can be a mouse, keyboard, touch screen, or sensor device.
[0177] The above-mentioned network device can be a router, and the embodiment of the present application does not limit the specific type of the network device.
[0178] It should be understood that each step in the above method embodiments provided herein can be implemented by hardware integrated logic circuits in a processor or by software instructions. The method steps disclosed in the embodiments of this application can be directly implemented as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.
[0179] The present application also provides a chip system, which includes at least one processor for implementing the functions involved in the method executed by the electronic device in any of the above embodiments.
[0180] In one possible design, the chip system further includes a memory, which is used to store program instructions and data, and the memory is located inside or outside the processor.
[0181] The chip system can be composed of chips, or can include chips and other discrete devices.
[0182] Optionally, there may be one or more processors in the chip system. The processor may be implemented in hardware or software. When implemented in hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented in software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.
[0183] Optionally, the memory in the chip system may be one or more. The memory may be integrated with the processor or may be provided separately from the processor, which is not limited in the embodiments of the present application. For example, the memory may be a non-transient processor, such as a read-only memory (ROM), which may be integrated with the processor on the same chip or provided on different chips. The embodiments of the present application do not specifically limit the type of memory or the configuration of the memory and the processor.
[0184] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.
[0185] The present application also provides a computer program product, which includes: a computer program (also referred to as code, or instruction), which, when executed, enables a computer to execute the method executed by the electronic device in any of the above embodiments.
[0186] The present application also provides a computer-readable storage medium storing a computer program (also referred to as code or instruction). When the computer program is executed, the computer executes the method executed by the electronic device in any of the above embodiments.
[0187] The various implementation modes of this application can be combined arbitrarily to achieve different technical effects.
[0188] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described herein are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated therein. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive).
[0189] Those skilled in the art will appreciate that all or part of the process steps in the above-described method embodiments can be implemented by a computer program instructing the relevant hardware. The program can be stored in a computer-readable storage medium, and when executed, the program can include the process steps in the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
[0190] In short, the above description is only an embodiment of the technical solution of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent replacements, improvements, etc. made based on the disclosure of the present invention should be included in the scope of protection of the present invention.
Claims
1. A software upgrade method, characterized in that: Applied to a network device, the network device includes at least two network cards, and the method includes: In the U-Boot state, obtaining the physical states corresponding to the at least two network cards respectively; When the physical states respectively corresponding to the at least two network cards are in a connected state, obtaining one or more of a data packet detection result and a server address detection result respectively corresponding to the at least two network cards, wherein the data packet detection result is used to indicate whether the network card has received an upgrade data packet from the server, and the server address detection result is used to indicate a connection state between the network card and the address of the server; A target network card is determined from the at least two network cards according to one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards, wherein the target network card is used to communicate with the server to perform software upgrade on the network device.
2. The method according to claim 1, characterized in that The obtaining one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards includes: The first network card detects whether the upgrade data packet can be received by detecting the first network card to determine the data packet detection result of the first network card, where the first network card is any one of the at least two network cards; wherein, if the upgrade data packet is detected, the data packet detection result of the first network card is a detection success; if the upgrade data packet is not detected, the data packet detection result to the first network card is a detection failure.
3. The method according to claim 2, characterized in that The determining the target network card from the at least two network cards according to one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards comprises: The network card with the data packet detection result being successful among the at least two network cards is used as the target network card.
4. The method according to claim 3, characterized in that The step of selecting the network card with the successful detection result of the data packet among the at least two network cards as the target network card includes: Determining whether a first network card receives a data packet, wherein the first network card is any one of the at least two network cards; When the first network card receives the data packet, determining whether the data packet is a multicast data packet; In the case where the data packet is the multicast data packet, determining whether the characteristic field position of the data packet is a characteristic field, wherein the characteristic field is used to indicate that the data packet is an upgrade data packet; When the characteristic field position of the data packet is a characteristic field, the first network card is used as the target network card.
5. The method according to any one of claims 2 to 4, characterized in that The obtaining one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards includes: In a case where the data packet detection result in the at least two network cards is a detection failure, an Internet packet explorer ping request is sent to the server through the second network card to determine the server address detection result of the second network card, where the second network card is any one of the at least two network cards; wherein, in a case where the second network card receives a ping response to the ping request, the server address detection result of the second network card is that the second network card is connected to the address of the server; in a case where the second network card does not receive a ping response to the ping request, the server address detection result of the second network card is that the second network card is not connected to the address of the server.
6. The method according to claim 5, characterized in that The determining the target network card from the at least two network cards according to one or more of the data packet detection results and the server address detection results respectively corresponding to the at least two network cards comprises: When the data packet detection results in the at least two network cards are detection failures, the network card among the at least two network cards whose server detection results show that the network card is connected to the address of the server is used as the target network card.
7. The method according to claim 6, characterized in that The ping request carries a first message header and a destination address, and the step of using a network card among the at least two network cards that is connected to the address of the server as a target network card includes: If the second message header parsed from the data received by the second network card is consistent with the message type of the first message header, and the source address of the data received by the second network card is consistent with the target address, the second network card is used as the target network card, wherein the second network card is any one of the at least two network cards, and the data received by the second network card is a ping response to the ping request.
8. A network device, characterized in that: The network device includes: a processor, a memory, and a communication interface; wherein the communication interface is used to receive a signal from a server and transmit it to the memory, and the communication interface is also used to send a signal from the processor or the memory to the server; The memory is used to store computer program codes, where the computer program codes include computer instructions. The processor calls the computer instructions to enable the network device to execute the method according to any one of claims 1 to 7.
9. A chip system, characterized in that: The chip system is applied to an electronic device, and the chip system includes one or more processors, and the processor is used to call computer instructions to enable the electronic device to execute the method as described in any one of claims 1 to 7.
10. A computer program product comprising instructions, characterized in that When the computer program product is run on an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 7.
11. A computer-readable storage medium comprising instructions, characterized in that: When the instructions are executed on an electronic device, the electronic device is caused to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Soft routing performance test method
CN104954205A
Software automatic upgrading method
CN107291520A
A rapid switching method and device for redundant double network cards
CN109831341A
Network card performance test method and device based on USB network card and electronic device
CN112653600A
Batch upgrading method and system, electronic equipment and medium
CN117478576A