CN-122001835-A - Port allocation method and device, storage medium and electronic equipment
Abstract
The invention provides a port allocation method and device, a storage medium and electronic equipment, wherein the port allocation method comprises the steps of respectively obtaining network port state information of each network port on a router, wherein the network port state information at least comprises connection state information, and the connection state information is used for indicating whether the network port is connected with a network cable. And according to the network port state information, determining the corresponding relation between different ports of the CPU of the router and different network ports on the router. And distributing the ports of the CPU to different network ports on the router according to the corresponding relation. According to the port allocation method provided by the embodiment of the invention, the corresponding relation between different network ports and different ports of the CPU can be dynamically adjusted according to the network port state information of different network ports, so that the bandwidth resources of the CPU ports are better utilized.
Inventors
- ZHENG YUANZHENG
- CHEN BO
- HAN JIAYAN
Assignees
- 北京小米移动软件有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20241108
Claims (10)
- 1. A port allocation method is characterized in that the method is applied to a router, a Central Processing Unit (CPU) of the router is provided with at least two ports, and the method comprises the following steps: The network port state information of each network port on the router is respectively obtained, wherein the network port state information at least comprises connection state information, and the connection state information is used for indicating whether the network port is connected with a network cable or not; According to the network port state information, determining the corresponding relation between different ports of the CPU and different network ports on the router; And distributing the ports of the CPU to different network ports on the router according to the corresponding relation.
- 2. The method according to claim 1, wherein determining the correspondence between different ports of the CPU and different ports on the router according to the port status information includes: When the number of the target network ports connected with the network cable is determined to be smaller than or equal to the number of the ports of the CPU according to the connection state information, the number of the target network ports corresponding to the ports of each CPU is determined to be smaller than or equal to 1.
- 3. The method of claim 1, wherein when the connection status information indicates that a portal is connected with a network cable, the portal status information further comprises at least one of: The negotiation rate information is used for indicating the highest data transmission rate obtained by negotiation of the router and equipment connected with the network port; The network port type information comprises a wide area network port and a local area network port.
- 4. The method according to claim 3, wherein determining the correspondence between different ports of the CPU and different ports on the router according to the port status information includes: When the number of the target network ports connected with the network cable is determined to be larger than the number of the ports of the CPU according to the connection state information, the corresponding relation between different ports of the CPU and different network ports on the router is determined according to the negotiation rate information and/or the network port type information corresponding to each target network port.
- 5. The method according to claim 1, wherein the method further comprises: In response to determining that the network port state of at least one network port is changed, respectively updating the network port state information of the at least one network port to obtain updated network port state information; And determining the corresponding relation between different ports of the CPU and different network ports on the router according to the network port state information, wherein the method comprises the following steps: And according to the updated network port state information, adjusting the corresponding relation between different ports of the CPU and different network ports on the router.
- 6. The method of claim 1, wherein the obtaining the port status information of each port on the router includes: and responding to the power-on startup of the router, and respectively acquiring the network port state information of each network port on the router.
- 7. A port allocation device is characterized in that the device is applied to a router, a CPU of the router is provided with at least two ports, and the device comprises: The network port state information acquisition module is used for respectively acquiring network port state information of each network port on the router, wherein the network port state information at least comprises connection state information which is used for indicating whether the network port is connected with a network cable or not; The corresponding relation determining module is used for determining the corresponding relation between different ports of the CPU and different network ports on the router according to the network port state information; And the port allocation module is used for allocating the ports of the CPU to different network ports on the router according to the corresponding relation.
- 8. The apparatus of claim 7, wherein the correspondence determining module, when configured to determine correspondence between different ports of the CPU and different ports on the router according to the port status information, includes: When the number of the target network ports connected with the network cable is determined to be smaller than or equal to the number of the ports of the CPU according to the connection state information, the number of the target network ports corresponding to the ports of each CPU is determined to be smaller than or equal to 1.
- 9. A computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of the method of any of claims 1-6.
- 10. An electronic device, comprising: A processor; A memory for storing processor-executable instructions; wherein the processor is configured for performing the steps of the method of any of claims 1-6.
Description
Port allocation method and device, storage medium and electronic equipment Technical Field The technical scheme of the present disclosure relates to the technical field of wired communication, and in particular, to a method and apparatus for port allocation, a storage medium, and an electronic device. Background Routers typically have multiple ports for connecting devices, such as computers, printers, etc., in external or internal networks via a network cable. Taking a connection computer as an example, after the router receives a data packet sent by the computer through the network port, the data packet needs to be transmitted to a CPU (Central Processing Unit ) of the router for processing. Fig. 1 illustrates a schematic structure of a router, where, as shown in fig. 1, a CPU of the router has two ports, each of which may have a bandwidth of 2.5G, for example, and the router has 4 ports. In the related technical solution, the correspondence between the ports of the router CPU and the network ports of the router is preset, and taking fig. 1 as an example, it may be preset that the port 1 corresponds to the network port 1 and the network port 2, and the port 2 corresponds to the network port 3 and the network port 4. That is, the data packets received based on the ports 1 and 2 are transmitted to the CPU through the port 1, and the data packets received based on the ports 3 and 4 are transmitted to the CPU through the port 2. In this case, when the network port 3 and the network port 4 are not connected to the device, and the sum of negotiation rates of the devices connected to the network port 1 and the network port 2 is larger than the bandwidth of the port 1, there may be a case where the packet transmission is delayed or the packet is lost. Disclosure of Invention In view of this, embodiments of the present disclosure provide a method and apparatus for port allocation, a storage medium, and an electronic device. According to a first aspect of the present disclosure, there is provided a port allocation method, the method comprising: The network port state information of each network port on the router is respectively obtained, wherein the network port state information at least comprises connection state information, and the connection state information is used for indicating whether the network port is connected with a network cable or not; According to the network port state information, determining the corresponding relation between different ports of the CPU and different network ports on the router; And distributing the ports of the CPU to different network ports on the router according to the corresponding relation. In combination with any one of the embodiments provided in the present disclosure, the determining, according to the network port status information, a correspondence between different ports of the CPU and different network ports on the router includes: When the number of the target network ports connected with the network cable is determined to be smaller than or equal to the number of the ports of the CPU according to the connection state information, the number of the target network ports corresponding to the ports of each CPU is determined to be smaller than or equal to 1. In combination with any one of the embodiments provided in the present disclosure, when the connection status information indicates that the network port is connected with a network cable, the network port status information further includes at least one of the following: The negotiation rate information is used for indicating the highest data transmission rate obtained by negotiation of the router and equipment connected with the network port; The network port type information comprises a wide area network port and a local area network port. In combination with any one of the embodiments provided in the present disclosure, the determining, according to the network port status information, a correspondence between different ports of the CPU and different network ports on the router includes: When the number of the target network ports connected with the network cable is determined to be larger than the number of the ports of the CPU according to the connection state information, the corresponding relation between different ports of the CPU and different network ports on the router is determined according to the negotiation rate information and/or the network port type information corresponding to each target network port. In connection with any one of the embodiments provided by the present disclosure, the method further comprises: In response to determining that the network port state of at least one network port is changed, respectively updating the network port state information of the at least one network port to obtain updated network port state information; And determining the corresponding relation between different ports of the CPU and different network ports on the router according to the network port sta