Communication method and device

By performing master device election and DHCP server backoff mechanisms in the LAN, the problem of IP address conflict in the multi-gateway LAN is solved, and automatic networking and zero configuration start are realized.

CN120499155AActive Publication Date: 2025-08-15NEW H3C TECH CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202510779773.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-11
Publication Date
2025-08-15
Estimated Expiration
2045-06-11

AI Technical Summary

Technical Problem

In the case where multiple gateways exist in the LAN, network devices may not be able to automatically start up due to IP address conflicts or different network segments, resulting in low start efficiency and high operation and maintenance difficulties.

Method used

By performing the master device election in the LAN, the network device determines itself as the master device or slave device, and the master device enables the DHCP client function to detect whether there is a DHCP server. If it exists, turn off the DHCP server function to avoid repeated allocation of IP addresses; the slave device closes the DHCP server function to ensure that only one device provides DHCP services.

Benefits of technology

It realizes automatic networking of multi-gateway LAN startup, avoids IP address conflicts, and users can complete automatic networking of network devices without configuration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120499155A_ABST
    Figure CN120499155A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a communication method and device, and relates to the technical field of networks, and the method comprises the steps: first network equipment and other network equipment except the first network equipment in a local area network carry out main equipment election; if the first network device is elected as a main device, the first network device is configured with a DHCP server function, and a DHCP server backoff function is started, the first network device detects other DHCP servers; after other DHCP servers are detected, the dynamic IP addresses distributed by the other DHCP servers take effect, and the DHCP server function is closed; and if the other network devices are elected as slave devices, the other network devices are configured with the DHCP server function, and the DHCP server backoff function is started, the DHCP server function is closed, and the DHCP server backoff function is closed. According to the scheme, automatic networking during startup under the condition of multiple gateways can be realized, and zero-configuration opening of a user can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of network technology, and in particular to a communication method and device. Background Art

[0002] With the rapid development of digital transformation, networks in large, medium, and small scenarios—such as campus networks, villas and guesthouses, retail chains, and corporate offices—are facing challenges such as low deployment efficiency, difficult operations and maintenance, and complex management. To address these challenges, major network equipment providers have launched solutions that enable rapid local deployment and management, such as automatic network configuration at startup.

[0003] The core highlight of the automatic startup networking solution is that network devices automatically form a network after being connected and powered on. Users can access the management device through a personal computer (PC) or mobile phone, directly enter the startup page, and achieve rapid startup. The basis for the implementation of automatic startup networking is: the management virtual local area network (VLAN) of the network device is the same, the network segment of the Internet Protocol (IP) address is the same, and there are no IP address conflicts. Within the local area network (LAN), the gateway acts as the Dynamic Host Configuration Protocol (DHCP) server, and other network devices act as DHCP clients. The DHCP server assigns IP addresses to DHCP clients, ensuring that the network devices in the LAN obtain legal IP addresses after startup, join the Layer 2 management network, complete automatic networking, and support rapid startup.

[0004] However, the networking type of a LAN is determined by the user based on their own needs. This means that the LAN may include multiple network devices with gateway functions (i.e., multiple gateways). These multiple gateways simultaneously assign IP addresses to other network devices. The network segments of the address pools included in these multiple gateways may be the same or different. If the network segments of the address pools are the same, the IP addresses applied for by the network devices will conflict. If the network segments of the address pools are different, the IP addresses applied for by the network devices will be in different network segments. This makes it impossible for the network devices in the LAN to automatically form a network when they are powered on. Summary of the Invention

[0005] The purpose of the embodiments of the present application is to provide a communication method and apparatus to achieve automatic network formation upon startup in the case of multiple gateways, and zero-configuration deployment by the user. The specific technical solution is as follows:

[0006] In a first aspect, an embodiment of the present application provides a communication method, applied to a first network device in a local area network, the method comprising:

[0007] Conducting master device election with other network devices in the local area network except the first network device;

[0008] If the first network device is elected as the master device, and the first network device has been configured with a DHCP server function and has a DHCP server backoff function enabled, the DHCP client function is enabled and a first DHCP request message is sent; if the other network device is elected as the slave device, and the other network device has been configured with a DHCP server function and has a DHCP server backoff function enabled, the DHCP server function is disabled and the DHCP server backoff function is disabled;

[0009] If a first DHCP response message corresponding to the first DHCP request message is received, the first dynamic IP address carried in the first DHCP response message is validated, and the DHCP server function is disabled.

[0010] In some embodiments, the method further comprises:

[0011] If the first DHCP response message is not received, the static IP address configured in the first network device is valid, and the DHCP server function is enabled.

[0012] In some embodiments, after enabling the DHCP server function, the method further includes:

[0013] Resend the first DHCP request message.

[0014] In some embodiments, the method further comprises:

[0015] If the first network device is elected as the master device, and the first network device has been configured with a DHCP server function, and the DHCP server backoff function is not enabled, the static IP address configured in the first network device is valid, and the DHCP server function is enabled.

[0016] In some embodiments, after validating the first dynamic IP address carried in the first DHCP response message and disabling the DHCP server function, the method further includes:

[0017] When the aging timer corresponding to the first dynamic IP address times out, deleting the first dynamic IP address;

[0018] The static IP address configured in the first network device is enabled, and the DHCP server function is enabled.

[0019] In some embodiments, the method further comprises:

[0020] If the first network device is elected as a slave device, and the first network device has been configured with the DHCP server function and the DHCP server backoff function is enabled, the DHCP server function is disabled and the DHCP server backoff function is disabled. If the other network device is elected as a master device and the other network device has been configured with the DHCP server function and the DHCP server backoff function is enabled, the DHCP client function is enabled and a second DHCP request message is sent.

[0021] In some embodiments, the method further comprises:

[0022] If the first network device is elected as the master device, periodically broadcasting a first scanning message;

[0023] If the first network device is elected as a slave device, it periodically receives the second scanning message sent by the second network device, and the second network device is the master device in the local area network; if the second scanning message is not received within the first preset time period, the step of electing the master device with other network devices in the local area network except the first network device is re-executed.

[0024] In some embodiments, the method further comprises:

[0025] If the first network device is elected as the master device and receives the third scanning message sent by the third network device, then when the priority of the third network device is higher than the priority of the first network device, the first network device is switched to a slave device, and the third network device is a newly added master device in the local area network. The priority of the third network device is determined according to the information carried by the third scanning message.

[0026] In some embodiments, performing master device election with other network devices in the local area network except the first network device includes:

[0027] Periodically broadcast the first election message;

[0028] receiving, within a second preset time period, a target message sent by the other network device, where the target message is the second election message or the second scanning message;

[0029] If the priority of the other network device is higher than the priority of the first network device, the first network device is determined to be a slave device, and the priority of the other network device is determined according to the information carried by the target message;

[0030] If the priority of the other network device is lower than the priority of the first network device, the first network device is determined to be the master device.

[0031] In a second aspect, an embodiment of the present application provides a communication device, applied to a first network device in a local area network, the device comprising:

[0032] an election unit, configured to perform master device election with other network devices in the local area network except the first network device;

[0033] The control unit is configured to, if the first network device is elected as a master device and the first network device has been configured with a DHCP server function and a DHCP server backoff function is enabled, enable a DHCP client function and send a first DHCP request message; and, if the other network devices are elected as slave devices and the other network devices have been configured with a DHCP server function and a DHCP server backoff function is enabled, disable the DHCP server function and disable the DHCP server backoff function; and if a first DHCP response message corresponding to the first DHCP request message is received, validate a first dynamic IP address carried in the first DHCP response message and disable the DHCP server function.

[0034] In some embodiments, the control unit is further configured to, if the first DHCP response message is not received, validate the static IP address configured in the first network device and enable the DHCP server function.

[0035] In some embodiments, the control unit is further configured to resend the first DHCP request message after enabling the DHCP server function.

[0036] In some embodiments, the control unit is further used to, if the first network device is elected as the main device, and the first network device has been configured with a DHCP server function and the DHCP server backoff function is not enabled, then the static IP address configured in the first network device will take effect and the DHCP server function will be enabled.

[0037] In some embodiments, the control unit is further used to, after validating the first dynamic IP address carried in the first DHCP response message and turning off the DHCP server function, delete the first dynamic IP address when the aging timer corresponding to the first dynamic IP address times out; validate the static IP address configured in the first network device, and turn on the DHCP server function.

[0038] In some embodiments, the control unit is further configured to, if the first network device is elected as a slave device and the first network device has been configured with the DHCP server function and the DHCP server backoff function is enabled, turn off the DHCP server function and turn off the DHCP server backoff function; the other network devices are elected as master devices and the other network devices have been configured with the DHCP server function and the DHCP server backoff function is enabled, turn on the DHCP client function and send a second DHCP request message.

[0039] In some embodiments, the control unit is also used to periodically broadcast a first scanning message if the first network device is elected as a master device; if the first network device is elected as a slave device, periodically receive a second scanning message sent by a second network device, which is the master device in the local area network; if the second scanning message is not received within a first preset time period, re-execute the step of electing a master device with other network devices in the local area network except the first network device.

[0040] In some embodiments, the control unit is also used to switch the first network device to a slave device if the first network device is elected as a master device and receives a third scanning message sent by a third network device, when the priority of the third network device is higher than the priority of the first network device. The third network device is a newly added master device in the local area network, and the priority of the third network device is determined according to the information carried by the third scanning message.

[0041] In some embodiments, the election unit is specifically configured to:

[0042] Periodically broadcast a first election message; within a second preset time period, receive a target message sent by the other network device, where the target message is a second election message or the second scanning message; if the priority of the other network device is higher than that of the first network device, determine that the first network device is a slave device, and the priority of the other network device is determined according to the information carried by the target message; if the priority of the other network device is lower than that of the first network device, determine that the first network device is a master device.

[0043] In a third aspect, an embodiment of the present application provides a network device comprising a processor and a machine-readable storage medium, wherein the machine-readable storage medium stores machine-executable instructions that can be executed by the processor, and the processor is prompted by the machine-executable instructions to implement any method provided in the first aspect.

[0044] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any one of the methods provided in the first aspect is implemented.

[0045] In a fifth aspect, an embodiment of the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any one of the methods provided in the first aspect.

[0046] Beneficial effects of the embodiments of the present application:

[0047] In the technical solution provided by the embodiment of the present application, a master device election is performed between network devices in a local area network, and each network device determines whether it is a master device or a slave device. For a network device, if the network device is a slave device, and the network device has been configured with a DHCP server function and has turned on the DHCP server backoff function, then the network device turns off the DHCP server function and turns off the DHCP server backoff function. The network device does not perform the DHCP server function, that is, it is not responsible for allocating IP addresses to DHCP clients, and the network device does not need to back off from other DHCP servers in the local area network. If the network device is a master device, and the network device has been configured with a DHCP server function and has turned on the DHCP server backoff function, then the network device turns on the DHCP client function to detect whether there is a DHCP server in the local area network. When it is detected that there is a DHCP server in the local area network, if a first DHCP response message corresponding to a first DHCP request message is received, the DHCP server function is turned off, and it is not responsible for allocating IP addresses to DHCP clients, thereby backing off from other DHCP servers in the local area network.

[0048] In the embodiment of the present application, the network devices in the local area network use the DHCP server fallback function to achieve a situation where there are multiple gateways, and only one device in the local area network provides the DHCP server function, thereby avoiding the problem that the network devices in the local area network apply for IP addresses with different network segments or IP address conflicts, and realizing automatic networking at startup in the case of multiple gateways, and user-zero configuration start.

[0049] Of course, it is not necessary to achieve all of the above advantages at the same time when implementing any product or method of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other embodiments can also be obtained based on these drawings.

[0051] Figure 1 This is the first schematic diagram of LAN networking;

[0052] Figure 2 The second schematic diagram for LAN networking;

[0053] Figure 3 This is the third schematic diagram for LAN networking;

[0054] Figure 4 This is the fourth schematic diagram for LAN networking;

[0055] Figure 5 A first flow chart of the communication method provided in an embodiment of the present application;

[0056] Figure 6 A schematic diagram of a standard Ethernet message provided in an embodiment of the present application;

[0057] Figure 7 A second flow chart of the communication method provided in an embodiment of the present application;

[0058] Figure 8 A third flow chart of the communication method provided in an embodiment of the present application;

[0059] Figure 9 A schematic diagram of a first flow chart of a message processing method provided in an embodiment of the present application;

[0060] Figure 10 A second flow chart of the message processing method provided in an embodiment of the present application;

[0061] Figure 11 A flowchart of a master device election method provided in an embodiment of the present application;

[0062] Figure 12 A schematic diagram of the DHCP server backoff system architecture provided in an embodiment of the present application;

[0063] Figure 13 A schematic diagram of a state machine provided in an embodiment of the present application;

[0064] Figure 14 A schematic diagram of the DHCP server automatic backoff mechanism provided in an embodiment of the present application;

[0065] Figure 15 A schematic diagram of the structure of a communication device provided in an embodiment of the present application;

[0066] Figure 16 A schematic diagram of the structure of a network device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0067] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field based on this application are within the scope of protection of this application.

[0068] Zero Touch Provisioning (ZTP): An automated deployment technology for network devices that allows newly shipped or blank-configured network devices to automatically retrieve and load required configuration files, system software, and patches upon power-up, completing initial configuration and connecting to the network without manual intervention.

[0069] DHCP server candidate: referred to as "candidate." Candidates include network devices with factory-configured DHCP server functionality, such as ACs and firewalls. Candidates support the DHCP server backoff function.

[0070] DHCP server non-candidates: referred to as "non-candidates." Non-candidates include network devices such as routers, third-party routers, access points (APs), cameras, PCs, access switches, and core switches. Routers and third-party routers are default gateways and are factory-configured as DHCP servers. DHCP server fallback is not performed. Network devices such as APs, cameras, PCs, access switches, and core switches are factory-configured as DHCP clients and do not require DHCP server fallback.

[0071] The network type of LAN is determined by the user according to his / her own needs for building LAN. The current network types of LAN can be found in Figures 1 to 4 As shown, Figures 1 to 4 The LAN shown includes network devices such as access points (APs), cameras, PCs, access switches, core switches, firewalls, routers, and access controllers (ACs). The default management VLAN for these devices is VLAN 1. The factory configuration sets the IP address of the VLAN 1 virtual interface. The configuration includes two modes: DHCP dynamic allocation (DHCP alloc) + DHCP server mode and static IP address + DHCP server mode. Figures 1 to 3 In the example, all network devices are from the same manufacturer. Figure 4 In the network, AP, camera, PC, access switch, core switch, firewall and AC are all from the same manufacturer. Figure 4 The third-party routers mentioned in the preceding figure are devices from other manufacturers. Devices from different manufacturers cannot be directly managed locally.

[0072] Network devices such as firewalls, routers, and ACs have gateway capabilities. Their factory configuration sets the VLAN1 interface to a static IP address and binds it to the DHCP server configuration. The DHCP address pools of these devices may differ or conflict. Network devices such as APs, cameras, PCs, access switches, and core switches also set their VLAN1 interface to DHCP dynamic allocation and bind it to the DHCP client configuration.

[0073] In a LAN with routers, firewalls, AC, etc., after the network devices are connected and started, there will be a DHCP server conflict problem. The dynamic IP addresses of the network devices in the LAN are not allocated by the same DHCP server, which leads to problems such as IP addresses not being in the same network segment or IP address conflicts, which in turn causes the failure of automatic networking.

[0074] To solve the above problems, the present invention provides a communication method. Figure 5 As shown, the method is applied to a first network device in a local area network, and includes the following steps:

[0075] Step S501, performing master device election with other network devices in the local area network except the first network device;

[0076] Step S502: If the first network device is elected as the master device, and the first network device has been configured with the DHCP server function and has enabled the DHCP server backoff function, then the DHCP client function is enabled and a first DHCP request message is sent. If the other network devices are elected as slave devices, and the other network devices have been configured with the DHCP server function and have enabled the DHCP server backoff function, then the other network devices disable the DHCP server function and the DHCP server backoff function.

[0077] Step S503: If a first DHCP response message corresponding to the first DHCP request message is received, the first dynamic IP address carried in the first DHCP response message is validated, and the DHCP server function is disabled.

[0078] In the technical solution provided by the embodiment of the present application, a master device election is performed between network devices in a local area network, and each network device determines whether it is a master device or a slave device. For a network device, if the network device is a slave device, and the network device has been configured with a DHCP server function and has turned on the DHCP server backoff function, then the network device turns off the DHCP server function and turns off the DHCP server backoff function. The network device does not perform the DHCP server function, that is, it is not responsible for allocating IP addresses to DHCP clients, and the network device does not need to back off from other DHCP servers in the local area network. If the network device is a master device, and the network device has been configured with a DHCP server function and has turned on the DHCP server backoff function, then the network device turns on the DHCP client function to detect whether there is a DHCP server in the local area network. When it is detected that there is a DHCP server in the local area network, if a first DHCP response message corresponding to a first DHCP request message is received, the DHCP server function is turned off, and it is not responsible for allocating IP addresses to DHCP clients, thereby backing off from other DHCP servers in the local area network.

[0079] In the embodiment of the present application, the network devices in the local area network use the DHCP server fallback function to achieve a situation where there are multiple gateways, and only one device in the local area network provides the DHCP server function, thereby avoiding the problem that the network devices in the local area network apply for IP addresses with different network segments or IP address conflicts, and realizing automatic networking at startup in the case of multiple gateways, and user-zero configuration start.

[0080] In the embodiment of the present application, the first network device can be any network device in an undeployed local area network, such as an AP, a camera, a PC, an access switch, a core switch, a firewall, an AC, or a router. A local area network may include one or more network devices. That is, when the local area network includes the first network device, other network devices may also be included, such as a second network device, a third network device, etc.

[0081] In step S501, the first network device interacts with other network devices in the local area network to implement master device election, that is, to determine the master and slave devices in the local area network. In a layer 2 local area network, there is only one master device, and all network devices except the master device are slave devices.

[0082] In the embodiment of the present application, after the first network device is powered on and initialized, it enters the election state and conducts master device election with other network devices in the local area network to obtain the status of the first network device. The status of the first network device is a master device or a slave device. Here, after initialization is completed, the network devices that perform the master device election belong to network devices of the same manufacturer, that is, devices with the same initial communication protocol. Third-party devices (such as the third-party router mentioned above) cannot participate in the master device election because they cannot use the same initial communication protocol as the first network device.

[0083] For example, after each network device in a domain network is powered on and initialized, it periodically broadcasts an election message within a fixed time period. The election message carries key information such as the network device's bridge Media Access Control (MAC) address, device type, device priority, capabilities, project key, and device serial number. Each network device determines the priority of other network devices and its own priority based on the key information of other network devices carried in the received election message, as well as its own key information. If the priority of other network devices is higher than its own priority, it determines itself as a slave device. If the priorities of other network devices are all lower than its own priority, it determines itself as a master device.

[0084] The key information that network devices use to determine the priority of other network devices can be determined based on actual needs. For example, network devices can be prioritized based on device type. Specifically, the priority of various types of network devices is ranked from high to low as follows: AP, camera, PC, access switch, core switch, firewall, AC, router.

[0085] The frequency of periodic broadcasting election messages can be sent once every 5 seconds, for a total of 20 times, that is, the fixed time is 100 seconds after the power is turned on. The election message can use the protocol stack of the standard Ethernet message. In this case, the structure of the election message is as follows Figure 6 As shown, it includes fields such as preamble, destination address, source address, type, data and frame check sequence (FCS). Among them, the length of the preamble field is 8 bytes, the length of the destination address and source address fields is 4 bytes, the length of the type field is 2 bytes, the length of the data field is variable, ranging from 46 bytes to 1500 bytes, and the length of the FCS field is 4 bytes.

[0086] In this embodiment of the present application, the value carried by the type field can be fixed to a preset value, such as 0xabb0, which indicates that the subsequent message is a message for the DHCP server backoff process, such as an election message. The value carried by the data field is key information about the network device, which can be stored in the data field in a type-length-value (TLV) format.

[0087] After determining that the first network device is the master device (ie, the first network device is elected as the master device), the first network device executes step S502.

[0088] In step S502 above, the DHCP server function is the ability to assign IP addresses to DHCP clients. The DHCP server backoff function is the ability to backoff to other DHCP servers in the LAN, that is, the ability to disable its own DHCP server function when there are other DHCP servers (standalone DHCP servers or high-priority devices with DHCP server functions) in the LAN.

[0089] When the first network device is elected as the main device, it means that the first network device may need to act as a DHCP server to assign IP addresses to DHCP clients, and because it itself may need to act as a DHCP server, it needs to back off from other DHCP servers. In this case, if the first network device has been configured with a DHCP server function (such as the factory-configured DHCP server function), and the first network device has enabled the DHCP server backoff function, such as the above-mentioned firewall, AC, etc., then the first network device will enable the DHCP client function, and then the first network device will act as a DHCP client and execute step S502, and may periodically broadcast or multicast DHCP request messages (such as the first DHCP request message) to detect whether there are other DHCP servers in the local area network. The frequency of periodically sending DHCP request messages can be set according to actual needs. For example, the frequency of periodically sending DHCP request messages can be once every 5 seconds, once every 10 seconds, etc.

[0090] If there are other DHCP servers in the local area network (such as a third-party router, or a network device with a higher priority than the first network device), after receiving the first DHCP request message, the other DHCP servers send a DHCP response message (such as a first DHCP response message) corresponding to the first DHCP request message to the first network device. The first DHCP response message carries the first dynamic IP address allocated by the other DHCP server to the first network device.

[0091] If the first network device receives the first DHCP response message, that is, the first network device detects that there are other DHCP servers in the local area network, the first network device executes step S503, takes into account the first dynamic IP address carried in the first DHCP response message, and disables the DHCP server function. That is, the first network device does not need to act as a DHCP server to assign IP addresses to DHCP clients; instead, the detected other DHCP servers assign IP addresses to DHCP clients.

[0092] If the first network device does not receive the first DHCP response message, that is, if the first network device detects that there is no other DHCP server in the local area network, the first network device can validate the static IP address configured in the first network device and enable the DHCP server function. In this way, the first network device can act as a DHCP server and assign IP addresses to DHCP clients in the local area network.

[0093] When the first network device is elected as the master device, the other network devices are elected as slave devices, which means that the other network devices do not need to act as DHCP servers to allocate IP addresses to DHCP clients, and since they do not need to act as DHCP servers themselves, they do not need to back off from other DHCP servers. In this case, if the other network devices have configured the DHCP server function and the other network devices have turned on the DHCP server backoff function, such as the above-mentioned firewall, AC, etc., then the other network devices will execute the DHCP server function shutdown and turn off the DHCP server backoff function. Subsequently, the slave device can take effect on the static IP address configured in the slave device, or turn on the DHCP client function and send a DHCP request message; after receiving the DHCP response message corresponding to the DHCP request message, the dynamic IP address carried in the DHCP response message will take effect.

[0094] In the embodiment of the present application, when the DHCP server fallback function is turned on for network devices in the local area network, even if multiple network devices are configured with the DHCP server function, that is, there are multiple gateways in the local area network, there will only be one device in the local area network that acts as a DHCP server to allocate IP addresses to DHCP clients in the local area network, thereby solving the DHCP server conflict problem. The dynamic IP addresses of network devices in the local area network are all allocated by the same DHCP server, realizing automatic networking at startup in the case of multiple gateways, and user-zero configuration start.

[0095] In some embodiments, when the first network device is a master device and the first network device has been configured with a DHCP server function and a DHCP server backoff function is enabled, if the first network device detects that there are no other DHCP servers in the local area network, that is, the first network device has not received the first DHCP response message, then the first network device can continue to periodically send the first DHCP request message as a DHCP client while taking into account the static IP address configured in the first network device and enabling the DHCP server function, that is, continue to detect whether there are other DHCP servers in the local area network.

[0096] If it detects that there are other DHCP servers in the LAN, that is, if it receives the first DHCP response message, the first dynamic IP address carried in the first DHCP response message will be activated and the DHCP server function will be disabled. If it detects that there are no other DHCP servers in the LAN, the DHCP server function will remain enabled. This can effectively avoid DHCP server conflicts caused by newly added DHCP servers in the LAN.

[0097] When the first network device is the master device, it means that the first network device may need to act as a DHCP server to assign IP addresses to DHCP clients, and because it itself may need to act as a DHCP server, it needs to back off from other DHCP servers. In this case, if the first network device has been configured with a DHCP server function, and the first network device has not enabled the DHCP server backoff function, such as the router mentioned above that belongs to the same manufacturer as other network devices, then the first network device may not back off from other DHCP servers, and the static IP address configured in the first network device may take effect, and the DHCP server function may be enabled, that is, the first network device itself may be used as a DHCP server. In an embodiment of the present application, in a scenario where routers from the same manufacturer exist, the router may be elected as a master device or a slave device.

[0098] The present application embodiment provides a communication method, such as Figure 7 As shown, the method is applied to a first network device in a local area network, and may include the following steps:

[0099] Step S701, performing master device election with other network devices in the local area network except the first network device;

[0100] Step S702: If the first network device is elected as the master device, and the first network device has been configured with the DHCP server function and has enabled the DHCP server backoff function, then the DHCP client function is enabled and a first DHCP request message is sent. If the other network devices are elected as slave devices, and the other network devices have been configured with the DHCP server function and have enabled the DHCP server backoff function, then the other network devices are disabled from the DHCP server function and the DHCP server backoff function.

[0101] Step S703: If a first DHCP response message corresponding to the first DHCP request message is received, the first dynamic IP address carried in the first DHCP response message is validated, and the DHCP server function is disabled;

[0102] The above steps S701 to S703 are the same as the above steps S501 to S503.

[0103] In step S704, if the first network device is elected as a slave device and the first network device has been configured with a DHCP server function and has enabled a DHCP server backoff function, the DHCP server function is disabled and the DHCP server backoff function is disabled. If the other network device is elected as a master device and the other network device has been configured with a DHCP server function and has enabled a DHCP server backoff function, the other network device enables a DHCP client function and sends a second DHCP request message.

[0104] When the first network device is elected as a slave device, it means that the first network device does not need to act as a DHCP server to allocate IP addresses to DHCP clients, and since it does not need to act as a DHCP server itself, it does not need to back off from other DHCP servers. In this case, if the first network device has been configured with a DHCP server function, and the first network device has enabled the DHCP server back-off function, such as the above-mentioned firewall, AC, etc., then the first network device executes step S704, turns off the DHCP server function, and turns off the DHCP server back-off function. Subsequently, the first network device can validate the static IP address configured in the slave device, or it can enable the DHCP client function and send a DHCP request message; after receiving the DHCP response message corresponding to the DHCP request message, the dynamic IP address carried in the DHCP response message is validated.

[0105] When a first network device is elected as a slave device, if it has been configured with DHCP client functionality, such as the aforementioned AP, camera, PC, access switch, or core switch, it does not act as a DHCP server and thus conflict with other DHCP servers. Therefore, the first network device does not need to perform other processing operations. Subsequently, the first network device can send a DHCP request message; if it receives a DHCP response message corresponding to the DHCP request message, the dynamic IP address carried in the DHCP response message will be activated.

[0106] When the first network device is elected as a slave device, if the first network device has been configured with a DHCP server function but the first network device has not enabled the DHCP server backoff function, that is, the first network device does not support the DHCP server backoff function, the first network device may not perform other processing operations and end the DHCP server backoff processing flow; the first network device may also output a prompt message to notify the user that there is a risk of DHCP server conflict, so as to enable or install the DHCP server backoff function in time to resolve the DHCP server conflict problem.

[0107] In some embodiments, as Figure 8 As shown, a communication method is also provided, which is applied to a first network device in a local area network. The method may include the following steps:

[0108] Step S801, performing master device election with other network devices in the local area network except the first network device;

[0109] In step S802, if the first network device is elected as the master device, and the first network device has been configured with the DHCP server function and the DHCP server backoff function is enabled, the DHCP client function is enabled and a first DHCP request message is sent; wherein, other network devices, when other network devices are elected as slave devices, and the other network devices have been configured with the DHCP server function and the DHCP server backoff function is enabled, disable the DHCP server function and the DHCP server backoff function.

[0110] Step S803: If a first DHCP response message corresponding to the first DHCP request message is received, the first dynamic IP address carried in the first DHCP response message is validated, and the DHCP server function is disabled.

[0111] The above steps S801 to S803 are the same as the above steps S501 to S503 and are not described again here.

[0112] Step S804: when the aging timer corresponding to the first dynamic IP address times out, the first dynamic IP address is deleted;

[0113] Step S805: The static IP address configured in the first network device is validated, and the DHCP server function is enabled.

[0114] In an embodiment of the present application, each dynamic IP address is configured with a corresponding aging timer, and the duration of the aging timer can be set according to actual needs. For example, the duration of the aging timer can be 5 seconds, 10 seconds, etc.

[0115] After the first network device validates the first dynamic IP address and disables the DHCP server function, it starts an aging timer corresponding to the first dynamic IP address. When the aging timer expires, the first network device ages out the first dynamic IP address. Simultaneously, the static IP address configured in the first network device is validated and the DHCP server function is enabled. This prevents other DHCP servers in the local area network from going offline, preventing the first network device from being able to join the local area network, and preventing new network devices from being unable to obtain IP addresses.

[0116] When the static IP address configured on the first network device is activated and the DHCP server function is enabled, the first network device can continue to act as a DHCP client, periodically sending the first DHCP request message, that is, continuing to detect whether there are other DHCP servers in the LAN. If other DHCP servers are detected in the LAN, that is, receiving the first DHCP response message, the first dynamic IP address carried in the first DHCP response message is activated and the DHCP server function is disabled. If no other DHCP servers are detected in the LAN, the DHCP server function remains enabled. This can effectively avoid DHCP server conflicts caused by newly added DHCP servers in the LAN.

[0117] In some embodiments, in order to ensure that there is only one master device in the local area network and implement the above-mentioned DHCP server backoff function, the embodiment of the present application also provides a message processing method, such as Figure 9 As shown, the method is applied to a first network device in a local area network, and may include the following steps:

[0118] Step S901 , performing master device election with other network devices in the local area network except the first network device; the same as the above step S501 .

[0119] Step S902: If the first network device is elected as the master device, it periodically broadcasts a first scanning message;

[0120] In an embodiment of the present application, the first scanning message is a scanning message (scan message) sent by the first network device serving as the master device. The scan message is used to inform other network devices of the key information of the master device in the local area network (i.e., the key information of the first network device) so that other network devices know that there is a master device in the local area network.

[0121] Among them, the scan message can use the protocol stack of the standard Ethernet message. In this case, the structure of the scan message is as follows: Figure 6 In this embodiment of the present application, the value carried by the type field can be fixed to a preset value, such as 0xabb0, which indicates that the subsequent message is a message for the DHCP server backoff process, such as a scan message. The value carried by the data field is key information of the master device, and the key information of the master device can be stored in the data field in TLV format.

[0122] After the first network device is elected as the primary device, Figure 5 While the process of steps S502 to S503 is being performed, the first scanning message may be broadcasted periodically. The frequency of periodically sending the first scanning message may be set according to actual needs, for example, the frequency of periodically sending the first scanning message may be once every 5 seconds, once every 10 seconds, etc.

[0123] In this case, other network devices within the local area network, acting as slave devices, can periodically receive the first scan message sent by the first network device. After receiving the first scan message, the other network devices can record the key information of the master device, i.e., the key information of the first network device, and reply to the master device (i.e., the first network device) with a scan confirmation message (scan_ack message). The scan_ack message can carry the key information of the slave device (i.e., the other network device), thereby implementing Layer 2 discovery of the device.

[0124] Among them, the scan_ack message can use the protocol stack of the standard Ethernet message. In this case, the structure of the scan_ack message is as follows: Figure 6 In the embodiment of the present application, the value carried by the type field can be fixed to a preset value, such as 0xabb0, which indicates that the subsequent message is a message for the DHCP server backoff process, such as a scan_ack message. The value carried by the data field is key information of the slave device, and the key information of the slave device can be stored in the data field in TLV format.

[0125] In step S903, if the first network device is selected as a slave device, it periodically receives a second scanning message sent by the second network device, which is the master device in the local area network; if the second scanning message is not received within the first preset time, step S901 is executed again.

[0126] The second network device can be any other network device in the local area network (LAN) other than the first network device. The second scan message is a scan message sent by the second network device as the master device. The scan message is used to inform other network devices of the key information of the master device in the LAN (i.e., the key information of the second network device), so that the first network device and other network devices are aware of the presence of the master device in the LAN. The first preset duration can be set according to actual needs. For example, the first preset duration can be 1 minute, 2 minutes, or 3 scan message transmission cycles.

[0127] After the second network device is elected as the primary device, Figure 5 While the process of steps S502 to S503 is being performed, the second scanning message may be broadcasted periodically. The frequency of periodically sending the second scanning message may be set according to actual needs, for example, the frequency of periodically sending the second scanning message may be once every 5 seconds, once every 10 seconds, etc.

[0128] In this case, the first network device, acting as a slave device, can periodically receive the second scan message sent by the second network device. After receiving the second scan message, the first network device can record the key information of the master device, i.e., the key information of the second network device, and reply to the master device (i.e., the second network device) with a scan confirmation message (scan_ack message). The scan_ack message can carry the key information of the slave device (i.e., the first network device) to achieve Layer 2 discovery of the device.

[0129] If the second scanning message is not received within the first preset time, it means that the second network device has left the local area network. To ensure that subsequent devices can automatically form a network after joining the local area network, the first network device re-executes step S901 to re-determine the master device in the local area network and implement the DHCP server backoff function.

[0130] In some embodiments, in order to ensure that there is only one master device in the local area network and implement the above-mentioned DHCP server backoff function, the embodiment of the present application also provides a message processing method, such as Figure 10 As shown, the method is applied to a first network device in a local area network, and may include the following steps:

[0131] Step S1001 , performing master device election with other network devices in the local area network except the first network device; the same as the above step S501 .

[0132] In step S1002, if the first network device is elected as the master device and receives the third scanning message sent by the third network device, then when the priority of the third network device is higher than the priority of the first network device, the first network device is switched to a slave device, and the third network device is a newly added master device in the local area network. The priority of the third network device is determined according to the information carried in the third scanning message.

[0133] In the embodiment of the present application, the third network device may be a master device introduced after the merger of two local area networks, or the third network device may be a master device configured by a user, or the first network device and the third network device may determine the master device for a local sub-network within the local area network, etc. The third scan message is a scan message (scan message) sent by the third network device as the master device. The scan message is used to inform other network devices of key information of the master device within the local area network (i.e., key information of the third network device) so that the other network devices are aware of the existence of the master device within the local area network.

[0134] After the first network device receives the third scanning message, it can determine the priority of the third network device according to the key information of the third network device carried in the third scanning message; at the same time, it can determine the priority of the first network device according to the key information of the first network device; and compare the priority of the third network device with the priority of the first network device.

[0135] If the priority of the third network device is higher than that of the first network device, the first network device switches the first network device to a slave device. After being downgraded to a slave device, the first network device may execute step S903 (in this case, the third network device functions as a second network device) and step S704. That is, if the first network device is a slave device and the first network device has been configured with a DHCP server function and has enabled a DHCP server backoff function, the DHCP server function is disabled, and the DHCP server backoff function is disabled.

[0136] If the priority of the third network device is lower than that of the first network device, the first network device maintains the first network device as the primary device. Furthermore, the first network device may continue to execute steps S1002 and S902. Furthermore, if the first network device is the primary device and has been configured with the DHCP server function and has enabled the DHCP server backoff function, the first network device may continue to detect whether there are other DHCP servers in the LAN. Alternatively, if the first network device is the primary device and has been configured with the DHCP server function but has not enabled the DHCP server backoff function, the first network device may not perform any other processing.

[0137] In the embodiment of the present application, if the first network device is a slave device, the first network device may also receive the third scan message sent by the third network device. The first network device determines the priority of the second network device and the priority of the third network device based on the key information carried in the second scan message and the third scan message, and then determines the master device from the second and third network devices, and records the key information of the determined master device.

[0138] In the technical solution provided by the embodiment of the present application, the master device in the local area network sends a scan message by broadcasting, thereby ensuring that there is only one master device in the local area network, thereby realizing the DHCP server backoff function, realizing automatic networking at startup, and user zero configuration start.

[0139] In some embodiments, as Figure 11 As shown, a master device election method is also provided, which is applied to a first network device in a local area network. The method may include the following steps:

[0140] Step S1101: periodically broadcast a first election message;

[0141] In the embodiment of the present application, the first election message is an election message sent by the first network device. After the first network device is powered on and initialized and enters the election state, it periodically broadcasts and sends the first election message.

[0142] After other network devices in the LAN are powered on and initialized and enter the election state, they will also send election messages, such as the second election message.

[0143] Step S1102: receiving a target message sent by other network devices in the local area network within a second preset time period, where the target message is a second election message or a second scanning message;

[0144] In the embodiment of the present application, the second preset duration can be set according to actual needs. For example, the second preset duration can be 3 minutes, 5 minutes, etc. After entering the election state, the first network device can continuously receive the second election message or the second scanning message sent by other network devices within the second preset duration. The second scanning message is a scanning message sent by the second network device that is elected as the master device. The number of other network devices can be one or more, and accordingly, the number of target messages received by the first network device can be one or more.

[0145] Step S1103: If the priority of the other network devices is higher than that of the first network device, the first network device is determined to be a slave device, and the priority of the other network devices is determined according to the information carried in the target message;

[0146] Step S1104: If the priorities of the other network devices are lower than the priority of the first network device, the first network device is determined to be the master device.

[0147] The first network device determines the priority of the other network device based on the key information of the other network device carried in the target message, and compares the priority of the other network device with the priority of the first network device. If any of the other network devices has a higher priority than the first network device, the first network device executes step S1103 to determine that the first network device is a slave device. If the first network device is a slave device, step S704 and step S903 may be executed.

[0148] If the priorities of other network devices are lower than that of the first network device, the first network device executes step S1104 to determine that the first network device is the master device; if the first network device is the master device, step S502 may be executed, as well as step S902 or step S1002.

[0149] In the technical solution provided by the embodiment of the present application, the network devices in the local area network can implement the election of master and slave devices based on the election message and the scan message, so that the network devices newly added to the local area network can participate in the DHCP server backoff scheme, further ensuring the automatic networking when booting up in the case of multiple gateways and the user's zero-configuration start.

[0150] The following combination Figure 12 The DHCP server backoff system architecture shown, Figure 13 The state machine shown, Figure 14 The DHCP server automatic backoff mechanism shown is used to provide a detailed description of the communication method provided in the embodiment of the present application.

[0151] In an embodiment of the present application, to enable mutual discovery and master device election among network devices within a local area network, network devices within the local area network automatically start a role control module 1201 upon power-up. Role control module 1201 may also be referred to as a role control process. Role control module 1201 implements device discovery and master device election by broadcasting and unicasting Layer 2 Ethernet messages (such as the aforementioned election messages, scan messages, and scan confirmation messages) within the local area network. These Layer 2 Ethernet messages can carry key information such as the bridge MAC address, device serial number, priority, capability set, and project key.

[0152] For ease of understanding, the network device running the role control module 1201 is referred to as a network element device. Figures 1 to 4 In addition to the third-party router, the network device that does not run the role control module 1201 is called a third-party device. Figure 4 In the embodiment of the present application, the network element device may include the first network device, the second network device, the third network device, etc.

[0153] The network element device adopts a DHCP server backoff system architecture, including a role control module 1201 and a DHCP module 1202. The role control module 1201 may include a state machine, a private layer 2 message processing submodule, a DHCP event processing submodule, and a DHCP role control submodule.

[0154] The state machine is a finite state machine that allows network element devices to operate in the designed role in the local area network, while supporting adaptive role changes to ensure the stability of the local area network as a whole system: there is only one master device in a two-layer local area network, and all other devices are slave devices. The time from the discovery of the master device conflict to the reaching of the steady state in the local area network does not exceed 5 minutes. In the embodiment of the present application, the state machine can realize Figure 13 The four states shown are the initialization (Init) state, the election (Electing) state, the slave (Slave) state and the master (Manager) state.

[0155] Init state: is the state when the role control module 1201 is started or the state before the role control module 1201 is reset (exited). Specifically, when the network device is powered on, that is, when the role control module 1201 is started, the state machine remains in the Init state.

[0156] Electing state: Indicates that the network element is in the process of electing a master device. After initialization is complete, the state machine transitions to the Electing state.

[0157] Slave status: indicates that the network element device election is completed and the device is elected as a slave device.

[0158] Manager status: indicates that the network element device election is completed and the device is elected as the master device.

[0159] When the state machine is in the Electing state, if the network element device receives an election message or a scan message sent by other network element devices with a higher priority than the network element device itself, the state of the state machine is migrated to the Slave state; if the election message or the scan message sent by other network element devices with a higher priority is received within the specified time (such as the second preset time length), it means that the election has failed, and the state of the state machine is migrated to the Slave state; if the election message or the scan message sent by other network element devices with a higher priority is not received within the specified time (such as the second preset time length), it means that the election is successful, and the state of the state machine is migrated to the Manager state.

[0160] When the state machine is in the Slave state, if no scan message is received within a specified time (such as a first preset time length), it means that the master device is offline or has left, and the state machine transitions to the Electing state.

[0161] When the state machine is in the Manager state, if the network element device receives an election message or a scan message from a network element device with a higher priority than itself, the state machine state transitions to the Slave state.

[0162] When the state machine is in the Electing state, the Slave state, or the Manager state, if the role control module 1201 is reset (exited), the state machine transitions to the Init state.

[0163] The state machine is one of the core elements of the role-based DHCP server automatic backoff mechanism. The state machine runs through the entire life cycle of the network element device system startup, operation, and shutdown.

[0164] The private layer 2 message processing submodule is used to implement the protocol stack of standard Ethernet messages, such as Figure 6 Specifically, Figure 13 As shown, when the state machine is in the Electing state, the private layer 2 message processing submodule periodically broadcasts and sends election messages; when the state machine is in the Manager state, the private layer 2 message processing submodule periodically broadcasts and sends scan messages.

[0165] The DHCP event processing submodule is used to respond to the event of detecting other DHCP servers reported by the DHCP module 1202. It combines the current role, device type and other information to perform event processing, such as calculating the local DHCP role and configuring the DHCP role of the DHCP module 1202. DHCP roles include DHCP server and DHCP client.

[0166] For example, the DHCP module 1202 reports "an event of detecting other DHCP servers"; the network element device is a main device, and the device type is a firewall. The DHCP event processing submodule can calculate the DHCP role of the local device as a DHCP client, and then configure the DHCP role of the DHCP module 1202 as a DHCP client, so that the network element device realizes the DHCP client function.

[0167] For another example, the DHCP module 1202 reports "another DHCP server event is detected"; the network element device is a main device, and the device type is a router. The DHCP event processing submodule can calculate the local DHCP role as a DHCP server, and then configure the DHCP role of the DHCP module 1202 as a DHCP server, so that the network element device can realize the DHCP server function.

[0168] The DHCP role control submodule is used to configure and control the role of the DHCP module 1202 and realize the automatic backoff and startup functions of the DHCP server. For example, the DHCP role control submodule configures the role of the DHCP module 1202 according to the calculation results of the DHCP event processing submodule.

[0169] The DHCP module 1202 may include a DHCP server detection submodule, a DHCP function control submodule, a DHCP server submodule, and a DHCP client submodule.

[0170] The DHCP server detection submodule is used to detect whether other DHCP servers exist on the local area network. Specifically, the DHCP server detection submodule can periodically broadcast DHCP request messages and, upon receiving a corresponding DHCP response message, report a "no other DHCP server detected" event to the role control module 1201. If no corresponding DHCP response message is received, the DHCP server detection submodule can report a "no other DHCP server detected" event to the role control module 1201, or it can not report a "no other DHCP server detected" event to the role control module 1201.

[0171] The DHCP function control submodule is used to implement the relevant interfaces for configuring DHCP function parameters, so that the role control module 1201 can set the DHCP role configuration. For example, the DHCP function control submodule receives the DHCP role configuration issued by the role control module 1201, and according to the DHCP role configuration, it pulls up the DHCP client submodule or pulls up the DHCP server submodule.

[0172] The DHCP client submodule is used to implement DHCP client functions, such as validating the dynamic IP address assigned by the DHCP server.

[0173] The DHCP server submodule is used to implement DHCP server functions, such as assigning dynamic IP addresses to DHCP clients.

[0174] Combined with the above Figure 12 and Figure 13 ,right Figure 14 The following describes the automatic backoff mechanism of the DHCP server.

[0175] Step S1401: Determine the start status.

[0176] In the embodiment of the present application, the network element device can be a non-candidate or a candidate. After the network element device is powered on and started, the role control module 1201 of the network element device determines the startup status of the device, that is, determines whether the device is started; if the device is started, step S1402 is executed; if the device is not started, step S1403 is executed.

[0177] Step S1402: disable the DHCP server backoff function.

[0178] In the embodiment of the present application, the role control module 1201 of the network element device turns off the DHCP server backoff function when determining that the network element device has been deployed. In this case, the network element device does not need to perform the DHCP server backoff function.

[0179] Step S1403: role switching.

[0180] In this embodiment of the present application, the role control module 1201 of the network element device can determine the local role by sending election messages and scan messages to implement role switching. After the role switch is implemented, if the network element device is a candidate, when the local role switches to a slave device, the role control module 1201 can execute step S1404; when the local role switches to a master device, the role control module 1201 can execute step S1405. If the network element device is not a candidate, such as a router, switch, or AP, the network element device does not need to perform subsequent processing regardless of whether the local role switches to a slave device or a master device.

[0181] When the state machine is functioning properly, after a 2-3 minute election, there is only one master device in the LAN, and all other devices are slaves. Each network element has a defined role within the specific LAN. In other words, the state machine is functioning properly, ensuring that both the LAN and the device roles (master or slave) are as expected.

[0182] Step S1404: disable the DHCP server backoff function and disable the DHCP server function.

[0183] In the embodiment of the present application, when the role of the local device is switched to a slave device, the role control module 1201 can turn off the DHCP server backoff function; if the DHCP server function of the network element device is turned on, the role control module 1201 can also control the DHCP module 1202 to turn off the DHCP server function.

[0184] Step S1405: Detect other DHCP servers.

[0185] When the local device is in the master role, DHCP module 1202 can activate the DHCP client function and, as a DHCP client, periodically send DHCP request messages to detect whether there are other DHCP servers in the LAN. If other DHCP servers are detected in the LAN, step S1406 is executed; if no other DHCP servers are detected in the LAN, step S1408 is executed.

[0186] In the embodiment of the present application, the DHCP module 1202 supports the function of full-time DHCP server detection.

[0187] Step S1406: Validate the dynamic IP address and disable the DHCP server function.

[0188] When the DHCP module 1202 detects that there are other DHCP servers in the LAN, the DHCP module 1202 acts as a DHCP client and takes into account the dynamic IP addresses allocated by other DHCP servers, and the role control module 1201 turns off the DHCP server function.

[0189] Step S1407: The dynamic IP is aged and the detection is restarted.

[0190] When the aging timer corresponding to the dynamic IP address times out, the DHCP module 1202 ages and deletes the dynamic IP address, and the DHCP module 1202 re-executes step S1405 to detect other DHCP servers.

[0191] In step S1408, the static IP address is validated and the DHCP server function is enabled, and then step S1405 is executed again.

[0192] When the DHCP module 1202 detects that there is no other DHCP server in the LAN, the DHCP module 1202 takes effect on the static IP address of the network element device, and the role control module 1201 turns on the DHCP server function. Subsequently, the network element device can act as a DHCP server to assign IP addresses to DHCP clients.

[0193] After the static IP address is valid and the DHCP server function is enabled, the DHCP module 1202 can continue to enable the DHCP client function, and then act as a DHCP client to periodically send DHCP request messages to detect whether there are other DHCP servers in the LAN.

[0194] above Figure 14 The DHCP server automatic backoff mechanism shown can determine the master device, slave device, and DHCP server in different networking types, as shown in Table 1 below.

[0195] Table 1

[0196]

[0197] In Table 1 above, the third-party gateway may be a third-party router. When accessing the local area network, the third-party gateway may send an authorization request to the manufacturer of the network element device. If authorized, the third-party gateway may participate in the communication method process provided in the embodiment of the present application, such as responding to the first DHCP response message after receiving the first DHCP request message.

[0198] By adopting the technical solution provided in the embodiment of the present application, when there are multiple DHCP servers conflicting in the undeployed network, the network can complete the DHCP server backoff without the intervention of a network engineer, ensuring that there is only one gateway in the network, realizing automatic startup of the network in the case of multiple gateways, and user zero configuration start.

[0199] Corresponding to the above communication method, the embodiment of the present application also provides a communication device, such as Figure 15 As shown, the first network device applied to the local area network includes:

[0200] An election unit 1501 is configured to perform a master device election with other network devices in the local area network except the first network device;

[0201] The control unit 1502 is configured to enable the DHCP client function and send a first DHCP request message if the first network device is elected as the master device, and the first network device has been configured with the DHCP server function and the DHCP server backoff function is enabled; and to disable the DHCP server function and the DHCP server backoff function of other network devices if the other network devices are elected as slave devices, and the other network devices have been configured with the DHCP server function and the DHCP server backoff function is enabled; and if a first DHCP response message corresponding to the first DHCP request message is received, take into effect the first dynamic IP address carried in the first DHCP response message and disable the DHCP server function.

[0202] In some embodiments, the control unit 1502 may be further configured to validate the static IP address configured in the first network device and enable the DHCP server function if the first DHCP response message is not received.

[0203] In some embodiments, the control unit 1502 may be further configured to resend the first DHCP request message after enabling the DHCP server function.

[0204] In some embodiments, the control unit 1502 can also be used to take into account the static IP address configured in the first network device and enable the DHCP server function if the first network device is elected as the main device and the first network device has been configured with a DHCP server function and the DHCP server backoff function is not enabled.

[0205] In some embodiments, the control unit 1502 can also be used to turn off the DHCP server function and the DHCP server backoff function if the first network device is elected as a slave device and the first network device has been configured with a DHCP server function and the DHCP server backoff function is turned on. Other network devices turn on the DHCP client function and send a second DHCP request message when the other network devices are elected as master devices and the other network devices have been configured with a DHCP server function and the DHCP server backoff function is turned on.

[0206] In some embodiments, the control unit 1502 can also be used to delete the first dynamic IP address carried in the first DHCP response message after the first dynamic IP address is validated and the DHCP server function is turned off, when the aging timer corresponding to the first dynamic IP address times out; validate the static IP address configured in the first network device, and turn on the DHCP server function.

[0207] In some embodiments, the control unit 1502 can also be used to periodically broadcast a first scanning message if the first network device is elected as a master device; if the first network device is elected as a slave device, periodically receive a second scanning message sent by a second network device, which is the master device in the local area network; if the second scanning message is not received within a first preset time period, re-execute the steps of electing a master device with other network devices in the local area network except the first network device.

[0208] In some embodiments, the control unit 1502 can also be used to switch the first network device to a slave device if the first network device is elected as the master device and receives a third scanning message sent by a third network device. When the priority of the third network device is higher than the priority of the first network device, the third network device is a newly added master device in the local area network, and the priority of the third network device is determined according to the information carried by the third scanning message.

[0209] In some embodiments, the election unit 1501 may be specifically configured to:

[0210] Periodically broadcast a first election message; within a second preset time period, receive target messages sent by other network devices in the local area network, where the target message is a second election message or a second scanning message; if the priority of the other network devices is higher than that of the first network device, the first network device is determined to be a slave device, and the priority of the other network devices is determined according to the information carried in the target message; if the priority of the other network devices is lower than that of the first network device, the first network device is determined to be a master device.

[0211] In the technical solution provided by the embodiment of the present application, a master device election is performed between network devices in a local area network, and each network device determines whether it is a master device or a slave device. For a network device, if the network device is a slave device, and the network device has been configured with a DHCP server function and has turned on the DHCP server backoff function, then the network device turns off the DHCP server function and turns off the DHCP server backoff function. The network device does not perform the DHCP server function, that is, it is not responsible for allocating IP addresses to DHCP clients, and the network device does not need to back off from other DHCP servers in the local area network. If the network device is a master device, and the network device has been configured with a DHCP server function and has turned on the DHCP server backoff function, then the network device turns on the DHCP client function to detect whether there is a DHCP server in the local area network. When it is detected that there is a DHCP server in the local area network, if a first DHCP response message corresponding to a first DHCP request message is received, the DHCP server function is turned off, and it is not responsible for allocating IP addresses to DHCP clients, thereby backing off from other DHCP servers in the local area network.

[0212] In the embodiment of the present application, the network devices in the local area network use the DHCP server fallback function to achieve a situation where there are multiple gateways, and only one device in the local area network provides the DHCP server function, thereby avoiding the problem that the network devices in the local area network apply for IP addresses with different network segments or IP address conflicts, and realizing automatic networking at startup in the case of multiple gateways, and user-zero configuration start.

[0213] Corresponding to the above communication method, the embodiment of the present application also provides a network device, such as Figure 16 As shown, it includes a processor 1601 and a machine-readable storage medium 1602. The machine-readable storage medium 1602 stores machine-executable instructions that can be executed by the processor 1601. The processor 1601 is prompted by the machine-executable instructions to implement any of the above communication methods.

[0214] The machine-readable storage medium may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage. Alternatively, the machine-readable storage medium may be at least one storage device located remote from the processor.

[0215] The processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.

[0216] In another embodiment provided by the present application, a computer-readable storage medium is further provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the above-mentioned communication methods is implemented.

[0217] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the above communication methods.

[0218] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part 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, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a 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 (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can 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 integrations. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).

[0219] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0220] Each embodiment in this specification is described in a related manner. Similar portions between embodiments can be referenced to each other. Each embodiment focuses on the differences between the other embodiments. In particular, the apparatus, network device, storage medium, and program product embodiments are generally similar to the method embodiments, so their descriptions are relatively simplified. For related portions, reference can be made to the descriptions of the method embodiments.

[0221] The above are only preferred embodiments of the present application and are not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application are included in the scope of protection of the present application.

Claims

1. A communication method, characterized in that: Applied to a first network device in a local area network, the method comprises: Conducting master device election with other network devices in the local area network except the first network device; If the first network device is elected as the master device, and the first network device has been configured with a DHCP server function and has a DHCP server backoff function enabled, the DHCP client function is enabled and a first DHCP request message is sent; if the other network device is elected as the slave device, and the other network device has been configured with a DHCP server function and has a DHCP server backoff function enabled, the DHCP server function is disabled and the DHCP server backoff function is disabled; If a first DHCP response message corresponding to the first DHCP request message is received, the first dynamic IP address carried in the first DHCP response message is validated, and the DHCP server function is disabled.

2. The method according to claim 1, characterized in that The method further comprises: If the first DHCP response message is not received, the static IP address configured in the first network device is valid, and the DHCP server function is enabled.

3. The method according to claim 2, characterized in that After enabling the DHCP server function, the method further includes: Resend the first DHCP request message.

4. The method according to claim 1, wherein The method further comprises: If the first network device is elected as the master device, and the first network device has been configured with a DHCP server function, and the DHCP server backoff function is not enabled, the static IP address configured in the first network device is valid, and the DHCP server function is enabled.

5. The method according to claim 1, wherein After validating the first dynamic IP address carried in the first DHCP response message and disabling the DHCP server function, the method further includes: When the aging timer corresponding to the first dynamic IP address times out, deleting the first dynamic IP address; The static IP address configured in the first network device is enabled, and the DHCP server function is enabled.

6. The method according to claim 1, characterized in that The method further comprises: If the first network device is elected as a slave device, and the first network device has been configured with a DHCP server function and has a DHCP server backoff function enabled, the DHCP server function is disabled and the DHCP server backoff function is disabled. If the other network device is elected as a master device and the other network device has been configured with a DHCP server function and has a DHCP server backoff function enabled, the DHCP client function is enabled and a second DHCP request message is sent.

7. The method according to claim 1, characterized in that The method further comprises: If the first network device is elected as the master device, periodically broadcasting a first scanning message; If the first network device is elected as a slave device, it periodically receives the second scanning message sent by the second network device, and the second network device is the master device in the local area network; if the second scanning message is not received within the first preset time period, the step of electing the master device with other network devices in the local area network except the first network device is re-executed.

8. The method according to claim 7, characterized in that The method further comprises: If the first network device is elected as the master device and receives the third scanning message sent by the third network device, then when the priority of the third network device is higher than the priority of the first network device, the first network device is switched to a slave device, and the third network device is a newly added master device in the local area network. The priority of the third network device is determined according to the information carried by the third scanning message.

9. The method according to claim 7, characterized in that The performing master device election with other network devices in the local area network except the first network device includes: Periodically broadcast the first election message; receiving, within a second preset time period, a target message sent by the other network device, where the target message is the second election message or the second scanning message; If the priority of the other network device is higher than the priority of the first network device, the first network device is determined to be a slave device, and the priority of the other network device is determined according to the information carried by the target message; If the priority of the other network device is lower than the priority of the first network device, the first network device is determined to be the master device.

10. A communication device, characterized in that: Applied to a first network device in a local area network, the apparatus comprises: an election unit, configured to perform master device election with other network devices in the local area network except the first network device; A control unit, configured to, if the first network device is elected as a master device and the first network device has been configured with a DHCP server function and has a DHCP server backoff function enabled, enable a DHCP client function and send a first DHCP request message; and, if the other network devices are elected as slave devices and the other network devices have been configured with the DHCP server function and have a DHCP server backoff function enabled, disable the DHCP server function and disable the DHCP server backoff function; and, if a first DHCP response message corresponding to the first DHCP request message is received, validate a first dynamic IP address carried in the first DHCP response message and disable the DHCP server function.

Citation Information

Patent Citations

  • Method for implementing DHCP service redundant and DHCP server

    CN101090309A

  • Master-slave switching method, network device and DHCP server

    CN102404146A

  • Alternative address allocation method based on DHCP detection, storage medium and terminal

    CN109981822A

  • Multi-activation detection method and system

    CN114124902A

  • Method and gateway device for dynamically allocating access device address to multi-DHCP server network

    CN114844863A