WO2013177891A1 - 一种分配公网地址的方法及装置 - Google Patents

一种分配公网地址的方法及装置 Download PDF

Info

Publication number
WO2013177891A1
WO2013177891A1 PCT/CN2012/083177 CN2012083177W WO2013177891A1 WO 2013177891 A1 WO2013177891 A1 WO 2013177891A1 CN 2012083177 W CN2012083177 W CN 2012083177W WO 2013177891 A1 WO2013177891 A1 WO 2013177891A1
Authority
WO
WIPO (PCT)
Prior art keywords
port
address
public network
ports
user equipment
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2012/083177
Other languages
English (en)
French (fr)
Inventor
郭英辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to EP12823122.2A priority Critical patent/EP2683138A1/en
Publication of WO2013177891A1 publication Critical patent/WO2013177891A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2517Translation of Internet protocol [IP] addresses using port numbers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2557Translation policies or rules
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2514Translation of Internet protocol [IP] addresses between local and global IP addresses

Definitions

  • the present invention relates to the field of communications, and in particular, to a method and an apparatus for allocating a public network address.
  • IP Internet Protocol
  • the English full name is Internet Protocol Version 6, and the English abbreviation is IPv6.
  • Technology and network address translation English name is Network Address Translation, English abbreviation is NAT).
  • IPv6 Internet Protocol Version 4
  • IPv4 Internet Protocol Version 4
  • NAT technology is the main choice for solving the shortage of IP addresses due to user perception, technology maturity and ease of deployment.
  • NAPT Network Address and Port Translation
  • the method is specifically: in the local area network, each private network user device occupies an internal address and an internal port number, and the internal address is a private network address, and the internal port number is a private network port number, when the private network user equipment To communicate with the external network, the NAT device translates the private network address and the private network port number into an idle external address and an external port number.
  • the free external address is the public network address, and the external port number is public.
  • the network port number is used to implement normal communication between the private network user equipment of the local area network and the external network.
  • the NAT technology can enable multiple devices to share a common network address, so as to better solve the problem of shortage of public IP addresses.
  • the NAT device applies for a new public network port for the private network user equipment, resulting in a low connection rate, and for the NAT device, The usage log of each port assigned to the user device of the private network is recorded, which results in complicated management.
  • the connection established between the private network user equipment and the external network device can be established through the Transmission Control Protocol (English called Transmission Control Protocol, abbreviated as TCP).
  • the prior art also provides a port range.
  • the NAT device selects an idle public network address and a public network port block to allocate to the private network user equipment.
  • the public network port block is composed of a continuous idle port in the public network port corresponding to the public network address. If the private network user equipment is in communication, the private network port block is allocated to the public network port block of the private network user equipment. All ports are occupied. If you need to use the public network port, you need to apply again. However, because the same private network user device must use the same public network address, when there is no free port in the public network port corresponding to the public network address.
  • Embodiments of the present invention provide a method and an apparatus for allocating a public network address, which are used to establish a connection between a private network device and a public network device after the public network user address is assigned to the private network user device. The probability of not being assigned to the public network port.
  • a method for allocating a public network address includes: receiving a first request packet sent by a private network user equipment, where the first request packet is used by the private network user equipment and the public The network device in the network establishes a connection;
  • the first public network IP address is allocated to the private network user device from the public network address pool, and the port corresponding to the first public network IP address is configured.
  • the second port set includes at least one port
  • the first public network IP address corresponding to the first port set has an idle port
  • the first public network IP address Allocating a first set of free ports to the private network user equipment in the idle port of the corresponding first port set, where the first idle port set includes at least one port;
  • the second port set corresponding to the first public network IP address When it is determined that the ports in the first set of free ports are occupied, and the second port set corresponding to the first public network IP address has a free port, the second port corresponding to the first public network IP address is set. Assigning a second to the private network user equipment in the idle port A set of free ports, the second set of free ports comprising at least one port.
  • a method for allocating a public network address includes: receiving a first request packet sent by a private network user equipment, where the first request packet is used by the private network user equipment and The network device in the public network establishes a connection;
  • the first public network IP address is allocated to the private network user equipment from the public network address pool, and the first public network IP address is corresponding to the first public network IP address.
  • Allocating a first set of free ports for the private network user equipment, the first set of free ports includes at least one port, and storing the ports in the first set of free ports in the first port set.
  • the first port set corresponds to the first public network IP address, and the number of ports in the first port set is not greater than the first threshold;
  • the private network user equipment is Allocating a second set of free ports, the second set of free ports includes at least one port, and storing the ports in the second set of free ports in the second set of ports, where the second set of ports corresponds to the first public port a network IP address, where the number of the ports in the second port set is not greater than the second threshold, and the sum of the first threshold value and the second threshold value is not greater than the first public network IP address.
  • the total number of ports is Allocating a second set of free ports, the second set of free ports includes at least one port, and storing the ports in the second set of free ports in the second set of ports, where the second set of ports corresponds to the first public port a network IP address, where the number of the ports in the second port set is not greater than the second threshold, and the sum of the first threshold value and the second threshold value is not greater than the first public network IP address.
  • an apparatus for allocating a public network address includes: a first receiving unit, configured to receive a first request packet sent by a private network user equipment, where the first request packet is used by The private network user equipment establishes a connection with the network equipment in the public network;
  • a first allocation unit configured to allocate a first public network IP address to the private network user equipment from the public network address pool, when the public network user equipment is not assigned any public network IP address, the first The port corresponding to the public network IP address is divided into a first port set and a second port set, the second port set includes at least one port, and the first port set corresponding to the first public network IP address has an idle port. Allocating a first set of free ports to the private network user equipment in the idle port of the first port set corresponding to the first public network IP address, where the first set of free ports includes at least one port;
  • a second allocation unit configured to: when it is determined that the ports in the first set of free ports are occupied, and the second port set corresponding to the first public network IP address has a free port, Allocating a second set of free ports to the private network user equipment from the idle port of the second port set corresponding to the first public network IP address, where the second set of free port ports includes at least one port.
  • an apparatus for allocating a public network address includes: a third receiving unit, configured to receive a first request packet sent by a private network user equipment, where the first request packet is used by The private network user equipment establishes a connection with the network equipment in the public network;
  • a fourth allocation unit configured to allocate a first public IP address to the private network user equipment from the public network address pool when it is determined that the public network user equipment is not assigned any public network IP address, and Allocating a first set of free ports to the private network user equipment in the idle port corresponding to the first public network IP address, where the first set of free port ports includes at least one port, and depositing the port in the first set of free port ports In the first port set, the first port set corresponds to the first public network IP address, and the number of ports in the first port set is not greater than a first threshold;
  • a fifth allocating unit configured to: when it is determined that a port that is stored in the first port set from the first set of free ports is occupied, and that a port exists in a port corresponding to the first public network IP address, Allocating a second set of free ports for the private network user equipment, where the second set of free ports includes at least one port, and storing the ports in the second set of free ports into the second port set, the second port The set corresponds to the first public network
  • the IP address, the number of the ports in the second port set is not greater than the second threshold, and the sum of the first threshold and the second threshold is not greater than the first public IP address.
  • a method and an apparatus for allocating a public network address are configured by dividing a port corresponding to a public network IP address into a first port set and a second port set, and for the private network that applies for the public network IP address for the first time.
  • the network device allocates a port to the private network device from the first port set of the assigned public network IP address after the public network IP address is allocated, and when the private network device newly establishes a connection with the public network device, And assigning a port to the private network device from the second port set of the allocated public network IP address, by using the second port set of the allocated public network IP address for the private network
  • the port assignment is made when the device is connected to the public network device.
  • a method and an apparatus for allocating a public network address are limited to a first port by assigning a port of a public network IP address to a port of a private network device that first applies for a public network IP address.
  • the port of the second threshold value of the port of the public network IP address is reserved for the port allocation when the private network device and the public network device are newly connected, so that the private When a new network device is connected to a public network device, the new connection between the private network user and the public network device is not allocated to the public network port.
  • FIG. 1 is a schematic flowchart of a method for allocating a public network address according to an embodiment of the present invention
  • FIG. 2 is a schematic structural diagram of a public network IP address and a corresponding port thereof according to an embodiment of the present invention
  • FIG. 3 is a schematic flowchart of a method for allocating a public network address according to an embodiment of the present invention.
  • FIG. 4 is a schematic flowchart of a method for allocating a public network address according to an embodiment of the present invention.
  • FIG. 6 is a schematic flowchart of a method for allocating a public network address according to an embodiment of the present invention.
  • FIG. 7 is a schematic structural diagram of an apparatus for allocating a public network address according to an embodiment of the present invention.
  • FIG. 8 is a schematic structural diagram of an apparatus for allocating a public network address according to an embodiment of the present invention.
  • FIG. 9 is a schematic structural diagram of an apparatus for allocating a public network address according to an embodiment of the present invention.
  • FIG. 10 is a schematic structural diagram 4 of an apparatus for allocating a public network address according to an embodiment of the present invention.
  • an embodiment of the present invention provides a method for allocating a public network address, including the following content.
  • the first request message is sent by the user equipment of the private network to establish a connection with the network device in the public network.
  • the connection may be a TCP connection or a UDP connection or an SSL connection or a TSL connection.
  • the first request message may be a TCP connection establishment request message or a UDP connection establishment request message or an SSL connection connection request message or
  • the TSL establishes a connection request message, which is not specifically limited in the embodiment of the present invention.
  • the first public network IP address is allocated to the private network user equipment from the public network address pool, where the first public network IP address is corresponding.
  • the port is divided into a first port set and a second port set, the second port set includes at least one port, and the first port set corresponding to the first public network IP address has an idle port, from the first public network
  • the private network user equipment is allocated a first idle port set in the idle port of the first port set corresponding to the IP address, and the first idle port set includes at least one port.
  • the first port set corresponding to the first public network IP address is a port set for assigning a port to a private network user device that has not assigned any public network IP address
  • the second port set corresponding to the first public network IP address is The port collection of the port is assigned to the private network device that has been assigned the public network IP address.
  • the structure of the port corresponding to the first public network IP address is as shown in Figure 2.
  • 10.0.0.1: 4567 is used as the private network IP address and the private network port number, and 128.0.0.1 is taken as the first.
  • the public network IP address is used as an example for description.
  • the port 0 65535 corresponding to the first public network IP address 128.0.0.1 is divided into a first port set and a second port set, where the IP address 128.0.0.1 corresponds to the port of the first port set.
  • the range is 0 50000
  • the port range corresponding to the second port set corresponding to the IP address 128.0.0.1 is 50001 65535.
  • the first request packet carries the private network IP address 10.0.0.1, and is determined not to be the private network user according to the private network IP address 10.0.0.1.
  • the first public network IP address 128.0.0.1 is allocated to the private network user equipment from the public network address pool, and corresponds to the first public network IP address 128.0.0.1.
  • the private port user equipment is allocated a first set of free ports in the idle port of the first port set, where the first set of free ports includes at least one port, for example, the port range of the first set of free ports is 3812 ⁇ 4812 .
  • the method for determining that the public network IP address is not assigned to the private network user equipment may be: searching for a database storing the private network user table, where the private network user table information stores the private network IP address assigned If the private network user table of the private network IP address of the private network user device is not found in the database, it is determined that the public network user device is not allocated a public network. IP address.
  • the second port set corresponding to the first public network IP address is used.
  • the private network user equipment is allocated a second set of free ports in the set of idle ports, and the second set of free ports includes at least one port.
  • the port in the first idle port set is used, the first The fact that the ports in the set of idle ports are occupied means that the ports in the first set of free ports are used by the private network user equipment.
  • the method further includes receiving a second request packet sent by the private network user equipment, triggering occupation of a port in the first idle port set.
  • the second request message is used to establish a connection between the private network user equipment and the network device in the public network; or a detection timer is started, and when the detection timer expires, the triggering is performed.
  • the port occupancy in a set of free ports is detected.
  • the method further includes:
  • the port corresponding to the second public network IP address is divided into a port set and a second port set, where the first port set of the second public network IP address has a free port, the private network user device is assigned a third public network IP address, and the third public network IP address
  • the corresponding port is divided into a first port set and a second port set, and the second port set corresponding to the third public network IP address has an idle port, and the second port set corresponding to the third public network IP address is idle.
  • the third private port set is allocated to the private network user equipment in the port, and the third free port set includes at least one port.
  • the third public network IP address may also be the first public network IP address, and the second public network IP address corresponds to When the second port set has a free port, the third public network IP address may also be the second public network IP address.
  • the advantage of this is that when other private network user devices need to apply for a public network IP address, if there is no free port in the first port set corresponding to all public network IP addresses in the public network address pool at this time, The other private network user equipment allocates a public network IP address, the second port set of the allocated public network IP address has an idle port, and the second port set from the allocated public network IP address is the other private network.
  • the user equipment is assigned a public network port. This ensures that the private network user equipment is assigned a public network IP address and port in time to ensure that the private network user equipment establishes communication with the network equipment in the public network.
  • the method further includes:
  • the device receives an offline notification message of the private network user equipment, and collect the first idle port set and the second idle port set.
  • the device sends a offline notification message carrying the private network IP address, and after receiving the offline notification, releasing
  • the public network IP address and the public network port of the private network user equipment are allocated, so that the public network IP address resource can be reassigned to other private network user equipments, thereby fully utilizing the public network IP address, saving Resources. Recycling the first set of free ports and the second set of free ports means clearing the occupied flags of the ports in the first set of free ports and the ports in the second set of free ports, such that It can be reassigned to other private network user devices.
  • the third set of free ports is allocated to the private network user equipment, the third set of free ports needs to be recovered.
  • the method further includes:
  • the public network IP address resource can be redistributed to other private network user equipments, so that the public network IP address is fully utilized, resources are saved, and the first idle port set and the first The two sets of free ports are used to clear the occupied flags of the ports in the first set of free ports and the ports in the second set of free ports, so that they can be reassigned to other private network user equipments.
  • the third idle port set needs to be reclaimed.
  • the method further includes:
  • the first idle port set and the second idle port set are recovered.
  • the public network IP address and the public network port allocated to the private network user device are released. Therefore, the public network IP address resource can be redistributed to other private network user equipments, so that the public network IP address is fully utilized, resources are saved, and the first idle port set and the first The two idle port sets refer to the ports in the first set of free ports and the ports in the second set of free ports. The occupancy flag is cleared so that it can be reassigned to other private network user devices. When the third set of free ports is allocated to the private network user equipment, the third set of free ports also needs to be reclaimed.
  • the method further includes:
  • the recovery of the port in the second set of idle ports does not need to wait until the private network user sends the offline notification, and the second can be recovered as long as it is determined that the ports in the second set of free ports are not occupied.
  • the port in the set of the idle port is configured to speed up the recovery of the idle port in the second set of free ports, and further improve the utilization of the port in the second port set corresponding to the first public network IP address, and improve the private network.
  • the port corresponding to the public network IP address is divided into the first port set and the second port set, and the private network that applies for the public network IP address for the first time is obtained.
  • the device is configured to allocate a port to the private network device. Allocating a port from the second port set of the allocated public network IP address to the private network device, such that the second port set of the allocated public network IP address is reserved for the private network device.
  • the port assignment is the same as that of the public network device. This reduces the probability that the new network connection between the private network user and the public network device cannot be allocated to the public network port.
  • an embodiment of the present invention provides another method for allocating a public network address, including the following content.
  • 501 Receive a first request message sent by a user equipment of a private network, where the first request message is used to establish a connection between the user equipment of the private network and the network equipment in the public network.
  • the connection may be a TCP connection or a UDP connection or an SSL connection or a TSL connection.
  • the first request message may be a TCP connection establishment request message or a UDP connection establishment request message or an SSL connection connection request message or
  • the TSL establishes a connection request message, which is not specifically limited in the embodiment of the present invention.
  • the first set of free ports includes at least one port, and the port in the first set of free ports is stored in the first port set, and the first port set corresponds to the first public network IP address, where the first The number of ports in a port set is not greater than the first threshold.
  • 10.0.0.1: 4567 is used as the private network IP address and the private network port number, and 128.0.0.1 is taken as the first.
  • the public network IP address is used as an example for description.
  • the private network IP address 10.0.0.1 determines that the public network user equipment is not assigned any public network IP address
  • the first public network is allocated to the private network user equipment from the public network address pool.
  • An IP address of 128.0.0.1, and a first set of free ports is allocated to the private network user equipment from the idle port corresponding to the first public network IP address 128.0.0.1, for example, the port range in the first idle port set
  • the port of the first set of free ports is stored in the first port set, and the number of ports in the first port set is not greater than the first threshold, that is, to the private network.
  • the IP address 10.0.0.1 is assigned to the public network IP address. After the number of ports in the first port set corresponding to the public network IP address is not greater than the first threshold, the public network user equipment is assigned a public IP address.
  • An address, where the port stored in the first port set is a port allocated for a private network user device that does not have any public network IP address assigned.
  • the method for determining that the public network IP address is not assigned to the private network user equipment may be: searching for a database storing the private network user table, where the private network user table information stores the private network IP address assigned If the private network user table of the private network IP address of the private network user device is not found in the database, it is determined that the public network user device is not allocated a public network. IP address.
  • the network user equipment allocates a second set of free ports, the second set of free ports includes at least one port, and the port in the second set of free ports is stored in the second port set, where the second port set corresponds to the The first public network IP address, the number of the ports in the second port set is not greater than the second threshold, and the sum of the first threshold and the second threshold is not greater than the first public network All ports corresponding to the IP address Quantity.
  • the first threshold is used to define a maximum value of the number of ports in the first port set corresponding to the first public network IP address
  • the second threshold is used to define the first public network IP address.
  • the maximum number of ports in the second port set Exemplarily, when it is determined that the ports stored in the first port set from the first idle port set 3812 ⁇ 4812 are occupied, and the free port exists in the port corresponding to the first public network IP address Allocating a second set of free ports, such as 50678 ⁇ 60678, to the private network user equipment, where the second set of free ports includes at least one port, and storing the port in the second set of free ports into the first
  • the second port set of the public network IP address, and the number of the ports in the second port set is not greater than the second threshold, that is, the first public network IP address is to be allocated to the private network user equipment again.
  • the port After the port number of the second port set corresponding to the first public network IP address is not greater than the second threshold, the port is allocated from the idle port corresponding to the first public network IP address.
  • the second idle port is sent to the private network user equipment, and the sum of the first threshold value and the second threshold value is not greater than the total number of ports corresponding to the first public network IP address.
  • the method further includes receiving a second request packet sent by the private network user equipment, triggering occupation of a port in the first idle port set.
  • the second request message is used to establish a connection between the private network user equipment and the network device in the public network; or a detection timer is started, and when the detection timer expires, the triggering is performed.
  • the port occupancy in a set of free ports is detected.
  • the method further includes:
  • the first port set corresponding to the second public network IP address is determined.
  • the number of ports in the network is less than the third threshold, and the third public network IP address is allocated to the private network user equipment, and the private network user equipment is allocated the third in the idle port corresponding to the third public network IP address.
  • a set of idle ports, the third set of free ports includes at least one port, and the port in the third set of free ports is stored in the second port set, and the second port set corresponds to the third public network IP address.
  • the number of ports in the second port set is not greater than a fourth threshold.
  • the third threshold is used to define the first corresponding to the second public network IP address
  • the maximum value of the port in the port set, the fourth threshold value being used to define a maximum value of the port in the second port set corresponding to the third public network IP address.
  • the advantage of this is that when the private network user equipment needs to apply for the public network IP address, the number of ports in the first port set corresponding to each public network IP address in the public network address pool has reached the threshold. At this time, the other private network user equipment is assigned a public network IP address, the allocated public network IP address has an idle port, and the number of ports in the second port set corresponding to the allocated public network IP address is not The threshold value is reached, and the public network port is allocated to the other private network user equipment from the idle port of the public network IP address. This ensures that the public network IP address and port are allocated to the private network user equipment in time. The private network user equipment establishes communication with the network equipment in the public network in time.
  • the method further includes:
  • Receive an offline notification message of the private network user equipment and collect, from the first idle port set, a port in a first port set corresponding to the first public network IP address, and a second idle The port set is stored in a port corresponding to the second port set of the first public network IP address.
  • an offline notification message carrying the private network IP address is sent, and after receiving the offline notification, the release is allocated to the The public network IP address of the private network user device and the public network port, so that the public network IP address resource can be redistributed to other private network user equipments. In this way, the public network IP address is fully utilized, which saves resources.
  • the method further includes:
  • the recovery is performed from the first idle port set to the corresponding first public a port in the first port set of the network IP address, and reclaiming the port from the second set of free ports to the port in the second port set corresponding to the first public network IP address, where the private network user equipment is
  • the third set of free ports is allocated, it is also required to recover the second set from the third set of free ports to the second corresponding to the third public network IP address.
  • the port in the port set is configured to facilitate the full utilization of the public network IP address and the port corresponding to the public network IP address, thereby improving resource utilization.
  • the method further includes:
  • the collection is saved from the first idle port set to the first public network IP address. a port in the first port set and a port from the second idle port set to a second port set corresponding to the first public network IP address.
  • the public network device sends the message to the private network user device within the preset time threshold, that is, the message carrying the private network address 10.0.0.1 is sent, Retrieving a port stored in the first port set corresponding to the first public network IP address from the first idle port set and storing from the second idle port set to a first corresponding public network IP address
  • the port in the two-port set when the third idle port set is allocated to the private network user equipment, the third storage port set needs to be reclaimed from the third free port set to the third public network IP address.
  • the port in the two-port set so that the public network IP address and the port corresponding to the public network IP address are fully utilized, thereby improving resource utilization.
  • the method further includes:
  • Retrieving the port stored in the second port set corresponding to the first public network IP address from the second set of idle ports does not need to wait for the private network user to send an offline notification, as long as it is determined from the second And storing, by the set of the idle port, the port in the second port set corresponding to the first public network IP address is not occupied, and recovering from the second idle port set to the first public network IP address.
  • a port in the second port set which can speed up the recovery of the port from the second idle port set to the second port set corresponding to the first public network IP address, thereby further improving the first public The probability of applying the port to the port set corresponding to the first public network IP address when the private network device is connected to the network device in the public network.
  • a method for allocating a public network address is provided by using an embodiment of the present invention.
  • the port is configured to allocate a port when the private network device and the public network device are newly connected, so that when the private network device newly establishes a connection with the public network device, the private network user is reduced.
  • the new connection with the public network device is not assigned the 4 rate of the public network port.
  • an embodiment of the present invention provides a device 70 for allocating a public network address, and the device 70 includes:
  • the first receiving unit 701 is configured to receive a first request message sent by the private network user equipment, where the first request message is used by the private network user equipment to establish a connection with the network device in the public network.
  • the first allocating unit 702 is configured to allocate, by the public network address pool, the first public network IP address to the private network user equipment, when the public network user equipment is not assigned any public network IP address,
  • the port corresponding to the public network IP address is divided into a first port set and a second port set, and the second port set includes at least one port, the first public network
  • the first port set corresponding to the IP address has an idle port, and the first idle port set is allocated to the private network user equipment from the idle port of the first port set corresponding to the first public network IP address, where the first idle port is set.
  • the port collection contains at least one port.
  • a second allocation unit 703 configured to: when it is determined that the ports in the first set of free ports are occupied, and the second port set corresponding to the first public network IP address has an idle port, from the first public network IP
  • the private network user equipment is allocated a second set of free ports in the idle port of the second port set corresponding to the address, and the second set of free ports includes at least one port.
  • the connection may be a TCP connection or a UDP connection or an SSL connection or a TSL connection.
  • the first request message may be a TCP connection establishment request message or a UDP connection establishment request message or an SSL connection connection request message or
  • the TSL establishes a connection request message, which is not specifically limited in the embodiment of the present invention.
  • the first port set corresponding to the first public network IP address is a port set for assigning a port to a private network user device that has not assigned any public network IP address
  • the second port set corresponding to the first public network IP address is Reassigning the port set of the port to the private network user device that has been assigned the public network IP address, and the structure of the port corresponding to the first public network IP address Schematic diagram, as shown in Figure 2.
  • 10.0.0.1: 4567 is used as the private network IP address and the private network port number, and 128.0.0.1 is taken as the first.
  • the public network IP address is used as an example for description.
  • the port 0-65535 corresponding to the first public network IP address 128.0.0.1 is divided into a first port set and a second port set, where the IP address 128.0.0.1 corresponds to the first port set.
  • the port range is 0 50000
  • the port range corresponding to the second port set corresponding to the IP address 128.0.0.1 is 50001 to 65535.
  • the first public network IP address 128.0.0.1 is allocated from the public network address pool to the private network user equipment, and Assigning, to the private network user equipment, the first set of free ports in the idle port of the first port set corresponding to the first public network IP address 128.0.0.1, where the first set of free ports includes at least one port, for example, The port range in the first set of free ports is 3812 ⁇ 4812.
  • the method for determining that the public network IP address is not assigned to the private network user equipment may be: searching for a database storing the private network user table, where the private network user table information stores the private network IP address assigned If the private network user table of the private network IP address of the private network user device is not found in the database, it is determined that the public network user device is not allocated a public network. IP address.
  • the port in the first idle port set is used, the first The fact that the ports in the set of idle ports are occupied means that the ports in the first set of free ports are used by the private network user equipment.
  • the second allocating unit 703 determines that the ports in the first free port set 3812-4812 are occupied, and the second port corresponding to the first public network IP address 128.0.0.1
  • the private network user equipment is allocated a second set of free ports, such as 50678 ⁇ 60678, from the idle port of the second port set corresponding to the first public network IP address 128.0.0.1.
  • the apparatus 70 further includes: The second receiving unit 704 is configured to receive a second request packet sent by the private network user equipment, and trigger detection on a port occupation status in the first idle port set, where the second request packet is used in the The private network user equipment establishes a connection with the network equipment in the public network.
  • the device further includes:
  • the first startup triggering unit 705 is configured to start a detection timer, and when the detection timer expires, trigger detection of a port occupancy condition in the first idle port set.
  • the device 70 further includes:
  • the third allocating unit 706 is configured to: when it is determined that the private network user device is not assigned any public network IP address, and the second public network IP address does not exist in the public network address pool, the second public network IP address The corresponding port is divided into a first port set and a second port set, and when the first port set corresponding to the second public network IP address has an idle port, the third public network IP address is allocated to the private network user equipment.
  • the port corresponding to the third public network IP address is divided into a first port set and a second port set, and the second port set corresponding to the third public network IP address has an idle port, and the third public network IP address corresponds to
  • the private network user equipment is allocated a third set of free ports in the idle port of the second port set, and the third set of free ports includes at least one port.
  • the third public network IP address may also be the first public network IP address, and the second public network IP address corresponds to When the second port set has a free port, the third public network IP address may also be the second public network IP address.
  • the advantage of this is that when other private network user devices need to apply for a public network IP address, if there is no free port in the first port set corresponding to all public network IP addresses in the public network address pool at this time, the first The third allocating unit 706 allocates a public network IP address to the other private network user equipment, the second port set of the allocated public network IP address has an idle port, and the second port from the allocated public network IP address A set of public network ports is allocated to the other private network user devices. This ensures that the public network user devices are assigned public network IP addresses and ports in time to ensure that the private network user equipment establishes communication with the network devices in the public network.
  • the apparatus 70 further includes:
  • the first reclaiming unit 707 is configured to receive the offline notification message of the private network user equipment, and recover the first idle port set and the second idle port set.
  • an offline notification message carrying the private network IP address is sent, and the first recycling unit 707 receives the location.
  • the public network IP address and the public network port allocated to the private network user equipment are released, so that the public network IP address resource can be redistributed to other private network user equipments, so that the full use
  • the public network IP address saves resources. Recycling the first set of free ports and the second set of free ports means clearing the occupied flags of the ports in the first set of free ports and the ports in the second set of free ports, such that It can be reassigned to other private network user devices.
  • the third set of free ports is allocated to the private network user equipment, the third set of free ports also needs to be reclaimed.
  • the device 70 further includes:
  • the second reclaiming unit 708 is configured to reclaim the first idle port set and the second idle port set if the packet sent by the private network user equipment is not received within a preset time threshold.
  • the second reclaiming unit 708 does not receive the packet carrying the private network IP address 10.0.0.1, the public network allocated to the private network user equipment is released.
  • the IP address and the public network port so that the public network IP address resource can be redistributed to other private network user equipments, so that the public network IP address is fully utilized, resources are saved, and the first idle is recovered.
  • the port set and the second set of free ports refer to clearing the occupied flag of the port in the first set of free ports and the port in the second set of free ports so that they can be reassigned to other private network users. device.
  • the third set of free ports is allocated to the private network user equipment, the third set of free ports needs to be reclaimed.
  • the device 70 further includes:
  • a third recovery unit 709 configured to: if the public network device sends no message to the private network user device within a preset time threshold, recover the first idle port set and the second idle Port collection.
  • the release is allocated to the private party.
  • the public network IP address and the public network port of the network user equipment so that the public network IP address resource can be redistributed to other private network user equipments, so that the public network IP address is fully utilized, and resources are saved. Recycling the first set of free ports and the second set of free ports means clearing the occupied flags of the ports in the first set of free ports and the ports in the second set of free ports, so that the Assigned to other private network user devices.
  • the third set of free ports is allocated to the private network user equipment, the third set of free ports needs to be recovered.
  • the device 70 further includes:
  • the fourth reclaiming unit 710 is configured to reclaim the second set of free ports when none of the ports in the second set of free ports are occupied.
  • the recovery of the port in the second set of free ports does not need to wait until the private network user sends an offline notification, and the fourth reclaiming unit 710 is determined as long as the ports in the second set of free ports are not occupied.
  • the port in the second set of free ports can be reclaimed, which can speed up the recovery of the free ports in the second set of free ports, and further improve the utilization of the ports in the second set of ports corresponding to the first public network IP address. Rate, the probability of applying the second public port address to the port from the first public network IP address when the private network user equipment is newly connected to the network device in the public network.
  • the foregoing units provided by the embodiments of the present invention may be combined into one or more.
  • the first receiving unit 701 and the second receiving unit 704 may be implemented by one or more physical interfaces
  • the unit 706 may be a processor
  • the first startup trigger unit 705 may be a timer
  • the fourth recycling unit 710 can also be a processor.
  • the one or more physical interfaces and processors cause the apparatus to perform the operations performed in this embodiment.
  • the device that allocates the public network address the device corresponding to the IP address of the public network is divided into the first port set and the second port set, and the private network that applies for the public network IP address for the first time.
  • the device is configured to allocate a port to the private network device. Allocating a port from the second port set of the allocated public network IP address to the private network device, so that Reserving a second port set of the public network IP address that is allocated for the port allocation when the private network device and the public network device are newly connected, thereby reducing the private network user and the public network device The probability that a new connection will not be assigned to a public network port.
  • the apparatus 90 for allocating a public network address provided by the embodiment of the present invention, as shown in FIG. 9, includes:
  • the third receiving unit 901 is configured to receive a first request message sent by the private network user equipment, where the first request message is used by the private network user equipment to establish a connection with the network device in the public network.
  • the fourth allocating unit 902 is configured to: when the public network user equipment is not assigned any public network IP address, allocate the first public network IP address to the private network user equipment from the public network address pool; Assigning, to the private port corresponding to the first public network IP address, the first set of free ports to the private network user equipment, where the first set of free ports includes at least one port, and storing the ports in the first set of free ports.
  • the first port set corresponds to the first public network IP address, and the number of ports in the first port set is not greater than the first threshold.
  • the fifth allocating unit 903 is configured to: when it is determined that the ports that are stored in the first port set from the first set of free ports are occupied, and that there are idle ports in all ports corresponding to the first public network IP address Allocating a second set of free ports to the private network user equipment, where the second set of free ports includes at least one port, and storing the ports in the second set of free ports in the second port set, where The two-port set corresponds to the first public network IP address, the number of the ports in the second port set is not greater than the second threshold, and the sum of the first threshold and the second threshold is not greater than The total number of ports corresponding to the first public network IP address.
  • 10.0.0.1: 4567 is used as the private network IP address and the private network port number, and 128.0.0.1 is taken as the first.
  • the public network IP address is used as an example for description.
  • the fourth allocation unit 902 determines that the public network user equipment is not assigned any public network IP address according to the private network IP address 10.0.0.1, the private network address pool is the private network.
  • the user equipment allocates a first public network IP address 128.0.0.1, and allocates a first idle port set to the private network user equipment from the idle port corresponding to the first public network IP address 128.0.0.1, for example, the first The port range of a free port set is 3812 ⁇ 4812.
  • the port in the first set of free ports in the first port set where the number of ports in the first port set is not greater than the first threshold, that is, if the private network IP address is to be 10.0.0.1
  • the public network IP address is allocated, it is determined that the number of the ports in the first port set corresponding to the public network IP address is not greater than the first threshold, and then the public network user device is assigned a public network IP address, where The port stored in the first port set is a port allocated for a private network user device that does not have any public network IP address assigned.
  • the fourth allocating unit 902 determines that the private network IP address is not allocated to the private network user equipment by searching the database of the private network user table, where the private network user table information is stored. The IP address of the private network user and the public network port of the public network IP address are allocated. If the private network user table storing the private network IP address of the private network user device is not found in the database, it is determined that the private network user table is not configured. The private network user equipment allocates a public network IP address.
  • the first threshold is used to define a maximum value of the number of ports in the first port set corresponding to the first public network IP address
  • the second threshold is used to define the first public network IP address.
  • the second port set of the first public network IP address corresponds to the second port set of the first public network IP address, and the number of ports in the second port set is not greater than a second threshold, that is, if the private network user equipment is to be allocated again
  • the number of ports in the second port set corresponding to the first public network IP address is not greater than the second threshold, and then the first public network IP address is corresponding to the first public network IP address.
  • Assigning the second idle port to the private network user equipment in the idle port, and the sum of the first threshold value and the second threshold value is not greater than the first public network IP address The number of ports.
  • the apparatus 90 further includes:
  • the fourth receiving unit 904 is configured to receive a second request packet sent by the private network user equipment, and trigger a terminal that is stored in the first port set from the first idle port set. The port occupancy situation is detected, and the second request message is used to establish a connection between the private network user equipment and the network equipment in the public network.
  • the second startup triggering unit 905 is configured to start a detection timer, and when the detection timer expires, triggering a port occupancy condition of the first port collection set to be stored in the first port set. Detection.
  • the device 90 further includes:
  • the sixth allocating unit 906 is configured to: when it is determined that the private network user device is not assigned any public network IP address, and the second public network IP address does not exist in the public network address pool, corresponding to the second public network IP address.
  • the number of ports in the first port set of the address is less than the third threshold, and the third public network IP address is allocated to the private network user equipment, and the private port corresponding to the third public network IP address is the private port.
  • the network user equipment allocates a third set of free ports, the third set of free ports includes at least one port, and the ports in the third set of free ports are stored in the second port set, where the second port set corresponds to the The third public network IP address, the number of ports in the second port set is not greater than the fourth threshold.
  • the advantage of this is that when the private network user equipment needs to apply for the public network IP address, the number of ports in the first port set corresponding to each public network IP address in the public network address pool has reached the threshold.
  • the sixth allocating unit 906 allocates a public network IP address to the other private network user equipment, the allocated public network IP address has an idle port, and corresponds to the second public network IP address.
  • the number of the ports in the port set does not reach the threshold, and the public network port is allocated to the other private network device from the free port of the public network IP address, so that the public network device can be allocated in time.
  • the IP address and port of the network ensure that the private network user equipment establishes communication with the network equipment in the public network in time.
  • the device 90 further includes:
  • a fifth reclaiming unit 907 configured to receive a offline notification message of the private network user equipment, and recover a port that is stored in the first port set corresponding to the first public network IP address from the first idle port set and And storing from the second set of free ports to a port in the second port set corresponding to the first public network IP address.
  • an offline notification message carrying the private network IP address is sent, and the fifth recycling unit 907 receives the offline notification.
  • the IP address and the public network port are used to make the public network IP address resource re-allocate to other private network user equipments. In this way, the public network IP address is fully utilized, which saves resources.
  • the device 90 further includes:
  • the sixth reclaiming unit 908 is configured to: if the content sent by the private network user equipment is not received within a preset time threshold, recovering from the first idle port set to the first public network a port in the first port set of the IP address and a port from the second set of free ports to a port in the second port set corresponding to the first public network IP address.
  • the sixth recovery unit 908 does not receive the packet carrying the private network IP address 10.0.0.1 within a preset time threshold, the recovery is performed from the first idle port set to the corresponding a port in the first port set of the first public network IP address, and recovering a port from the second idle port set to a second port set corresponding to the first public network IP address, where
  • the private network user equipment allocates the third set of free ports, it is also required to collect the ports from the third set of free ports to the second port set corresponding to the third public network IP address, so that it is convenient
  • the public network IP address and the port corresponding to the public network IP address are fully utilized, which improves resource utilization.
  • the device 90 further includes:
  • the seventh recovery unit 909 is configured to: if the packet sent by the public network device to the private network user device is not received within the preset time threshold, recovering from the first idle port set to the corresponding A port in a first port set of a public network IP address and a port in the second port set corresponding to the first public network IP address stored in the second free port set.
  • the packet carries the private network address 10.0.0.1. Transmitting, storing, from the first set of idle ports to a port in the first port set corresponding to the first public network IP address, and from the second idle port set to the corresponding first public The port in the second port set of the network IP address, when the third idle port set is allocated to the private network user equipment, the third free port set is also required to be reclaimed to correspond to the third public The port in the second port set of the network IP address, so that the public network IP address and the port corresponding to the public network IP address are fully utilized, thereby improving resource utilization.
  • the device 90 further includes:
  • the eighth reclaiming unit 910 is configured to reclaim the second idle port set when the port in the second port set corresponding to the first public network IP address is not occupied from the second idle port set. And storing the port in the second port set corresponding to the first public network IP address.
  • the recovering the port stored in the second port set corresponding to the first public network IP address from the second idle port set does not need to wait for the private network user to send an offline notification, as long as the eighth recycling unit 910.
  • the second idle port set is collected and corresponding to the corresponding a port in the second port set of the first public network IP address, which can speed up the recovery of the port from the second idle port set to the second port set corresponding to the first public network IP address, so that And further improving the utilization of the port of the first public network IP address, and increasing the connection between the private network user device and the network device in the public network, and applying from the port set corresponding to the first public network IP address The probability of the port.
  • the foregoing units provided by the embodiments of the present invention may be combined into one or more.
  • the third receiving unit 901 and the fourth receiving unit 904 may be implemented by one or more physical interfaces
  • the unit 906 may be a processor
  • the second activation trigger unit 905 may be a timer
  • the 910 can also be a processor.
  • the one or more physical interfaces and processors cause the apparatus to perform the operations performed in this embodiment.
  • the device for assigning a public network address by using the device for assigning a public network address, the number of ports allocated to the private network device that applies for the public network IP address for the first time is limited to the first threshold. And the port of the second threshold value of the port of the public network IP address is reserved for the port allocation when the private network device and the public network device are newly connected, so that the private network When a new connection is established between the device and the public network device, the new connection between the private network user and the public network device is less than the public network port.
  • the device for allocating a public network address may be a router supporting NAT function, a switch supporting NAT function, or a carrier-level address forwarding (English)
  • the full name is Carrier Grade NAT (abbreviated as CGN), or it is implemented by other network devices that support NAT.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Small-Scale Networks (AREA)

Abstract

本发明实施例提供了分配公网地址的方法,该方法包括:接收私网用户设备发送的第一请求报文;当确定没有为所述私网用户设备分配任何公网IP地址时,从公网地址池中为所述私网用户设备分配第一公网IP地址,从所述第一公网IP地址对应的第一端口集合的空闲端口中为所述私网用户设备分配第一空闲端口集合;当确定所述第一空闲端口集合中的端口都被占用,从所述第一公网IP地址对应的第二端口集合的空闲端口中为所述私网用户设备分配第二空闲端口集合,本发明实施例还提供了分配公网地址的装置,通过本发明实施例提供的技术方案,降低了所述私网用户与公网网络设备新增连接分配不到公网端口的概率。

Description

一种分配公网地址的方法及装置
技术领域 本发明涉及通信领域, 尤其涉及一种分配公网地址的方法及装 置。 背景技术 随着因特网的发展, 互联网协议 (英文全称为 Internet Protocol , 英文缩写为 IP ) 地址短缺已经成为一个越来越严重的问题, 目前, 有 两种主要解决方法, 引入互联网协议第六版 (英文全称为 Internet Protocol Version 6 , 英文缩写为 IPv6 ) 技术和网络地址转换 (英文全 称为 Network Address Translation, 英文缩写为 NAT ) 。 虽然引入 IPv6 可从根本上解决地址耗尽问题, 但由于目前大部分内容和应用还是基 于互联网协议第四版(英文全称为 Internet Protocol Version 4 , 英文缩 写为 IPv4 ) , 若硬性的全面切换到 IPv6可能面临现有业务无法承担的 风险。 在 IPv4向 IPv6 的演进这一较为长期的过程中, 出于用户感知 度、技术成熟度和部署难易度等方面考虑, NAT技术是解决 IP地址短 缺的主要选择方案。
在 NAT 技术中, 最典型的地址转换方法是网络地址和端口转换 (英文全称为 Network Address and Port Translation , 英文缩写为 NAPT )方法。 该方法具体为, 在局域网中, 每个私网用户设备占用一 个内部地址和一个内部端口号, 该内部地址即为私网地址, 该内部端 口号即为私网端口号,当私网用户设备要与外部网络进行通信时, NAT 设备将该私网地址和该私网端口号转换为空闲的外部地址和外部端口 号, 该空闲的外部地址即为公网地址, 该外部端口号即为公网端口号, 从而实现该局域网的该私网用户设备与外部网络的正常通信, 因此, 通过 NAT技术可以使多台设备共享一个公有网络地址, 实现较好地解 决公共 IP地址短缺的问题。 但是利用这种方法, 当私网用户设备每次 与外部网络设备建立连接时 , NAT设备都会为该私网用户设备申请新 的公网端口, 导致连接速率低, 并且对于 NAT设备来说, 需要记录每 一个分配给私网用户设备的端口的使用日志, 导致管理复杂, 上述私 网用户设备与外部网络设备建立的连接可以通过传输控制协议(英文全 称为 Transmission Control Protocol, 英文缩写为 TCP )建立, 也可以通过安 全套接层 (英文全称为 Secure Sockets Layer, 英文缩写为 SSL )协议建立, 也可以通过安全传输层 (英文全称为 Transport Layer Security, 英文缩写为 TLS ) 协议建立, 也可以通过用户数据 4艮协议(英文全称为 User Datagram Protocol, 英文缩写为 UDP )建立。
为解决上述问题, 现有技术还提供了一种按照端口 范围
( Port-range ) 分配地址方法, 具体是, 当私网用户设备与外部网络通 过建立连接进行通信时, NAT设备会选择一个空闲的公网地址和公网 端口块分配给该私网用户设备, 该公网端口块是由该公网地址对应的 公网端口中的一段连续的空闲端口组成,若该私网用户设备在通信时, 将已分配给该私网用户设备的公网端口块中的端口全部占用, 如还需 要使用公网端口则需要再次申请, 但是, 由于同一私网用户设备必须 釆用同一公网地址, 当该公网地址对应的公网端口中没有空闲端口可 分配时, 也就是该公网地址对应的公网端口已经全部被分配出去时, 将导致该私网用户设备申请不到公网端口, 进而使该私网用户设备无 法与外部网络设备建立新的连接。 发明内容 本发明的实施例提供一种分配公网地址的方法及装置,用于降低 在为私网用户设备分配公网 IP地址后, 所述私网用户设备新增与公 网网络设备建立连接时分配不到公网端口的概率。
根据本发明实施例的一个方面, 一种分配公网地址的方法, 包括: 接收私网用户设备发送的第一请求报文,所述第一请求报文用于 所述私网用户设备和公网中的网络设备建立连接;
当确定没有为所述私网用户设备分配任何公网 IP地址时, 从公 网地址池中为所述私网用户设备分配第一公网 IP地址, 所述第一公 网 IP地址对应的端口分为第一端口集合和第二端口集合, 所述第二 端口集合包括至少一个端口, 所述第一公网 IP地址对应的第一端口 集合存在空闲端口, 从所述第一公网 IP地址对应的第一端口集合的 空闲端口中为所述私网用户设备分配第一空闲端口集合,所述第一空 闲端口集合包含至少一个端口;
当确定所述第一空闲端口集合中的端口都被占用,并且第一公网 IP地址对应的第二端口集合存在空闲端口时, 从所述第一公网 IP地 址对应的第二端口集合的空闲端口中为所述私网用户设备分配第二 空闲端口集合, 所述第二空闲端口集合至少包含一个端口。
根据本发明实施例的另一个方面,一种分配公网地址的方法,包括: 接收私网用户设备发送的第一请求报文,所述第一请求报文用于 所述私网用户设备和公网中的网络设备建立连接;
当确定没有为所述私网用户设备分配任何公网 IP地址时, 从公 网地址池中为所述私网用户设备分配第一公网 IP地址, 且从所述第 一公网 IP地址对应的空闲端口中为所述私网用户设备分配第一空闲 端口集合, 所述第一空闲端口集合至少包含一个端口, 将所述第一空 闲端口集合中的端口存入第一端口集合中,所述第一端口集合对应所 述第一公网 IP地址, 所述第一端口集合中的端口数量不大于第一门 限值;
当确定从所述第一空闲端口集合存入所述第一端口集合中的端 口都被占用, 并且所述第一公网 IP地址对应的端口中存在空闲端口 时, 为所述私网用户设备分配第二空闲端口集合, 所述第二空闲端口 集合至少包含一个端口,将所述第二空闲端口集合中的端口存入第二 端口集合中, 所述第二端口集合对应所述第一公网 IP地址, 所述第 二端口集合中的端口数量不大于第二门限值,所述第一门限值与所述 第二门限值的和不大于所述第一公网 IP地址对应的全部端口数量。
根据本发明实施例的另一个方面,一种分配公网地址的装置,包括: 第一接收单元, 用于接收私网用户设备发送的第一请求报文, 所 述第一请求报文用于所述私网用户设备和公网中的网络设备建立连 接;
第一分配单元,用于当确定没有为所述私网用户设备分配任何公 网 IP地址时, 从公网地址池中为所述私网用户设备分配第一公网 IP 地址, 所述第一公网 IP地址对应的端口分为第一端口集合和第二端 口集合, 所述第二端口集合包括至少一个端口, 所述第一公网 IP地 址对应的第一端口集合存在空闲端口, 从所述第一公网 IP地址对应 的第一端口集合的空闲端口中为所述私网用户设备分配第一空闲端 口集合, 所述第一空闲端口集合包含至少一个端口;
第二分配单元,用于当确定所述第一空闲端口集合中的端口都被 占用, 并且第一公网 IP地址对应的第二端口集合存在空闲端口时, 从所述第一公网 IP地址对应的第二端口集合的空闲端口中为所述私 网用户设备分配第二空闲端口集合,所述第二空闲端口集合至少包含 一个端口。
根据本发明实施例的又一个方面,一种分配公网地址的装置,包括: 第三接收单元, 用于接收私网用户设备发送的第一请求报文, 所 述第一请求报文用于所述私网用户设备和公网中的网络设备建立连 接;
第四分配单元,用于当确定没有为所述私网用户设备分配任何公 网 IP地址时, 从公网地址池中为所述私网用户设备分配第一公网 IP 地址, 且从所述第一公网 IP地址对应的空闲端口中为所述私网用户 设备分配第一空闲端口集合,所述第一空闲端口集合至少包含一个端 口, 将所述第一空闲端口集合中的端口存入第一端口集合中, 所述第 一端口集合对应所述第一公网 IP地址, 所述第一端口集合中的端口 数量不大于第一门限值;
第五分配单元,用于当确定从所述第一空闲端口集合存入所述第 一端口集合中的端口都被占用, 并且所述第一公网 IP地址对应的端 口中存在空闲端口时, 为所述私网用户设备分配第二空闲端口集合, 所述第二空闲端口集合至少包含一个端口,将所述第二空闲端口集合 中的端口存入第二端口集合中,所述第二端口集合对应所述第一公网
IP 地址, 所述第二端口集合中的端口数量不大于第二门限值, 所述 第一门限值与所述第二门限值的和不大于所述第一公网 IP地址对应 的全部端口数量。
根据本发明实施例的一个方面提供的分配公网地址的方法及装 置, 通过对公网 IP地址对应的端口分为第一端口集合和第二端口集 合,对于首次申请公网 IP地址的私网网络设备 ,分配公网 IP地址后 , 从所分配的公网 IP地址的第一端口集合为所述私网网络设备分配端 口, 所述私网网络设备新增与公网网络设备建立连接时, 则从所述分 配的公网 IP地址的第二端口集合为所述私网网络设备分配端口, 这 样通过预留所述分配的公网 IP地址的第二端口集合, 用于所述私网 网络设备与公网网络设备新增连接时的端口分配,从而降低了所述私 网用户与公网网络设备新增连接分配不到公网端口的概率。 根据本发明实施例的另一个方面提供的分配公网地址的方法及 装置, 通过将公网 IP地址的端口中分配给首次申请公网 IP地址的私 网网络设备的端口数量限制在第一门限值内, 并且预留该公网 IP地 址的端口中第二门限值数量的端口,用于所述私网网络设备与公网网 络设备新增连接时的端口分配,从而当所述私网网络设备新增与公网 网络设备建立连接时,降低了所述私网用户与公网网络设备新增连接 分配不到公网端口的 ^既率。 附图说明 为了更清楚地说明本发明实施例或现有技术中的技术方案,下面 将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而 易见地, 下面描述中的附图仅仅是本发明的一些实施例, 对于本领域 普通技术人员来讲, 在不付出创造性劳动的前提下, 还可以根据这些 附图获得其他的附图。
图 1 为本发明实施例提供的分配公网地址的方法的流程示意图 图 2为本发明实施例提供的公网 IP地址及其对应的端口的结构 示意图;
图 3 为本发明实施例提供的分配公网地址的方法的流程示意图 图 4 为本发明实施例提供的分配公网地址的方法的流程示意图 图 5 为本发明实施例提供的分配公网地址的方法的流程示意图 四;
图 6 为本发明实施例提供的分配公网地址的方法的流程示意图 五;
图 7 为本发明实施例提供的分配公网地址的装置的结构示意图 图 8 为本发明实施例提供的分配公网地址的装置的结构示意图 图 9 为本发明实施例提供的分配公网地址的装置的结构示意图 图 10为本发明实施例提供的分配公网地址的装置的结构示意图 四。
具体实施方式 下面将结合本发明实施例中的附图,对本发明实施例中的技术方 案进行清楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部 分实施例, 而不是全部的实施例。 基于本发明中的实施例, 本领域普 通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例, 都属于本发明保护的范围。
参见图 1 , 本发明实施例提供了一种分配公网地址的方法, 包括 以下内容。
101、 接收私网用户设备发送的第一请求报文, 所述第一请求报 文用于所述私网用户设备和公网中的网络设备建立连接。
所述连接可以为 TCP连接或 UDP连接或 SSL连接或 TSL连接, 相应地, 所述第一请求报文可以为 TCP建立连接请求报文或 UDP建 立连接请求报文或 SSL建立连接请求报文或 TSL建立连接请求报文, 本发明实施例不做具体限制。
102、 当确定没有为所述私网用户设备分配任何公网 IP地址时, 从公网地址池中为所述私网用户设备分配第一公网 IP地址, 所述第 一公网 IP地址对应的端口分为第一端口集合和第二端口集合, 所述 第二端口集合包括至少一个端口, 所述第一公网 IP地址对应的第一 端口集合存在空闲端口, 从所述第一公网 IP地址对应的第一端口集 合的空闲端口中为所述私网用户设备分配第一空闲端口集合,所述第 一空闲端口集合包含至少一个端口。
所述第一公网 IP地址对应的第一端口集合是为没有分配过任何 公网 IP地址的私网用户设备分配端口的端口集合, 所述第一公网 IP 地址对应的第二端口集合是为已经分配过公网 IP地址的私网用户设 备再次分配端口的端口集合, 该第一公网 IP地址对应的端口的结构 示意图, 如图 2所示。 为了清楚描述本发明实施例提供的分配公网地址的方法,示例性 的, 在本发明实施例中以 10.0.0.1 : 4567作为私网 IP地址和私网端 口号, 以 128.0.0.1作为第一公网 IP地址为例进行说明。 举例来说, 例如, 所述第一公网 IP地址 128.0.0.1对应的端口 0 65535分为第一 端口集合和第二端口集合, 其中所述 IP地址 128.0.0.1对应的第一端 口集合的端口范围为 0 50000 , 所述 IP地址 128.0.0.1对应的第二端 口集合对应的端口范围为 50001 65535。 当收到私网用户设备发送的 第一请求报文, 所述第一请求报文携带有私网 IP地址 10.0.0.1 , 根据 所述私网 IP地址 10.0.0.1确定没有为所述私网用户设备分配任何公 网 IP地址时, 从公网地址池中为所述私网用户设备分配所述第一公 网 IP地址 128.0.0.1 , 并且从所述第一公网 IP地址 128.0.0.1对应的 第一端口集合的空闲端口中为所述私网用户设备分配第一空闲端口 集合, 所述第一空闲端口集合包含至少一个端口, 例如, 所述第一空 闲端口集合中端口范围为 3812~4812。
具体的, 确定没有为所述私网用户设备分配公网 IP地址的方法 可以是, 通过查找存储私网用户表的数据库, 所述私网用户表信息中 存储有已分配公网 IP地址的私网用户 IP地址和公网端口, 当在所述 数据库中没有查找到存储了所述私网用户设备的私网 IP地址的私网 用户表, 则确定没有为所述私网用户设备分配公网 IP地址。
103、 当确定所述第一空闲端口集合中的端口都被占用, 并且第 一公网 IP地址对应的第二端口集合存在空闲端口时, 从所述第一公 网 IP地址对应的第二端口集合的空闲端口中为所述私网用户设备分 配第二空闲端口集合, 所述第二空闲端口集合至少包含一个端口。
所述私网用户设备每次与公网中的网络设备连接一个业务,也就 是每次与公网中的网络设备建立一次连接都会使用所述第一空闲端 口集合中的端口,所述第一空闲端口集合中的端口都被占用是指所述 第一空闲端口集合中的端口都被所述私网用户设备使用。
示例性的, 当确定所述第一空闲端口集合 3812~4812 中的端口 都被占用的情况下, 并且所述第一公网 IP地址 128.0.0.1对应的第二 端口集合中存在空闲端口时, 从所述第一公网 IP地址 128.0.0.1对应 的第二端口集合的空闲端口中为所述私网用户设备分配第二空闲端 口集合, 如 50678 60678。
可选地,当确定所述第一空闲端口集合中的端口都被占用之前还 包括接收所述私网用户设备发送的第二请求报文,触发对所述第一空 闲端口集合中的端口占用情况进行检测,所述第二请求报文用于所述 私网用户设备和公网中的网络设备建立连接; 或者启动检测定时器, 当所述检测定时器到时后,触发对所述第一空闲端口集合中的端口占 用情况进行检测。
进一步的, 如图 3所示, 所述方法还包括:
104、 当确定没有为所述私网用户设备分配任何公网 IP地址, 并 且所述公网地址池中不存在第二公网 IP地址, 所述第二公网 IP地址 对应的端口分为第一端口集合和第二端口集合, 所述第二公网 IP地 址的第一端口集合存在空闲端口时,为所述私网用户设备分配第三公 网 IP地址, 所述第三公网 IP地址对应的端口分为第一端口集合和第 二端口集合, 所述第三公网 IP地址对应的第二端口集合存在空闲端 口, 从所述第三公网 IP地址对应的第二端口集合的空闲端口中为所 述私网用户设备分配第三空闲端口集合,所述第三空闲端口集合至少 包含一个端口。
当所述第一公网 IP地址对应的第二端口集合存在空闲端口时, 所述第三公网 IP地址也可以为所述第一公网 IP地址, 当所述第二公 网 IP地址对应的第二端口集合存在空闲端口时, 所述第三公网 IP地 址也可以为所述第二公网 IP地址。
这样实现的好处在于, 当其他私网用户设备需要申请公网 IP地 址时, 如果此时公网地址池中所有公网 IP地址对应的第一端口集合 中都没有空闲端口, 这时为所述其他私网用户设备分配一个公网 IP 地址, 所述分配的公网 IP地址的第二端口集合存在空闲端口, 并且 从所述分配的公网 IP地址的第二端口集合为所述其他私网用户设备 分配公网端口, 这样能够保证及时为私网用户设备分配公网 IP地址 和端口, 保障私网用户设备与公网中网络设备及时建立通信。
可选地, 如图 4所示, 所述方法还包括:
105、 接收所述私网用户设备的下线通知消息, 回收所述第一空 闲端口集合和所述第二空闲端口集合。 具体的,当所述私网用户设备不再需要公网地址和公网端口资源 时, 会发送一个携带有带私网 IP地址的下线通知消息, 在接收到所 述下线通知后, 释放分配给所述私网用户设备的公网 IP地址和公网 端口,以使得所述公网 IP地址资源可以再分配给其他私网用户设备, 这样一来, 充分利用了公网 IP地址, 节约了资源。 所述回收所述第 一空闲端口集合和所述第二空闲端口集合是指将所述第一空闲端口 集合中的端口和所述第二空闲端口集合中的端口的被占用标志清除, 使其可以再分配给其他私网用户设备。当为所述私网用户设备分配了 所述第三空闲端口集合时, 还需要回收所述第三空闲端口集合。
可选地, 参考图 4所示, 所述方法还包括:
106、 若在预设的时间门限内没有接收到所述私网用户设备发送 来的 4艮文, 回收所述第一空闲端口集合和所述第二空闲端口集合。
示例性的, 若在预设的时间门限内, 没有接收到携带有所述私网 IP地址 10.0.0.1 的 ^艮文, 释放分配给所述私网用户设备的公网 IP地 址和公网端口, 以使得所述公网 IP地址资源可以再分配给其他私网 用户设备, 这样一来, 充分利用了公网 IP地址, 节约了资源, 所述 回收所述第一空闲端口集合和所述第二空闲端口集合是指将所述第 一空闲端口集合中的端口和所述第二空闲端口集合中的端口的被占 用标志清除, 使其可以再分配给其他私网用户设备。 当为所述私网用 户设备分配了所述第三空闲端口集合时,还需要回收所述第三空闲端 口集合。
可选的, 参考图 4所示, 所述方法还包括:
107、 若在预设的时间门限内没有接收到公网网络设备向所述私 网用户设备发送的报文 ,回收所述第一空闲端口集合和所述第二空闲 端口集合。
示例性的, 若在预设的时间门限内, 没有接收到向所述私网 IP 地址 10.0.0.1 发送的 4艮文, 释放分配给所述私网用户设备的公网 IP 地址和公网端口, 以使得所述公网 IP地址资源可以再分配给其他私 网用户设备, 这样一来, 充分利用了公网 IP地址, 节约了资源, 所 述回收所述第一空闲端口集合和所述第二空闲端口集合是指将所述 第一空闲端口集合中的端口和所述第二空闲端口集合中的端口的被 占用标志清除, 使其可以再分配给其他私网用户设备。 当为所述私网 用户设备分配了所述第三空闲端口集合时,还需要回收所述第三空闲 端口集合。
可选地, 参考图 4所示, 所述方法还包括:
108、 当所述第二空闲端口集合中的端口都没有被占用时, 回收 所述第二空闲端口集合。
所述第二空闲端口集合中的端口的回收不需要等到所述私网用 户发送下线通知,只要判断所述第二空闲端口集合中的端口都没有被 占用时, 即可回收所述第二空闲端口集合中的端口, 这样能够加速所 述第二空闲端口集合中的空闲端口的回收,进一步提高所述第一公网 IP 地址对应第二端口集合中端口的利用率, 提高所述私网用户设备 与公网中网络设备新增连接时, 从所述第一公网 IP地址对应第二端 口集合申请到端口的概率。
可见, 通过本发明实施例提供的一种分配公网地址的方法, 通过 对公网 IP地址对应的端口分为第一端口集合和第二端口集合, 对于 首次申请公网 IP地址的私网网络设备, 分配公网 IP地址后, 从所分 配的公网 IP地址的第一端口集合为所述私网网络设备分配端口, 所 述私网网络设备新增与公网网络设备建立连接时,则从所述分配的公 网 IP地址的第二端口集合为所述私网网络设备分配端口, 这样通过 预留所述分配的公网 IP地址的第二端口集合, 用于所述私网网络设 备与公网网络设备新增连接时的端口分配,从而降低了所述私网用户 与公网网络设备新增连接分配不到公网端口的概率。
参见图 5 , 本发明实施例提供了另一种分配公网地址的方法, 包 括以下内容。
501、 接收私网用户设备发送的第一请求报文, 所述第一请求报 文用于所述私网用户设备和公网中的网络设备建立连接。
所述连接可以为 TCP连接或 UDP连接或 SSL连接或 TSL连接, 相应地, 所述第一请求报文可以为 TCP建立连接请求报文或 UDP建 立连接请求报文或 SSL建立连接请求报文或 TSL建立连接请求报文, 本发明实施例不做具体限制。
502、 当确定没有为所述私网用户设备分配任何公网 IP地址时, 从公网地址池中为所述私网用户设备分配第一公网 IP地址, 且从所 述第一公网 IP地址对应的空闲端口中为所述私网用户设备分配第一 空闲端口集合, 所述第一空闲端口集合至少包含一个端口, 将所述第 一空闲端口集合中的端口存入第一端口集合中,所述第一端口集合对 应所述第一公网 IP地址, 所述第一端口集合中的端口数量不大于第 一门限值。
为了清楚描述本发明实施例提供的分配公网地址的方法,示例性 的, 在本发明实施例中以 10.0.0.1 : 4567作为私网 IP地址和私网端 口号, 以 128.0.0.1作为第一公网 IP地址为例进行说明。 示例性的, 当 居所述私网 IP地址 10.0.0.1确定没有为所述私网用户设备分配 任何公网 IP地址后, 从公网地址池中为所述私网用户设备分配第一 公网 IP地址 128.0.0.1 , 且从所述第一公网 IP地址 128.0.0.1对应的 空闲端口中为所述私网用户设备分配第一空闲端口集合, 例如, 所述 第一空闲端口集合中端口范围为 3812~4812 , 将所述第一空闲端口集 合中的端口存入第一端口集合中,所述第一端口集合中的端口数量不 大于第一门限值, 即若要给所述私网 IP地址 10.0.0.1分配公网 IP地 址, 需要确定所述公网 IP地址对应的第一端口集合中的端口数量不 大于第一门限值后, 再给所述私网用户设备分配公网 IP地址, 其中, 所述第一端口集合中存储的端口是为没有分配任何公网 IP地址的私 网用户设备分配的端口。
具体的, 确定没有为所述私网用户设备分配公网 IP地址的方法 可以是, 通过查找存储私网用户表的数据库, 所述私网用户表信息中 存储有已分配公网 IP地址的私网用户 IP地址和公网端口, 当在所述 数据库中没有查找到存储了所述私网用户设备的私网 IP地址的私网 用户表, 则确定没有为所述私网用户设备分配公网 IP地址。
503、 当确定从所述第一空闲端口集合存入所述第一端口集合中 的端口都被占用, 并且所述第一公网 IP地址对应的全部端口中存在 空闲端口时, 为所述私网用户设备分配第二空闲端口集合, 所述第二 空闲端口集合至少包含一个端口,将所述第二空闲端口集合中的端口 存入第二端口集合中,所述第二端口集合对应所述第一公网 IP地址, 所述第二端口集合中的端口数量不大于第二门限值,所述第一门限值 与所述第二门限值的和不大于所述第一公网 IP地址对应的全部端口 数量。
所述第一门限值用于限定对应所述第一公网 IP地址的第一端口 集合中端口数量的最大值,所述第二门限值用于限定对应所述第一公 网 IP地址的第二端口集合中端口数量的最大值。 示例性的, 当确定 从所述第一空闲端口集合 3812~4812 存入到所述第一端口集合中的 端口都被占用, 并且所述第一公网 IP地址对应的端口中存在空闲端 口时,为所述私网用户设备分配第二空闲端口集合,如 50678~60678 , 所述第二空闲端口集合至少包含一个端口,将所述第二空闲端口集合 中的端口存入对应所述第一公网 IP地址的第二端口集合中, 且所述 第二端口集合中的端口数量不大于第二门限值,即若要给所述私网用 户设备再次分配所述第一公网 IP地址对应的端口, 需要确定所述第 一公网 IP地址对应的第二端口集合中的端口数量不大于第二门限值 后, 再从所述第一公网 IP地址对应的空闲端口中分配所述第二空闲 端口给所述私网用户设备,并且所述第一门限值与所述第二门限值的 和不大于所述第一公网 IP地址对应的全部端口数量。
可选地,当确定所述第一空闲端口集合中的端口都被占用之前还 包括接收所述私网用户设备发送的第二请求报文,触发对所述第一空 闲端口集合中的端口占用情况进行检测,所述第二请求报文用于所述 私网用户设备和公网中的网络设备建立连接; 或者启动检测定时器, 当所述检测定时器到时后,触发对所述第一空闲端口集合中的端口占 用情况进行检测。
进一步的, 如图 5所示, 所述方法还包括:
504、 当确定没有为所述私网用户设备分配任何公网 IP地址, 并 且所述公网地址池中不存在第二公网 IP地址, 对应所述第二公网 IP 地址的第一端口集合中的端口数量小于第三门限值,为所述私网用户 设备分配第三公网 IP地址, 从所述第三公网 IP地址对应的空闲端口 中为所述私网用户设备分配第三空闲端口集合,所述第三空闲端口集 合至少包含一个端口,将所述第三空闲端口集合中的端口存入第二端 口集合中, 所述第二端口集合对应所述第三公网 IP地址, 所述第二 端口集合中的端口数量不大于第四门限值。
所述第三门限值用于限定对应所述第二公网 IP地址的所述第一 端口集合中端口的最大数值,所述第四门限值用于限定对应所述第三 公网 IP地址的所述第二端口集合中端口的最大数值。
这样实现的好处在于, 当其他私网用户设备需要申请公网 IP地 址时, 如果此时公网地址池中对应每个公网 IP地址的第一端口集合 中的端口数量都已经达到门限值,这时为所述其他私网用户设备分配 一个公网 IP地址, 所述分配的公网 IP地址存在空闲端口, 并且对应 所述分配的公网 IP地址的第二端口集合中的端口数量没有达到门限 值, 并且从所述分配的公网 IP地址的空闲端口中为所述其他私网用 户设备分配公网端口, 这样能够保证及时为私网用户设备分配公网 IP地址和端口, 保障私网用户设备与公网中网络设备及时建立通信。
可选地, 如图 6所示, 所述方法还包括:
505、 接收所述私网用户设备的下线通知消息, 回收从所述第一 空闲端口集合存到对应所述第一公网 IP地址的第一端口集合中的端 口和从所述第二空闲端口集合存到对应所述第一公网 IP地址的第二 端口集合中的端口。
具体的, 当私网用户设备不再需要公网地址和公网端口资源,会 发送一个携带有带私网 IP地址的下线通知消息, 在接收到该下线通 知后, 释放分配给所述私网用户设备的公网 IP地址和公网端口, 以 使得所述公网 IP地址资源可以再分配给其他私网用户设备, 这样一 来, 充分利用了公网 IP地址, 节约了资源。
可选地, 参考图 6所示, 所述方法还包括:
506、 若在预设的时间门限内没有接收到所述私网用户设备发送 来的报文, 回收从所述第一空闲端口集合存到对应所述第一公网 IP 地址的第一端口集合中的端口和从所述第二空闲端口集合存到对应 所述第一公网 IP地址的第二端口集合中的端口。
示例性的, 若在预设的时间门限内, 没有接收到携带有所述私网 IP地址 10.0.0.1的 ^艮文,则回收从所述第一空闲端口集合存到对应所 述第一公网 IP地址的第一端口集合中的端口, 回收从该所述第二空 闲端口集合存到对应所述第一公网 ip 地址的第二端口集合中的端 口, 当为所述私网用户设备分配了所述第三空闲端口集合时, 还需要 回收从所述第三空闲端口集合存到对应所述第三公网 IP地址的第二 端口集合中的端口, 这样, 便于充分利用了公网 IP地址及对应所述 公网 IP地址的端口, 提高了资源利用率。
可选地, 参考图 6所示, 所述方法还包括:
507、 若在预设的时间门限内没有接收到公网网络设备向所述私 网用户设备发送的 4艮文,回收从所述第一空闲端口集合存到对应所述 第一公网 IP地址的第一端口集合中的端口和从所述第二空闲端口集 合存到对应所述第一公网 IP地址的第二端口集合中的端口。
示例性的,若在预设的时间门限内没有接收到公网网络设备向所 述私网用户设备发送的 ^艮文, 即发送携带有所述私网地址 10.0.0.1的 才艮文, 则回收从所述第一空闲端口集合存到对应所述第一公网 IP地 址的第一端口集合中的端口和从所述第二空闲端口集合存到对应所 述第一公网 IP地址的第二端口集合中的端口, 当为所述私网用户设 备分配了所述第三空闲端口集合时,还需要回收从所述第三空闲端口 集合存到对应所述第三公网 IP地址的第二端口集合中的端口,这样, 便于充分利用了公网 IP地址及对应所述公网 IP地址的端口,提高了 资源利用率。
可选地, 参考图 6所示, 所述方法还包括:
508、当从所述第二空闲端口集合存到对应所述第一公网 IP地址 的第二端口集合中的端口没有被占用时,回收从所述第二空闲端口集 合存到对应所述第一公网 IP地址的第二端口集合中的端口。
所述回收从所述第二空闲端口集合存到对应所述第一公网 IP地 址的第二端口集合中的端口不需要等到所述私网用户发送下线通知, 只要判断从所述第二空闲端口集合存到对应所述第一公网 IP地址的 第二端口集合中的端口没有被占用时,即可回收从所述第二空闲端口 集合存到对应所述第一公网 IP地址的第二端口集合中的端口, 这样 能够加速从所述第二空闲端口集合存到对应所述第一公网 IP地址的 第二端口集合中的端口的回收, 这样, 进一步提高所述第一公网 IP 地址的端口的利用率,提高所述私网用户设备与公网中网络设备新增 连接时, 从所述第一公网 IP地址对应的端口集合中申请到端口的概 率。
可见, 通过本发明实施例提供的一种分配公网地址的方法, 通过 将公网 IP地址的端口中分配给首次申请公网 IP地址的私网网络设备 的端口数量限制在第一门限值内, 并且预留该公网 IP地址的端口中 第二门限值数量的端口,用于所述私网网络设备与公网网络设备新增 连接时的端口分配,从而当所述私网网络设备新增与公网网络设备建 立连接时,降低了所述私网用户与公网网络设备新增连接分配不到公 网端口的 4既率。
参见图 7 , 本发明实施例提供了一种分配公网地址的装置 70 , 所 述装置 70包括:
第一接收单元 701 , 用于接收私网用户设备发送的第一请求报 文,所述第一请求报文用于所述私网用户设备和公网中的网络设备建 立连接。
第一分配单元 702 , 用于当确定没有为所述私网用户设备分配任 何公网 IP地址时, 从公网地址池中为所述私网用户设备分配第一公 网 IP地址, 所述第一公网 IP地址对应的端口分为第一端口集合和第 二端口集合, 所述第二端口集合包括至少一个端口, 所述第一公网
IP地址对应的第一端口集合存在空闲端口, 从所述第一公网 IP地址 对应的第一端口集合的空闲端口中为所述私网用户设备分配第一空 闲端口集合, 所述第一空闲端口集合包含至少一个端口。
第二分配单元 703 , 用于当确定所述第一空闲端口集合中的端口 都被占用, 并且第一公网 IP地址对应的第二端口集合存在空闲端口 时, 从所述第一公网 IP地址对应的第二端口集合的空闲端口中为所 述私网用户设备分配第二空闲端口集合,所述第二空闲端口集合至少 包含一个端口。
所述连接可以为 TCP连接或 UDP连接或 SSL连接或 TSL连接, 相应地, 所述第一请求报文可以为 TCP建立连接请求报文或 UDP建 立连接请求报文或 SSL建立连接请求报文或 TSL建立连接请求报文, 本发明实施例不做具体限制。
所述第一公网 IP地址对应的第一端口集合是为没有分配过任何 公网 IP地址的私网用户设备分配端口的端口集合, 所述第一公网 IP 地址对应的第二端口集合是为已经分配过公网 IP地址的私网用户设 备再次分配端口的端口集合, 该第一公网 IP地址对应的端口的结构 示意图, 如图 2所示。 为了清楚描述本发明实施例提供的分配公网地 址的装置, 示例性的, 在本发明实施例中以 10.0.0.1 : 4567作为私网 IP地址和私网端口号, 以 128.0.0.1作为第一公网 IP地址为例进行说 明。 举例来说, 例如, 所述第一公网 IP 地址 128.0.0.1 对应的端口 0-65535 分为第一端口集合和第二端口集合, 其中所述 IP 地址 128.0.0.1对应的第一端口集合的端口范围为 0 50000 , 所述 IP地址 128.0.0.1对应的第二端口集合对应的端口范围为 50001~65535。 当所 述第一接收单元 701收到私网用户设备发送的第一请求报文,所述第 一请求 文携带有私网 IP地址 10.0.0.1 ,所述第一分配单元 702根据 所述私网 IP地址 10.0.0.1确定没有为所述私网用户设备分配任何公 网 IP地址时, 从公网地址池中为所述私网用户设备分配所述第一公 网 IP地址 128.0.0.1 , 并且从所述第一公网 IP地址 128.0.0.1对应的 第一端口集合的空闲端口中为所述私网用户设备分配第一空闲端口 集合, 所述第一空闲端口集合包含至少一个端口, 例如, 所述第一空 闲端口集合中端口范围为 3812~4812。
具体的, 确定没有为所述私网用户设备分配公网 IP地址的方法 可以是, 通过查找存储私网用户表的数据库, 所述私网用户表信息中 存储有已分配公网 IP地址的私网用户 IP地址和公网端口, 当在所述 数据库中没有查找到存储了所述私网用户设备的私网 IP地址的私网 用户表, 则确定没有为所述私网用户设备分配公网 IP地址。
所述私网用户设备每次与公网中的网络设备连接一个业务,也就 是每次与公网中的网络设备建立一次连接都会使用所述第一空闲端 口集合中的端口,所述第一空闲端口集合中的端口都被占用是指所述 第一空闲端口集合中的端口都被所述私网用户设备使用。
示例性的,当所述第二分配单元 703确定所述第一空闲端口集合 3812-4812 中的端口都被占用的情况下, 并且所述第一公网 IP地址 128.0.0.1 对应的第二端口集合中存在空闲端口时, 从所述第一公网 IP地址 128.0.0.1对应的第二端口集合的空闲端口中为所述私网用户 设备分配第二空闲端口集合, 如 50678~60678。
进一步的,为了确定所述第一空闲端口集合中的端口是否全被占 用, 如图 7所示, 该装置 70还包括: 第二接收单元 704 , 用于接收所述私网用户设备发送的第二请求 报文, 触发对所述第一空闲端口集合中的端口占用情况进行检测, 所 述第二请求报文用于所述私网用户设备和公网中的网络设备建立连 接。
或者, 参考图 7所示, 该装置还包括:
第一启动触发单元 705 , 用于启动检测定时器, 当所述检测定时 器到时后, 触发对所述第一空闲端口集合中的端口占用情况进行检 测。
进一步的, 如图 8所示, 该装置 70还包括:
第三分配单元 706 , 用于当确定没有为所述私网用户设备分配任 何公网 IP地址, 并且所述公网地址池中不存在第二公网 IP地址, 所 述第二公网 IP地址对应的端口分为第一端口集合和第二端口集合, 所述第二公网 IP地址对应的第一端口集合存在空闲端口时, 为所述 私网用户设备分配第三公网 IP地址, 所述第三公网 IP地址对应的端 口分为第一端口集合和第二端口集合, 所述第三公网 IP地址对应的 第二端口集合存在空闲端口, 从所述第三公网 IP地址对应的第二端 口集合的空闲端口中为所述私网用户设备分配第三空闲端口集合,所 述第三空闲端口集合至少包含一个端口。
当所述第一公网 IP地址对应的第二端口集合存在空闲端口时, 所述第三公网 IP地址也可以为所述第一公网 IP地址, 当所述第二公 网 IP地址对应的第二端口集合存在空闲端口时, 所述第三公网 IP地 址也可以为所述第二公网 IP地址。
这样实现的好处在于, 当其他私网用户设备需要申请公网 IP地 址时, 如果此时公网地址池中所有公网 IP地址对应的第一端口集合 中都没有空闲端口,这时所述第三分配单元 706为所述其他私网用户 设备分配一个公网 IP地址, 所述分配的公网 IP地址的第二端口集合 存在空闲端口, 并且从所述分配的公网 IP地址的第二端口集合为所 述其他私网用户设备分配公网端口,这样能够保证及时为私网用户设 备分配公网 IP地址和端口, 保障私网用户设备与公网中网络设备及 时建立通信。
可选地, 参考图 7所示, 该装置 70 , 还包括: 第一回收单元 707 , 用于接收所述私网用户设备的下线通知消 息, 回收所述第一空闲端口集合和所述第二空闲端口集合。
具体的,当所述私网用户设备不再需要公网地址和公网端口资源 时, 会发送一个携带有带私网 IP地址的下线通知消息, 在所述第一 回收单元 707接收到所述下线通知后,释放分配给所述私网用户设备 的公网 IP地址和公网端口, 以使得所述公网 IP地址资源可以再分配 给其他私网用户设备, 这样一来, 充分利用了公网 IP地址, 节约了 资源。所述回收所述第一空闲端口集合和所述第二空闲端口集合是指 将所述第一空闲端口集合中的端口和所述第二空闲端口集合中的端 口的被占用标志清除, 使其可以再分配给其他私网用户设备。 当为所 述私网用户设备分配了所述第三空闲端口集合时,还需要回收所述第 三空闲端口集合。
可选地, 该装置 70 , 还包括:
第二回收单元 708 , 用于若在预设的时间门限内没有接收到所述 私网用户设备发送来的 4艮文,回收所述第一空闲端口集合和所述第二 空闲端口集合。
示例性的, 若在预设的时间门限内, 所述第二回收单元 708没有 接收到携带有所述私网 IP地址 10.0.0.1 的报文, 释放分配给所述私 网用户设备的公网 IP地址和公网端口, 以使得所述公网 IP地址资源 可以再分配给其他私网用户设备, 这样一来, 充分利用了公网 IP地 址, 节约了资源, 所述回收所述第一空闲端口集合和所述第二空闲端 口集合是指将所述第一空闲端口集合中的端口和所述第二空闲端口 集合中的端口的被占用标志清除 ,使其可以再分配给其他私网用户设 备。 当为所述私网用户设备分配了所述第三空闲端口集合时, 还需要 回收所述第三空闲端口集合。
可选地, 该装置 70 , 还包括:
第三回收单元 709 , 用于若在预设的时间门限内没有接收到公网 网络设备向所述私网用户设备发送的 4艮文,回收所述第一空闲端口集 合和所述第二空闲端口集合。
示例性的, 若在预设的时间门限内, 所述第三回收单元 709没有 接收到向所述私网 IP地址 10.0.0.1发送的 ^艮文, 释放分配给所述私 网用户设备的公网 IP地址和公网端口, 以使得所述公网 IP地址资源 可以再分配给其他私网用户设备, 这样一来, 充分利用了公网 IP地 址, 节约了资源, 所述回收所述第一空闲端口集合和所述第二空闲端 口集合是指将所述第一空闲端口集合中的端口和所述第二空闲端口 集合中的端口的被占用标志清除 ,使其可以再分配给其他私网用户设 备。 当为所述私网用户设备分配了所述第三空闲端口集合时, 还需要 回收所述第三空闲端口集合。
可选地, 该装置 70还包括:
第四回收单元 710 , 用于当所述第二空闲端口集合中的端口都没 有被占用时, 回收所述第二空闲端口集合。
所述第二空闲端口集合中的端口的回收不需要等到所述私网用 户发送下线通知,只要判断所述第二空闲端口集合中的端口都没有被 占用时,所述第四回收单元 710即可回收所述第二空闲端口集合中的 端口, 这样能够加速所述第二空闲端口集合中的空闲端口的回收, 进 一步提高所述第一公网 IP地址对应第二端口集合中端口的利用率, 提高所述私网用户设备与公网中网络设备新增连接时,从所述第一公 网 IP地址对应第二端口集合申请到端口的概率。
可选地, 本发明实施例提供的上述单元可以合并为一个或者多 个。 在实现时, 所述第一接收单元 701和所述第二接收单元 704可以 由一个或多个物理接口实现, 所述第一分配单元 702、 所述第二分配 单元 703和所述第三分配单元 706可以为处理器,所述第一启动触发 单元 705可以为定时器, 所述第一回收单元 707、 所述第二回收单元 708、 所述第三回收单元 709和所述第四回收单元 710也可以为处理 器。所述一个或多个物理接口和处理器使所述装置完成了本实施例中 执行的操作。
可见, 通过本发明实施例提供的一种分配公网地址的装置, 通过 对公网 IP地址对应的端口分为第一端口集合和第二端口集合, 对于 首次申请公网 IP地址的私网网络设备, 分配公网 IP地址后, 从所分 配的公网 IP地址的第一端口集合为所述私网网络设备分配端口, 所 述私网网络设备新增与公网网络设备建立连接时,则从所述分配的公 网 IP地址的第二端口集合为所述私网网络设备分配端口, 这样通过 预留所述分配的公网 IP地址的第二端口集合, 用于所述私网网络设 备与公网网络设备新增连接时的端口分配,从而降低了所述私网用户 与公网网络设备新增连接分配不到公网端口的概率。
本发明实施例提供的分配公网地址的装置 90 , 如图 9所示, 包 括:
第三接收单元 901 , 用于接收私网用户设备发送的第一请求报 文,所述第一请求报文用于所述私网用户设备和公网中的网络设备建 立连接。
第四分配单元 902 , 用于当确定没有为所述私网用户设备分配任 何公网 IP地址时, 从公网地址池中为所述私网用户设备分配第一公 网 IP地址; 并从所述第一公网 IP地址对应的空闲端口中为所述私网 用户设备分配第一空闲端口集合,所述第一空闲端口集合至少包含一 个端口, 将所述第一空闲端口集合中的端口存入第一端口集合中, 所 述第一端口集合对应所述第一公网 IP地址, 所述第一端口集合中的 端口数量不大于第一门限值。
第五分配单元 903 , 用于当确定从所述第一空闲端口集合存入所 述第一端口集合中的端口都被占用, 并且所述第一公网 IP地址对应 的全部端口中存在空闲端口时,为所述私网用户设备分配第二空闲端 口集合, 所述第二空闲端口集合至少包含一个端口, 将所述第二空闲 端口集合中的端口存入第二端口集合中,所述第二端口集合对应所述 第一公网 IP地址, 所述第二端口集合中的端口数量不大于第二门限 值, 所述第一门限值与所述第二门限值的和不大于所述第一公网 IP 地址对应的全部端口数量。
为了清楚描述本发明实施例提供的分配公网地址的方法,示例性 的, 在本发明实施例中以 10.0.0.1 : 4567作为私网 IP地址和私网端 口号, 以 128.0.0.1作为第一公网 IP地址为例进行说明。 示例性的, 当所述第四分配单元 902根据所述私网 IP地址 10.0.0.1确定没有为 所述私网用户设备分配任何公网 IP地址后, 从公网地址池中为所述 私网用户设备分配第一公网 IP地址 128.0.0.1 , 且从所述第一公网 IP 地址 128.0.0.1 对应的空闲端口中为所述私网用户设备分配第一空闲 端口集合, 例如, 所述第一空闲端口集合中端口范围为 3812~4812 , 将所述第一空闲端口集合中的端口存入第一端口集合中,所述第一端 口集合中的端口数量不大于第一门限值, 即若要给所述私网 IP地址 10.0.0.1分配公网 IP地址, 需要确定所述公网 IP地址对应的第一端 口集合中的端口数量不大于第一门限值后,再给所述私网用户设备分 配公网 IP地址, 其中, 所述第一端口集合中存储的端口是为没有分 配任何公网 IP地址的私网用户设备分配的端口。
具体的,所述第四分配单元 902确定没有为所述私网用户设备分 配公网 IP地址的方法可以是, 通过查找存储私网用户表的数据库, 所述私网用户表信息中存储有已分配公网 IP地址的私网用户 IP地址 和公网端口,当在所述数据库中没有查找到存储了所述私网用户设备 的私网 IP地址的私网用户表, 则确定没有为所述私网用户设备分配 公网 IP地址。
所述第一门限值用于限定对应所述第一公网 IP地址的第一端口 集合中端口数量的最大值,所述第二门限值用于限定对应所述第一公 网 IP地址的第二端口集合中端口数量的最大值。 示例性的, 当所述 第五分配单元 903确定从所述第一空闲端口集合 3812 4812存入到所 述第一端口集合中的端口都被占用, 并且所述第一公网 IP地址对应 的端口中存在空闲端口时,为所述私网用户设备分配第二空闲端口集 合, 如 50678 60678 , 所述第二空闲端口集合至少包含一个端口, 将 所述第二空闲端口集合中的端口存入对应所述第一公网 IP地址的第 二端口集合中, 且所述第二端口集合中的端口数量不大于第二门限 值, 即若要给所述私网用户设备再次分配所述第一公网 IP地址对应 的端口, 需要确定所述第一公网 IP地址对应的第二端口集合中的端 口数量不大于第二门限值后, 再从所述第一公网 IP地址对应的空闲 端口中分配所述第二空闲端口给所述私网用户设备,并且所述第一门 限值与所述第二门限值的和不大于所述第一公网 IP地址对应的全部 端口数量。
进一步的,为了确定从该第一空闲端口集合存入该第一端口集合 中的端口都被占用, 参考图 9所示, 该装置 90还包括:
第四接收单元 904 , 用于接收所述私网用户设备发送的第二请求 报文,触发对从所述第一空闲端口集合存入所述第一端口集合中的端 口占用情况进行检测,所述第二请求报文用于所述私网用户设备和公 网中的网络设备建立连接。
或者, 第二启动触发单元 905 , 用于启动检测定时器, 当所述检 测定时器到时后,触发对从所述第一空闲端口集合存入所述第一端口 集合中的端口占用情况进行检测。
进一步的, 如图 10所示, 该装置 90还包括:
第六分配单元 906 , 用于当确定没有为所述私网用户设备分配任 何公网 IP地址, 并且所述公网地址池中不存在第二公网 IP地址, 对 应所述第二公网 IP地址的第一端口集合中的端口数量小于第三门限 值, 为所述私网用户设备分配第三公网 IP地址, 从所述第三公网 IP 地址对应的空闲端口中为所述私网用户设备分配第三空闲端口集合 , 所述第三空闲端口集合至少包含一个端口,将所述第三空闲端口集合 中的端口存入第二端口集合中,所述第二端口集合对应所述第三公网 IP地址, 所述第二端口集合中的端口数量不大于第四门限值。
这样实现的好处在于, 当其他私网用户设备需要申请公网 IP地 址时, 如果此时公网地址池中对应每个公网 IP地址的第一端口集合 中的端口数量都已经达到门限值,这时所述第六分配单元 906为所述 其他私网用户设备分配一个公网 IP地址, 所述分配的公网 IP地址存 在空闲端口, 并且对应所述分配的公网 IP地址的第二端口集合中的 端口数量没有达到门限值, 并且从所述分配的公网 IP地址的空闲端 口中为所述其他私网用户设备分配公网端口,这样能够保证及时为私 网用户设备分配公网 IP地址和端口, 保障私网用户设备与公网中网 络设备及时建立通信。
可选地, 如图 10所示, 该装置 90还包括:
第五回收单元 907 , 用于接收所述私网用户设备的下线通知消 息, 回收从所述第一空闲端口集合存到对应所述第一公网 IP地址的 第一端口集合中的端口和从所述第二空闲端口集合存到对应所述第 一公网 IP地址的第二端口集合中的端口。
具体的, 当私网用户设备不再需要公网地址和公网端口资源,会 发送一个携带有带私网 IP地址的下线通知消息, 当所述第五回收单 元 907 接收到该下线通知后, 释放分配给所述私网用户设备的公网 IP地址和公网端口, 以使得所述公网 IP地址资源可以再分配给其他 私网用户设备, 这样一来, 充分利用了公网 IP地址, 节约了资源。
可选地, 参考图 10所示, 该装置 90还包括:
第六回收单元 908, 用于若在预设的时间门限内没有接收到所述 私网用户设备发送来的 4艮文,回收从所述第一空闲端口集合存到对应 所述第一公网 IP地址的第一端口集合中的端口和从所述第二空闲端 口集合存到对应所述第一公网 IP地址的第二端口集合中的端口。
示例性的, 若在预设的时间门限内, 第六回收单元 908没有接收 到携带有所述私网 IP地址 10.0.0.1 的 ^艮文, 则回收从所述第一空闲 端口集合存到对应所述第一公网 ip地址的第一端口集合中的端口, 回收从该所述第二空闲端口集合存到对应所述第一公网 IP地址的第 二端口集合中的端口,当为所述私网用户设备分配了所述第三空闲端 口集合时,还需要回收从所述第三空闲端口集合存到对应所述第三公 网 IP地址的第二端口集合中的端口, 这样, 便于充分利用了公网 IP 地址及对应所述公网 IP地址的端口, 提高了资源利用率。
可选地, 参考图 10所示, 该装置 90还包括:
第七回收单元 909, 用于若在预设的时间门限内没有接收到公网 网络设备向所述私网用户设备发送的报文,回收从所述第一空闲端口 集合存到对应所述第一公网 IP地址的第一端口集合中的端口和从所 述第二空闲端口集合存到对应所述第一公网 IP地址的第二端口集合 中的端口。
示例性的,若在预设的时间门限内所述第七回收单元 909没有接 收到公网网络设备向所述私网用户设备发送的报文,即发送携带有所 述私网地址 10.0.0.1的报文, 则回收从所述第一空闲端口集合存到对 应所述第一公网 IP地址的第一端口集合中的端口和从所述第二空闲 端口集合存到对应所述第一公网 IP地址的第二端口集合中的端口, 当为所述私网用户设备分配了所述第三空闲端口集合时,还需要回收 从所述第三空闲端口集合存到对应所述第三公网 IP地址的第二端口 集合中的端口, 这样, 便于充分利用了公网 IP地址及对应所述公网 IP地址的端口, 提高了资源利用率。
可选地, 参考图 10所示, 该装置 90还包括: 第八回收单元 910 , 用于当从所述第二空闲端口集合存到对应所 述第一公网 IP地址的第二端口集合中的端口没有被占用时, 回收从 所述第二空闲端口集合存到对应所述第一公网 IP地址的第二端口集 合中的端口。
所述回收从所述第二空闲端口集合存到对应所述第一公网 IP地 址的第二端口集合中的端口不需要等到所述私网用户发送下线通知, 只要所述第八回收单元 910 判断从所述第二空闲端口集合存到对应 所述第一公网 IP地址的第二端口集合中的端口没有被占用时, 即可 回收从所述第二空闲端口集合存到对应所述第一公网 IP地址的第二 端口集合中的端口,这样能够加速从所述第二空闲端口集合存到对应 所述第一公网 IP地址的第二端口集合中的端口的回收, 这样, 进一 步提高所述第一公网 IP地址的端口的利用率, 提高所述私网用户设 备与公网中网络设备新增连接时, 从所述第一公网 IP地址对应的端 口集合中申请到端口的概率。
可选地, 本发明实施例提供的上述单元可以合并为一个或者多 个。 在实现时, 所述第三接收单元 901和所述第四接收单元 904可以 由一个或多个物理接口实现, 所述第四分配单元 902、 所述第五分配 单元 903和所述第六分配单元 906可以为处理器, 所述第二 启 动 触发单元 905可以为定时器, 所述第五回收单元 907、 所述第六回收 单元 908、 所述第七回收单元 909和所述第八回收单元 910也可以为 处理器。所述一个或多个物理接口和处理器使所述装置完成了本实施 例中执行的操作。
可见, 通过本发明实施例提供的一种分配公网地址的装置, 通过 将公网 IP地址的端口中分配给首次申请公网 IP地址的私网网络设备 的端口数量限制在第一门限值内, 并且预留该公网 IP地址的端口中 第二门限值数量的端口,用于所述私网网络设备与公网网络设备新增 连接时的端口分配,从而当所述私网网络设备新增与公网网络设备建 立连接时,降低了所述私网用户与公网网络设备新增连接分配不到公 网端口的 ^既率。
在本发明所有实施例中,所述分配公网地址的装置可以通过支持 NAT功能的路由器、支持 NAT功能的交换机或是运营级地址转发(英 文全称为 Carrier Grade NAT, 英文缩写为 CGN ) 设备来实现, 或者 是通过支持 NAT功能的其他网络设备来实现。
本领域普通技术人员可以理解: 实现上述方法实施例的全部或部 分步骤可以通过程序指令相关的硬件来完成, 前述程序可以存储于一 计算机可读取存储介质中, 该程序在执行时, 执行包括上述方法实施 例的步骤; 而前述的存储介质包括: ROM、 RAM, 磁碟或者光盘等各 种可以存储程序代码的介质。
最后应说明的是: 以上实施例仅用以说明本发明的技术方案, 而非对 其限制; 尽管参照前述实施例对本发明进行了详细的说明, 本领域的普 通技术人员应当理解: 其依然可以对前述各实施例所记载的技术方案进行 修改, 或者对其中部分技术特征进行等同替换; 而这些修改或者替换, 并 不使相应技术方案的本质脱离本发明各实施例技术方案的范围。

Claims

权利要求
1、 一种分配公网地址的方法, 其特征在于, 包括:
接收私网用户设备发送的第一请求报文,所述第一请求报文用于 所述私网用户设备和公网中的网络设备建立连接;
当确定没有为所述私网用户设备分配任何公网互联网协议 IP地 址时, 从公网地址池中为所述私网用户设备分配第一公网 IP地址, 所述第一公网 IP 地址对应的端口分为第一端口集合和第二端口集 合, 所述第二端口集合包括至少一个端口, 所述第一公网 IP地址对 应的第一端口集合存在空闲端口, 从所述第一公网 IP地址对应的第 一端口集合的空闲端口中为所述私网用户设备分配第一空闲端口集 合, 所述第一空闲端口集合包含至少一个端口;
当确定所述第一空闲端口集合中的端口都被占用,并且第一公网
IP地址对应的第二端口集合存在空闲端口时, 从所述第一公网 IP地 址对应的第二端口集合的空闲端口中为所述私网用户设备分配第二 空闲端口集合, 所述第二空闲端口集合至少包含一个端口。
2、 根据权利要求 1所述的方法, 其特征在于, 在所述当确定所 述第一空闲端口集合中的端口都被占用之前还包括:
接收所述私网用户设备发送的第二请求报文,触发对所述第一空 闲端口集合中的端口占用情况进行检测,所述第二请求报文用于所述 私网用户设备和公网中的网络设备建立连接; 或者,
启动检测定时器, 当所述检测定时器到时后, 触发对所述第一空 闲端口集合中的端口占用情况进行检测。
3、 根据权利要求 1或 2所述的方法, 其特征在于, 所述方法还 包括:
当确定没有为所述私网用户设备分配任何公网 IP地址, 并且所 述公网地址池中不存在第二公网 IP地址, 所述第二公网 IP地址对应 的端口分为第一端口集合和第二端口集合, 所述第二公网 IP地址对 应的第一端口集合存在空闲端口时,为所述私网用户设备分配第三公 网 IP地址, 所述第三公网 IP地址对应的端口分为第一端口集合和第 二端口集合, 所述第三公网 IP地址对应的第二端口集合存在空闲端 口, 从所述第三公网 IP地址对应的第二端口集合的空闲端口中为所 述私网用户设备分配第三空闲端口集合,所述第三空闲端口集合至少 包含一个端口。
4、根据权利要求 1至 3任一权利要求所述的方法, 其特征在于, 所述方法还包括:
接收所述私网用户设备的下线通知消息,回收所述第一空闲端口 集合和所述第二空闲端口集合; 或者
若在预设的时间门限内没有接收到所述私网用户设备发送来的 报文, 回收所述第一空闲端口集合和所述第二空闲端口集合; 或者 若在预设的时间门限内没有接收到公网网络设备向所述私网用 户设备发送的 4艮文,回收所述第一空闲端口集合和所述第二空闲端口 集合。
5、根据权利要求 1至 4任一权利要求所述的方法, 其特征在于, 所述方法还包括:
当所述第二空闲端口集合中的端口都没有被占用时,回收所述第 二空闲端口集合。
6、 一种分配公网地址的方法, 其特征在于, 包括:
接收私网用户设备发送的第一请求报文,所述第一请求报文用于 所述私网用户设备和公网中的网络设备建立连接;
当确定没有为所述私网用户设备分配任何公网互联网协议 IP地 址时, 从公网地址池中为所述私网用户设备分配第一公网 IP地址, 且从所述第一公网 IP地址对应的空闲端口中为所述私网用户设备分 配第一空闲端口集合, 所述第一空闲端口集合至少包含一个端口, 将 所述第一空闲端口集合中的端口存入第一端口集合中,所述第一端口 集合对应所述第一公网 IP地址, 所述第一端口集合中的端口数量不 大于第一门限值;
当确定从所述第一空闲端口集合存入所述第一端口集合中的端 口都被占用, 并且所述第一公网 IP地址对应的端口中存在空闲端口 时, 为所述私网用户设备分配第二空闲端口集合, 所述第二空闲端口 集合至少包含一个端口,将所述第二空闲端口集合中的端口存入第二 端口集合中, 所述第二端口集合对应所述第一公网 IP地址, 所述第 二端口集合中的端口数量不大于第二门限值,所述第一门限值与所述 第二门限值的和不大于所述第一公网 IP地址对应的全部端口数量。
7、 根据权利要求 6所述的方法, 其特征在于, 在所述当确定从 所述第一空闲端口集合存入所述第一端口集合中的端口都被占用之 前还包括:
接收所述私网用户设备发送的第二请求报文,触发对从所述第一 空闲端口集合存入所述第一端口集合中的端口占用情况进行检测,所 述第二请求报文用于所述私网用户设备和公网中的网络设备建立连 接; 或者
启动检测定时器, 当所述检测定时器到时后, 触发对从所述第一 空闲端口集合存入所述第一端口集合中的端口占用情况进行检测。
8、 根据权利要求 6或 7所述的方法, 其特征在于, 所述方法还 包括:
当确定没有为所述私网用户设备分配任何公网 IP地址, 并且所 述公网地址池中不存在第二公网 IP地址,对应所述第二公网 IP地址 的第一端口集合中的端口数量小于第三门限值,为所述私网用户设备 分配第三公网 IP地址, 从所述第三公网 IP地址对应的空闲端口中为 所述私网用户设备分配第三空闲端口集合,所述第三空闲端口集合至 少包含一个端口,将所述第三空闲端口集合中的端口存入第二端口集 合中, 所述第二端口集合对应所述第三公网 IP地址, 所述第二端口 集合中的端口数量不大于第四门限值。
9、根据权利要求 6至 8任一权利要求所述的方法,其特征在于, 所述方法还包括:
接收所述私网用户设备的下线通知消息,回收从所述第一空闲端 口集合存到对应所述第一公网 IP地址的第一端口集合中的端口和从 所述第二空闲端口集合存到对应所述第一公网 IP地址的第二端口集 合中的端口; 或者
若在预设的时间门限内没有接收到所述私网用户设备发送来的 才艮文, 回收从所述第一空闲端口集合存到对应所述第一公网 IP地址 的第一端口集合中的端口和从所述第二空闲端口集合存到对应所述 第一公网 IP地址的第二端口集合中的端口; 或者
若在预设的时间门限内没有接收到公网网络设备向所述私网用 户设备发送的报文,回收从所述第一空闲端口集合存到对应所述第一 公网 IP地址的第一端口集合中的端口和从所述第二空闲端口集合存 到对应所述第一公网 IP地址的第二端口集合中的端口。
10、根据权利要求 6至 9任一权利要求所述的方法,其特征在于, 所述方法还包括:
当从所述第二空闲端口集合存到对应所述第一公网 IP地址的第 二端口集合中的端口没有被占用时,回收从所述第二空闲端口集合存 到对应所述第一公网 IP地址的第二端口集合中的端口。
11、 一种分配公网地址的装置, 其特征在于, 包括:
第一接收单元, 用于接收私网用户设备发送的第一请求报文, 所 述第一请求报文用于所述私网用户设备和公网中的网络设备建立连 接;
第一分配单元,用于当确定没有为所述私网用户设备分配任何公 网 IP地址时, 从公网地址池中为所述私网用户设备分配第一公网互 联网协议 IP地址, 所述第一公网 IP地址对应的端口分为第一端口集 合和第二端口集合, 所述第二端口集合包括至少一个端口, 所述第一 公网 IP地址对应的第一端口集合存在空闲端口, 从所述第一公网 IP 地址对应的第一端口集合的空闲端口中为所述私网用户设备分配第 一空闲端口集合, 所述第一空闲端口集合包含至少一个端口;
第二分配单元,用于当确定所述第一空闲端口集合中的端口都被 占用, 并且第一公网 IP地址对应的第二端口集合存在空闲端口时, 从所述第一公网 IP地址对应的第二端口集合的空闲端口中为所述私 网用户设备分配第二空闲端口集合,所述第二空闲端口集合至少包含 一个端口。
12、 根据权利要求 11所述的装置, 其特征在于, 还包括: 第二接收单元, 用于接收所述私网用户设备发送的第二请求报 文, 触发对所述第一空闲端口集合中的端口占用情况进行检测, 所述 第二请求报文用于所述私网用户设备和公网中的网络设备建立连接; 或者,
第一启动触发单元, 用于启动检测定时器, 当所述检测定时器到 时后, 触发对所述第一空闲端口集合中的端口占用情况进行检测。
13、 根据权利要求 11或 12所述的装置, 其特征在于, 还包括: 第三分配单元,用于当确定没有为所述私网用户设备分配任何公 网 IP地址, 并且所述公网地址池中不存在第二公网 IP地址, 所述第 二公网 IP地址对应的端口分为第一端口集合和第二端口集合, 所述 第二公网 IP地址对应的第一端口集合存在空闲端口时, 为所述私网 用户设备分配第三公网 IP地址, 所述第三公网 IP地址对应的端口分 为第一端口集合和第二端口集合, 所述第三公网 IP地址对应的第二 端口集合存在空闲端口, 从所述第三公网 IP地址对应的第二端口集 合的空闲端口中为所述私网用户设备分配第三空闲端口集合,所述第 三空闲端口集合至少包含一个端口。
14、根据权利要求 11至 13任一权利要求所述的装置, 其特征在 于, 还包括:
第一回收单元, 用于接收所述私网用户设备的下线通知消息, 回 收所述第一空闲端口集合和所述第二空闲端口集合; 或者
第二回收单元,用于若在预设的时间门限内没有接收到所述私网 用户设备发送来的报文,回收所述第一空闲端口集合和所述第二空闲 端口集合; 或者
第三回收单元,用于若在预设的时间门限内没有接收到公网网络 设备向所述私网用户设备发送的 ^艮文,回收所述第一空闲端口集合和 所述第二空闲端口集合。
15、根据权利要求 11至 14任一权利要求所述的装置, 其特征在 于, 还包括:
第四回收单元,用于当所述第二空闲端口集合中的端口都没有被 占用时, 回收所述第二空闲端口集合。
16、 一种分配公网地址的装置, 其特征在于, 包括:
第三接收单元, 用于接收私网用户设备发送的第一请求报文, 所 述第一请求报文用于所述私网用户设备和公网中的网络设备建立连 接;
第四分配单元,用于当确定没有为所述私网用户设备分配任何公 网 IP地址时, 从公网地址池中为所述私网用户设备分配第一公网互 联网协议 IP地址, 并且从所述第一公网 IP地址对应的空闲端口中为 所述私网用户设备分配第一空闲端口集合,所述第一空闲端口集合至 少包含一个端口,将所述第一空闲端口集合中的端口存入第一端口集 合中, 所述第一端口集合对应所述第一公网 IP地址, 所述第一端口 集合中的端口数量不大于第一门限值;
第五分配单元,用于当确定从所述第一空闲端口集合存入所述第 一端口集合中的端口都被占用, 并且所述第一公网 IP地址对应的端 口中存在空闲端口时, 为所述私网用户设备分配第二空闲端口集合, 所述第二空闲端口集合至少包含一个端口,将所述第二空闲端口集合 中的端口存入第二端口集合中,所述第二端口集合对应所述第一公网
IP 地址, 所述第二端口集合中的端口数量不大于第二门限值, 所述 第一门限值与所述第二门限值的和不大于所述第一公网 IP地址对应 的全部端口数量。
17、 根据权利要求 16所述的装置, 其特征在于, 所述分配公网 地址的装置还包括:
第四接收单元, 用于接收所述私网用户设备发送的第二请求报 文,触发对从所述第一空闲端口集合存入所述第一端口集合中的端口 占用情况进行检测 ,所述第二请求报文用于所述私网用户设备和公网 中的网络设备建立连接; 或者
第二启动触发单元, 用于启动检测定时器, 当所述检测定时器到 时后,触发对从所述第一空闲端口集合存入所述第一端口集合中的端 口占用情况进行检测。
18、 根据权利要求 16或 17所述的装置, 其特征在于, 还包括: 第六分配单元,用于当确定没有为所述私网用户设备分配任何公 网 IP地址, 并且所述公网地址池中不存在第二公网 IP地址, 对应所 述第二公网 IP地址的第一端口集合中的端口数量小于第三门限值, 为所述私网用户设备分配第三公网 IP地址, 从所述第三公网 IP地址 对应的空闲端口中为所述私网用户设备分配第三空闲端口集合 ,所述 第三空闲端口集合至少包含一个端口,将所述第三空闲端口集合中的 端口存入第二端口集合中, 所述第二端口集合对应所述第三公网 IP 地址, 所述第二端口集合中的端口数量不大于第四门限值。
19、根据权利要求 16至 18任一权利要求所述的装置, 其特征在 于, 还包括:
第五回收单元, 用于接收所述私网用户设备的下线通知消息, 回 收从所述第一空闲端口集合存到对应所述第一公网 IP地址的第一端 口集合中的端口和从所述第二空闲端口集合存到对应所述第一公网 IP地址的第二端口集合中的端口; 或者
第六回收单元,用于若在预设的时间门限内没有接收到所述私网 用户设备发送来的报文,回收从所述第一空闲端口集合存到对应所述 第一公网 IP地址的第一端口集合中的端口和从所述第二空闲端口集 合存到对应所述第一公网 IP地址的第二端口集合中的端口; 或者 第七回收单元,用于若在预设的时间门限内没有接收到公网网络 设备向所述私网用户设备发送的报文,回收从所述第一空闲端口集合 存到对应所述第一公网 IP地址的第一端口集合中的端口和从所述第 二空闲端口集合存到对应所述第一公网 IP地址的第二端口集合中的 端口 。
20、根据权利要求 16至 19任一权利要求所述的装置, 其特征在 于, 还包括:
第八回收单元,用于当从所述第二空闲端口集合存到对应所述第 一公网 IP地址的第二端口集合中的端口没有被占用时, 回收从所述 第二空闲端口集合存到对应所述第一公网 IP地址的第二端口集合中 的端口。
PCT/CN2012/083177 2012-05-30 2012-10-19 一种分配公网地址的方法及装置 Ceased WO2013177891A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
EP12823122.2A EP2683138A1 (en) 2012-05-30 2012-10-19 Public network address allocation method and device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201210174333.7 2012-05-30
CN201210174333.7A CN102685272B (zh) 2012-05-30 2012-05-30 一种分配公网地址的方法及装置

Publications (1)

Publication Number Publication Date
WO2013177891A1 true WO2013177891A1 (zh) 2013-12-05

Family

ID=46816624

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2012/083177 Ceased WO2013177891A1 (zh) 2012-05-30 2012-10-19 一种分配公网地址的方法及装置

Country Status (3)

Country Link
EP (1) EP2683138A1 (zh)
CN (1) CN102685272B (zh)
WO (1) WO2013177891A1 (zh)

Families Citing this family (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102685272B (zh) * 2012-05-30 2015-03-11 华为技术有限公司 一种分配公网地址的方法及装置
CN103701941B (zh) * 2012-09-28 2018-06-15 中国电信股份有限公司 一种地址转换设备分配端口的方法和地址转换设备
CN103067536A (zh) * 2013-01-11 2013-04-24 清华大学 基于Buddy方式的端口分配方法及系统
CN103338275B (zh) * 2013-05-30 2016-05-25 中国联合网络通信集团有限公司 端口分配方法和装置
CN104243628A (zh) * 2014-09-11 2014-12-24 杭州华三通信技术有限公司 一种连续多端口申请方法和装置
CN105812497B (zh) * 2014-12-30 2019-04-26 北京华为数字技术有限公司 网络地址分配方法、设备和系统
CN104519150B (zh) * 2014-12-31 2018-03-02 迈普通信技术股份有限公司 网络地址转换端口分配方法及系统
CN105100297B (zh) * 2015-06-30 2019-01-22 新华三技术有限公司 一种资源处理方法及装置
CN106302848B (zh) * 2016-07-25 2021-01-01 新华三技术有限公司 一种资源分配方法及装置
CN106254577B (zh) * 2016-09-18 2019-04-19 东软集团股份有限公司 端口分配的方法及装置
CN106878487B (zh) * 2017-03-29 2020-02-11 新华三技术有限公司 公网地址分配方法及装置
CN108924272B (zh) * 2018-06-26 2021-09-17 新华三信息安全技术有限公司 一种端口资源分配方法及装置
CN108833611A (zh) * 2018-08-01 2018-11-16 中国联合网络通信集团有限公司 一种方法nat地址转换的分配方法
CN109167846B (zh) * 2018-08-02 2022-01-25 杭州迪普科技股份有限公司 一种通信端口的分配方法与装置
CN113329057B (zh) * 2021-04-30 2022-05-27 新华三技术有限公司成都分公司 一种设备的访问方法和网络设备
US11799822B2 (en) * 2022-01-21 2023-10-24 Google Llc Proxyless network address translation with dynamic port allocation

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101030919A (zh) * 2006-03-02 2007-09-05 中兴通讯股份有限公司 复用接口板地址时网络地址转换的实现方法
CN101262506A (zh) * 2008-04-21 2008-09-10 杭州华三通信技术有限公司 分布式架构下的网络地址转换端口资源分配方法及系统
CN102685272A (zh) * 2012-05-30 2012-09-19 华为技术有限公司 一种分配公网地址的方法及装置

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6993595B1 (en) * 2001-12-28 2006-01-31 Nortel Networks Limited Address translation change identification
KR101619736B1 (ko) * 2008-10-23 2016-05-12 삼성전자주식회사 세션 관리 프로토콜을 이용하여 사설망을 원격관리하기 위한 방법, 장치 및 시스템
CN101605105B (zh) * 2009-07-14 2012-05-09 中兴通讯股份有限公司 一种对分片报文进行网络地址转换的方法及设备
CN102377833B (zh) * 2010-08-19 2015-07-22 华为技术有限公司 一种网络地址转换的管理方法及装置

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101030919A (zh) * 2006-03-02 2007-09-05 中兴通讯股份有限公司 复用接口板地址时网络地址转换的实现方法
CN101262506A (zh) * 2008-04-21 2008-09-10 杭州华三通信技术有限公司 分布式架构下的网络地址转换端口资源分配方法及系统
CN102685272A (zh) * 2012-05-30 2012-09-19 华为技术有限公司 一种分配公网地址的方法及装置

Also Published As

Publication number Publication date
EP2683138A4 (en) 2014-01-08
CN102685272B (zh) 2015-03-11
CN102685272A (zh) 2012-09-19
EP2683138A1 (en) 2014-01-08

Similar Documents

Publication Publication Date Title
WO2013177891A1 (zh) 一种分配公网地址的方法及装置
US20130166776A1 (en) Method, apparatus, and system for allocating public ip address
CN110071984A (zh) 一种网络标识映射方法和系统以及终端、标识网关
CN101951417A (zh) 多服务器地址分配方法、系统及中继设备
WO2008153193A1 (ja) アドレス変換装置及びアドレス変換方法
WO2013159641A1 (zh) 地址分配方法、设备和系统
CN103297461B (zh) Nat会话保活时长设置方法以及客户端和服务器
CN104780232B (zh) 一种资源分配方法、控制器及系统
WO2020001045A1 (zh) 管理地址的方法和装置
CN104468574A (zh) 一种虚拟机动态获取ip地址的方法、系统及装置
CN104348928B (zh) 一种分配地址资源的方法、管理设备、请求设备及系统
CN113014680B (zh) 一种宽带接入的方法、装置、设备和存储介质
US10419392B2 (en) Method, device and system for implementing address sharing
CN103595638B (zh) 一种mac地址学习方法及装置
CN102118453A (zh) Ip地址自动配置方法、服务端设备、客户机和通信系统
CN106506724B (zh) 一种分配端口块的方法及装置
CN104519145A (zh) 一种地址资源管理方法、系统和dhcp服务器
CN102664971B (zh) 网络地址资源管理方法、系统及外部地址资源服务器
CN105979202B (zh) 一种数据传输方法及装置
WO2017059742A1 (zh) 用户侧设备、服务器、端口资源管理方法及系统
CN104065656B (zh) 一种媒体流数据识别方法
CN103118115B (zh) 面向云计算用户的虚拟机管理方法及装置
EP3029913A1 (en) Method for processing raw ip packet, and corresponding apparatus
EP2568666A1 (en) Ip address obtaining method and network access device
CN1992675A (zh) 一种保证网络地址转换设备与外网互通的方法

Legal Events

Date Code Title Description
WWE Wipo information: entry into national phase

Ref document number: 2012823122

Country of ref document: EP

NENP Non-entry into the national phase

Ref country code: DE