Patent Description:
Documents TSOU PHILIPS LIGHTING W LI CHINA TELECOM T TAYLOR <NPL>" and <NPL>",NAT44 WITH PRE-ALLOCATED PORTS; DRAFT-CHENG-BEHAVE-NAT44-PRE-ALLOCATED-PORTS-<NUM>. TXT disclose port group management in network address translation.

The following description provides an efficient method of allocating external source port addresses for the multiple connections that share the limited set of external source IP addresses for a destination IP address, or destination IP/port address pair, outside of a network. For instance, in some examples, the method specifies multiple pre-allocated port groups, each with multiple external port addresses. The port addresses are each port addresses corresponding to the same external source network IP address. When external port addresses are available in the pre-allocated port groups, the method allocates external port addresses from the pre-allocated port groups for new connections to the destination IP address. The method also dynamically modifies the number of pre-allocated port groups as the number of connections to destinations outside of the network increases or decreases. Each pre-allocated group may include several source port addresses and these source port addresses may be contiguous in a particular group. In some examples, the method performs these operations in order to provide a fast and efficient mechanism for (i) tracking source port addresses assigned to connections to the destination IP address, and (ii) allocating new source port addresses when no previously pre-allocated source port addresses are available.

As the number of connections to a particular destination address rises, the pre-allocated port groups may assign all of their available ports. In order to assign new ports, the method dynamically modifies the number of pre-allocated port groups by identifying a new connection for which an external source port has to be assigned, determining that the existing set of pre-allocated port groups does not have an external source port address available to assign to the new connection, and specifying a new set of pre-allocated port groups. The method then allocates an external port address from the new set of pre-allocated port groups.

In some examples, dynamically modifying the number of groups may include reducing the number of groups. The method may reduce the number of groups by identifying a pre-allocated group that was (i) previously used to assign source port addresses to connections and (ii) has had all of its pre-allocated source ports unassigned for at least some threshold period. The method then removes the identified pre-allocated group from the pre-allocated port groups. Removing the identified pre-allocated group may mean deleting the group, setting the group into an idle state, or otherwise eliminating it from use, at least temporarily.

The method of some examples provides an efficient way to search the multiple pre-allocated port groups. In some such methods, each particular pre-allocated group includes a set of metadata. The metadata includes an indicator of a number of ports available in the group for allocating to packet flows and a next port available for allocating to a packet flow. The method modifies the number of available ports and the next-available port in the metadata set of the particular pre-allocated group as ports from the particular group are allocated to packet flows and as ports from the particular group are de-allocated from packet flows that have been terminated.

The method may also determine whether a pre-allocated group has an available port for allocation to a new packet flow by examining the number of available ports in the metadata set of the group. When the number of available ports is zero for a group, the method selects another pre-allocated group from which a port should be selected for the new packet flow. The method of some examples also determines whether the set of pre-allocated ports indicates any available ports at all by iteratively examining metadata for each pre-allocated port group. If a metadata for a particular pre-allocated port group indicates an available port, the method identifies that the port is available. However, if the metadata for each pre-allocated port group indicates no ports are available in that pre-allocated port group, the method determines that no port tracked by the present pre-allocated port group is available. In some examples, determining from the metadata that no port is available in the present pre-allocated groups of ports causes the method to dynamically increase the number of pre-allocated port groups.

The method of some examples defines different sets of pre-allocated port groups, with each set associated with a different external destination IP address. The method identifies, for a new packet flow, the port-group set associated with an external destination IP address stored in a header field of the new flow. The method then allocates, for the new packet flow, an external port address from a particular pre-allocated port group in the identified port-group set. The method may also define, for each external destination IP address, a connection-tracking data store for storing connection-tracking records that map allocated external source port addresses to internal source IP and port addresses within the network. The connection-tracking records are used in performing network address translation on packets of flows exiting or entering the network.

The method of some examples allocates a bitmap of available source ports and allocates contiguous blocks of source ports in the bitmap to different pre-allocated groups of ports. The method uses the bitmap to identify the pre-allocated port groups and adjust the number of pre-allocated port groups.

The preceding Summary is intended to serve as a brief introduction to some aspects as described in more detail herein. It is not meant to be an introduction or overview of all inventive subject matter disclosed in this document. The Detailed Description that follows and the Drawings that are referred to in the Detailed Description will further describe the examples considered herein. Accordingly, to understand all the examples described by this document, a full review of the Summary, Detailed Description, the Drawings and the Claims is needed. Moreover, the claimed subject matters are not to be limited by the illustrative details in the Summary, Detailed Description and the Drawing.

The novel features of the invention are set forth in the appended claims. However, for purpose of explanation, several examples are set forth in the following figures.

In the following detailed description, numerous details are set forth and described. However, it will be clear and apparent to one skilled in the art that the discussion is not limited to specific illustrative details set forth and that the concepts may be practiced without some of the specific details and examples discussed.

Some examples provide a method for performing network address translation to share a limited number of external source network addresses among a large number of connections. This method is implemented in some examples by a first network (e.g., a private or public datacenter network) that uses the limited number of external source network addresses to communicate with one or more other networks. In some examples, a gateway of the first network performs the operations of this method.

Instead of allocating an external source network address for an egressing packet just based on its internal source network address, the method of some examples allocates the external source network address based on the egressing packet's source network address and destination network address. This allows a limited number of external source network addresses to be re-used for different destination network address. For instance, in some examples, the method's network address allocation scheme allows the same <NUM> external source ports to be used for <NUM> connections for each destination network address.

To keep track of the allocated external source network addresses, some examples create connection-tracking records that map allocated external source network addresses to internal source network addresses and external destination network addresses. <FIG> conceptually illustrates a process <NUM> of some examples that creates such a connection-tracking record for a packet flow. The process <NUM> creates the connection-tracking record for an egressing packet flow when it receives the first packet of the flow. The packet includes a header with an internal source address (e.g., an address of a machine or device in the datacenter) and an external destination address (e.g., an address of a machine or device outside of the datacenter).

The process <NUM> receives (at <NUM>) a packet of a packet flow. The packet includes a header with an internal source address and an external destination address. The internal source address is an address of a machine or device in the datacenter. The external destination address is an address of a machine or device outside of the datacenter such as an external website IP address.

From a pool of external source network addresses, the process <NUM> allocates (at <NUM>) an external source network address for the packet flow. The allocated external source network address will serve as an address on the Internet (or other outside network) to which the destination machine can send reply packets.

The process <NUM> then uses (at <NUM>) the allocated address to perform network address translation on the packet before forwarding the packet to its destination. The network address translation replaces the internal source address with the allocated external source network address. When the packet reaches its destination, the replaced source address provides the destination machine with a location to which to send reply packets over the Internet or other external network.

For a second packet flow that is received in response to the first packet flow, the process <NUM> creates (at <NUM>) a connection-tracking record. The connection-tracking record maps the external destination address and the external source network address to the internal source address, in order to translate the destination addresses of packets in the second flow to the internal network address. This mapping allows packets sent in response to the first flow to be routed to the correct machine of the datacenter.

The mapping is used in the method of some examples by a network address translator (NAT) to implement an addressing system that determines the internal machine to which an incoming packet is addressed based on both the external source network address that the network uses to communicate with an external machine and the external destination address. This allows the NAT to route packets to the correct internal machine when the external source network address and port are receiving packets from an arbitrarily large number of external machines. That is, the same external source IP and source port address could receive packets from thousands or more different external machines and correctly route the packets to the machines at the appropriate internal network addresses. The NAT uses the connection-tracking records to identify the internal machine for each incoming packet flow.

<FIG> illustrates a network address translation (NAT) system with a connection tracker. <FIG> includes connection tracker <NUM>, network address translator (NAT) <NUM>, and connection tracker storage <NUM>.

The connection tracker storage <NUM> includes connection-tracking records used by the NAT <NUM> to determine which internal addresses to apply to incoming packets and which external source addresses to apply to outgoing packets. In some examples, the method creates a single connection-tracking record (<NUM>) for packets of a first, outgoing packet flow, and (<NUM>) for packets of a second, incoming packet flow that is received in response to the first packet flow.

In <FIG>, each connection-tracking record in the connection tracker storage <NUM> includes multiple attributes. The NAT <NUM> uses these attributes as a set of match attributes and a set of action attributes. In the method of some examples, which attributes are used as the match attributes and which are used as action attributes depends on whether the packet to be matched is an incoming or an outgoing packet. For example, for an incoming packet, the match attribute set for each connection-tracking record are external destination IP (E. IP) and external source network addresses (E. port), while the action attributes are internal source addresses (I.

The network address translator <NUM> identifies the source and destination addresses for a header of an incoming packet received at the network and uses the connection tracker <NUM> to determine whether the source and destination addresses in the header match the (incoming) match attributes of a connection-tracking record in the connection tracker storage <NUM>. The network address translator <NUM> then uses the (incoming) action attributes, I. port, to replace the destination network address of the reply packet with the internal network address stored by the connection-tracking record. The reply packet is then forwarded to the machine at the internal network IP address and internal network port.

For outgoing packets, the match attributes are (E. IP) and internal source addresses (I. port) while the action attributes are the external source network addresses (E. The NAT <NUM> identifies the source and destination addresses for a header of an outgoing packet to be sent from the network. The NAT <NUM> then uses the connection tracker <NUM> to determine whether the source and destination addresses in the header match the (outgoing) match attributes of a connection-tracking record in the connection tracker storage <NUM>. The network address translator <NUM> then uses the (outgoing) action attributes, E. port, to replace the destination network address of the outgoing packet with the internal network address stored by the connection-tracking record. The outgoing packet is then forwarded to the external destination. Some examples use hash functions to quickly locate connection-tracking records in connection-tracking storages. The use of such hash functions is further described with respect to <FIG>, below.

The above described method creates only one mapping connection-tracking record, and then uses different portions of this record for the match and action attributes for flows in the forward and reverse directions. However, in some examples, the connection-tracking record includes two sub-records, a first sub-record for the forward direction (i.e., for the subsequent packets of the outgoing flow), and a second sub-record for the reverse direction (i.e., for the packets of the incoming packet flow that is in response to the outgoing packet flow). In such examples, the first sub-record maps the combination of the internal source network address and external destination address to the allocated external source network address while the second sub-record maps the combination of the external destination address and the external source network address to the internal source network address. In other examples two separate connection-tracking records similar to such sub-records are created, one record for outgoing packets of a flow and one for incoming packets of a response flow.

In some examples, in addition to the connection-tracking record including the external destination IP, the match attributes also include an external destination port. Such a system allows up to <NUM> connections for each external destination IP/external destination port pair rather than <NUM> connections for each external destination IP. <FIG> illustrates a network address translation system with a connection tracker <NUM> that includes external destination ports in its attributes. The network address translator <NUM> uses a connection tracker <NUM> to access connection tracker storage <NUM> in which each connection-tracking record includes, for incoming packets, (<NUM>) match attributes: external destination IP (E. IP), external destination port (E. port), and external source network addresses (E. port), and (<NUM>) action attributes: internal source addresses (I. For outgoing packets, the match attributes are: external destination IP (E. IP), external destination port (E. port), and internal source addresses (I. port), while the action attributes are: external source network addresses (E. Some examples that include destination port addresses in the connection-tracking records also create two sub-records or two separate connection-tracking records, rather than using a single connection-tracking record and determining which attributes are match or action attributes based on the direction of the packet flow.

In some examples, the connection-tracking record uses both the external destination address and external source network address for mapping to the internal network address because the external source network address is used as an external source network address for different packet flows to different destination addresses. For instance, as mentioned above, the method of some examples uses the same external source IP address along with the same <NUM> source port range for multiple different destination IP addresses. The method of some examples further extends the sharing of the <NUM> source ports by using this port range not only for different destination IP addresses but also for different destination port addresses to the same destination IP address. This allows the method to support up to <NUM>,<NUM>,<NUM>,<NUM> (<NUM> multiplied by <NUM>) connections for each destination IP address.

Because of the potentially huge number of ports to be allocated for the multiple flows, it is useful to have a fast and efficient method of allocating and de-allocating ports of an external source network address (e.g., an external source IP address). For the sake of efficiency, rather than allocating the <NUM> ports of an external source IP in a random manner, some examples use a source-port allocation process that pre-allocates groups of source port addresses, assigns source port addresses to new connections from these pre-allocated port groups, and adds new and removes old pre-allocated port groups as the number of connections increases and decreases.

<FIG> conceptually illustrates such a source-port allocation process <NUM>. The process <NUM> will be described by reference to an example shown in <FIG>, which illustrates pre-allocation of groups of source port addresses and dynamic growth and reduction of these groups as the number of connections increases and decreases. <FIG> includes a column of port addresses <NUM> of an external source IP address, multiple pre-allocated port groups <NUM> at time T=<NUM>, multiple pre-allocated port groups <NUM> at time T=<NUM>, and multiple pre-allocated port groups <NUM> at time T=<NUM>. The available ports <NUM> include <NUM>,<NUM> (<NUM>) ports numbered from <NUM> to <NUM>,<NUM>.

The process <NUM> (of <FIG>) specifies (at <NUM>) multiple pre-allocated port groups of external port addresses. The port addresses in the pre-allocated port groups are each port addresses of the same external source network address (e.g., of an external source IP address) and are all assigned with respect to the same external destination IP address. In some examples, a particular port value is not available to be allocated to a connection unless that port is in a pre-allocated port group. In <FIG>, at time T=<NUM>, the pre-allocated port groups include two groups <NUM> and <NUM>. Each of these groups contains <NUM> pre-allocated ports from the set of possible port addresses <NUM>. Within each pre-allocated port group, the source port addresses are contiguous. Group <NUM> includes ports <NUM>-<NUM> and group <NUM> includes ports <NUM>-<NUM>.

The process <NUM> (of <FIG>) allocates/de-allocates (at <NUM>) external source port addresses from the pre-allocated port groups. Ports are allocated (as needed) between machines of the datacenter and machines at external destination addresses. As <FIG> shows, operation <NUM> is applied repeatedly as new connections are needed.

When the process <NUM> determines (at <NUM>) that all pre-allocated ports in the pre-allocated port groups have not been used (e.g., some ports are still available in the pre-allocated port groups) the process <NUM> determines (at <NUM>) whether new connections that need a new port are to be allocated or an existing connection has terminated and the port for that connection needs to be de-allocated. When ports for new connections are being allocated more frequently than ports for old (terminated) connections are being de-allocated, the process <NUM> will eventually determine (at <NUM>) that all available ports of the pre-allocated groups are in use (e.g., assigned to connections between machines of the datacenter and the external destination address). In that case, the process <NUM> pre-allocates (at <NUM>) additional port groups, then returns to operation <NUM>.

<FIG> illustrates an example of such dynamic modifications of multiple pre-allocated groups <NUM>-<NUM> from time T=<NUM> to time T=<NUM>. In this example, <NUM> external source port addresses in the pre-allocated port groups <NUM> and <NUM> have been allocated by time T=<NUM>. The pre-allocated group <NUM> is shown completely shaded to indicate that all <NUM> ports in group <NUM> are allocated to various connections between the external source IP address and the particular destination IP address associated with the pre-allocated port groups. Group <NUM> is partially shaded, with the port number <NUM> shown as the lowest available port, indicating that group <NUM> still has available ports <NUM>-<NUM> to be assigned to new connections.

Between time T=<NUM> and time T=<NUM> the process <NUM> (of <FIG>) allocates (at <NUM>) additional external source port addresses from the pre-allocated port group <NUM> (of <FIG>) for new connections between the external source IP address and the destination IP address associated with the port groups. At first, each new allocated port address will be one of the available ports in the range <NUM>-<NUM> from group <NUM>. However, in the illustrated example, the process <NUM> (of <FIG>) eventually allocates all the available ports in the pre-allocated port group <NUM>. After that, the process <NUM> determines (at <NUM>) that all pre-allocated ports in the existing port groups are in use. The process <NUM> then pre-allocates (at <NUM>) an additional port group, group <NUM> of <FIG>. Group <NUM> also has <NUM> ports, specifically ports <NUM>-<NUM>. The process <NUM> (of <FIG>) then continues to allocate ports (at <NUM>) until all ports of group <NUM> (of <FIG>) are used, then pre-allocates (at <NUM>) additional port group <NUM>, which also has <NUM> ports, specifically ports <NUM>-<NUM>.

The process <NUM> (of <FIG>), when no connection is being allocated/de-allocated determines (at <NUM>) whether it is time to re-examine port group allocation. In some examples, this determination is made periodically (e.g., every <NUM> seconds, every <NUM> seconds, etc.). In other examples, a state of the system may trigger the re-examination (e.g., the process may re-examine group allocation when the existing pre-allocated ports are nearly all used and/or when all ports of a pre-allocated group have become available either at all or for a threshold amount of time). When the process <NUM> determines (at <NUM>) that it is not time to re-examine port group allocation, the process <NUM> returns to operation <NUM>.

When the process <NUM> determines (at <NUM>) that it is time for a re-examination and the re-examination determines that the number of connections that need external source ports to connect to the external destination address has changed, the process <NUM> will dynamically modify (at <NUM>) the number of pre-allocated groups, by either increasing or reducing the number of pre-allocated groups. For example, the process <NUM> (of <FIG>) reduces (at <NUM>) the number of groups by identifying a pre-allocated port group that is no longer active and removing it after de-allocating (at <NUM>) all of the ports of that pre-allocated port group. Removing the group may mean deleting the group, setting the group into an idle state, or otherwise eliminating it from use. After modifying the number of groups, the process <NUM> then returns to operation <NUM> to determine whether connections need to be allocated/de-allocated.

In <FIG>, sometime between the process adding group <NUM> and time T=<NUM>, connections using ports in group <NUM> began to terminate. When those connections terminated, the ports became available again and the process <NUM> de-allocated (at <NUM>) the ports. The newly available ports are shown as the unshaded portion of group <NUM>. In this example, sometime between time T=<NUM> and time T=<NUM>, all of the connections in group <NUM> terminated and the process <NUM> (of <FIG>) dynamically modified (at <NUM>) the number of groups by removing (e.g., deleting) group <NUM> (of <FIG>). In the illustrated example, some connections using ports tracked by groups <NUM> and <NUM> also terminated between T=<NUM> and T=<NUM>, as shown by the unshaded portions of those groups. However, since not all connections with ports tracked by either of those groups terminated, the groups <NUM> and <NUM> were not removed by process <NUM>.

Although for simplicity of explanation, the description described ports as either only being allocated or only being de-allocated at various times, the process <NUM> can allocate and de-allocate ports as necessary. For example, the process <NUM> can allocate a particular port for a new connection after an old connection (to which that port was allocated) terminates. In some examples, the method preferentially assigns the lowest available ports to new connections, resulting in a tendency for higher pre-allocated port groups to empty out sooner than lower pre-allocated port groups as overall demand for connections to the destination IP address decreases.

Although the above described figures show operations in a particular order, one of ordinary skill in the art will realize that other orders of operations are possible. For example, in the illustrated example, a new port group is created once the last port of the groups are allocated, but in other examples, the new port group may be created when the number of available ports in the pre-allocated groups drops below a threshold, in anticipation of a need for more capacity. In still other examples, a new port group may be created only when a new connection needs a port and all available ports are already allocated.

The illustrated groups track port availability only for connections between one particular external source IP and one particular destination IP. Although packets may come in to or be forwarded from the ports of the external source IP from other destination IP addresses, those connections are not tracked by the illustrated pre-allocated port groups of <FIG>, but rather by separate pre-allocated port groups (not shown). That is, in some examples, there is a separate set of pre-allocated port groups for the external source address associated with each destination IP address. Furthermore, in some examples, there is a separate set of pre-allocated port groups for the external source address associated with each destination IP address/destination port pair. Although the illustrated pre-allocated port groups are each the same size (contain the same number of ports), in other examples, some pre-allocated port groups may be different sizes than others.

The methods of some examples provide efficient ways to search the multiple pre-allocated port groups for available ports. In some methods, each pre-allocated port group is associated with a set of metadata. The set of metadata for each group may include an indicator of how many of the ports tracked by that group are available and may also identify a specific available port tracked by that group (e.g., the lowest available port number tracked by the group).

<FIG> conceptually illustrates a process <NUM> of some examples to identify and allocate available ports using metadata of pre-allocated port groups. The process <NUM> uses the metadata to determine whether the existing pre-allocated port groups contain any available ports by iteratively examining metadata for each pre-allocated port group. The process will be described with respect to <FIG> conceptually illustrates iteratively searching metadata of pre-allocated port groups. <FIG> includes <NUM> pre-allocated port groups, specifically two pre-allocated port groups <NUM> and <NUM> with four ports each and a pre-allocated port group <NUM> with eight ports. The groups <NUM>, <NUM>, and <NUM> each have accompanying metadata <NUM>, <NUM>, and <NUM>, respectively.

The process <NUM> (of <FIG>) begins when a new connection requires a port allocation. The process <NUM> identifies (at <NUM>) a new connection that requires an external source port. The new connection will be a connection between a particular external source IP address and a particular external destination IP address. The pre-allocated port groups to be examined are groups of ports for connections to that particular external destination address.

The process <NUM> examines (at <NUM>) the metadata for an unexamined (so far in the port allocation process <NUM>) pre-allocated port group. If the process <NUM> determines (at <NUM>) that the metadata of the first group indicates that no ports are available, the process <NUM> determines (at <NUM>) whether any other groups have not had their metadata examined and then cycles through operations <NUM>, <NUM>, and <NUM> until it identifies (at <NUM>) an available port and proceeds to operation <NUM> (as described in the next paragraph) or determines (at <NUM>) that the metadata of the last group indicates no available ports. If the metadata of every group indicates no available ports, the process <NUM> creates a new pre-allocated port group and identifies a first port of the new pre-allocated port group as available before proceeding to operation <NUM>.

In the example of <FIG> the process <NUM> starts with the first pre-allocated port group and proceeds sequentially until it finds an available port. The pre-allocated port group <NUM> has no available ports, as indicated by all four ports of the first pre-allocated port group being shaded. Accordingly, the metadata <NUM> for group <NUM> shows no ports available. Therefore, the process <NUM> (of <FIG>) determines, at <NUM>, that the metadata identifies no port available in the first group. The process <NUM> then determines (at <NUM>) that the group was not the last pre-allocated port group, because groups <NUM> and <NUM> have not been examined.

The process <NUM> then examines (at <NUM>) the metadata for the next pre-allocated port group and returns to operation <NUM> to determine the results. In the example of <FIG>, the next group is pre-allocated port group <NUM>. Pre-allocated port group <NUM> has two ports available, as indicated in the figure by two unshaded ports. The metadata <NUM> indicates that two ports are available in the group and that the next assignable port number is <NUM>. Therefore the process <NUM> (of <FIG>) determines (at <NUM>) that port <NUM> is available. The process <NUM> (of <FIG>) then proceeds to operation <NUM> and allocates port <NUM> to the new connection.

The process <NUM> then updates (at <NUM>) the pre-allocated port group to indicate that the port is now allocated and updates the metadata to indicate the remaining number of available ports in the group and the number of the next available port. The process <NUM> then ends. In <FIG>, at time T=<NUM>, the newly allocated port of group <NUM> has been shaded to indicate that the port has been allocated and metadata <NUM> has been updated to indicate only one available port rather than two (as was the case at time T=<NUM>) and the next available port is identified in the metadata <NUM> as port number <NUM>.

The metadata in the illustrated example includes the available port with the lowest numerical value as the next port for allocation. However, in other examples some other port of the port group may be designated as the next available port (e.g., the longest unused port, the highest numbered available port, etc.).

As mentioned above, in some examples, the connection using an allocated port may terminate. When the connection terminates, the port is de-allocated. The method of some examples, updates (<NUM>) the pre-allocated port group to which the de-allocated port belongs and (<NUM>) the metadata for that group to indicate that the port is available to be allocated to a new connection for a new outgoing flow (and its reply flow). Furthermore, when all the ports in a particular pre-allocated port group are de-allocated, the method of some examples removes the pre-allocated port group as well.

<FIG> illustrates a process <NUM> for de-allocating ports. The process <NUM> will be described with reference to <FIG> illustrates modifications of pre-allocated port groups upon the de-allocation of ports. The figure includes pre-allocated groups <NUM>, <NUM>, and <NUM> with metadata sets <NUM>, <NUM>, and <NUM> respectively. The figure is shown at times T=<NUM> to T=<NUM> as ports of pre-allocated group <NUM> are de-allocated and at time T=<NUM> after the process <NUM> has ended and a separate cleanup process of some examples has removed an empty (e.g., with no allocated ports) pre-allocated port group.

The process <NUM> (of <FIG>) determines (at <NUM>) that a connection using an external source IP and port to connect to a particular external destination IP address has terminated. In some examples, the termination of a connection may be determined by a process that calculates how much time has passed since a packet of an outgoing and/or incoming flow of that connection has been received and identifies the connection as terminated after a threshold time has passed. Additionally or alternatively, a connection may be explicitly terminated by a termination code received from one or both of the machines at the original internal source address and the external destination address.

The process <NUM> then updates (at <NUM>) the pre-allocated port group for that port in the set of pre-allocated port groups associated with that external destination to indicate that the port is available. Two examples of port-group updating are conceptually illustrated in <FIG>. At time T=<NUM>, the first port of pre-allocated port group <NUM> is shown by its shading as being allocated to a connection. By time T=<NUM>, the first port has been de-allocated, as shown by the lack of shading in the first port of group <NUM> at time T=<NUM>. Similarly, from time T=<NUM> to time T=<NUM>, the last remaining allocated port of group <NUM> is de-allocated, as shown by the removal of its shading.

The process <NUM> (of <FIG>) then updates (at <NUM>) the metadata for the pre-allocated port group. In <FIG>, metadata <NUM> of group <NUM> is updated from showing <NUM> available ports in the associated pre-allocated port group <NUM> at time T=<NUM> to showing <NUM> available ports at time T=<NUM>. In the illustrated example, the metadata includes the first (lowest port numbered) available port as the next available port for allocation. The first available port identified in the metadata is updated from port <NUM> at time T=<NUM> to port <NUM> (the de-allocated port) at time T=<NUM>. The metadata <NUM> is updated again at time T=<NUM> to show <NUM> available ports in group <NUM>. The process <NUM> (of <FIG>) then ends.

In some examples, a separate clean-up process (e.g., as discussed with respect to operation <NUM> and <NUM> of <FIG>) removes pre-allocated port groups with no allocated ports. In <FIG>, group <NUM> has a remaining allocated port at time T=<NUM>, so the group is not removed by such a clean-up process at that time. However, after the last remaining allocated port of group <NUM> is de-allocated, the group <NUM> is removed by the clean-up process, leaving only groups <NUM> and <NUM> as active pre-allocated groups at time T=<NUM>.

One of ordinary skill in the art will understand that in the illustrated examples of <FIG> and <FIG> the process <NUM> updates the metadata <NUM> for the empty pre-allocated port group <NUM> before a separate clean-up process removes the group (e.g., using the metadata to identify the group as empty), while other examples may simply remove the group when it becomes empty, without updating the metadata first. Although the metadata in the illustrated example includes the available port with the lowest numerical value as the next port for allocation, in other examples some other port of the port group may be designated as the next available port (e.g., the longest unused port, the highest numbered available port, etc.).

In some examples, the pre-allocated port groups are stored as bitmap chunks. In such examples, each bit of a bitmap chunk represents a single port, with (i) the port number based on the position of the bit within the bitmap and (ii) the state of the port (allocated or not-allocated) determined by the value of the bit. In some such examples, as the number of connections to a destination IP grows, larger pre-allocated port groups are allocated (i.e., as larger bitmap chunks). For example, in some examples, the first two pre-allocated chunks are implemented as two <NUM>-bit chunks, the next four pre-allocated chunks are implemented as four <NUM>-bit chunks, the next eight pre-allocated chunks are implemented as eight <NUM>-bit chunks, and the next eleven pre-allocated chunks are implemented as eleven <NUM>-bit chunks. In some examples, the maximum total number of bits in all the bitmap chunks for a given destination IP address (or destination IP address and port) is <NUM>. Other examples that implement pre-allocated port groups as bitmaps may use different sizes of bitmap chunks to reach <NUM> bits or may have other maximum numbers of bits (e.g., in order to limit the number of ports available for connections to a particular destination address).

As mentioned above, the method of some examples uses hash functions to quickly locate connection-tracking records. <FIG> illustrates the use of a hash function to locate tracking-records. The figure includes a set of packet header data <NUM>, a hash function <NUM>, and hash buckets <NUM> (e.g., rows of a hash table) with tracking record entries <NUM>. Some of the entries are stored in linked lists <NUM> and <NUM>. One of ordinary skill in the art will understand that although both the data to which the hash function is applied in this figure, and the match and action attributes described with respect to <FIG> and <FIG>, are packet header data, some or all of the packet header data on which the hash is performed may not be the same as any of the match or action attributes.

In the illustrated example of <FIG>, when a packet comes into the network, the method identifies the external destination IP (EDI) and external destination port (EDP) values from the packet header data <NUM>. A hash function <NUM> is then applied to the EDI/EDP pairs to identify a particular bucket <NUM> of a hash table in which the connection-tracking records <NUM> are stored.

In some examples, hash collisions occur for some flows, such as when multiple connection-tracking records <NUM> have the same EDI/EDP pair or when connection-tracking records <NUM> of flows with different EDI/EDP pairs hash to the same location. In the event of a hash collision the connection-tracking record entries <NUM> are stored in linked lists, such as linked list <NUM>, which includes three connection-tracking records <NUM> from EDI2/EDP3 and linked list <NUM> which contains one connection-tracking record <NUM> for flows with the EDI1/EDP2 pair and two connection-tracking records <NUM> for flows with the EDI2/EDP4 pair.

One of ordinary skill in the art will understand that the methods of some examples may use other packet header values as inputs for hash functions. For example, the methods of some examples may use the entire connection tuple of a packet or any chosen subset of its values as inputs for a hash function. Some examples may use multiple instances of one or more hash functions to populate multiple hash tables with the same general purpose. For example, some examples may provide a separate hash table for connection-tracking records for each external source IP address. Similarly, in some examples, the methods may use multiple hash functions for different purposes. For example, some examples use a hash function to sort entries of a hash table containing connection-tracking records and another hash function to identify where pre-allocation port groups are stored for each ESI/EDI pair or ESI/EDI/EDP combination. Additionally, although the example of <FIG> shows connection-tracking records <NUM> in the buckets <NUM>, in some examples, the hash function identifies the location in the hash table of a pointer that in turn identifies a first entry in a linked list of connection-tracking records, the location of another hash table, the location of a binary tree, etc..

<FIG> conceptually illustrates an electronic system <NUM> with which some examples are implemented. The electronic system <NUM> can be used to execute any of the control, virtualization, or operating system applications described above. The electronic system <NUM> may be a computer (e.g., a desktop computer, personal computer, tablet computer, server computer, mainframe, a blade computer etc.), or any other sort of electronic device. Such an electronic system includes various types of computer readable media and interfaces for various other types of computer readable media. Electronic system <NUM> includes a bus <NUM>, processing unit(s) <NUM>, a system memory <NUM>, a read-only memory <NUM>, a permanent storage device <NUM>, input devices <NUM>, and output devices <NUM>.

For instance, the bus <NUM> communicatively connects the processing unit(s) <NUM> with the read-only memory <NUM>, the system memory <NUM>, and the permanent storage device <NUM>.

From these various memory units, the processing unit(s) <NUM> retrieve instructions to execute and data to process in order to execute the processes. The processing unit(s) may be a single processor or a multi-core processor in different examples.

The read-only-memory (ROM) <NUM> stores static data and instructions that are needed by the processing unit(s) <NUM> and other modules of the electronic system. The permanent storage device <NUM>, on the other hand, is a read-and-write memory device. This device is a non-volatile memory unit that stores instructions and data even when the electronic system <NUM> is off. Some examples use a mass-storage device (such as a magnetic or optical disk and its corresponding disk drive) as the permanent storage device <NUM>.

Other examples use a removable storage device (such as a floppy disk, flash drive, etc.) as the permanent storage device. Like the permanent storage device <NUM>, the system memory <NUM> is a read-and-write memory device. However, unlike storage device <NUM>, the system memory is a volatile read-and-write memory, such a random access memory. The system memory <NUM> stores some of the instructions and data that the processor needs at runtime. In some examples, the processes are stored in the system memory <NUM>, the permanent storage device <NUM>, and/or the read-only memory <NUM>. From these various memory units, the processing unit(s) <NUM> retrieve instructions to execute and data to process in order to execute the processes of some examples.

The bus <NUM> also connects to the input and output devices <NUM> and <NUM>. The input devices <NUM> enable the user to communicate information and select commands to the electronic system. The input devices <NUM> include alphanumeric keyboards and pointing devices (also called "cursor control devices"). The output devices <NUM> display images generated by the electronic system <NUM>. The output devices <NUM> include printers and display devices, such as cathode ray tubes (CRT) or liquid crystal displays (LCD). Some examples include devices such as a touchscreen that function as both input and output devices.

Finally, as shown in <FIG>, bus <NUM> also couples electronic system <NUM> to a network <NUM> through a network adapter (not shown). In this manner, the computer can be a part of a network of computers (such as a local area network ("LAN"), a wide area network ("WAN"), or an Intranet, or a network of networks, such as the Internet. Any or all components of electronic system <NUM> may be used.

Some examples include electronic components, such as microprocessors, storage and memory that store computer program instructions in a machine-readable or computer-readable medium (alternatively referred to as computer-readable storage media, machine-readable media, or machine-readable storage media). Some examples of such computer-readable media include RAM, ROM, read-only compact discs (CD-ROM), recordable compact discs (CD-R), rewritable compact discs (CD-RW), read-only digital versatile discs (e.g., DVD-ROM, dual-layer DVD-ROM), a variety of recordable/rewritable DVDs (e.g., DVD-RAM, DVD-RW, DVD+RW, etc.), flash memory (e.g., SD cards, mini-SD cards, micro-SD cards, etc.), magnetic and/or solid state hard drives, read-only and recordable Blu-Ray® discs, ultra-density optical discs, any other optical or magnetic media, and floppy disks. The computer-readable media may store a computer program that is executable by at least one processing unit and includes sets of instructions for performing various operations. Examples of computer programs or computer code include machine code, such as is produced by a compiler, and files including higher-level code that are executed by a computer, an electronic component, or a microprocessor using an interpreter.

While the above discussion primarily refers to microprocessor or multi-core processors that execute software, some examples are performed by one or more integrated circuits, such as application-specific integrated circuits (ASICs) or field-programmable gate arrays (FPGAs). In some examples, such integrated circuits execute instructions that are stored on the circuit itself.

As used in this specification, the terms "computer", "server", "processor", and "memory" all refer to electronic or other technological devices. As used in this specification, the terms "computer readable medium," "computer readable media," and "machine readable medium" are entirely restricted to tangible, physical objects that store information in a form that is readable by a computer.

This specification refers throughout to computational and network environments that include virtual machines (VMs). However, virtual machines are merely one example of data compute nodes (DCNs) or data compute end nodes, also referred to as addressable nodes. DCNs may include non-virtualized physical hosts, virtual machines, containers that run on top of a host operating system without the need for a hypervisor or separate operating system, and hypervisor kernel network interface modules.

VMs, in some examples, operate with their own guest operating systems on a host using resources of the host virtualized by virtualization software (e.g., a hypervisor, virtual machine monitor, etc.). The tenant (i.e., the owner of the VM) can choose which applications to operate on top of the guest operating system. Some containers, on the other hand, are constructs that run on top of a host operating system without the need for a hypervisor or separate guest operating system. In some examples, the host operating system uses name spaces to isolate the containers from each other and therefore provides operating-system level segregation of the different groups of applications that operate within different containers. This segregation is akin to the VM segregation that is offered in hypervisor-virtualized environments that virtualize system hardware, and thus can be viewed as a form of virtualization that isolates different groups of applications that operate in different containers. Such containers are more lightweight than VMs.

Hypervisor kernel network interface modules, in some examples, are non-VM DCNs that include a network stack with a hypervisor kernel network interface and receive/transmit threads. One example of a hypervisor kernel network interface module is the vmknic module that is part of the ESXi™ hypervisor of VMware, Inc.

It should be understood that while the specification refers to VMs, the examples given could be any type of DCNs, including physical hosts, VMs, non-VM containers, and hypervisor kernel network interface modules. In fact, the example networks could include combinations of different types of DCNs in some examples.

Claim 1:
A method of allocating external source port addresses for a plurality of connections that share a limited set of external source IP addresses for connections to a destination IP address outside of a network, the method comprising:
specifying (<NUM>), for the destination IP address, a plurality of pre-allocated port groups (<NUM>) with each group (<NUM>, <NUM>) comprising a plurality of external source port addresses, the external source port addresses being port addresses of the same external source IP address that is obtained by network address translation;
allocating (<NUM>), for new connections to the destination IP address, external source port addresses from the pre-allocated groups (<NUM>) when external source port addresses are available in the pre-allocated groups (<NUM>), wherein the lowest available external source port addresses in the pre-allocated groups (<NUM>) are allocated to said new connections; and
dynamically modifying (<NUM>) a number of the pre-allocated groups as a number of connections increases or decreases to destinations outside of the network.