Network device and packet forwarding method

TWI931818BActive Publication Date: 2026-07-11AIROHA TECH (SUZHOU) LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
TW113132029
Authority / Receiving Office
TW · TW
Patent Type
Patents
Current Assignee / Owner
Priority Date
2024-06-28
Filing Date
2024-08-26
Publication Date
2026-07-11
Estimated Expiration
2044-08-25

Smart Images

  • Figure IMG-2_DRAW_113132029-A0305-14-0001-1
    Figure IMG-2_DRAW_113132029-A0305-14-0001-1
  • Figure IMG-2_DRAW_113132029-A0305-14-0002-2
    Figure IMG-2_DRAW_113132029-A0305-14-0002-2
  • Figure IMG-2_DRAW_113132029-A0305-14-0003-3
    Figure IMG-2_DRAW_113132029-A0305-14-0003-3
Patent Text Reader

Abstract

This invention discloses a network device comprising a storage device, a hardware acceleration forwarding circuit, and a network processor. The storage device stores a software flow table, wherein the software flow table includes a plurality of entries. The hardware acceleration forwarding circuit receives a first packet from a network, obtains a first hash value of the first packet, and determines that the first hash value has a hash collision in the hardware flow table. The network processor receives the first packet from the hardware acceleration forwarding circuit, and when the first packet hits an entry in the software flow table, processes the forwarding of the first packet according to the forwarding information recorded in the entry.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to network packet forwarding, and more particularly to a network device and related packet forwarding method that improves packet forwarding efficiency in the event of hardware flow table hash collisions by establishing software flow tables through a central processing unit and performing fast forwarding by a network processor. Prior Technology

[0002] A gateway is a common network device used to connect different networks and forward packets from one network to another. When packets are forwarded by software execution of the central processing unit (CPU) (for example, through the network protocol stack of the Linux kernel), forwarding information is usually written to hardware-accelerated forwarding circuitry. Therefore, the forwarding of subsequent packets can be offloaded from software (i.e., the network protocol stack executed by the CPU) to hardware (i.e., hardware-accelerated forwarding circuitry), thereby improving packet forwarding efficiency.

[0003] Generally, hardware-accelerated forwarding circuits have a hardware flow table. Each packet's key is used to obtain a corresponding hash value, which serves as an index. Therefore, the hardware-accelerated forwarding circuit can access table entries based on this hash value. However, during the creation of the hardware flow table, different packets may have the same hash value, leading to hash collisions. Hardware-accelerated forwarding circuits are typically designed to tolerate a certain number of hash collisions. However, when forwarding a large number of packets simultaneously, the number of hash collisions may exceed the circuit's limit. Packets that cannot be directly forwarded by the hardware-accelerated forwarding circuit due to hash collisions must be sent to the central processing unit (CPU). The CPU then executes software (e.g., network protocol stacking) to forward the packets. This not only consumes significant processor resources but also reduces overall packet forwarding efficiency. Summary of the Invention

[0004] One of the objectives of this invention is to provide a network device and a related packet forwarding method that improves packet forwarding efficiency in the event of hardware flow table hash collisions by establishing software flow tables through a central processing unit and performing fast forwarding by a network processor.

[0005] In one embodiment of the present invention, a network device is disclosed. The network device includes a storage device, a hardware-accelerated forwarding circuit, and a network processor. The storage device stores a software flow table, wherein the software flow table includes a plurality of entries. The hardware-accelerated forwarding circuit receives a first packet from a network, obtains a first hash value of the first packet, and determines that the first hash value has a hash collision in the hardware flow table. The network processor receives the first packet from the hardware-accelerated forwarding circuit, and when the first packet hits an entry in the software flow table, processes the forwarding of the first packet according to the forwarding information recorded in the entry.

[0006] In another embodiment of the present invention, a network device is disclosed. The network device includes a storage device, a hardware acceleration forwarding circuit, a network processor, and a central processing unit (CPU). The storage device stores a software flow table, wherein the software flow table includes a plurality of entries. The hardware acceleration forwarding circuit receives a packet from a network, obtains a hash value of the packet, and determines that the hash value has a hash collision in a hardware flow table. The network processor receives the packet from the hardware acceleration forwarding circuit, determines that the packet does not match any entry in the software flow table, and finds a usable entry in the software flow table. The CPU receives the packet from the network processor, processes the forwarding of the packet, and fills the usable entry with the original information and forwarding information corresponding to the packet.

[0007] In another embodiment of the present invention, a packet forwarding method is disclosed. The packet forwarding method includes: storing a software flow table in a storage device, wherein the software flow table includes a plurality of entries; receiving a packet from a network and obtaining a hash value of the packet; when the hash value causes a hash collision in a hardware flow table of a hardware acceleration forwarding circuit, transmitting the packet from the hardware acceleration forwarding circuit to a network processor; when the packet hits an entry in the software flow table, processing the forwarding of the packet according to forwarding information recorded in the entry through the network processor; and when the packet does not hit any entry in the software flow table, transmitting the packet from the network processor to a central processing unit (CPU), and processing the forwarding of the packet through the CPU and filling the original information and forwarding information corresponding to the packet into a usable entry of the software flow table.

[0008] Compared to having the central processing unit (CPU) handle all packets in the event of hardware flow table hash collisions, the present invention first establishes a software flow table through the CPU and then has the network processor perform fast forwarding, which does not consume too much processor resources and can achieve better packet forwarding efficiency. Simple Explanation of the Diagram

[0009] Figure 1 is a schematic diagram of a network device according to an embodiment of the present invention. Figure 2 is a flowchart of a packet forwarding method according to an embodiment of the present invention, which improves packet forwarding efficiency in the case of hardware flow table hash collision by establishing software flow tables through a central processing unit and performing fast forwarding by a network processor. Figure 3 is a flowchart of the operation of the network processor shown in Figure 1 under hardware flow table hash collision conditions. Figure 4 is a flowchart of the operation of the central processing unit in the case of hardware flow table hash collision, as shown in Figure 1. Implementation

[0010] Certain terms are used in this specification and the claims to refer to specific components. Those skilled in the art will understand that hardware manufacturers may use different names to refer to the same component. This specification and the claims do not distinguish components by name differences, but by functional differences. The terms "comprising" and "including" used throughout this specification and the claims are open-ended and should be interpreted as "comprising but not limited to." Furthermore, the terms "coupled" or "coupled" herein include any direct and indirect electrical connection means. Therefore, if a first device is described as coupled to a second device, it means that the first device can be directly electrically connected to the second device, or indirectly electrically connected to the second device through other devices and connection means.

[0011] Figure 1 is a schematic diagram of a network device according to an embodiment of the present invention. For example, the network device 100 may be a gateway for connecting different networks (e.g., Ethernet (ETH) 10 and Passive Optical Network (PON) 20). In this embodiment, the network device 100 includes a central processing unit (CPU) 102, a network processing unit (NPU) 104, a storage device 106, and a hardware-accelerated forwarding circuit 108. Please note that Figure 1 only illustrates the elements relevant to the present invention; in practice, the network device 100 may include other elements to implement the desired network functions.

[0012] The central processing unit 102 can be implemented by a general-purpose processor and will load and execute a plurality of software modules, including a network driver 118, a Linux network protocol stack 120, and a flow learning module 122. When a packet needs to be forwarded via the central processing unit 102, the packet will be received by the network driver 118 of the Ethernet 10 and provided to the Linux network protocol stack 120 for packet forwarding processing. The packets to be forwarded generated by the Linux network protocol stack 120 will be transmitted through the network driver 118 of the passive fiber optic network 20.

[0013] The network processor 104 can be implemented by an application-specific integrated circuit (ASIC) optimized for network applications and can execute a fast forwarding module 112 to assist in packet forwarding. In other words, the network processor 104 can have packet forwarding capabilities, so the packet forwarding of the central processing unit 102 can be offloaded to the network processor 104 to improve packet forwarding efficiency.

[0014] Storage device 106 can be implemented using dynamic random access memory (DRAM) and used to store a software flow table (FTSW) 110. For example, storage device 106 can be configured with a storage space for the software flow table 110 and divided into a plurality of storage units. Each storage unit is used to store a table entry 111 of the software flow table 110. For example, each table entry 111 can record a plurality of fields, including a state field, a pkt_type field, a time_stamp field, an ipv4_info field, and an ipv6_info field. The state field is used to indicate the usage status of the table entry. When the state field indicates "unbind", it means that this table entry has not been used before and records the initial value filled in during initialization when it was first created. When the state field indicates "bind", it means that this table entry has been used before, and therefore stores information related to packets that were previously forwarded. The `pkt_type` field indicates whether the packet to be forwarded is an IPv4 packet or an IPv6 packet. The `time_stamp` field indicates the timestamp of the last time this entry was read for packet forwarding. Therefore, by comparing the current time with the time recorded in the `time_stamp` field, it can be determined whether this entry has been idle for too long (i.e., whether the time recorded in the `time_stamp` field is more than a threshold from the current time) and can be considered invalid. The `ipv4_info` field records the original information of the IPv4 packet (e.g., the original IPv4 packet header information) and forwarding information (e.g., the forwarding information may include the header information of the forwarded IPv4 packet). The `ipv6_info` field records the original information of the IPv6 packet (e.g., the original IPv6 packet header information) and forwarding information (e.g., the forwarding information may include the header information of the forwarded IPv6 packet).

[0015] The hardware acceleration forwarding circuit 108 acts as a frame engine, providing hardware acceleration to reduce the workload of the central processing unit 102 and accelerate packet forwarding. The hardware acceleration forwarding circuit 108 may include a hardware forwarding circuit 114 and a hardware hash table 116, wherein the hardware forwarding circuit 114 has a hardware flow table (denoted as "FTHW") 115. The hardware hash table 116 can store a plurality of pre-calculated hash values ​​and look up the corresponding hash value of the packet using the packet's key. However, this is only an example; the invention does not limit the method of hash value generation. For example, in other embodiments, hash values ​​can be directly calculated using a hash function. The hardware forwarding circuit 114 has packet forwarding capabilities, thus offloading packet forwarding from the central processing unit 102 to the hardware forwarding circuit 114 to improve packet forwarding efficiency.

[0016] The hardware acceleration forwarding circuit 108 is designed to tolerate a certain number of hash collisions. However, when forwarding a large number of packets simultaneously, the number of hash collisions exceeds the upper limit allowed by the hardware acceleration forwarding circuit 108. If the packets are sent to the central processing unit (CPU) for forwarding, it will consume a large amount of processor resources and reduce the overall packet forwarding efficiency. To solve this problem, this invention discloses a method to improve packet forwarding efficiency under hardware flow table hash collision conditions by establishing a software flow table 111 through the CPU 102 and using the network processor 104 for fast forwarding. Furthermore, the software flow table 110 disclosed in this invention can be regarded as an extension of the hardware flow table 115. When the hardware forwarding circuit 114 cannot use the hardware flow table 115 for forwarding due to hash collisions, fast forwarding can be achieved subsequently through the network processor 104 and the software flow table 110.

[0017] In one operational example, the hardware acceleration forwarding circuit 108 receives packet PKT1” from Ethernet 10 and obtains the hash value HV” of packet PKT1” through the hardware hash table 116. Furthermore, the hardware flow table 115 contains multiple entries, each indexed by a different hash value. Therefore, the hardware forwarding circuit 114 refers to the hash value HV” to read the corresponding entry in the hardware flow table 115. If the original information recorded in the entry corresponding to the hash value HV” matches… If the information carried by packet "PKT1" is matched, the hardware forwarding circuit 114 determines that packet "PKT1" hits an entry in the hardware flow table 115. Therefore, the hardware forwarding circuit 114 modifies packet "PKT1" according to the forwarding information recorded in the entry corresponding to the hash value "HV" to generate the modified packet "PKT2" (that is, the packet to be forwarded), and forwards packet "PKT2" directly to the passive fiber optic network 20 without the intervention of the central processing unit 102.

[0018] In another operational example, the hardware acceleration forwarding circuit 108 receives packet PKT1 from Ethernet 10 and obtains the hash value HV of packet PKT1 through hardware hash table 116. Furthermore, the hardware forwarding circuit 114 refers to the hash value HV to read the corresponding entry in hardware flow table 115. If the original information recorded in the entry corresponding to hash value HV cannot match the information carried by packet PKT1, the hardware forwarding circuit 114 determines that a hash collision has occurred in hardware flow table 115 for the hash value HV of packet PKT1 (i.e., the entry corresponding to hash value HV records forwarding information for other data flows), and transmits packet PKT1 and hash value HV to network processor 104. Since network processor 104 directly uses the hash value HV already obtained by hardware acceleration forwarding circuit 108, hash value processing / computation time can be saved, thereby improving packet conversion efficiency. However, this is only an example and is not intended to limit the invention.

[0019] The fast forwarding module 112 in the network processor 104 reads the corresponding entry in the software flow table 110 by referring to the hash value (e.g., the hash value HV provided by the hardware accelerated forwarding circuit 108). If the original information recorded in the entry corresponding to the hash value HV matches the information carried by packet PKT1, the fast forwarding module 112 determines that packet PKT1 matches the entry in the software flow table 110. Therefore, the fast forwarding module 112 modifies packet PKT1 according to the forwarding information recorded in the entry corresponding to the hash value HV to generate the modified packet PKT2 (i.e., the packet to be forwarded), and forwards packet PKT2 directly to the passive fiber optic network 20 without the intervention of the central processor 102.

[0020] The forwarding information recorded in the software flow table 110 is obtained by the flow learning module 122 based on the packets to be forwarded during the packet forwarding process handled by the central processing unit 102 in the executing software (e.g., Linux network protocol stack 120). For example, the hardware accelerated forwarding circuit 108 receives packet PKT1' from Ethernet 10 and obtains the hash value HV' of packet PKT1' through the hardware hash table 116. In addition, the hardware forwarding circuit 114 refers to the hash table 116. The hash value HV' is used to read the corresponding entry in the hardware flow table 115. If the original information recorded in the entry corresponding to the hash value HV' cannot match the information carried by the packet PKT1, the hardware forwarding circuit 114 determines that the hash value HV' of the packet PKT1' has a hash collision in the hardware flow table 115 (that is, the entry corresponding to the hash value HV' records forwarding information of other data flows), and transmits the packet PKT1' and the hash value HV' to the network processor 104. Since the network processor 104 directly uses the hash value HV' already obtained by the hardware acceleration forwarding circuit 108, it can save hash value processing time and improve packet conversion efficiency. However, this is only an example and is not intended to limit the invention.

[0021] The fast forwarding module 112 in the network processor 104 reads the corresponding entry in the software flow table 110 by referring to the hash value HV'. If the entry corresponding to the hash value HV' is an unused entry, the fast forwarding module 112 directly determines that the packet PKT1' cannot hit any entry in the software flow table 110, and sends the packet PKT1' to the central processing unit 102 for forwarding processing. If the entry corresponding to the hash value HV' is an entry that has been used and has not yet expired, and the original information recorded therein cannot match the information carried by the packet PKT1', then the fast forwarding module 112 determines that the hash value HV' of the packet PKT1' has a hash collision in the software flow table 110 (that is, the entry corresponding to the hash value HV' records forwarding information of other data flows). At this time, the fast forwarding module 112 will activate the hash collision handling procedure. If the fast forwarding module 112 still determines in the hash collision handling procedure that the packet PKT1' cannot hit any entry in the software flow table 110, then the fast forwarding module 112 will send the packet PKT1' to the central processing unit 102 for forwarding processing. Since neither the network processor 104 nor the hardware acceleration forwarding circuit 108 can handle the forwarding of packet PKT1', the central processing unit 102 needs to intervene to handle the forwarding of packet PKT1'. If the network processor 104 can find a usable entry in the software flow table 110, the network processor 104 will also provide the index value FI of the usable entry in the software flow table 110 to the central processing unit 122 (especially the flow learning module 122 executed by the central processing unit 122). In addition to the Linux network protocol stack 120 processing packet PKT1' to generate the modified packet PKT2 (i.e., the packet to be forwarded), the central processing unit 102 will also execute the flow learning module 122 to parse the packet to be forwarded and write the forwarding information into the usable entry in the software flow table 110 according to the index value FI. Finally, the central processing unit 102 will forward packet PKT2 to the passive fiber optic network 20.

[0022] Figure 2 is a flowchart of a packet forwarding method according to an embodiment of the present invention, which improves packet forwarding efficiency in the event of hardware flow table hash collisions by establishing a software flow table 111 through a central processing unit 102 and performing fast forwarding by a network processor 104. If the same result can be obtained, the steps of the packet forwarding method of the present invention do not necessarily have to be executed in the exact order shown in Figure 2. In step S202, the hardware acceleration forwarding circuit 108 receives packet PKT (e.g., PKT = PKT1 / PKT1') from the Ethernet network 10, obtains the hash value Hash_index of the packet PKT through the hardware hash table 116 (e.g., Hash_index = HV / HV'), and reads the entry in the hardware flow table 115 through the hash value Hash_index. In step S204, the hardware accelerated forwarding circuit 108 determines that the hash value Hash_index of the packet PKT has a hash collision in the hardware flow table 115, and therefore writes the packet PKT and hash value Hash_index to the receive ring buffer (RX ring buffer) of the network processor 104. In step S206, the network processor 104 reads the packet PKT and hash value Hash_index from the receive ring buffer, and parses the packet PKT (especially the packet PKT header). In step S208, the network processor 104 reads the entries in the software flow table 110 according to the hash value Hash_index, and determines whether the entries in the software flow table 110 match the packet PKT based on the parsed packet information (especially the packet header information) (that is, whether the packet PKT hits the entry corresponding to the hash value Hash_index). If the packet PKT (e.g., PKT = PKT1) matches the entry corresponding to the hash value Hash_index (step S210), then in step S212 the network processor 104 modifies the packet PKT according to the forwarding information recorded in the matching entry and forwards the modified packet (e.g., PKT 2).

[0023] If the packet PKT (e.g., PKT = PKT1') does not match the entry corresponding to the hash value Hash_index (step S210), then in step S214, the network processor 104 writes the packet PKT and the index value flow_index (e.g., flow_index = FI) into the receive ring buffer of the central processing unit 102. In step S216, the central processing unit 102 reads the packet PKT (e.g., PKT = PKT1') and the index value flow_index (e.g., flow_index = FI) from the receive ring buffer, and writes the original information obtained from parsing the packet PKT (e.g., the original information may include the header information of the packet PKT) into the entry corresponding to the index value flow_index in the software flow table 110. In step S218, the central processing unit 102 executes the Linux network protocol stack 120 to process the forwarding of the packet PKT (e.g., PKT = PKT1') and generates a modified packet (e.g., packet PKT 2' to be forwarded). In step S220, the central processing unit 102 executes the flow learning module 122 to parse the packet to be forwarded (e.g., PKT 2'), and fills the parsed forwarding information (e.g., the forwarding information may include the header information of packet PKT 2') into the table entry with the same index value flow_index. Finally, the central processing unit 102 forwards the packet (e.g., PKT 2') to the passive fiber optic network 20.

[0024] Figure 2 is only a simple illustration of the inventive concept of the packet forwarding method of the present invention. The detailed operation of the stream learning module 122 of the central processing unit 102 and the fast forwarding module 112 of the network processor 104 will be described in detail below with the relevant flowcharts.

[0025] Figure 3 is a flowchart illustrating the operation of the network processor 104 shown in Figure 1 under hardware flow table hash collision conditions. If the same result can be obtained, it is not necessary to strictly follow the order shown in Figure 3 when performing these steps. In step S302, the network processor 104 reads the packet PKT and the hash value Hash_index. In step S304, the network processor 104 sets the index value flow_index to an initial value (e.g., flow_index = -1). In this embodiment, the index value flow_index is used to indicate whether there are available entries in the software flow table 110 (e.g., unused entries or used but expired entries) and the position of the available entries in the software flow table 110. For example, if the index value flow_index is not equal to the initial value, it indicates that there are available entries in the software flow table 110, and the index value flow_index itself can also be used as a hash value to access the available entries in the software flow table 110.

[0026] In step S306, the network processor 104 reads an entry from the software flow table 110 based on the hash value Hash_index. In step S308, the network processor 104 checks the state field recorded in the read entry. If the state field indicates "unbind", it means that this entry was not previously used and the record was initialized with the initial value when it was first created. This also implies that the packet PKT cannot hit any entry in the software flow table 110. Therefore, the subsequent process will proceed to step S310 to update the index value flow_index from the initial value (e.g., flow_index = -1) to the hash value Hash_index (i.e., flow_index = Hash_index). Then, in step S326, the network processor 104 writes the packet PKT and the final index value flow_index (i.e., flow_index = Hash_index) to the receive ring buffer of the central processing unit 102.

[0027] If the state field checked by the network processor 104 in step S308 indicates "bind", it means that this table entry has been used before. In other words, the central processing unit 102 has previously processed the forwarding of another packet, and the final index value flow_index of that other packet and the hash value Hash_index of the current packet PKT will have the same value. In other words, the flow learning module 122 has previously written the original information and forwarding information of the other packet to the table entry indicated by the hash value Hash_index of the current packet PKT based on the index value flow_index of that other packet. In step S312, the network processor 104 reads the time_stamp field of this entry to determine whether this entry has been idle for too long and can be considered invalid. If this entry has not been idle for too long, the network processor 104 checks in step S314 whether the information carried by the packet PKT matches the original data of the previously forwarded packet recorded in this entry (for example, the original data may contain header information). If the two match, the network processor 104 determines that the packet PKT matches this entry. Therefore, the network processor 104 updates the time_stamp field of this entry using the current time (step S316), and modifies the packet PKT according to the forwarding information of the previously forwarded packet recorded in this entry and forwards the modified packet (step S318).

[0028] If the network processor 104 determines in step S312 that this entry has been idle for an extended period and can be considered invalid, this means that this entry can be selected as an available entry in the software flow table 110. Therefore, the subsequent process will proceed to step S320 to update the index value flow_index from the initial value (e.g., flow_index = -1) to the hash value Hash_index (i.e., flow_index = Hash_index).

[0029] On the other hand, when the network processor 104 determines in step S312 that this entry has been idle for an extended period and can be considered invalid, this also implies that the packet PKT did not hit this entry. Since the state field checked in step S308 indicates "bind", it means that this entry has already been used, so the hash value Hash_index has a hash collision in the software flow table 110. Similarly, when the network processor 104 determines in step S314 that the packet PKT did not hit this entry, since the state field checked in step S308 indicates "bind", it means that this entry has already been used, so the hash value Hash_index has a hash collision in the software flow table 110. In the event of a hash collision in the software flow table 110, the network processor 104 will activate the hash collision handling procedure. In this embodiment, the network processor 104 may use open addressing to probe for available entries in the software flow table 110 (e.g., unused entries or used but expired entries) or entries that can be hit by packet PKT. For example, the network processor 104 may use linear probing to search for available entries (e.g., unused entries or used but expired entries) or entries that can be hit by packet PKT within the probe depth DEP. In step S322, the hash value Hash_index is updated to the next hash value (i.e., Hash_index = Hash_index + 1). In step S324, the network processor 104 will determine whether the current hash value Hash_index exceeds the probe depth DEP. If it exceeds the probe depth DEP, it indicates that the hash collision handling procedure has been completed. If a used but expired entry is found in the hash collision handling procedure (i.e., step S320 has been executed at least once), the index value flow_index will record the corresponding hash value Hash_index of the used but expired entry. However, if no used but expired entry is found in the hash collision handling procedure (i.e., step S320 has not been executed), the index value flow_index will remain at its initial value (e.g., flow_index = -1). In step S326, the network processor 104 writes the packet PKT and the index value flow_index (e.g., flow_index = -1 (step S304) or flow_index = Hash_index (step S320)) to the receive ring buffer of the central processing unit 102. If the network processor 104 determines in step S324 that the current hash value Hash_index has not exceeded the probe depth DEP, the process will return to step S306 to continue probing.Please note that if an entry that can be matched by packet PKT is found in the hash collision handling procedure (step S314), packet forwarding will be performed directly (steps S316, S318) without enabling subsequent stream learning operations.

[0030] Figure 4 is a flowchart illustrating the operation of the CPU 102 shown in Figure 1 under hardware flow table hash collision conditions. If the same result can be obtained, it is not necessary to strictly follow the order shown in Figure 4 when performing these steps. In step S402, the CPU 102 reads the packet PKT (e.g., PKT=PKT1') and the index value flow_index. In step S404, the CPU 102 determines whether the index value flow_index is no longer its initial value (e.g., -1). If the index value flow_index is no longer its initial value (e.g., ...), ... This indicates that network processor 104 has found an available entry in software flow table 110 (e.g., an unused entry or an entry that has been used but expired). Therefore, the process proceeds to step S406. In step S406, CPU 102 parses the packet PKT and writes the original information of the packet PKT into the entry corresponding to the index value flow_index in software flow table 110. In step S408, CPU 102 executes Linux network protocol stack 120 to process the forwarding of packet PKTs and generates modified packets (e.g., packet PKT2' to be forwarded). In step S410, CPU 102 parses the packet to be forwarded (e.g., PKT2') and writes the forwarding information into the entry corresponding to the same index value flow_index in software flow table 110. Since the entry corresponding to the index value flow_index has already been used, the CPU 102 sets the state field to "bind" in step S412. Additionally, since the entry corresponding to the index value flow_index was previously used for packet forwarding, the CPU 102 sets the timestamp recorded in the time_stamp field (i.e., the timestamp of the last time this entry was read for packet forwarding) to the current time in step S412. In step S414, the CPU 102 transmits the packet to be forwarded (e.g., PKT2') to the passive fiber optic network 20.

[0031] If the CPU 102 determines in step S404 that the index value flow_index remains at its initial value (e.g., flow_index = -1), it means that the network processor 104 has not found any usable entries in the software flow table 110 within the range of the probe depth DEP (e.g., unused entries or entries that have been used but have expired). Therefore, the process proceeds to step S416. In step S416, the CPU 102 updates the current hash collision count value SW_hash_collision (i.e., SW_hash_collision = SW_hash_collision + 1). In step S418, the CPU 102 checks one or more judgment conditions to determine whether the current probe depth DEP needs to be dynamically adjusted. For example, the CPU 102 determines whether the hash collision count value SW_hash_collision exceeds the threshold TH, and / or whether the increased probe depth (e.g., DEP + 1) has not reached the allowable predetermined maximum value DEPMAX. In this embodiment, the central processing unit 102 will execute step S420 to notify the network processor 104 to use the increased probe depth (e.g., DEP + 1) only when both the judgment conditions SW_hash_collision > TH and DEP + 1 < DEPMAX are met. In addition, the central processing unit 102 will reset the hash collision count value SW_hash_collision to its initial value (e.g., SW_hash_collision = 0). In step S422, the central processing unit 102 executes the Linux network protocol stack 120 to process the packet PKT to generate a modified packet (e.g., packet PKT2' to be forwarded) and forwards the modified packet (e.g., packet PKT2' to be forwarded) to the passive fiber network 20.

[0032] Please note that, in addition to dynamically increasing the probe depth DEP based on judgment conditions (e.g., SW_hash_collision > TH and DEP + 1 < DEPMAX), the CPU 102 also checks other judgment conditions to determine whether to restore the probe depth DEP to its initial value. In some embodiments of the present invention, the CPU 102 periodically checks the number of entries in the software flow table 110 that have been used and have not expired due to idle timeout, and determines whether to restore the current probe depth DEP to its initial value based on this number. For example, when this number is less than a predetermined percentage of the total number of entries in the software flow table 110, the CPU 102 will restore the current probe depth DEP to its initial value.

[0033] When a large number of packets cause hash collisions in the hardware flow table 115, the utilization of the CPU 102 will briefly increase to handle packet forwarding and the establishment of the software flow table 110. After the software flow table 110 is learned, the network processor 104 can use the software flow table 110 to assist in packet forwarding, thus the utilization of the CPU 102 can be quickly reduced. Compared to having the CPU handle all packets in the case of hardware flow table hash collisions, the present invention's approach of first establishing the software flow table through the CPU and then having the network processor perform fast forwarding does not consume excessive processor resources and can achieve better packet forwarding efficiency. The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made in accordance with the claims of the present invention shall be covered by the present invention.

[0034] 10: Ethernet 20: Passive fiber optic network 100: Network Devices 102: Central Processing Unit 104: Network Processor 106: Storage device 108: Hardware Acceleration Forwarding Circuit 110: Software Flow Table 111: Item 112: Fast forwarding module 114: Hardware forwarding circuit 115: Hardware Flow Table 116: Hardware Hash Table 118: Network Driver 120: Linux Network Protocol Stacking 122: Stream Learning Module S202~S220, S302~S326, S402~S422: Steps PKT1, PKT1', PKT1”, PKT2, PKT2', PKT2”: Packet HV, HV', HV”: Hash value

Claims

1. A network apparatus, comprising: a storage device for storing a software flow table, wherein the software flow table includes a plurality of entries; a hardware acceleration forwarding circuit for receiving a first packet from a network, obtaining a first hash value of the first packet, and determining that the first hash value has a hash collision in a hardware flow table; and a network processor for receiving the first packet from the hardware acceleration forwarding circuit, and processing the forwarding of the first packet according to forwarding information recorded in the software flow table when the first packet hits an entry in the software flow table.

2. The network device as claimed in claim 1, wherein the network processor further receives the first hash value from the hardware acceleration forwarding circuit and accesses the software flow table based on the first hash value.

3. The network apparatus as claimed in claim 1, wherein the network processor is further configured to perform a linear probe on the software flow table, and the first packet hits the entry in the software flow table before exceeding a probe depth of the linear probe.

4. The network apparatus as claimed in claim 1, wherein the hardware acceleration forwarding circuit is further configured to receive a second packet from the network, obtain a second hash value of the second packet, and determine that the second hash value has a hash collision in the hardware flow table; the network processor is further configured to receive the second packet from the hardware acceleration forwarding circuit and determine that the second packet does not hit any entry in the software flow table; and the network apparatus further comprises: a central processing unit configured to receive the second packet from the network processor and process the forwarding of the second packet.

5. The network device as described in claim 4, wherein the network processor is further configured to find an available entry from the software flow table, and the central processing unit further fills the available entry with the original information and forwarding information corresponding to the second packet.

6. The network apparatus as claimed in claim 5, wherein the network processor is further configured to perform a linear probe on the software flow table, and to find the available entry in the software flow table before exceeding a probe depth of the linear probe.

7. The network device as described in claim 5, wherein the available entries are unused entries in the software flow table.

8. The network device as described in claim 5, wherein the available entries are entries in the software flow table that have been used but have been idle for an extended period.

9. The network apparatus of claim 4, wherein the network processor is further configured to perform a linear probe on the software flow table, and the network processor cannot find any usable entries in the software flow table before a probe depth exceeding the linear probe; the central processing unit is further configured to update a hash collision count value, and at least based on the hash collision count value to determine whether to increase the probe depth.

10. The network device as claimed in claim 9, wherein when the hash collision count exceeds a threshold and the increased probe depth does not reach a predetermined maximum value, the central processing unit notifies the network processor to use the increased probe depth.

11. The network device as described in claim 9, wherein the central processing unit further periodically checks the number of entries in the software flow table that have been used and have not expired due to inactivity, and determines whether to restore the probe depth to an initial value based on the number.

12. The network device as described in claim 11, wherein when the number is less than a predetermined percentage of the total number of entries in the software flow table, the central processing unit restores the probe depth to the initial value.

13. A network apparatus comprising: a storage device for storing a software flow table, wherein the software flow table includes a plurality of entries; a hardware acceleration forwarding circuit for receiving a packet from a network, obtaining a hash value of the packet, and determining that the hash value has a hash collision in the hardware flow table; a network processor for receiving the packet from the hardware acceleration forwarding circuit, determining that the packet does not hit any entry in the software flow table, and finding a usable entry in the software flow table; and a central processing unit for receiving the packet from the network processor, processing the forwarding of the packet, and filling the usable entry with original information and forwarding information corresponding to the packet.

14. The network apparatus as claimed in claim 13, wherein the network processor further receives the hash value from the hardware acceleration forwarding circuit and accesses the software flow table based on the hash value.

15. The network apparatus as claimed in claim 13, wherein the network processor is further configured to perform a linear probe on the software flow table, and to find the available entry in the software flow table before exceeding a probe depth of the linear probe.

16. The network apparatus as described in claim 13, wherein the available entries are entries that are not yet used in the software flow table.

17. The network device as described in claim 13, wherein the available entries are entries in the software flow table that have been used but have been idle for an extended period.

18. A packet forwarding method, comprising: storing a software flow table in a storage device, wherein the software flow table includes a plurality of entries; receiving a packet from a network and obtaining a hash value of the packet; when the hash value causes a hash collision in a hardware flow table of a hardware acceleration forwarding circuit, transmitting the packet from the hardware acceleration forwarding circuit to a network processor; when the packet hits an entry in the software flow table, processing the forwarding of the packet by the network processor according to forwarding information recorded in the entry; and when the packet does not hit any entry in the software flow table, transmitting the packet from the network processor to a central processing unit, and processing the forwarding of the packet by the central processing unit and filling the original information and forwarding information corresponding to the packet into a usable entry of the software flow table.