A communication method and apparatus
Patent Information
- Application Number
- CN202510779773.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-11
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2045-06-11
AI Technical Summary
[0004]然而,局域网的组网类型由用户根据自身搭建局域网的需求确定,这使得搭建的局域网中可能包括多个具有网关功能的网络设备(即多个网关),这多个网关同时为网关外的其他网络设备分配IP地址,而这多个网关包括的地址池的网段可能相同或不同,地址池的网段相同,会导致网络设备申请到的IP地址冲突,地址池的网段不同,会导致网络设备申请到的IP地址的网段不同
[0047]本申请实施例提供的技术方案中,局域网内的网络设备间进行主设备选举,每个网络设备分别确定自身为主设备或从设备。对于一个网络设备,若该网络设备为从设备,且该网络设备已配置DHCP服务器功能,并开启DHCP服务器退避功能,则该网络设备关闭DHCP服务器功能,并关闭DHCP服务器退避功能,该网络设备不执行DHCP服务器功能,即不负责为DHCP客户端分配IP地址,且该网络设备不需要退避局域网内的其他DHCP服务器。若该网络设备为主设备,且该网络设备已配置DHCP服务器功能,并开启DHCP服务器退避功能,则该网络设备开启DHCP客户端功能,以探测局域网内是否存在DHCP服务器,当探测到局域网内存在DHCP服务器,如接收到第一DHCP请求报文对应的第一DHCP响应报文,则关闭DHCP服务器功能,不负责为DHCP客户端分配IP地址,实现对局域网内的其他DHCP服务器的退避。
Smart Images

Figure CN120499155B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network technology, and in particular to a communication method and apparatus. Background Technology
[0002] With the rapid development of digital transformation, networks in various scenarios, including industrial parks, villas, chain stores, and corporate offices, are facing challenges such as low deployment efficiency, high maintenance difficulty, and complex management. To address these challenges, major network equipment providers have successively launched solutions that enable rapid local deployment and management, such as automatic network setup upon startup.
[0003] The core highlight of the automatic network setup solution is that network devices automatically form a network after being connected and powered on. Users can access the management device via a personal computer (PC) or mobile phone and directly enter the setup page for quick setup. The foundation for automatic network setup is that the network devices share the same management Virtual Local Area Network (VLAN) and the same Internet Protocol (IP) address segment, with no IP address conflicts. Within the Local Area Network (LAN), the gateway acts as a Dynamic Host Configuration Protocol (DHCP) server, and other network devices act as DHCP clients. The DHCP server assigns IP addresses to the DHCP clients, ensuring that network devices in the LAN obtain valid IP addresses after power-on, join the Layer 2 management network, complete automatic network setup, and support quick setup.
[0004] However, the network topology of a local area network (LAN) is determined by the user based on their specific LAN needs. This results in a LAN potentially including multiple network devices with gateway functionality (i.e., multiple gateways). These multiple gateways simultaneously assign IP addresses to other network devices outside the gateway itself. The network segments of the address pools included by these multiple gateways may be the same or different. If the address pool segments are the same, it will lead to IP address conflicts for the network devices; if the address pool segments are different, it will result in the network devices obtaining IP addresses from different network segments. This prevents the network devices in the LAN from automatically forming a network upon startup. Summary of the Invention
[0005] The purpose of this application is to provide a communication method and apparatus to achieve automatic network formation upon startup in a multi-gateway environment, enabling users to start the service with zero configuration. The specific technical solution is as follows:
[0006] In a first aspect, embodiments of this application provide a communication method applied to a first network device within a local area network, the method comprising:
[0007] A master device election is performed with other network devices within the local area network, excluding the first network device.
[0008] If the first network device is elected as the master device, and the first network device has configured the DHCP server function and enabled the DHCP server backoff function, then the DHCP client function is enabled and the first DHCP request message is sent. If the other network device is elected as the slave device, and the other network device has configured the DHCP server function and enabled the DHCP server backoff function, then 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 made effective, and the DHCP server function is turned off.
[0010] In some embodiments, the method further includes:
[0011] If the first DHCP response message is not received, the static IP address configured in the first network device will be activated, and the DHCP server function will be 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 includes:
[0015] If the first network device is elected as the master device, and the first network device has configured DHCP server function but has not enabled DHCP server backoff function, then the static IP address configured in the first network device will take effect, and the DHCP server function will be enabled.
[0016] In some embodiments, after taking effect 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 expires, the first dynamic IP address is deleted.
[0018] The static IP address configured in the first network device is activated, and the DHCP server function is enabled.
[0019] In some embodiments, the method further includes:
[0020] If the first network device is elected as the slave device, and the first network device has configured the DHCP server function and enabled the DHCP server backoff function, then the DHCP server function and the DHCP server backoff function are disabled. If the other network device is elected as the master device, and the other network device has configured the DHCP server function and enabled the DHCP server backoff function, then the other network device enables the DHCP client function and sends a second DHCP request message.
[0021] In some embodiments, the method further includes:
[0022] If the first network device is elected as the master device, it will periodically broadcast the first scan message;
[0023] If the first network device is elected as the slave device, it periodically receives the second scan message sent by the second network device, which is the master device in the local area network; if the second scan message is not received within a first preset time period, the step of electing a master device with other network devices in the local area network other than the first network device is re-executed.
[0024] In some embodiments, the method further includes:
[0025] If the first network device is elected as the master device and receives a third scan 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. 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 in the third scan message.
[0026] In some embodiments, the master device election process with other network devices within the local area network besides the first network device includes:
[0027] Periodically broadcast the first election message;
[0028] Within a second preset time period, a target message sent by the other network device is received, wherein the target message is a second election message or a second scan message;
[0029] If the priority of the other network devices is higher than that of the first network device, then 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;
[0030] If the priority of the other network devices is lower than that of the first network device, then the first network device is determined to be the master device.
[0031] Secondly, embodiments of this application provide a communication device, applied to a first network device within a local area network, the device comprising:
[0032] An election unit is used to elect a master device among other network devices in the local area network, excluding the first network device.
[0033] The control unit is configured to, if the first network device is elected as the master device and the first network device has configured DHCP server function and enabled DHCP server backoff function, enable DHCP client function and send a first DHCP request message; if the other network device is elected as the slave device and the other network device has configured DHCP server function and enabled DHCP server backoff function, disable the DHCP server function and disable the DHCP server backoff function; if a first DHCP response message corresponding to the first DHCP request message is received, activate the 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, activate 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 the DHCP server function is enabled.
[0036] In some embodiments, the control unit is further configured to, if the first network device is elected as the master device and the first network device has configured a DHCP server function but has not enabled the DHCP server backoff function, then to activate the static IP address configured in the first network device and enable the DHCP server function.
[0037] In some embodiments, the control unit is further configured to, after activating the first dynamic IP address carried in the first DHCP response message and disabling the DHCP server function, delete the first dynamic IP address when the aging timer corresponding to the first dynamic IP address times out; activate the static IP address configured in the first network device and enable the DHCP server function.
[0038] In some embodiments, the control unit is further configured to disable 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 configured the DHCP server function and enabled the DHCP server backoff function; and if the other network device is elected as a master device and the other network device has configured the DHCP server function and enabled the DHCP server backoff function, the other network device enables the DHCP client function and sends a second DHCP request message.
[0039] In some embodiments, the control unit is further configured to: periodically broadcast a first scan message if the first network device is elected as the master device; periodically receive a second scan message sent by a second network device, where the second network device is the master device in the local area network, if the first network device is elected as the slave device; and if the second scan 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 besides the first network device.
[0040] In some embodiments, the control unit is further configured to, if the first network device is elected as the master device and a third scan message is received from the third network device, then, if the priority of the third network device is higher than the priority of the first network device, switch the first network device to a slave device, wherein 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 in the third scan message.
[0041] In some embodiments, the election unit is specifically used for:
[0042] The system periodically broadcasts a first election message; within a second preset time period, it receives target messages sent by other network devices, the target messages being either a second election message or a second scan 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 based on the information carried in 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 a master device.
[0043] Thirdly, embodiments of this application provide a network device including a processor and a machine-readable storage medium storing machine-executable instructions executable by the processor, which in turn cause the processor to implement any of the methods provided in the first aspect.
[0044] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the methods provided in the first aspect.
[0045] Fifthly, embodiments of this application provide a computer program product containing instructions that, when run on a computer, cause the computer to perform any of the methods provided in the first aspect.
[0046] Beneficial effects of the embodiments in this application:
[0047] In the technical solution provided in this application embodiment, a master device election is performed among network devices within a local area network (LAN), with each network device determining itself as either a master or a slave device. For a network device, if it is a slave device and has configured a DHCP server function with DHCP server backoff enabled, then the network device disables both the DHCP server function and the DHCP server backoff function. The network device does not perform the DHCP server function, meaning it is not responsible for assigning IP addresses to DHCP clients, and it does not need to back off other DHCP servers within the LAN. If the network device is a master device and has configured a DHCP server function with DHCP server backoff enabled, then the network device enables the DHCP client function to detect the presence of a DHCP server within the LAN. When a DHCP server is detected, and a first DHCP response message corresponding to a first DHCP request message is received, the DHCP server function is disabled, and it is not responsible for assigning IP addresses to DHCP clients, thus achieving backoff from other DHCP servers within the LAN.
[0048] In this embodiment, network devices within a local area network (LAN) utilize the DHCP server backoff function to ensure that, in the case of multiple gateways, only one device in the LAN provides the DHCP server function. This avoids the problem of different network segments or IP address conflicts for IP addresses obtained by network devices within the LAN, enabling automatic network formation upon startup in the case of multiple gateways and zero-configuration startup for users.
[0049] Of course, implementing any product or method of this application does not necessarily require achieving all of the above advantages at the same time. Attached Figure Description
[0050] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0051] Figure 1 This is a schematic diagram of the first type of local area network (LAN) setup.
[0052] Figure 2 This is a second schematic diagram of a local area network (LAN) setup.
[0053] Figure 3 This is a diagram illustrating the third type of local area network (LAN) setup.
[0054] Figure 4 This is the fourth diagram of a local area network (LAN) setup.
[0055] Figure 5 This is a schematic diagram of a first type of communication method provided in an embodiment of this application;
[0056] Figure 6 A schematic diagram of a standard Ethernet packet provided in an embodiment of this application;
[0057] Figure 7 This is a second flowchart illustrating the communication method provided in an embodiment of this application;
[0058] Figure 8 This is a third flowchart illustrating the communication method provided in the embodiments of this application;
[0059] Figure 9 A schematic diagram of a first type of message processing method provided in an embodiment of this application;
[0060] Figure 10 A second flowchart illustrating the message processing method provided in the embodiments of this application;
[0061] Figure 11 A schematic flowchart of the master device election method provided in the embodiments of this application;
[0062] Figure 12 A schematic diagram of a DHCP server backoff system architecture provided in an embodiment of this application;
[0063] Figure 13 A schematic diagram of a state machine provided in an embodiment of this application;
[0064] Figure 14 A schematic diagram of the DHCP server automatic backoff mechanism provided in the embodiments of this application;
[0065] Figure 15 A schematic diagram of the structure of a communication device provided in an embodiment of this application;
[0066] Figure 16 This is a schematic diagram of the structure of a network device provided in an embodiment of this application. Detailed Implementation
[0067] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0068] Zero Touch Provisioning (ZTP): A network device automatic deployment technology that allows newly manufactured or unconfigured network devices to automatically acquire and load the necessary configuration files, system software, patches, etc. after power-on, completing the initial configuration and connecting to the network without manual intervention.
[0069] DHCP server candidates: These can include network devices such as AC (Access Controller) and firewalls, which are factory-configured with DHCP server functionality. Candidates must support DHCP server backoff functionality.
[0070] DHCP server non-candidate: This refers to network devices such as routers, third-party routers, access points (APs), cameras, PCs, access switches, and core switches. Routers and third-party routers are the default gateways and are factory-configured with DHCP server functionality, without performing DHCP server backoff processing. APs, cameras, PCs, access switches, and core switches are factory-configured with DHCP client functionality and do not require DHCP server backoff processing.
[0071] The network topology of a local area network (LAN) is determined by the user based on their specific LAN setup needs. Current LAN topology types can be found in [link to relevant documentation]. Figures 1-4 As shown, Figures 1-4 The local area network 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 network devices is VLAN 1. In the factory configuration, the IP address configuration for the VLAN 1 virtual interface includes two modules: DHCP dynamic allocation (dhcp alloc) + DHCP server mode and static IP address + DHCP server mode. Figures 1-3 In this system, all network devices are from the same manufacturer. Figure 4 In this configuration, network devices such as APs, cameras, PCs, access switches, core switches, firewalls, and ACs are all from the same manufacturer, as are routers (i.e.,...). Figure 4 The third-party routers in the system are devices from other manufacturers, and devices from different manufacturers cannot be directly managed locally.
[0072] Firewalls, routers, and ACs, among other network devices, have gateway capabilities. Their factory configuration sets the VLAN 1 virtual interface to a static IP address and binds it to a DHCP server. However, the DHCP address pools of these network devices may differ or conflict. Access points (APs), cameras, PCs, access switches, and core switches, on the other hand, are configured by default to dynamically assign VLAN 1 virtual interfaces via DHCP and bind them to DHCP client functionality.
[0073] In a local area network (LAN) with routers, firewalls, and ACs, after the network devices are connected and started, DHCP server conflicts may occur. The dynamic IP addresses of the network devices in the LAN are not assigned by the same DHCP server, which leads to problems such as IP addresses not being in the same network segment or IP address conflicts, and consequently, automatic network formation failure.
[0074] To address the above problems, embodiments of this application provide a communication method, such as... Figure 5 As shown, the method, applied to a first network device within a local area network, includes the following steps:
[0075] Step S501: Elect a master device with other network devices in the local area network, excluding the first network device;
[0076] In step S502, if the first network device is elected as the master device, and the first network device has configured DHCP server function and enabled DHCP server backoff function, then the DHCP client function is enabled, and a first DHCP request message is sent. If other network devices are elected as slave devices, and other network devices have configured DHCP server function and enabled DHCP server backoff function, then the DHCP server function and DHCP server backoff function are disabled.
[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 made effective, and the DHCP server function is turned off.
[0078] In the technical solution provided in this application embodiment, a master device election is performed among network devices within a local area network (LAN), with each network device determining itself as either a master or a slave device. For a network device, if it is a slave device and has configured a DHCP server function with DHCP server backoff enabled, then the network device disables both the DHCP server function and the DHCP server backoff function. The network device does not perform the DHCP server function, meaning it is not responsible for assigning IP addresses to DHCP clients, and it does not need to back off other DHCP servers within the LAN. If the network device is a master device and has configured a DHCP server function with DHCP server backoff enabled, then the network device enables the DHCP client function to detect the presence of a DHCP server within the LAN. When a DHCP server is detected, and a first DHCP response message corresponding to a first DHCP request message is received, the DHCP server function is disabled, and it is not responsible for assigning IP addresses to DHCP clients, thus achieving backoff from other DHCP servers within the LAN.
[0079] In this embodiment, network devices within a local area network (LAN) utilize the DHCP server backoff function to ensure that, in the case of multiple gateways, only one device in the LAN provides the DHCP server function. This avoids the problem of different network segments or IP address conflicts for IP addresses obtained by network devices within the LAN, enabling automatic network formation upon startup in the case of multiple gateways and zero-configuration startup for users.
[0080] In this embodiment, the first network device can be any network device within an unestablished local area network (LAN), such as an access point (AP), camera, PC, access switch, core switch, firewall, AC, or router. The LAN can include one or more network devices; that is, in addition to the first network device, the LAN can also include other network devices, such as a second network device, a third network device, etc.
[0081] In step S501 above, within the local area network (LAN), the first network device interacts with other network devices to elect a master device, thus determining the master and slave devices within the LAN. Within a Layer 2 LAN, there is one and only one master device, and all other network devices are slave devices.
[0082] In this embodiment, after power-on and initialization, the first network device enters an election state to elect a master device with other network devices within the local area network, thus determining the status of the first network device. The first network device can be classified as either a master or a slave device. Here, after initialization, the network devices participating in the master device election belong to the same vendor, meaning they share the same initial communication protocol. Third-party devices (such as the aforementioned third-party router) cannot participate in the master device election because their initial communication protocol cannot differ from that of the first network device.
[0083] For example, after powering on and initializing, each network device within a domain network periodically broadcasts election messages at fixed intervals. These election messages carry crucial information such as the network device's bridge Media Access Control (MAC) address, device type, priority, capabilities, key, and serial number. Each network device determines its own and other network device priorities based on the key information carried in the received election messages. If a network device has a higher priority than itself, it is designated as a slave device; if all other network devices have lower priorities than itself, it is designated as the master device.
[0084] The key information referenced by network devices in determining the priority of other network devices can be determined based on actual needs. For example, network devices can determine their priority based on device type. The specific priority order of various device types from highest to lowest is: AP, camera, PC, access switch, core switch, firewall, AC, router.
[0085] The election message can be sent periodically every 5 seconds, for a total of 20 times, meaning the fixed interval is 100 seconds after power-on. The election message can use the standard Ethernet protocol stack; 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). The preamble field is 8 bytes long, the destination address and source address fields are 4 bytes long, the type field is 2 bytes long, the data field is variable in length from 46 bytes to 1500 bytes, and the FCS field is 4 bytes long.
[0086] In this embodiment, the value carried by the type field can be fixed to a preset value, such as 0xabb0. This preset value indicates that the subsequent message is a message in the DHCP server backoff process, such as an election message. The value carried by the data field is key information of the network device, which can be stored in the data field in the format of a Type Length Value (TLV).
[0087] After determining that the first network device is the master device (i.e., 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 back off other DHCP servers within the local area network (LAN), that is, the ability to disable its own DHCP server function when other DHCP servers (independent DHCP servers or high-priority devices with DHCP server functions) exist within the LAN.
[0089] When the first network device is elected as the primary device, it indicates that the first network device may need to act as a DHCP server to assign IP addresses to DHCP clients. Since it may need to act as a DHCP server, it needs to back off other DHCP servers. In this case, if the first network device is already configured with DHCP server functionality (such as factory-configured DHCP server functionality) and has enabled DHCP server backoff functionality (such as through a firewall or AC), then the first network device enables DHCP client functionality. As a DHCP client, the first network device executes step S502, which allows it to periodically broadcast or multicast DHCP request messages (such as the first DHCP request message) to detect the presence of other DHCP servers within the local area network. The frequency of periodically sending DHCP request messages can be set according to actual needs; for example, it can be sent every 5 seconds, every 10 seconds, etc.
[0090] If other DHCP servers exist on the local area network (such as a third-party router or a network device with higher priority than the first network device), after receiving the first DHCP request message, the other DHCP servers will send a DHCP response message (such as the 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 assigned to the first network device by the other DHCP server.
[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 to activate the first dynamic IP address carried in the first DHCP response message and disable 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 other DHCP servers detected will assign IP addresses to DHCP clients.
[0092] If the first network device does not receive the first DHCP response message, meaning it detects that no other DHCP server exists within the local area network, then the first network device can activate the static IP address configured in its configuration and enable the DHCP server function. In this way, the first network device can act as a DHCP server, assigning IP addresses to DHCP clients within the local area network.
[0093] When the first network device is elected as the master device, other network devices are elected as slave devices. This indicates that the other network devices do not need to act as DHCP servers to assign IP addresses to DHCP clients, and since they do not need to act as DHCP servers themselves, they do not need to back off other DHCP servers. In this case, if other network devices are already configured with DHCP server functionality and have enabled DHCP server backoff functionality (such as firewalls or ACs), then these other network devices will disable their DHCP server functionality and DHCP server backoff functionality. Subsequently, the slave devices can either implement the static IP address configured in the slave device, or enable DHCP client functionality and send DHCP request messages; upon receiving the corresponding DHCP response message, they will implement the dynamic IP address carried in the DHCP response message.
[0094] In this embodiment, when the DHCP server backoff function is enabled on the network devices within the local area network (LAN), even if multiple network devices are configured with DHCP server functionality (i.e., multiple gateways exist within the LAN), only one device within the LAN will act as the DHCP server to assign IP addresses to DHCP clients within the LAN. This resolves the DHCP server conflict issue, and the dynamic IP addresses of the network devices within the LAN are all assigned by the same DHCP server, enabling automatic network formation upon startup in the case of multiple gateways and zero-configuration startup for users.
[0095] In some embodiments, when the first network device is the master device and the first network device has been configured with DHCP server function and enabled DHCP server backoff function, 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, that is, continue to detect whether there are other DHCP servers in the local area network, under the condition that the static IP address configured in the first network device is effective and the DHCP server function is enabled.
[0096] If another DHCP server is detected on the local area network (LAN), i.e., upon receiving the first DHCP response message, the first dynamic IP address carried in the first DHCP response message is made effective, and the DHCP server function is disabled. If no other DHCP server is detected on the LAN, the DHCP server function remains enabled. This effectively avoids DHCP server conflicts caused by newly added DHCP servers on 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. Since it may need to act as a DHCP server itself, it needs to back off other DHCP servers. In this case, if the first network device has already configured DHCP server functionality and has not enabled DHCP server backoff functionality (such as routers from the same vendor as other network devices mentioned above), then the first network device can choose not to back off other DHCP servers, implement the static IP address configured in the first network device, and enable DHCP server functionality, i.e., the first network device itself acts as a DHCP server. In this embodiment, in scenarios where routers from the same vendor exist, the router may be elected as either a master device or a slave device.
[0098] This application provides a communication method, such as... Figure 7 As shown, the method, applied to a first network device within a local area network, may include the following steps:
[0099] Step S701: Elect a master device with other network devices in the local area network, excluding the first network device;
[0100] Step S702: If the first network device is elected as the master device, and the first network device has configured DHCP server function and enabled DHCP server backoff function, then the DHCP client function is enabled, and a first DHCP request message is sent. Where other network devices are elected as slave devices, and other network devices have configured DHCP server function and enabled DHCP server backoff function, then the DHCP server function and DHCP server backoff function are disabled.
[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 made effective, and the DHCP server function is turned off.
[0102] The steps S701 to S703 described above are the same as those S501 to S503 described above.
[0103] In step S704, if the first network device is elected as the slave device, and the first network device has configured the DHCP server function and enabled the DHCP server backoff function, then the DHCP server function and the DHCP server backoff function are disabled. Meanwhile, if other network devices are elected as the master device, and other network devices have configured the DHCP server function and enabled the DHCP server backoff function, then the DHCP client function is enabled, and a second DHCP request message is sent.
[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 assign IP addresses to DHCP clients, and since it does not need to act as a DHCP server, it does not need to back off other DHCP servers. In this case, if the first network device has already configured DHCP server functionality and enabled DHCP server backoff functionality (such as the aforementioned firewall or AC), then the first network device executes step S704 to disable the DHCP server functionality and disable the DHCP server backoff functionality. Subsequently, the first network device can either enable the static IP address configured in the slave device, or enable the DHCP client function and send a DHCP request message; upon receiving the DHCP response message corresponding to the DHCP request message, it will enable the dynamic IP address carried in the DHCP response message.
[0105] When the first network device is elected as a slave device, if it has already configured DHCP client functionality (such as the aforementioned AP, camera, PC, access switch, core switch, etc.), it will not act as a DHCP server and thus will not conflict with other DHCP servers. Therefore, the first network device does not need to perform any further processing. 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 take effect.
[0106] When the first network device is elected as the slave device, if the first network device has configured the DHCP server function but 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 any other processing operations and end the DHCP server backoff process; the first network device may also output a prompt message to notify the user of the 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, such as Figure 8 As shown, a communication method is also provided, applied to a first network device within a local area network, the method comprising the following steps:
[0108] Step S801: Elect a master device with other network devices in the local area network, excluding 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 configured the DHCP server function and enabled the DHCP server backoff function, then the DHCP client function is enabled and the first DHCP request message is sent; wherein, if other network devices are elected as slave devices and other network devices have configured the DHCP server function and enabled the DHCP server backoff function, then the DHCP server function is disabled and the DHCP server backoff function is disabled.
[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 made effective, and the DHCP server function is turned off.
[0111] Steps S801 to S803 are the same as steps S501 to S503, and will not be repeated here.
[0112] Step S804: When the aging timer corresponding to the first dynamic IP address expires, delete the first dynamic IP address;
[0113] Step S805: Apply the static IP address configured in the first network device and enable the DHCP server function.
[0114] In this embodiment of the application, each dynamic IP address is configured with a corresponding aging timer. 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 activates the first dynamic IP address and disables the DHCP server function, it starts the aging timer corresponding to the first dynamic IP address. When the aging timer expires, the first network device deletes the first dynamic IP address, activates the static IP address configured in the first network device, and enables the DHCP server function. This avoids the problem of other DHCP servers in the local area network going offline, preventing the first network device from joining the local area network, and preventing newly joined network devices from obtaining IP addresses.
[0116] With the static IP address configured in the first network device in effect and the DHCP server function enabled, the first network device can continue to act as a DHCP client, periodically sending first DHCP request messages, i.e., continuing to probe for the existence of other DHCP servers within the local area network (LAN). If another DHCP server is detected within the LAN, i.e., a first DHCP response message is received, 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 server is detected within the LAN, the DHCP server function remains enabled. This effectively avoids DHCP server conflicts caused by newly added DHCP servers to the LAN.
[0117] In some embodiments, to ensure that there is only one master device within the local area network and to implement the DHCP server backoff function described above, this application also provides a message processing method, such as... Figure 9 As shown, the method, applied to a first network device within a local area network, may include the following steps:
[0118] Step S901: Elect a master device among the network devices in the local area network other than the first network device; the same as step S501 above.
[0119] Step S902: If the first network device is elected as the master device, the first scan message is broadcast periodically.
[0120] In this embodiment of the application, the first scan message is a scan message sent by the first 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 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] The scan message can use the standard Ethernet protocol stack, and in this case, the structure of the scan message is as follows: Figure 6 As shown. In this embodiment, the value carried by the type field can be fixed to a preset value, such as 0xabb0. This preset value indicates that the subsequent message is a message in the DHCP server backoff process, such as a scan message. The value carried by the data field is key information of the master device, which can be stored in the data field in TLV format.
[0122] After being elected as the primary network device, the first network device performs... Figure 5 While performing steps S502 to S503 as shown, the first scan message can be periodically broadcast. The frequency of periodically sending the first scan message can be set according to actual needs; for example, the frequency of periodically sending the first scan message can be once every 5 seconds, once every 10 seconds, etc.
[0123] In this scenario, other network devices within the local area network (LAN) can act as slave devices and 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 master device's key information, i.e., the first network device's key information, and reply to the master device (i.e., the first network device) with a scan acknowledgment message (scan_ack message). The scan_ack message can carry the key information of the slave devices (i.e., other network devices) to achieve Layer 2 device discovery.
[0124] The scan_ack message can use the standard Ethernet protocol stack, and in this case, the structure of the scan_ack message is as follows: Figure 6 As shown. In this embodiment, the value carried by the type field can be fixed to a preset value, such as 0xabb0. This preset value indicates that the subsequent message is a message in 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, which can be stored in the data field in TLV format.
[0125] In step S903, if the first network device is elected as the slave device, it periodically receives the second scan message sent by the second network device, which is the master device in the local area network; if the second scan message is not received within the first preset time period, step S901 is executed again.
[0126] The second network device can be any other network device within the local area network (LAN) besides the first network device. The second scan message is a scan message sent by the second network device acting as the master device. The scan message informs other network devices of the master device's key information within the LAN (i.e., the second network device's key information), allowing the first network device and other network devices to be aware of the presence of a master device within 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 the duration of 3 scan message sending cycles.
[0127] After being elected as the primary network device, the second network device performs... Figure 5 While performing steps S502 to S503 as shown, a second scan message can be periodically broadcast. The frequency of periodically sending the second scan message can be set according to actual needs; for example, the frequency of periodically sending the second scan message can be once every 5 seconds, once every 10 seconds, etc.
[0128] In this scenario, the first network device, acting as a slave device, can periodically receive second scan packets sent by the second network device. Upon receiving the second scan packet, the first network device can record key information about the master device (i.e., the second network device) and reply with a scan acknowledgment packet (scan_ack packet) to the master device (i.e., the second network device). The scan_ack packet can carry key information about the slave device (i.e., the first network device) to achieve Layer 2 device discovery.
[0129] If the second scan message is not received within the first preset time period, it means that the second network device has left the local area network. In order to ensure that the subsequent devices can automatically form a network after power-on 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 realize the DHCP server backoff function.
[0130] In some embodiments, to ensure that there is only one master device within the local area network and to implement the DHCP server backoff function described above, this application also provides a message processing method, such as... Figure 10 As shown, the method, applied to a first network device within a local area network, may include the following steps:
[0131] Step S1001: Elect a master device with other network devices in the local area network besides the first network device; the same as step S501 above.
[0132] In step S1002, if the first network device is elected as the master device and receives the third scan 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 the slave device, and the third network device is the 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 scan message.
[0133] In this embodiment, the third network device can be the master device introduced after merging two local area networks (LANs), or the third network device can be a master device configured by the user, or the first network device and the third network device can determine the master device for a local sub-network within the LAN, 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 the key information of the master device in the LAN (i.e., the key information of the third network device), so that other network devices know that there is a master device in the LAN.
[0134] After receiving the third scan message, the first network device can determine its priority based on the key information of the third network device carried in the third scan message; simultaneously, it can determine its priority based on the key information of the first network device; and then compare the priorities of the third and first network devices.
[0135] If the priority of the third network device is higher than that of the first network device, the first network device will switch to a slave device. After the first network device is demoted to a slave device, it can execute step S903 (at this time, the third network device acts as the second network device) and step S704. That is, if the first network device is a slave device and the first network device has configured the DHCP server function and enabled the DHCP server backoff function, then the DHCP server function will be disabled and the DHCP server backoff function will be disabled.
[0136] If the priority of the third network device is lower than that of the first network device, the first network device remains the master device. Then, the first network device can continue to execute steps S1002 and S902. Furthermore, if the first network device is the master device and has configured DHCP server functionality with DHCP server backoff enabled, the first network device continues to probe for other DHCP servers within the local area network; or, if the first network device is the master device and has configured DHCP server functionality but has not enabled DHCP server backoff, the first network device may not perform any further processing.
[0137] In this embodiment, if the first network device is a slave device, it can also receive the third scan message sent by the third network device. Based on the key information carried in the second and third scan messages, the first network device determines the priority of the second and third network devices, and then identifies the master device from the second and third network devices, recording the key information of the identified master device.
[0138] In the technical solution provided in this application embodiment, the master device in the local area network sends scanning messages through broadcast, ensuring that there is only one master device in the local area network, thereby realizing the DHCP server backoff function, realizing automatic network formation at boot, and enabling users to start with zero configuration.
[0139] In some embodiments, such as Figure 11 As shown, a master device election method is also provided, applied to the first network device in a local area network. The method may include the following steps:
[0140] Step S1101: Periodically broadcast the first election message;
[0141] In this embodiment, the first election message is an election message sent by the first network device. After the first network device powers on, completes initialization, and enters the election state, it periodically broadcasts and sends the first election message.
[0142] Other network devices within the local area network will also send election messages, such as the second election message, after powering on, starting up, and initializing, and entering the election state.
[0143] Step S1102: Within the second preset time period, receive target messages sent by other network devices in the local area network. The target messages are either second election messages or second scan messages.
[0144] In this embodiment, the second preset duration can be set according to actual needs, for example, the second preset duration can be 3 minutes, 5 minutes, etc. Within the second preset duration after entering the election state, the first network device can continuously receive second election messages or second scan messages sent by other network devices. The second scan message is a scan message sent by the second network device elected as the master device. The number of other network devices can be one or more, and correspondingly, the number of target messages received by the first network device can be one or more.
[0145] Step S1103: If the priority of other network devices is higher than that of the first network device, then the first network device is determined to be the slave device, and the priority of other network devices is determined according to the information carried in the target packet.
[0146] Step S1104: If the priority of other network devices is lower than that of the first network device, then the first network device is determined to be the master device.
[0147] The first network device determines the priority of other network devices based on the key information of other network devices carried in the target message; and compares the priority of other network devices with the priority of the first network device. If the priority of one other network device is higher than the priority of 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 can be executed.
[0148] If the priority of other network devices is lower than that of the first network device, the first network device executes step S1104 to determine the first network device as the master device. In the case that the first network device is the master device, step S502, as well as step S902 or step S1002, can be executed.
[0149] In the technical solution provided in this application embodiment, network devices in a local area network can elect master and slave devices based on election messages and scan messages, enabling newly added network devices in the local area network to participate in the DHCP server backoff scheme, further ensuring automatic network formation at startup in the case of multiple gateways and zero-configuration startup for users.
[0150] The following is combined with Figure 12 The DHCP server backoff system architecture shown is as follows: Figure 13 The state machine shown Figure 14 The DHCP server automatic backoff mechanism shown in the illustration provides a detailed description of the communication method provided in the embodiments of this application.
[0151] In this embodiment, to enable mutual discovery and master device election among network devices within the local area network (LAN), the network devices automatically start the role control module 1201 upon power-on. The role control module 1201 can also be referred to as the role control process. The role control module 1201 performs device discovery and master device election by broadcasting and unicasting Layer 2 Ethernet packets (such as the aforementioned election packets, scan packets, and scan confirmation packets) within the LAN. These Layer 2 Ethernet packets can carry key information such as 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 will be referred to as a network element device, such as... Figures 1-4 Network devices other than third-party routers, and network devices that do not run the role control module 1201, are referred to as third-party devices, such as... Figure 4 The network element device may include the aforementioned first network device, second network device, third network device, etc., in this embodiment of the application.
[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 elements to operate in their designed roles within a local area network (LAN), while supporting adaptive role changes to ensure the stability of the LAN as a whole system: In a Layer 2 LAN, there is one and only one master device, and all other devices are slave devices. The time from detecting a master device conflict to reaching a steady state in the LAN does not exceed 5 minutes. In the embodiments of this application, the state machine can achieve... Figure 13 The four states shown are: Initial, Electing, Slave, and Manager.
[0155] Init state: This refers to the state when the role control module 1201 starts up 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 starts up, the state machine remains in the Init state.
[0156] Electing state: This indicates that the network element is in the process of electing a master device. After initialization, the state machine transitions to the Electing state.
[0157] Slave status: Indicates that the network element device election is complete and the elected device is a slave device.
[0158] Manager status: Indicates that the network element device election is complete and the elected master device has been selected.
[0159] When the state machine is in the Electing state, compared to the network element itself, if the network element receives an election message or scan message sent by another network element with higher priority, the state machine transitions to the Slave state; if it receives an election message or scan message sent by another network element with higher priority within a specified time (such as a second preset time), it indicates that the election has failed, and the state machine transitions to the Slave state; if it does not receive an election message or scan message sent by another network element with higher priority within a specified time (such as a second preset time), it indicates that the election has succeeded, and the state machine transitions 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 the first preset time), it indicates 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 receives an election message or scan message from another network element with higher priority than itself, the state machine will transition to the Slave state.
[0162] When the state machine is in the Electing, Slave, or Manager state, if the role control module 1201 is reset (exited), the state machine will transition to the Init state.
[0163] The state machine is one of the core components for implementing the role-based DHCP server automatic backoff mechanism. This state machine runs through the entire lifecycle of network element equipment system startup, operation, and shutdown.
[0164] The private Layer 2 packet processing submodule is used to implement the protocol stack for standard Ethernet packets, such as... Figure 6 As shown. Specifically, as... Figure 13 As shown, when the state machine is in the Electing state, the private Layer 2 message processing submodule periodically broadcasts election messages; when the state machine is in the Manager state, the private Layer 2 message processing submodule periodically broadcasts scan messages.
[0165] The DHCP event handling submodule is used to respond to events reported by the DHCP module 1202 indicating the detection of other DHCP servers. It processes these events by combining information such as its own role and device type, including calculating and configuring the DHCP role of the local machine and the DHCP role of the DHCP module 1202. DHCP roles include DHCP server and DHCP client.
[0166] For example, DHCP module 1202 reports "Other DHCP server detected"; the network element device is the master device, the device type is firewall, and the DHCP event processing submodule can calculate the DHCP role of the local machine as a DHCP client, and then configure the DHCP role of DHCP module 1202 as a DHCP client, so that the network element device can realize the DHCP client function.
[0167] For example, DHCP module 1202 reports "Other DHCP server detected"; the network element device is the master device, the device type is router, and the DHCP event processing submodule can calculate the DHCP role of the local machine as a DHCP server, and then configure the DHCP role of 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 roles of DHCP module 1202, enabling the DHCP server to automatically back off and restart. For example, the DHCP role control submodule configures the role of DHCP module 1202 based on 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. Upon receiving a corresponding DHCP response message, it reports the detection of other DHCP servers to the role control module 1201. If no corresponding DHCP response message is received, the DHCP server detection submodule may or may not report the failure to detect other DHCP servers to the role control module 1201.
[0171] The DHCP function control submodule is used to implement the relevant interfaces for configuring DHCP function parameters, enabling the role control module 1201 to set DHCP role configurations. 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, launches either the DHCP client submodule or the DHCP server submodule.
[0172] The DHCP client submodule is used to implement DHCP client functions, such as activating dynamic IP addresses 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] In combination with the above Figure 12 and Figure 13 ,right Figure 14 The DHCP server's automatic backoff mechanism is explained below.
[0175] Step S1401: Determine the starting state.
[0176] In this embodiment of the application, the network element device can be a non-candidate or a candidate. After the network element device is powered on, the role control module 1201 of the network element device determines the on-premises status of the device, that is, whether the device is on-premises; if the device is on-premises, step S1402 is executed; if the device is not on-premises, step S1403 is executed.
[0177] Step S1402: Disable the DHCP server backoff function.
[0178] In this embodiment, the role control module 1201 of the network element device disables the DHCP server backoff function when it determines that the local device has already started the service. At this time, the network element device no longer needs to execute the DHCP server backoff function.
[0179] Step S1403, switch roles.
[0180] In this embodiment, the role control module 1201 of the network element device can determine its own role and achieve role switching by sending election messages and scan messages. After the role switching is achieved, if the network element device is a candidate, the role control module 1201 can execute step S1404 when the local device's role switches to slave device; and execute step S1405 when the local device's role switches to master device. If the network element device is not a candidate, such as a router, switch, or AP, then the network element device does not need to perform any subsequent processing regardless of whether its role switches to slave or master device.
[0181] When the state machine is functioning properly, after 2-3 minutes of election, there can be exactly one master device in the local area network (LAN), with all others being slave devices. The role of each network element in a specific LAN is determined. In other words, when the state machine is functioning properly, it can ensure that the LAN and device roles (master or slave) meet expectations.
[0182] Step S1404: Disable the DHCP server backoff function and disable the DHCP server function.
[0183] In this embodiment of the application, when the role of the local machine is switched to a slave device, the role control module 1201 can disable the DHCP server backoff function; if the DHCP server function of the network element device is activated, the role control module 1201 can also control the DHCP module 1202 to disable the DHCP server function.
[0184] Step S1405: Detect other DHCP servers.
[0185] When the local machine acts as the master device, the DHCP module 1202 can initiate the DHCP client function and act as a DHCP client to periodically send DHCP request messages to detect whether there are other DHCP servers in the local area network. When other DHCP servers are detected in the local area network, step S1406 is executed; when no other DHCP servers are detected in the local area network, step S1408 is executed.
[0186] In this embodiment, the DHCP module 1202 supports the function of DHCP server detection at all times.
[0187] Step S1406: Activate the dynamic IP address and disable the DHCP server function.
[0188] When DHCP module 1202 detects other DHCP servers in the local area network, DHCP module 1202 acts as a DHCP client, applies the dynamic IP address assigned by the other DHCP server, and role control module 1201 disables the DHCP server function.
[0189] Step S1407, Dynamic IP aging, restart detection.
[0190] When the aging timer corresponding to the dynamic IP address expires, the DHCP module 1202 ages and deletes the dynamic IP address, and the DHCP module 1202 re-executes step S1405 to probe other DHCP servers.
[0191] Step S1408: Apply the static IP address and enable the DHCP server function, then repeat step S1405.
[0192] When DHCP module 1202 detects that no other DHCP server exists within the local area network, DHCP module 1202 applies the static IP address of the network element device, and role control module 1201 enables the DHCP server function. Subsequently, this network element device can act as a DHCP server to assign IP addresses to DHCP clients.
[0193] After the static IP address is activated and the DHCP server function is enabled, the DHCP module 1202 can continue to launch 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 local area network.
[0194] The above Figure 14 The DHCP server automatic backoff mechanism shown below can determine the master device, slave device, and DHCP server under different network topologies, as shown in Table 1.
[0195] Table 1
[0196]
[0197] In Table 1 above, the third-party gateway can be a third-party router. When accessing the local area network, the third-party gateway can send an authorization request to the manufacturer of the network element device. If authorized, it can participate in the communication method process provided in this application embodiment, such as replying with a first DHCP response message after receiving a first DHCP request message.
[0198] Using the technical solution provided in this application embodiment, in the case of multiple DHCP server conflicts in the un-deployed network, no network engineer intervention is required. The network can complete DHCP server backoff, ensuring that there is only one gateway in the network, realizing automatic network formation at startup in the case of multiple gateways, and enabling users to start the network with zero configuration.
[0199] Corresponding to the above communication method, embodiments of this application also provide a communication device, such as... Figure 15 As shown, a first network device is applied within a local area network, the device comprising:
[0200] Election unit 1501 is used to elect a master device with other network devices in the local area network, excluding the first network device.
[0201] The control unit 1502 is configured to, if the first network device is elected as the master device and the first network device has been configured with DHCP server function and enabled DHCP server backoff function, enable DHCP client function and send a first DHCP request message; if other network devices are elected as slave devices and other network devices have been configured with DHCP server function and enabled DHCP server backoff function, disable DHCP server function and disable DHCP server backoff function; 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 made effective and the DHCP server function is disabled.
[0202] In some embodiments, the control unit 1502 can also be used to activate 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 can also be used to resend the first DHCP request message after the DHCP server function is enabled.
[0204] In some embodiments, the control unit 1502 can also be used to activate 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 master device and the first network device has been configured with DHCP server function but has not enabled DHCP server backoff function.
[0205] In some embodiments, the control unit 1502 can also be configured to disable 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 configured the DHCP server function and enabled the DHCP server backoff function, and if other network devices are elected as master devices and other network devices have configured the DHCP server function and enabled the DHCP server backoff function, enable the DHCP client function and send a second DHCP request message.
[0206] In some embodiments, the control unit 1502 can also be used to delete the first dynamic IP address when the aging timer corresponding to the first dynamic IP address expires after the first dynamic IP address carried in the first DHCP response message is activated and the DHCP server function is turned off; activate 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 configured to periodically broadcast a first scan message if the first network device is elected as the master device; periodically receive a second scan message sent by a second network device, where the second network device is the master device in the local area network, if the first network device is elected as the slave device; and if no second scan message is 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 besides 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 a third scan message is received from the third network device, and the priority of the third network device is higher than that 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 in the third scan message.
[0209] In some embodiments, the election unit 1501 may be specifically used for:
[0210] The system periodically broadcasts a first election message; within a second preset time period, it receives target messages sent by other network devices in the local area network, which are either second election messages or second scan messages; if the priority of 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 other network devices is determined according to the information carried in the target message; if the priority of 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 in this application embodiment, a master device election is performed among network devices within a local area network (LAN), with each network device determining itself as either a master or a slave device. For a network device, if it is a slave device and has configured a DHCP server function with DHCP server backoff enabled, then the network device disables both the DHCP server function and the DHCP server backoff function. The network device does not perform the DHCP server function, meaning it is not responsible for assigning IP addresses to DHCP clients, and it does not need to back off other DHCP servers within the LAN. If the network device is a master device and has configured a DHCP server function with DHCP server backoff enabled, then the network device enables the DHCP client function to detect the presence of a DHCP server within the LAN. When a DHCP server is detected, and a first DHCP response message corresponding to a first DHCP request message is received, the DHCP server function is disabled, and it is not responsible for assigning IP addresses to DHCP clients, thus achieving backoff from other DHCP servers within the LAN.
[0212] In this embodiment, network devices within a local area network (LAN) utilize the DHCP server backoff function to ensure that, in the case of multiple gateways, only one device in the LAN provides the DHCP server function. This avoids the problem of different network segments or IP address conflicts for IP addresses obtained by network devices within the LAN, enabling automatic network formation upon startup in the case of multiple gateways and zero-configuration startup for users.
[0213] Corresponding to the above communication method, embodiments of this application also provide 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, which in turn cause the processor 1601 to implement any of the aforementioned communication methods.
[0214] Machine-readable storage media may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the machine-readable storage medium may also be at least one storage device located remotely from the aforementioned 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, or discrete hardware components.
[0216] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements any of the above-described communication methods.
[0217] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to perform any of the above-described communication methods.
[0218] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. 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. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. 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 integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)).
[0219] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.
[0220] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments for apparatus, network devices, storage media, and program products are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0221] The above are merely preferred embodiments of this application and are not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A communication method, characterized in that, The method, applied to a first network device within a local area network, includes: A master device election is performed with other network devices within the local area network, excluding the first network device. If the first network device is elected as the master device, and the first network device has configured the DHCP server function and enabled the DHCP server backoff function, then the DHCP client function is enabled and the first DHCP request message is sent. If the other network device is elected as the slave device, and the other network device has configured the DHCP server function and enabled the DHCP server backoff function, then 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 made effective, and the DHCP server function is turned off. The method further includes: If the first network device is elected as the master device, it will periodically broadcast the first scan message; If the first network device is elected as the master device and receives a third scan 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. 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 in the third scan message.
2. The method according to claim 1, characterized in that, The method further includes: If the first DHCP response message is not received, the static IP address configured in the first network device will be activated, and the DHCP server function will be 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, characterized in that, The method further includes: If the first network device is elected as the master device, and the first network device has configured DHCP server function but has not enabled DHCP server backoff function, then the static IP address configured in the first network device will take effect, and the DHCP server function will be enabled.
5. The method according to claim 1, characterized in that, After activating 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 expires, the first dynamic IP address is deleted. The static IP address configured in the first network device is activated, and the DHCP server function is enabled.
6. The method according to claim 1, characterized in that, The method further includes: If the first network device is elected as the slave device, and the first network device has configured the DHCP server function and enabled the DHCP server backoff function, then the DHCP server function and the DHCP server backoff function are disabled. If the other network device is elected as the master device, and the other network device has configured the DHCP server function and enabled the DHCP server backoff function, then the other network device enables the DHCP client function and sends a second DHCP request message.
7. The method according to claim 1, characterized in that, The method further includes: If the first network device is elected as the slave device, it periodically receives the second scan message sent by the second network device, which is the master device in the local area network; if the second scan message is not received within a first preset time period, the step of electing a master device with other network devices in the local area network other than the first network device is re-executed.
8. The method according to claim 7, characterized in that, The process of electing a master device with other network devices within the local area network besides the first network device includes: Periodically broadcast the first election message; Within a second preset time period, a target message sent by the other network device is received, wherein the target message is a second election message or a second scan message; If the priority of the other network devices is higher than that of the first network device, then 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, then the first network device is determined to be the master device.
9. A communication device, characterized in that, A first network device applied within a local area network, the device comprising: An election unit is used to elect a master device among other network devices in the local area network, excluding the first network device. The control unit is configured to, if the first network device is elected as the master device and the first network device has configured the DHCP server function and enabled the DHCP server backoff function, enable the DHCP client function and send a first DHCP request message; if the other network device is elected as the slave device and the other network device has configured the DHCP server function and enabled the DHCP server backoff function, disable the DHCP server function and disable the DHCP server backoff function; if a first DHCP response message corresponding to the first DHCP request message is received, activate the first dynamic IP address carried in the first DHCP response message and disable the DHCP server function. The control unit is also used for: If the first network device is elected as the master device, it will periodically broadcast the first scan message; If the first network device is elected as the master device and receives a third scan 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. 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 in the third scan message.
Citation Information
Patent Citations
Method for implementing DHCP service redundant and DHCP server
CN101090309A
Master-slave switching method, network device and DHCP server
CN102404146A