Method and gateway for obtaining route according to requirement

A method and gateway obtain a route according to a requirement. The method includes: a first gateway receives a first packet; the first gateway searches a forwarding table for a next hop of a first IP address in the first packet, wherein the search fails; the first gateway sends a second packet carrying the first IP address to at least one gateway; the first gateway receives a third packet from a second gateway; and the first gateway writes an address of the second gateway into the forwarding table as a next hop address of the first IP address.

TECHNICAL FIELD

The present disclosure relates to the communications field, and in particular, to a method and gateway for obtaining a route according to a requirement.

BACKGROUND

In a network architecture of a distributed gateway, a local area network (English: local area network, LAN for short) includes multiple gateways. When a host changes its gateway, a Media Access Control (English: Media Access Control, MAC for short) address and an Internet Protocol (English: Internet Protocol, IP for short) address of the host are not changed. A packet forwarding manner in the distributed gateway architecture is that, regardless of whether a host sending a packet and a host receiving the packet are located in a same broadcast domain (English: broadcast domain, BD for short), the sender host sends the packet to a gateway of the sender host, and the gateway sends the packet to the receiver host according to a destination IP address of the packet. The receiver host may access a network by using another gateway in the local area network. Therefore, a forwarding table of the gateway of the sender host needs to include host routes of all hosts that access a network by using another gateway in the local area network. When the local area network includes a large quantity of hosts, a large quantity of host routes occupy many storage resources of the forwarding table.

SUMMARY

This application provides a method and an apparatus for obtaining a route according to a requirement, to obtain a route according to an actual packet forwarding requirement in a network architecture of a distributed gateway, thereby saving storage resources of a forwarding table.

According to a first aspect, a method for obtaining a route according to a requirement is provided, including:receiving, by a first gateway, a first packet, where the first packet includes a first Internet Protocol IP address;searching, by the first gateway, a forwarding table for a next hop of the first IP address, wherein the search fails;sending, by the first gateway, a second packet to at least one gateway, where the second packet carries the first IP address, and the second packet is used to instruct a gateway receiving the second packet to determine whether a host identified by the first IP address accesses a network by using the gateway receiving the second packet;receiving, by the first gateway, a third packet from a second gateway, where the second gateway is one of the at least one gateway, and the third packet is used to instruct the host identified by the first IP address to access the network by using the second gateway; andwriting, by the first gateway, an address of the second gateway into the forwarding table as a next hop address of the first IP address.

The first gateway does not need to prestore the next hop of the IP address in the first packet, but may obtain the route according to a requirement according to the accessing host. Therefore, if a network includes a large quantity of hosts, the first gateway does not need to store a next hop of an IP address of a host that has no requirement for communicating with the first gateway, thereby saving storage resources of the forwarding table.

Optionally, the second packet further carries a first virtual extensible local area network VXLAN network identifier VNI of the first packet. Before the sending, by the first gateway, a second packet to at least one gateway, the method further includes: determining, by the first gateway, the first VNI of the first packet.

For example, the determining, by the first gateway, the first VNI specifically includes: determining, by the first gateway, a port receiving the first packet; and determining, by the first gateway, the first VNI according to a mapping from the port to the first VNI. Before the first gateway searches the forwarding table for the next hop of the IP address in the first packet, the method further includes: determining, by the first gateway, the forwarding table according to a mapping from the first VNI to the forwarding table.

Optionally, the method further includes: receiving, by the first gateway, a fourth packet from a third gateway, where the fourth packet carries a second IP address; determining, by the first gateway, that a MAC address of a host identified by the second IP address can be obtained; and sending, by the first gateway, a fifth packet to the third gateway, where the fifth packet is used to instruct the host identified by the second IP address to access the network by using the first gateway. Optionally, the fourth packet further carries a second VNI, and the determining, by the first gateway, that a MAC address of a host identified by the second IP address can be obtained includes: attempting, by the first gateway, to obtain the MAC address of the host identified by the second IP address in a VXLAN segment identified by the second VNI.

Optionally, before the sending, by the first gateway, a second packet to at least one gateway, the method further includes: determining, by the first gateway according to a mapping table from multiple VNIs to multiple gateways, the at least one gateway corresponding to the VNI.

Optionally, the first packet is a data packet, the first IP address is a destination IP address of the first packet, the method further includes: performing, by the first gateway, VXLAN encapsulation on the first packet to obtain a sixth packet; and sending, by the first gateway, the sixth packet, where a value of a VNI field in a VXLAN header of the sixth packet is the VNI, and a destination IP address of an outer IP header of the sixth packet is the IP address of the second gateway.

According to a second aspect, a network device is provided, including:a processor, a memory, and a network interface, where the memory is configured to store a forwarding table, and the processor is configured to: receive a first packet by using the network interface, where the first packet includes a first Internet Protocol IP address;search the forwarding table stored in the memory for a next hop of the first IP address, wherein the search fails;send a second packet to at least one gateway by using the network interface, where the second packet carries the first IP address, and the second packet is used to instruct a gateway receiving the second packet to determine whether a host identified by the first IP address accesses a network by using the gateway receiving the second packet;receive a third packet from a first gateway by using the network interface, where the first gateway is one of the at least one gateway, and the third packet is used to instruct the host identified by the first IP address to access the network by using the first gateway; andwrite an address of the first gateway into the forwarding table stored in the memory as a next hop address of the first IP address.

A technical effect of this aspect is the same as that of the first aspect.

Optionally, the second packet further carries a first virtual extensible local area network VXLAN network identifier VNI of the first packet, and the processor is further configured to determine the first VNI of the first packet before sending the second packet to the at least one gateway.

Optionally, the processor is further configured to: receive a fourth packet from a second gateway by using the network interface, where the fourth packet carries a second IP address; determine that a MAC address of a host identified by the second IP address can be obtained; and send a fifth packet to the second gateway by using the network interface, where the fifth packet is used to instruct the host identified by the second IP address to access the network by using the first gateway.

Optionally, the fourth packet further carries a second VNI, and the determining that a MAC address of a host identified by the second IP address can be obtained specifically includes:attempting to obtain the MAC address of the host identified by the second IP address in a VXLAN segment identified by the second VNI.

According to a third aspect, a first gateway for obtaining a route according to a requirement is provided, including a first receiving unit, a storage unit, a searching unit, a sending unit, a second receiving unit, and a processing unit, wherethe first receiving unit is configured to receive a first packet, where the first packet includes a first Internet Protocol IP address;the storage unit is configured to store a forwarding table;the searching unit is configured to search the forwarding table stored in the storage unit for a next hop of the first IP address;the sending unit is configured to: after the searching unit searches the forwarding table stored in the storage unit for the next hop of the first IP address, wherein the search fails, send a second packet to at least one gateway, where the second packet carries the first IP address, and the second packet is used to instruct a gateway receiving the second packet to determine whether a host identified by the first IP address accesses a network by using the gateway receiving the second packet;the second receiving unit is configured to receive a third packet from a second gateway, where the second gateway is one of the at least one gateway, and the third packet is used to instruct the host identified by the first IP address to access the network by using the second gateway; andthe processing unit is configured to: obtain the third packet received by the second receiving unit, and write, as a next hop address of the first IP address according to the third packet, an address of the second gateway into the forwarding table stored in the storage unit.

A technical effect of this aspect is the same as that of the first aspect.

Optionally, the second packet further carries a first virtual extensible local area network VXLAN network identifier VNI of the first packet, and the searching unit is further configured to determine the first VNI of the first packet before the sending unit sends the second packet to the at least one gateway.

Optionally, the second receiving unit is further configured to receive a fourth packet from a third gateway, where the fourth packet carries a second IP address; the searching unit is further configured to: obtain the fourth packet received by the second receiving unit, and determine that a MAC address of a host identified by the second IP address carried in the fourth packet can be obtained; and the sending unit is further configured to send a fifth packet to the third gateway, where the fifth packet is used to instruct the host identified by the second IP address to access the network by using the first gateway.

Optionally, the fourth packet further carries a second VNI, and that the searching unit is configured to determine that a MAC address of a host identified by the second IP address can be obtained specifically configured to attempt to obtain the MAC address of the host identified by the second IP address in a VXLAN segment identified by the second VNI.

According to a fourth aspect, a computer storage medium is provided. The computer storage medium is configured to store computer software instructions used by the foregoing first gateway, and the instructions include a program designed to perform the foregoing aspects.

Optionally, based on any one of the first aspect, the second aspect, the third aspect, or the fourth aspect, the first packet is an Address Resolution Protocol ARP packet, and the first IP address is a target IP address of the first packet; or the first packet is a Neighbor Discovery Protocol NDP packet, and the first IP address is a target address of the first packet.

When the first gateway receives the ARP packet or the NDP packet, it means that a host sending the first packet may be about to communicate with the host identified by the first IP address. The first gateway sends, to another gateway when receiving the first packet, a next hop used to obtain the first IP address. In this way, a next hop of an IP address of a host having a communication requirement can be obtained early when no IP address of a host having no communication requirement is stored, thereby increasing efficiency of subsequent packet forwarding.

DESCRIPTION OF EMBODIMENTS

An application scenario described in an embodiment of this application is to describe the technical solutions of the embodiments of this application more clearly, but does not constitute limitation to the technical solutions of the embodiments of this application. A person of ordinary skill in the art will appreciate that, as a network architecture evolves and a new business scenario emerges, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.

FIG. 1is a schematic diagram of an application scenario according to an embodiment of this application. A data center network (English: data center network, DCN for short) includes a first gateway101, a second gateway102, and a third gateway103.

A host106may access the DCN by using any one of the first gateway101, the second gateway102, or the third gateway103. Similarly, a host107may access the DCN by using any one of the first gateway101, the second gateway102, or the third gateway103. For example, the host may be a personal computer (English: personal computer), a cell phone (English: cellphone), a smartphone (English: smartphone), a tablet computer (English: tablet computer), a wearable device (English: wearable device), a personal digital assistant (English: personal digital assistant, PDA for short), a mobile Internet device (English: mobile Internet device, MID for short), an e-book reader (English: e-book reader), or the like, or may be a virtual machine (English: virtual machine, VM for short). When the host is a virtual machine, the virtual machine can run on a server.

When a host, for example, the host106, accesses the DCN by using different gateways, neither a MAC address nor an IP address of the host106is changed. For example, the host106is a virtual machine. When the virtual machine migrates from a server connected to the first gateway101to a server connected to the second gateway102, neither a MAC address nor an IP address of the virtual machine is changed. Therefore, hosts located in a same broadcast domain (English: broadcast domain, BD for short) may access a network by using different gateways.

To reduce a quantity of broadcast packets, a packet forwarding manner in the foregoing network architecture of the distributed gateway is that: In a process in which the host106sends the packet to the host107, regardless of whether the host106and the host107are in a same broadcast domain, the host106uses a MAC address of a gateway of the host106as a MAC address of the packet sent to the host107. For example, when accessing the DCN by using the first gateway101, the host106sends a packet to the first gateway101. After receiving the packet, the first gateway101obtains a destination IP address in the packet by peeling off an Ethernet frame header (English: Ethernet frame header) of the packet, and forwards the packet according to the destination IP address in the packet.

When the foregoing packet forwarding manner is used, to enable the host106to send a packet to the host107, the first gateway101connected to the host106needs to prestore a host route (English: host route) of the host107in a forwarding table. The host route includes an IP address of the host107and a next hop (English: next hop) of the IP address of the host107. That is, the first gateway101needs to prestore a gateway that is currently used by the host107to access the network. For example, inFIG. 1, the first gateway101needs to know whether the host107currently accesses the network by using the second gateway102or by using the third gateway103.

Therefore, when the host107accesses the network by using the second gateway102, the second gateway102needs to advertise (English: advertise) the host route of the host107to another gateway in the DCN. For example, the host route is advertised to the first gateway101and the third gateway103, and the first gateway101and the third gateway103store the next hop of the IP address of the host107as the second gateway102.

The process of forwarding the packet and advertising the host route is described below by using an example in which the first gateway101, the second gateway102, and the third gateway103forward a data packet by using a virtual extensible local area network (English: Virtual eXtensible Local Area Network, VXLAN for short) tunnel, and advertise the host route by using the Border Gateway Protocol (English: Border Gateway Protocol, BGP for short).

The first gateway101, the second gateway102, and the third gateway103establish connections between each other in advance by using the Border Gateway Protocol (English: Border Gateway Protocol, BGP for short). That is, every two of the first gateway101, the second gateway102, and the third gateway103are BGP peers (English: BGP peer) of each other.

When the host107establishes a connection to the second gateway102, the second gateway102advertises the host route of the host107to other gateways, such as the first gateway101and the third gateway103, in the DCN by using a BGP packet. The first gateway101saves the host route of the host107in a routing table, and uses the second gateway102as the next hop of the host107.

The first gateway101, the second gateway102, and the third gateway103are all VXLAN tunnel end points (English: VXLAN Tunnel End Point, VTEP for short).

If the host106and the host107belong to different broadcast domains, and the host106intends to send a data packet to the host107, the host106uses the IP address of the host107as a destination IP address of the data packet, uses a MAC address of the first gateway as a destination MAC address of the data packet, and sends the data packet to the first gateway101.

If the host106and the host107belong to a same broadcast domain, the host106intends to use a MAC address of the host107as a destination MAC address of the data packet. Therefore, before sending the data packet, the host106first broadcasts a second packet that is used to request the MAC address of the host107in the broadcast domain. For example, the second packet may be an Address Resolution Protocol (English: address resolution protocol, ARP for short) request packet in the Internet Protocol version 4 (English: Internet Protocol version 4, IPv4 for short). For example, in the Internet Protocol version 6 (English: Internet Protocol version 6, IPv6 for short), the second packet may be a Neighbor Discovery Protocol (English: Neighbor Discovery Protocol, NDP for short) packet in the Internet Control Message Protocol (English: Internet Control Message Protocol, ICMP for short). After the first gateway101receives the second packet, the first gateway101sends a reply packet of the second packet to the host106by using a proxy (English: proxy) mechanism, to inform the host106that the MAC address corresponding to the IP address of the host107is the MAC address of the first gateway101. The host106uses the MAC address of the first gateway101as a MAC address of a first packet, and sends the first packet to the first gateway101.

Therefore, regardless of whether the host106and the host107belong to a same broadcast domain, when sending a data packet to the host107, the host106uses the MAC address of the first gateway101as a MAC address of the data packet. After receiving the data packet, the first gateway101determines, according to a port receiving the data packet, a VXLAN network identifier (English: VXLAN Network Identifier, VNI for short) of the data packet. The VNI may also be referred to as a VXLAN segment identifier (English: VXLAN Segment ID). A correspondence between each of multiple VNIs and the forwarding table is stored in the first gateway101. The first gateway101determines the forwarding table according to a VNI of the first packet. The host route of the host107that is advertised by the second gateway102by using the BGP protocol is prestored in the forwarding table. The host route includes the address of the host107, and that a next hop corresponding to the address of the host107is the second gateway102. The first gateway101sends the data packet to the second gateway102by using the VXLAN tunnel. That is, the first gateway101performs VXLAN encapsulation on the data packet. Specifically, the first gateway101encapsulates a VXLAN header (English: VXLAN header), an outer User Datagram Protocol (English: User Datagram Protocol, UDP for short) header (English: outer UDP header), and an outer IP header (English: outer IP header) in order at outer layer of the data packet. A VNI in the VXLAN header is the VNI of the data packet, and a destination IP address in the outer IP header is an IP address of the second gateway102. Refer to the Request for Comments (English: Request for Comments, RFC for short) 7348 protocol for encapsulation of other fields.

After receiving the data packet on which the VXLAN encapsulation is performed, the second gateway102determines the forwarding table according to the VNI in the VXLAN header of the packet. A correspondence between the IP address and the MAC address of the host in the VXLAN segment is stored in the forwarding table. The second gateway102finds the MAC address of the host107in the forwarding table, and sends the data packet to the host107.

In the solution, the first gateway101needs to prestore, in the forwarding table, all host routes accessing the network by using another gateway. When the DCN includes a large quantity of hosts, there are a huge quantity of host routes. Because some hosts may have no requirement for communicating with each other, the some host routes may not be desired by the first gateway101. Storing a host route not desired by the first gateway101occupies a storage resource of the forwarding table.

Embodiments of this application provide a method for obtaining a route according to a requirement. The method is used to obtain a route in a network architecture of a distributed gateway according to an actual packet forwarding demand, thereby saving storage resources of a forwarding table.

FIG. 2shows a method for obtaining a route according to a requirement according to an embodiment of this application. For example, the method may be applied to the distributed gateways shown inFIG. 1. A first gateway in the method shown inFIG. 2may be the first gateway101shown inFIG. 1. A second gateway in the method shown inFIG. 2may be the second gateway102shown inFIG. 1. The method includes the following steps.

S201: The first gateway receives a first packet, where the first packet includes a first IP address.

A host identified by the first IP address is not a sender of the first packet. For example, the first packet is from a first the host, but the host identified by the first IP address is a second host.

For example, the first packet is the packet that is sent by the host106to the first gateway101shown inFIG. 1.

In a possible example, the first packet is a data packet. The first IP address is a destination IP address (English: destination IP address) in the first packet. For example, the first packet is a data packet to be sent by the host106to the host107. The destination IP address is an IP address of the host107.

In another possible example, the first packet is an ARP packet, and the first IP address is a target protocol address (English: target protocol address, TPA for short) of the first packet. For example, the host106intends to send the data packet to the host107according to IPv4, and the host106and the host107belong to a same broadcast domain. Before sending the data packet to the host107, the host106first broadcasts the ARP packet, to obtain a MAC address of the host107.

In still another possible example, the first packet is an NDP packet, and the first IP address is a target address (English: target address) of the first packet. For example, the host106intends to send the data packet to the host107according to IPv6, and the host106and the host107belong to a same broadcast domain. Before sending the data packet to the host107, the host106first sends the NDP packet (for example, neighbor solicitation (English: Neighbor Solicitation)), to obtain a MAC address of the host107.

S202: The first gateway searches a forwarding table for a next hop of the first IP address, wherein the search fails.

In this application, multiple IP addresses and a next hop of each of the multiple IP addresses are stored in the forwarding table. For example, when a host accesses a network by using another gateway (for example, the second gateway), the next hops of the IP addresses stored in the forwarding table may include an IP address of the gateway (for example, the second gateway). That is, a mapping from an IP address of the host to the IP address of the gateway (for example, the second gateway) is stored in the forwarding table. For example, when a host accesses a network by using a gateway (for example, the first gateway) that stores the forwarding table, the next hops of the IP addresses stored in the forwarding table may include a MAC address of the host. That is, a mapping from an IP address of the host to the MAC address of the host is stored in the forwarding table. Further, outbound interface identifiers of the next hops of the IP addresses may further be stored in the forwarding table.

For example, the forwarding table may be a routing information base (English: routing information base, RIB for short) or a forwarding information base (English: forwarding information base, short FIB for).

Optionally, between S201and S202, the first gateway may further perform the following step: the first gateway determines a first VNI of the first packet.

For example, the first gateway determines a port receiving the first packet; the first gateway determines, according to a mapping between the port and a virtual extensible local area network VXLAN network identifier VNI, the VNI of the first packet; and the first gateway determines the forwarding table of the VNI according to the VNI.

Specifically, hosts in VXLAN segments identified by different VNIs cannot communicate with each other. The first gateway stores multiple forwarding tables and a mapping from each VNI to the forwarding tables. For example, each forwarding table is a virtual routing and forwarding (English: virtual routing and forwarding, VRF for short) instance (English: instance).

That the first gateway searches a forwarding table for a next hop of the first IP address, wherein the search fails, means that the first gateway does not find, in the forwarding table, the next hop of the IP address in the first packet.

S203: The first gateway sends a second packet to at least one gateway, where the second packet carries the first IP address, and the second packet is used to instruct a gateway receiving the second packet to determine whether a host identified by the first IP address accesses a network by using the gateway receiving the second packet.

In a possible example, the first gateway may search a mapping table from multiple VNIs to multiple gateways for a gateway having the VNI of the first packet. In the mapping table, a mapping from the VNI of the first packet to the at least one gateway is stored. The at least one gateway is a gateway to which a host identified by the VNI is allowed to connect in a local area network. The first gateway determines, according to a result of the searching, the at least one gateway having the VNI of the first packet.

In another possible example, the first gateway sends the second packet to all gateways in the local area network.

For example, the first gateway and the at least one gateway may be the BGP peers inFIG. 1. The second packet may be a BGP packet. Further, the second packet may be an update (English: update) packet defined in BGP. The first IP address may be carried in a path attribute (English: Path Attribute) field in the update packet. Specifically, a type is defined in type-length-value (English: Type-Length-Value, TLV for short) of the path attribute field, to identify the second packet. The first IP address is carried in a value field.

Optionally, the second packet further carries the VNI of the first packet. For example, the VNI of the first packet and the first IP address are both carried in the path attribute field in the update packet.

Optionally, the second packet further carries a broadcast domain identifier of the first IP address. For example, the first gateway stores a correspondence between multiple IP subnet segments and broadcast domains. The first gateway obtains the broadcast domain identifier according to a broadcast domain corresponding to the first IP address. For example, the broadcast domain identifier, the VNI of the first packet, and the first IP address are all carried in the path attribute field in the update packet.

S301: The second gateway receives the second packet from the first gateway, and the second gateway determines that a MAC address of the host identified by the first IP address carried in the second packet can be obtained.

Optionally, if the second packet further carries the VNI of the first packet, that the second gateway determines that a MAC address of the host identified by the first IP address carried in the second packet can be obtained specifically includes: determining, by the second gateway in a VXLAN segment corresponding to the VNI, that the MAC address of the host identified by the first IP address can be obtained.

For example, that the second gateway obtains the MAC address of the host identified by the first IP address carried in the second packet may include: searching, by the second gateway, multiple stored mapping tables between IP addresses and MAC addresses for a MAC address corresponding to the first IP address. For example, the host identified by the first IP address is the host107, and the MAC address that corresponds to the first IP address and that is stored in the mapping table is the MAC address of the host107. When establishing a connection to the second gateway, the host107sends the MAC address of the host107to the second gateway. The second gateway saves a correspondence between the MAC address of the host107and the IP address into the multiple mapping tables between the IP addresses and the MAC addresses. If the second packet further carries the VNI of the first packet, the second gateway further stores a correspondence between the VNI and the multiple mapping tables between the IP addresses and the MAC addresses. In the multiple mapping tables between the IP addresses and the MAC addresses, mappings between IP addresses and MAC addresses in the VXLAN segment corresponding to the VNI are stored.

For example, that the second gateway determines that a MAC address of the host identified by the first IP address carried in the second packet can be obtained may further include: broadcasting, by the second gateway, a request packet to a host accessing the network by using the second gateway. The request packet is used to request the MAC address of the host107. For example, the request packet, as shown inFIG. 1, may be an ARP packet in the IPv4 protocol, or may be an NDP packet in the IPv6. The second gateway obtains the MAC address corresponding to the first IP address according to a response of the host107to the request packet. If the second packet further carries the VNI of the first packet, when broadcasting the request packet, the second gateway determines, according to the VNI, a port broadcasting the request packet, and broadcasts the request packet to a host in the VXLAN segment corresponding to the VNI. If the second packet further carries the broadcast domain identifier in S202, when broadcasting the request packet, the second gateway determines, according to both the VNI and the broadcast domain identifier, a port broadcasting the request packet, and broadcasts the request packet to a host that is in the VXLAN segment corresponding to the VNI and that belongs to the broadcast domain.

S302: The second gateway sends a third packet to the first gateway, where the third packet is used to instruct a host identified by the first IP address to access the network by using the second gateway.

For example, the third packet may be a BGP packet. Specifically, the third packet may use a packet format the same as that of the second packet. For example, both of the packets are update packets in the BGP. A value field of a path attribute field carried in the third packet is the same as the value field in the second packet. A type field defines an identifier, to identify a type of the third packet.

S204: The first gateway receives the third packet from the second gateway, where the third packet is used to instruct the host identified by the first IP address to access the network by using the second gateway; and the first gateway writes an address of the second gateway into the forwarding table as a next hop address of the first IP address.

Specifically, the third packet carries a source address of a gateway sending the third packet, and the first gateway determines the second gateway according to the source address in the third packet.

For example, the first packet is a data packet, and the method further includes S205: The first gateway performs VXLAN encapsulation on the first packet to obtain an encapsulated first packet, and the first gateway sends the encapsulated first packet. A value of a VNI field in a VXLAN header of the encapsulated first packet is the VNI of the first packet; and a destination IP address of an outer IP header of the encapsulated first packet is the IP address of the second gateway.

For example, the first packet is a packet that is used by the host106to request, from the first gateway, the MAC address of the host identified by the first IP address, for example, an ARP packet or an NDP packet. The method further includes: sending, by the first gateway, a MAC address of the first gateway to the host106.

Optionally, in response to a requirement of another gateway for determining whether a host identified by an IP address (for example, a second IP address) accesses the network by using the first gateway, the first gateway may also determine whether the host identified by the IP address accesses the network by using the first gateway. Steps for determining, by the first gateway, whether the host identified by the IP address accesses the network by using the first gateway are similar to those in S301and S302of determining, by the second gateway, whether the host identified by the first IP address accesses the network by using the first gateway. For example, if the first gateway receives a fourth packet that is from a third gateway and that is used to instruct the first gateway to determine whether the host identified by the second IP address accesses the network by using the first gateway, as shown inFIG. 3, the method further includes S401, S402, and S403.

S401: The first gateway receives a fourth packet from a third gateway, where the fourth packet carries a second IP address.

S402: The first gateway obtains a MAC address corresponding to the second IP address.

S403: The first gateway sends a fifth packet to the third gateway, where the fifth packet is used to instruct the third gateway to use an address of the first gateway as a next hop address of the second IP address.

In S401and S402, a specific implementation of obtaining, by the first gateway according to the second IP address carried in the fourth packet, the MAC address corresponding to the second IP address may use the specific implementation of obtaining, by the second gateway according to the first IP address carried in the second packet, the MAC address corresponding to the first IP address in S301shown inFIG. 2.

In S403, a specific implementation of sending the fifth packet by the first gateway to the third gateway may use the specific implementation of sending the third packet by the second gateway to the first gateway in S302shown inFIG. 2.

FIG. 4is a schematic structural diagram of a first gateway500according to an embodiment of this application. As shown inFIG. 4, the first gateway500includes a processor501, a memory502, and a network interface503.

The memory502is configured to store a forwarding table. For example, the memory502includes, but is not limited to, a content-addressable memory (English: content-addressable memory, CAM for short), for example, a ternary content-addressable memory (English: ternary CAM, TCAM for short), and a random access memory (English: random-access memory, RAM for short).

The network interface503may be a wired interface, such as a fiber distributed data interface (English: Fiber Distributed Data Interface, FDDI for short), or an Ethernet (English: Ethernet) interface. Alternatively, the network interface503may be a wireless interface, for example, a wireless local area network interface.

The processor501includes, but is not limited to, one or more of a central processing unit (English: central processing unit, CPU for short), a network processor (English: network processor, NP for short), an application-specific integrated circuit (English: application-specific integrated circuit, ASIC for short), or a programmable logic device (English: programmable logic device, PLD for short). The PLD may be a complex programmable logic device (English: complex programmable logic device, CPLD for short), a field-programmable gate array (English: field-programmable gate array, FPGA for short), a generic array logic (English: generic array logic, GAL for short), or any combination thereof.

The memory502may also be integrated in the processor501. If the memory502and the processor501are mutually independent devices, the memory502is in communication with the processor501. For example, the memory502may communicate with the processor501by using a bus. The network interface503may communicate with the processor501by using the bus, or the network interface503may be directly connected to the processor501. The processor501is configured to perform the following operations:receiving a first packet by using the network interface503, where the first packet includes a first Internet Protocol IP address;searching the forwarding table stored in the memory502for a next hop of the first IP address, wherein the search fails;sending a second packet to at least one gateway by using the network interface503, where the second packet carries the first IP address, and the second packet is used to instruct a gateway receiving the second packet to determine whether a host identified by the first IP address accesses a network by using the gateway receiving the second packet;receiving a third packet from a second gateway by using the network interface503, where the second gateway is one of the at least one gateway, and the third packet is used to instruct the host identified by the first IP address to access the network by using the second gateway; andwriting an address of the second gateway into the forwarding table stored in the memory as a next hop address of the first IP address.

For example, the processor501may include an NP and a CPU. The NP communicates with the CPU by using the bus. The NP is configured to perform a forwarding-plane operation, and the CPU is configured to perform a control-plane operation. Specifically, the NP receives the first packet by using the network interface503, and searches the forwarding table stored in the memory502for the next hop of the IP address in the first packet. After the NP searches for the next hop of the IP address in the first packet, wherein the search fails, the NP sends the IP address to the CPU by using the bus. Specifically, when the NP searches for the next hop, one possible manner is that, if the memory is a RAM, the NP may read information about the forwarding table in the memory, and search for the next hop of the first IP address. Another possible manner is that, if the memory is a CAM, the NP sends the first IP address to the memory, and instructs the memory to search the forwarding table for an entry matching the first IP address, where the next hop of the first IP address is stored in the entry. The memory sends a result of the searching to the NP. Searching for the next hop, wherein the search fails, may mean that the NP does not find an entry matching the first IP address in the forwarding table. Searching for the next hop, wherein the search fails, may also mean that the memory sends a search failure result to the NP. For example, the forwarding table includes a general entry, and when the first IP address matches no entry in the forwarding table, the memory sends the general entry to the NP as the result of the searching. The CPU generates the second packet, and sends the second packet to the at least one gateway by using the network interface503. Further, the CPU receives the third packet from the second gateway by using the network interface503, and uses the address of the second gateway as the next hop address of the first IP address. The CPU sends the first IP address and the next hop address of the first IP address to the NP by using the bus. The NP writes the first IP address and the next hop address of the first IP address into the forwarding table stored in the memory501.

Optionally, before searching the forwarding table stored in the memory502for the next hop of the IP address in the first packet, the processor501further performs the following steps: determining a port receiving the first packet; determining a virtual extensible local area network VXLAN network identifier VNI according to a mapping from the port to the VNI; and determining the forwarding table according to a mapping from the VNI to the forwarding table. For example, the steps may be performed by the NP. When sending the IP address to the CPU by using the bus, the NP further sends the VNI to the CPU.

Optionally, the second packet further carries the VNI. Optionally, before the processor501sends the second packet to the at least one gateway by using the network interface503, the processor501further performs the following steps: searching a mapping table from multiple VNIs to multiple gateways for a gateway having the VNI; and determining the at least one gateway according to the result of the searching. For example, the steps may be performed by the CPU. The mapping table from the multiple VNIs to the multiple gateways may be stored in an internal memory of the CPU.

The first packet is a data packet, the first IP address is a destination IP address of the first packet, and the processor further performs the following steps: performing VXLAN encapsulation on the first packet, to obtain the third packet; and sending the third packet by using the network interface. A value of a VNI field in a VXLAN header of the third packet is the VNI, and a destination IP address of an outer IP header of the third packet is the IP address of the second gateway. For example, the steps may be performed by the NP.

Optionally, the first packet is an Address Resolution Protocol ARP packet, and the first IP address is a target IP address TPA of the first packet. Alternatively, the first packet is a Neighbor Discovery Protocol NDP packet, and the first IP address is a target address of the first packet.

Optionally, the processor501further performs the following steps: receiving a fourth packet from a third gateway by using the network interface503, where the fourth packet carries a second IP address; obtaining a MAC address corresponding to the second IP address; and sending a fifth packet to the third gateway by using the network interface, where the fifth packet is used to instruct the third gateway to use an address of the first gateway as a next hop address of the second IP address. For example, the steps may be performed by the CPU.

Optionally, the fourth packet further carries a virtual extensible local area network VXLAN network identifier VNI. That the processor501obtains the MAC address corresponding to the second IP address specifically includes: obtaining, by the processor501in a VXLAN segment corresponding to the VNI, the MAC address corresponding to the second IP address. For example, the step may be performed by the CPU.

The first gateway500provided in this embodiment may be applied to the methods of the embodiments inFIG. 2andFIG. 3, to implement functions of the first gateway. For other additional functions that may be implemented by the first gateway and an interaction process with another gateway, refer to the descriptions about the first gateway in the method embodiments, and details are not described herein again.

FIG. 5is a schematic structural diagram of another first gateway according to an embodiment of this application. As shown inFIG. 5, a first gateway600includes a first receiving unit601, a storage unit602, a searching unit603, a sending unit604, a second receiving unit605, and a processing unit606.

The first receiving unit601is configured to receive a first packet, where the first packet includes a first Internet Protocol IP address.

The storage unit602is configured to store a forwarding table.

The searching unit603is configured to: obtain the first packet received by the first receiving unit601, and search the forwarding table stored in the storage unit602for a next hop of the first IP address, wherein the search fails.

The sending unit604is configured to: after the searching unit603searches for the next hop of the first IP address, wherein the search fails, send a second packet to at least one gateway, where the second packet carries the first IP address, and the second packet is used to instruct a gateway receiving the second packet to determine whether a host identified by the first IP address accesses a network by using the gateway receiving the second packet.

The second receiving unit605is configured to receive a third packet from a second gateway, where the second gateway is one of the at least one gateway, and the third packet is used to instruct the host identified by the first IP address to access the network by using the second gateway.

The processing unit is configured to: obtain the third packet received by the second receiving unit, and write, as a next hop address of the first IP address according to the third packet, an address of the second gateway into the forwarding table stored in the storage unit.

Optionally, the second packet further carries a first virtual extensible local area network VXLAN network identifier VNI of the first packet, and the searching unit603is further configured to determine the first VNI of the first packet before the sending unit sends the second packet to the at least one gateway.

Optionally, the first packet is an Address Resolution Protocol ARP packet, and the first IP address is a target IP address TPA of the first packet. Alternatively, the first packet is a Neighbor Discovery Protocol NDP packet, and the first IP address is a target address of the first packet.

Optionally, the second receiving unit605is further configured to receive a fourth packet from a third gateway, where the fourth packet carries a second IP address. The searching unit603is further configured to: obtain the fourth packet received by the second receiving unit605, and determine that a MAC address of a host identified by the second IP address carried in the fourth packet can be obtained. The sending unit604is further configured to send a fifth packet to the third gateway, where the fifth packet is used to instruct the host identified by the second IP address to access the network by using the first gateway.

Optionally, the fourth packet further carries a second VNI. The searching unit603is configured to determine that the MAC address of the host identified by the second IP address can be obtained, and is specifically configured to attempt to obtain the MAC address of the host identified by the second IP address in a VXLAN segment identified by the second VNI.

The first gateway600shown inFIG. 5and the first gateway500shown inFIG. 4may be a same apparatus. For example, both are the first gateway in the methods shown inFIG. 2andFIG. 3. It may be considered that,FIG. 4shows content included in the first gateway physically, andFIG. 5shows content included in the first gateway logically. Optionally, the first receiving unit601, the second receiving unit602, and the sending unit604that are shown inFIG. 5may be implemented by using the network interface503shown inFIG. 4. The searching unit603and the processing unit606that are shown inFIG. 5may be implemented by using the processor501shown inFIG. 4. The storage unit602shown inFIG. 5may be implemented by using the memory502shown inFIG. 4.

The embodiments in this specification are all described in a progressive manner, for same or similar parts in the embodiments, refer to these embodiments, and each embodiment focuses on a difference from other embodiments. Especially, a system embodiment is basically similar to a method embodiment, and therefore is described briefly; for related parts, refer to partial descriptions in the method embodiment.