WO2021135491A1 - 流表的匹配方法及装置 - Google Patents

流表的匹配方法及装置 Download PDF

Info

Publication number
WO2021135491A1
WO2021135491A1 PCT/CN2020/120429 CN2020120429W WO2021135491A1 WO 2021135491 A1 WO2021135491 A1 WO 2021135491A1 CN 2020120429 W CN2020120429 W CN 2020120429W WO 2021135491 A1 WO2021135491 A1 WO 2021135491A1
Authority
WO
WIPO (PCT)
Prior art keywords
information
width
entry
flow table
message
Prior art date
Application number
PCT/CN2020/120429
Other languages
English (en)
French (fr)
Inventor
赵茂聪
赵子苍
钱超
Original Assignee
盛科网络(苏州)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 盛科网络(苏州)有限公司 filed Critical 盛科网络(苏州)有限公司
Publication of WO2021135491A1 publication Critical patent/WO2021135491A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • H04L45/745Address table lookup; Address filtering
    • H04L45/7453Address table lookup; Address filtering using hashing

Definitions

  • the present invention relates to the field of communications, and in particular to a method and device for matching flow tables.
  • control plane In Software Defined Network (SDN) technology, the control plane is separated from the forwarding plane, and programmability of the control plane is provided.
  • SDN Software Defined Network
  • the functions of the control plane realized by software programming can be realized on traditional high-level switches and routers, and the internal chip realizes inherent functions, or the flow table is realized through Ternary Content Addressable Memory (TCAM) .
  • TCAM Ternary Content Addressable Memory
  • the embodiment of the present invention provides a flow table matching method and device, so as to at least solve the problem of low flexibility of the flow table matching process in the related art.
  • a flow table matching method including:
  • the selecting the first information from the message header information of the message according to the indication information and the second information from the third information includes: parsing the message to obtain the message header information, and The third information is determined according to the message; the message header information is stored in a first storage location, and the third information is stored in a second storage location; according to the instruction information, from the first storage location The first information is obtained from a storage location, and the second information is obtained from the second storage location.
  • the third information includes at least one of the following: an ingress port of the message, a virtual routing and forwarding instance to which the message belongs, and a Layer 3 interface.
  • the obtaining the first information from the first storage location according to the instruction information, and obtaining the second information from the second storage location includes: according to the instruction information Determine the first width of the first information and the second width of the second information; determine the first target location of the first information in the first storage location, and determine the location of the second information in the A second target position in the second storage location; using a first selector at the first target position to obtain the first information, and using a second selector at the second target position to obtain the second Information, wherein the width of the first selector is the first width, and the width of the second selector is the second width.
  • the method further includes: determining the amount of the memory according to the indication information A storage strategy, wherein the storage strategy includes one of the following: divide the storage space of the memory into a plurality of storage units, and store a plurality of second entries of a first width in the memory, wherein the first width A width is the width of the item to be matched, the second table item includes the first table item, and each of the second table items occupies one storage unit in the storage space;
  • the storage space of is divided into the plurality of storage units, a first number of storage units are used in the memory to store the entries of the first width, and a second number of storage units are used to store the second table of the second width Item, wherein the second width is different from the first width.
  • the searching for the first entry that matches the item to be matched in the target flow table according to the hash value includes: searching for the first entry that matches the hash value in the target flow table. Three entries; compare the first keyword and the first flow table number in the to-be-matched entry with the second keyword and the second flow table number in the third entry; When the first keyword is the same as the second keyword and the first flow table number is the same as the second flow table number, it is determined that the third entry is the first entry.
  • the method further includes: forwarding according to the action in the first entry The message; obtain the outgoing port of the message, and add the outgoing port to the third information.
  • a flow table matching device including:
  • the selection module is configured to select the first information from the header information of the message according to the indication information, and select the second information from the third information, wherein the third information is used to indicate the forwarding of the message Information;
  • a first determining module configured to determine a first keyword composed of the first information and the second information, and a first flow table number corresponding to the first keyword
  • a second determining module configured to determine the hash value of the item to be matched composed of the first keyword and the first flow table number
  • the matching module is configured to search the target flow table for the first entry that matches the item to be matched according to the hash value.
  • the selection module is further configured to: parse the message to obtain the message header information, and determine the third information according to the message; and store the message header information in the first Storage location, and storing the third information in a second storage location; obtaining the first information from the first storage location according to the instruction information, and obtaining the first information from the second storage location Second information.
  • the third information includes at least one of the following: an ingress port of the message, a virtual routing and forwarding instance to which the message belongs, and a Layer 3 interface.
  • the selection module is further configured to: determine the first width of the first information and the second width of the second information according to the indication information; determine that the first information is in the first A first target location in the storage location, and a second target location of the second information in the second storage location; using a first selector at the first target location to obtain the first information, and Use a second selector to obtain the second information at the second target position, wherein the width of the first selector is the first width, and the width of the second selector is the second width.
  • the device further includes a third determining module configured to determine a storage strategy of the memory according to the instruction information, wherein the storage strategy includes one of the following: dividing the storage space of the memory into a plurality of A storage unit, storing a plurality of second entries of a first width in the memory, wherein the first width is the width of the item to be matched, and the second entry includes the first entry, Each of the second entries occupies one storage unit in the storage space; the storage space of the memory is divided into the plurality of storage units, and a first number of storage units are used for storage in the memory The entry of the first width and the second entry of the second width are stored by using a second number of storage units, wherein the second width is different from the first width.
  • the storage strategy includes one of the following: dividing the storage space of the memory into a plurality of A storage unit, storing a plurality of second entries of a first width in the memory, wherein the first width is the width of the item to be matched, and the second entry includes the first entry,
  • the matching module is further configured to: search for a third entry in the target flow table that matches the hash value; The first flow table number is compared with the second key and the second flow table number in the third table entry; when the first key is the same as the second key, and the first flow table number is equal to When the numbers of the second flow tables are the same, it is determined that the third table entry is the first table entry.
  • the device further includes a processing module configured to: forward the message according to the action in the first entry; obtain the outgoing port of the message, and add the outgoing port to the The third information.
  • a processing module configured to: forward the message according to the action in the first entry; obtain the outgoing port of the message, and add the outgoing port to the The third information.
  • a storage medium is provided, and a computer program is stored in the storage medium, wherein the computer program is configured to execute the above-mentioned method when running.
  • the first information is selected from the message header information of the message according to the indication information, and the second information is selected from the third information, wherein the third information is used to indicate the forwarding of the message Information; determine the first keyword composed of the first information and the second information, and the first flow table number corresponding to the first keyword; determine the first keyword and the first flow
  • the hash value of the item to be matched composed of the table number; and the first entry that matches the item to be matched is searched in the target flow table according to the hash value. Therefore, the problem of low flexibility of the matching process of the flow table in the related technology can be solved, the flexibility of the matching process of the flow table is improved, and the cost required for developing a new forwarding chip or expanding the chip is reduced.
  • Fig. 1 is a flowchart of a flow table matching method according to an embodiment of the present invention
  • FIG. 2 is a flowchart of a flow table matching method according to another embodiment of the present invention.
  • Fig. 3 is a flowchart of a method for selecting field information according to an embodiment of the present invention.
  • FIG. 4 is a schematic diagram of a method for storing independent entries in a memory according to an embodiment of the present invention
  • FIG. 5 is a schematic diagram of a memory storage method for a shared entry according to an embodiment of the present invention.
  • Fig. 6 is a structural block diagram of a flow table matching device according to an embodiment of the present invention.
  • Fig. 1 is a flowchart of a flow table matching method according to an embodiment of the present invention, as shown in Fig. 1, including:
  • Step S102 Select the first information from the header information of the message according to the indication information, and select the second information from the third information, where the third information is information used to indicate the forwarding of the message ;
  • Step S104 Determine a first keyword composed of the first information and the second information, and a first flow table number corresponding to the first keyword;
  • Step S106 Determine the hash value of the item to be matched composed of the first keyword and the first flow table number
  • Step S108 Search the target flow table for the first entry that matches the item to be matched according to the hash value.
  • the first information is selected from the message header information of the message according to the indication information, and the second information is selected from the third information, wherein the third information is used to indicate the forwarding of the message Information; determine the first keyword composed of the first information and the second information, and the first flow table number corresponding to the first keyword; determine the first keyword and the first flow
  • the hash value of the item to be matched composed of the table number; and the first entry that matches the item to be matched is searched in the target flow table according to the hash value. Therefore, the problem of low flexibility of the matching process of the flow table in the related technology can be solved, the flexibility of the matching process of the flow table is improved, and the cost required for developing a new forwarding chip or expanding the chip is reduced.
  • the matching process of the flow table can be selected according to the instructions of the instruction information, so that Choose which information to use to perform the flow table matching process according to needs, instead of just using fixed information to perform the flow table matching process based on the solidified matching in the forwarding chip, thereby improving the flexibility of the flow table matching process.
  • the virtual routing and forwarding instance to which the message belongs includes the id of the virtual routing and forwarding instance (Virtual Routing & Forwarding, referred to as VRF for short) to which the message belongs.
  • VRF Virtual Routing & Forwarding
  • the selection of the first information from the header information of the message according to the instruction information and the selection of the second information from the third information include:
  • the message header information is obtained by interpreting the message, for example: the source Mac address of the message, the destination Mac address, the virtual local area network instance id (ie VlanId), the Ethernet type, the destination ip address, and the source ip At least one of the address and other information.
  • the third information includes at least one of the following: an ingress port of the message, a virtual routing and forwarding instance to which the message belongs, and a Layer 3 interface.
  • the determining the third information according to the message includes: determining the ingress port of the message according to the message, the virtual routing and forwarding instance to which the message belongs, and a layer 3 interface.
  • the obtaining the first information from the first storage location according to the instruction information, and obtaining the second information from the second storage location includes: determining the first width of the first information and the second width of the second information according to the instruction information; determining the first target position of the first information in the first storage location, and The second information is a second target position in the second storage location; a first selector is used at the first target position to obtain the first information, and a second target position is used at the second target position.
  • the selector obtains the second information, wherein the width of the first selector is the first width, and the width of the second selector is the second width.
  • the width of the information to be obtained determines the selector used, and the corresponding selector is used to obtain the information from the target location, the accuracy of obtaining the information from the storage location is achieved.
  • the method before the selecting the first information from the header information of the message according to the indication information, and selecting the second information from the third information, the method further includes: The instruction information determines a storage strategy of the memory, wherein the storage strategy includes one of the following: dividing the storage space of the memory into a plurality of storage units, and storing a plurality of second tables of a first width in the memory Item, wherein the first width is the width of the item to be matched, the second item includes the first item, and each of the second items occupies one item in the storage space.
  • Storage unit divide the storage space of the memory into the plurality of storage units, use a first number of storage units in the memory to store the entries of the first width, and use a second number of storage units to store The second entry of the second width, wherein the second width is different from the first width.
  • a piece of memory In the first storage strategy, a piece of memory only stores entries of the same width, that is, this piece of memory is only used to match entries of a single width, and in the second In this storage strategy, a piece of memory can store items of different widths, that is, items of different widths can share the memory block, thereby improving the flexibility of item storage.
  • the searching for the first entry that matches the item to be matched in the target flow table according to the hash value includes: searching for the first entry in the target flow table that matches the The third entry matching the hash value; combining the first key and the first flow table number in the to-be-matched entry with the second key and second flow in the third entry Table numbers are compared; when the first key is the same as the second key, and the first flow table number is the same as the second flow table number, it is determined that the third table entry is the The first entry.
  • the first keyword and the first flow table number in the entry to be matched are respectively compared with the second keyword and the second flow table number of the found third entry.
  • the first keyword is the same as the second keyword and the first flow table number is the same as the second flow table number
  • the matched table entries ensure the accuracy of flow table matching.
  • the method further includes: The action in an entry forwards the message; obtains the outgoing port of the message, and adds the outgoing port to the third information.
  • the outgoing port of the message is added to the third information, which can be used for the next level of flow table matching.
  • FIG. 2 is a flowchart of a flow table matching method according to another embodiment of the present invention.
  • the technical solution of the example of the present invention will be described in detail below in conjunction with the flowchart shown in FIG. 2.
  • the technical solution of the example of the present invention is as follows:
  • Step 1 Information acquisition.
  • the field of the message (that is, the message header information in the above embodiment) is parsed through the message parser, for example, the MacDa and MacSa of the state network message are parsed.
  • VlanId, EtherType, IpDa, IpSa (that respectively correspond to the destination Mac address, source Mac address, virtual local area network instance id, Ethernet type, destination ip address, source ip address of the message in the above embodiment), etc., will be resolved
  • the result is stored in ParserResult (ParserResult is the storage space corresponding to the first storage location in the foregoing embodiment).
  • zaInfo can be regarded as intermediate information processed by the chip.
  • Step 2 Field information selection. From PacketInfo and ParserReulst, select the matching keyword used for table lookup. For example, the instruction information indicates that the ingress port and vlanid are used as matching keywords, then in the field information selection step, select the ingress port from PacketInfo, select the vlanid from ParserResult, and combine the selected fields into the matching keyword, and get The flow table number corresponding to the matching key, and the matching key and flow table number form a matching field ⁇ tblid, port, vlanid ⁇ (that is, the item to be matched in the above embodiment), and the hash algorithm (also called Is a hash algorithm) to obtain a hash index (that is, the hash value in the above embodiment);
  • the hash algorithm also called Is a hash algorithm
  • step 2 may be performed by the field information selection module.
  • Fig. 3 is a flowchart of a method for selecting field information according to an embodiment of the present invention. As shown in Figure 3, when selecting matching keywords from PacketInfo and ParserReulst, the field information selection module is implemented by performing the following steps:
  • Step 2-1 Combine the information stored in ParserResult (that is, the result of message analysis) and the information stored in PacketInfo (that is, the intermediate information processed by the chip) into a combined information.
  • the field information selection module is composed of multiple field selectors, such as 2, 4, 8, 16, 32 bit selectors;
  • Step 2-2 The field information selection module determines a selector according to the width of each field in the structure of the item to be matched indicated in the instruction information, and uses the determined selector to obtain the corresponding field content from the combined information.
  • the keyword to be matched is ⁇ port, vlanid ⁇ . Since the port is 16bits and the vlanid is 12bits, a 16bits selector is used to select the port field from the combined information, and an 8bit selector and a 4bit selector are used to select the port field from the combined information. Select the vlanid field.
  • each field in the combination information is fixed in the combination information, for example, the position of the port in the combination information is from 128bit to 128bit to 133bit.
  • the selector extracts the content between 128bit and 133bit (ie [128:133]) in the combined information to obtain the port.
  • Step 3 Check the table. Compare the hash index obtained in step 2 with the hash value of the entry in the flow table stored in the memory to find the third entry, and further compare the matching keywords in the matching fields ⁇ tblid, port, vlanid ⁇ (ie ⁇ tport,vlanid ⁇ ) is the same as the keyword in the third table, and whether the flow table number tblid in the matching field is the same as the flow table number in the third table entry. If they are the same, it means that the match is successful and confirm The third entry is the entry that matches the matching field;
  • Step 4 Process the message according to the action action in the third entry.
  • processing the message according to the action action in the third entry includes: forwarding the message according to the action action in the third entry.
  • the information of the processing result such as the outgoing port, is also put into the packetInfo for the next level of table lookup.
  • the foregoing steps 1 to 4 may be repeated.
  • the user can customize the fields to be matched according to requirements, and use the hash algorithm to search and match the flow table.
  • the hash algorithm to search and match the flow table.
  • only fixed fields can be used for flow table matching, which improves the flexibility of flow table matching. Sex.
  • the memory (ie, memory) storage of the forwarding chip is mostly divided into two types, namely, TCAM and random access memory (also known as RAM).
  • TCAM has a mask matching function, but the price is relatively expensive, while occupying a large chip area and power consumption, and the number of entries that can be stored is small (that is, the entry specifications are small).
  • hash index is often used for storage when the item specification needs to be large.
  • the hash scheme of the chip mostly uses a fixed key (ie, key) table, that is, the matching key of the matching field in the flow table is fixed, and then the hash index is obtained according to the fixed matching key.
  • the matching key of the host routing table is composed of ⁇ ipda, vrf ⁇ , where ipda and vrf are 32 bits and 16 bits respectively, that is, the hash index of the flow table stored in RAM is obtained according to ipda, vrf (that is, in RAM).
  • the flow table only supports matching of ipda and vrf fields).
  • the matching field supported by the flow table in the chip is fixed, and the width of the entry stored in the flow table is also fixed.
  • the matching fields involved are relatively small and the width of the matching field is small, for example, it only matches vlanid that only occupies 12 bits, and the chip cannot meet this matching setting.
  • the TCAM is relatively expensive, the specifications of the entries stored in the TCAM will be limited, and the use of the TCAM entries cannot cope with changes in the network protocol.
  • two memory storage strategies are provided.
  • independent entry is proposed, that is, a piece of memory is used for only one entry, and the size of the entry stored in the memory is determined by the width of the matching field.
  • shared entries are proposed, that is, a piece of memory can be used to match multiple entries.
  • FIG. 4 is a schematic diagram of a method for storing independent entries in a memory according to an embodiment of the present invention.
  • multiple table items with the same width ie, Table 1 to Table n
  • the width of the table items stored in the memory is determined by the total width of the matching field.
  • the flow table number tblid uses 4 bits. Since the port is 16 bits, the vlanid is 12 bits, and the tblid is 4 bits, the matching field The total width is 32bits.
  • the maximum number of table items that can be stored in the memory can be obtained (that is, the table item specifications are obtained). Therefore, the advantage of using the memory of an independent entry is that when the total width of the matching field is smaller, the specification of the entry is larger, so that the memory of the independent entry can support a larger entry specification.
  • Fig. 5 is a schematic diagram of a memory storage method for a shared entry according to an embodiment of the present invention. As shown in Figure 5, for the following four types of entries:
  • the matching keyword in Table 1 is ⁇ port[15:0], vlanid[11:0] ⁇ , that is, the width of the matching keyword is 28 bits (that is, the 16-bit port and the 12-bit vlanid are used as the matching key), and the flow Table number 1 occupies 4 bits, so the total width of the matching field in Table 1 is 32 bits;
  • the matching keyword in Table 2 is ⁇ ipda[31:0],vrf[15:0] ⁇ , and the width of the matching keyword is 48 bits (that is, the destination ip address of 32 bits and the vfr of 16 bits are used as the matching key), so The total width of the matching field in Table 2 is 36 bits;
  • the matching keywords in Table 3 are ⁇ port[15:0], vlan[11:0],macSa[47:0] ⁇ , and the width of the matching keywords is 76 bits, so the total width of the matching field in Table 3 is 40 bits ;
  • the matching keyword in Table 4 is ⁇ ipv6Da[127:0],vrf[15:0] ⁇ , and the width of the matching keyword is 144 bits, so the total width of the matching field in Table 4 is 148 bits;
  • the memory is subdivided into small storage units (cells).
  • Each cell is composed of a 4bits flow table number tbl id and a 32bits matching key.
  • the 4bits tbl id is used to distinguish different table entries to prevent mismatches; the 32bits matching key is used to store the matching keywords. Field. If the size of the matching key of a table is greater than 32 bits, multiple cells will be occupied. As shown in Figure 5, Table 1 occupies 1 cell, Table 2 occupies 2 cells, Table 3 occupies 4 cells, and Table 4 uses 8 cells.
  • the advantage of using shared table entries for storage is that the memory can support multiple table entries, and multiple table entries share a piece of memory, that is, resource sharing is realized. It should be noted that upper-layer applications can choose which memory storage strategy to use according to their needs (for example, entry application strategy). For example, the entry function is relatively independent and the entry specification requirements are large, then the independent entry memory strategy can be selected; if the table If the item functions are mixed, you can choose the shared table item memory strategy.
  • the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, of course, it can also be implemented by hardware, but in many cases the former is Better implementation.
  • the technical solution of the present invention essentially or the part that contributes to the existing technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM/RAM, magnetic disk, The optical disc) includes a number of instructions to enable a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the method described in each embodiment of the present invention.
  • a flow table matching device is provided, and the device is used to implement the above-mentioned embodiments and preferred implementations, and those that have been described will not be repeated.
  • the term "module” can implement a combination of software and/or hardware with predetermined functions.
  • the devices described in the following embodiments are preferably implemented by software, implementation by hardware or a combination of software and hardware is also possible and conceived.
  • Fig. 6 is a structural block diagram of a flow table matching device according to an embodiment of the present invention, and the device includes:
  • the selection module 62 is configured to select the first information from the header information of the message according to the indication information, and select the second information from the third information, wherein the third information is used to indicate the message Forwarded information;
  • the first determining module 64 is configured to determine a first keyword composed of the first information and the second information, and a first flow table number corresponding to the first keyword;
  • the second determining module 66 is configured to determine the hash value of the item to be matched composed of the first keyword and the first flow table number;
  • the matching module 68 is configured to search the target flow table for the first entry that matches the item to be matched according to the hash value.
  • the first information is selected from the message header information of the message according to the indication information, and the second information is selected from the third information, wherein the third information is used to indicate the forwarding of the message Information; determine the first keyword composed of the first information and the second information, and the first flow table number corresponding to the first keyword; determine the first keyword and the first flow
  • the hash value of the item to be matched composed of the table number; and the first entry that matches the item to be matched is searched in the target flow table according to the hash value. Therefore, the problem of low flexibility of the matching process of the flow table in the related technology can be solved, the flexibility of the matching process of the flow table is improved, and the cost required for developing a new forwarding chip or expanding the chip is reduced.
  • the selection module 62 is further configured to: parse the message to obtain the message header information, and determine the third information according to the message;
  • the message header information is stored in the first storage location, and the third information is stored in the second storage location; according to the instruction information, the first information is obtained from the first storage location, and the The second information is acquired in the second storage location.
  • the third information includes at least one of the following: an ingress port of the message, a virtual routing and forwarding instance to which the message belongs, and a Layer 3 interface.
  • the selection module 62 is further configured to: determine the first width of the first information and the second width of the second information according to the indication information; and determine the The first target location of the first information in the first storage location, and the second target location of the second information in the second storage location; using a first selector at the first target location Acquiring the first information, and acquiring the second information using a second selector at the second target position, wherein the width of the first selector is the first width, and the second selection The width of the device is the second width.
  • the device further includes a third determining module configured to determine a storage strategy of the memory according to the instruction information, wherein the storage strategy includes one of the following: The storage space of is divided into multiple storage units, and multiple second entries of a first width are stored in the memory, where the first width is the width of the item to be matched, and the second entry includes The first entry, each second entry occupies one storage unit in the storage space; the storage space of the memory is divided into the multiple storage units, and the storage unit is used in the memory A first number of storage units store entries of the first width, and a second number of storage units store second entries of a second width, wherein the second width is different from the first width.
  • the storage strategy includes one of the following: The storage space of is divided into multiple storage units, and multiple second entries of a first width are stored in the memory, where the first width is the width of the item to be matched, and the second entry includes The first entry, each second entry occupies one storage unit in the storage space; the storage space of the memory is divided into the multiple storage units, and
  • the matching module 68 is further configured to: search for a third entry in the target flow table that matches the hash value; The first keyword and the first flow table number are compared with the second keyword and the second flow table number in the third entry; when the first keyword and the second keyword are the same And in a case where the number of the first flow table is the same as the number of the second flow table, it is determined that the third table entry is the first table entry.
  • the device further includes a processing module configured to: forward the message according to the action in the first entry; obtain the outgoing port of the message, and set the The stated port is added to the third information.
  • An embodiment of the present invention also provides a storage medium, the storage medium including a stored program, wherein the above-mentioned program executes any of the above-mentioned methods when the program is running.
  • the aforementioned storage medium may be configured to store program code for executing the following steps:
  • S2 Determine a first keyword composed of the first information and the second information, and a first flow table number corresponding to the first keyword;
  • S4 Search the target flow table for a first entry that matches the item to be matched according to the hash value.
  • the above-mentioned storage medium may include but is not limited to: U disk, Read-Only Memory (Read-Only Memory, ROM for short), Random Access Memory (Random Access Memory, RAM for short), Various media that can store program codes, such as mobile hard disks, magnetic disks, or optical disks.
  • An embodiment of the present invention also provides an electronic device, including a memory and a processor, the memory is stored with a computer program, and the processor is configured to run the computer program to execute the steps in any of the foregoing method embodiments.
  • the aforementioned electronic device may further include a transmission device and an input-output device, wherein the transmission device is connected to the aforementioned processor, and the input-output device is connected to the aforementioned processor.
  • the foregoing processor may be configured to execute the following steps through a computer program:
  • S2 Determine a first keyword composed of the first information and the second information, and a first flow table number corresponding to the first keyword;
  • S4 Search the target flow table for a first entry that matches the item to be matched according to the hash value.
  • modules or steps of the present invention can be implemented by a general computing device, and they can be concentrated on a single computing device or distributed in a network composed of multiple computing devices.
  • they can be implemented with program codes executable by the computing device, so that they can be stored in the storage device for execution by the computing device, and in some cases, can be executed in a different order than here.
  • the first information is selected from the message header information of the message according to the indication information, and the second information is selected from the third information, wherein the third information is used to indicate the forwarding of the message Information; determine the first keyword composed of the first information and the second information, and the first flow table number corresponding to the first keyword; determine the first keyword and the first flow
  • the hash value of the item to be matched composed of the table number; and the first entry that matches the item to be matched is searched in the target flow table according to the hash value. Therefore, the problem of low flexibility of the matching process of the flow table in related technologies can be solved, the flexibility of the matching process of the flow table is improved, and the cost required for developing a new forwarding chip or expanding the chip is reduced.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明提供了一种流表的匹配方法及装置,上述方法包括:根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。通过本发明,解决了相关技术中流表的匹配流程灵活性较低的问题,提高了流表的匹配流程的灵活性。

Description

流表的匹配方法及装置 技术领域
本发明涉及通信领域,具体而言,涉及一种流表的匹配方法及装置。
背景技术
在软件定义网络(Software Defined Network,简称为SDN)技术中,将控制平面与转发平面分离,并且提供了对控制平面的可编程能力。目前通过软件编程实现的控制平面的功能,在传统的高级交换机和路由器上均可以实现,并且内部芯片实现固有功能,或者通过三态内容存储器(Ternary Content Addressable Memory,简称为TCAM)来实现流表。
然而,相关技术中开放的仅仅是对控制平面的可编程能力。对于转发平面,转发设备中的数据包解析流程和转发流程在转发设备的转发芯片中是固化的,即转发设备在协议的支持方面并不具备扩展能力。并且,设备生产厂商开发支持新协议的转发芯片,或者扩展转发芯片的协议特性时,需要对转发芯片的硬件重新进行设计,导致开发或扩展的代价非常高并且时间周期长。因此,将转发设备的功能、协议支持与硬件绑定的模式限制了网络的快速发展。
针对相关技术中,流表的匹配流程灵活性较低的问题,尚未提出有效的技术方案。
发明内容
本发明实施例提供了一种流表的匹配方法及装置,以至少解决相关技术中流表的匹配流程灵活性较低的问题。
根据本发明的一个实施例,提供了一种流表的匹配方法,包括:
根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;
确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;
确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;
根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。
可选地,所述根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,包括:解析所述报文得到所述报文头信息,并根据所述报文确定所述第三信息;将所述报文头信息存储到第一存储位置,以及将所述第三信息存储到第二存储位置;根据所述指示信息,从所述第一存储位置中获取所述第一信息,以及从所述第二存储位置中获取所述第二信息。
可选地,所述第三信息包括以下至少之一:所述报文的入端口,所述报文所属的虚拟路由转发实例以及三层接口。
可选地,所述根据所述指示信息,从所述第一存储位置中获取所述第一信息,以及从所述第二存储位置中获取所述第二信息,包括:根据所述指示信息确定所述第一信息的第一宽度以及所述第二信息的第二宽度;确定所述第一信息在所述第一存储位置中的第一目标位置,以及所述第二信息在所述第二存储位置中的第二目标位置;在所述第一目标位置处使用第一选择器获取所述第一信息,以及在所述第二目标位置处使用第二选择器获取所述第二信息,其中,所述第一选择器的宽度为所述第一宽度,所述第二选择器的宽度为所述第二宽度。
可选地,在所述根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息之前,所述方法还包括:根据所述指示信息确定内存的存储策略,其中,所述存储策略包括以下之一:将所述内存的存储空间划分为多个存储单元,在所述内存中存储第一宽度的多个第二表项,其中,所述第一宽度为所述待匹配项的宽度,所述第二表项包括所述第一表项,每个所述第二表项在所述存储空间中占用一个所述存储单元; 将所述内存的存储空间划分为所述多个存储单元,在所述内存中使用第一数量的存储单元存储所述第一宽度的表项,以及使用第二数量的存储单元存储第二宽度的第二表项,其中,所述第二宽度与所述第一宽度不同。
可选地,所述根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项,包括:在所述目标流表中查找与所述哈希值匹配的第三表项;将所述待匹配表项中的所述第一关键字、所述第一流表编号与所述第三表项中的第二关键字和第二流表编号进行比较;在所述第一关键字与所述第二关键字相同以及所述第一流表编号与所述第二流表编号相同的情况下,确定所述第三表项为所述第一表项。
可选地,在所述根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项之后,所述方法还包括:根据所述第一表项中的动作转发所述报文;获取所述报文的出端口,并将所述出端口添加到所述第三信息中。
根据本发明的另一个实施例,提供了一种流表的匹配装置,包括:
选择模块,设置为根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;
第一确定模块,设置为确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;
第二确定模块,设置为确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;
匹配模块,设置为根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。
可选地,所述选择模块,还设置为:解析所述报文得到所述报文头信息,并根据所述报文确定所述第三信息;将所述报文头信息存储到第一存储位置,以及将所述第三信息存储到第二存储位置;根据所述指示信息,从所述第一存储位置中获取所述第一信息,以及从所述第二存储位置中获取所述第二信息。
可选地,所述第三信息包括以下至少之一:所述报文的入端口,所述报文所属的虚拟路由转发实例以及三层接口。
可选地,所述选择模块,还设置为:根据所述指示信息确定所述第一信息的第一宽度以及所述第二信息的第二宽度;确定所述第一信息在所述第一存储位置中的第一目标位置,以及所述第二信息在所述第二存储位置中的第二目标位置;在所述第一目标位置处使用第一选择器获取所述第一信息,以及在所述第二目标位置处使用第二选择器获取所述第二信息,其中,所述第一选择器的宽度为所述第一宽度,所述第二选择器的宽度为所述第二宽度。
可选地,所述装置还包括第三确定模块,设置为:根据所述指示信息确定内存的存储策略,其中,所述存储策略包括以下之一:将所述内存的存储空间划分为多个存储单元,在所述内存中存储第一宽度的多个第二表项,其中,所述第一宽度为所述待匹配项的宽度,所述第二表项包括所述第一表项,每个所述第二表项在所述存储空间中占用一个所述存储单元;将所述内存的存储空间划分为所述多个存储单元,在所述内存中使用第一数量的存储单元存储所述第一宽度的表项,以及使用第二数量的存储单元存储第二宽度的第二表项,其中,所述第二宽度与所述第一宽度不同。
可选地,所述匹配模块还设置为:在所述目标流表中查找与所述哈希值匹配的第三表项;将所述待匹配表项中的所述第一关键字、所述第一流表编号与所述第三表项中的第二关键字和第二流表编号进行比较;在所述第一关键字与所述第二关键字相同以及所述第一流表编号与所述第二流表编号相同的情况下,确定所述第三表项为所述第一表项。
可选地,所述装置还包括处理模块,设置为:根据所述第一表项中的动作转发所述报文;获取所述报文的出端口,并将所述出端口添加到所述第三信息中。
可选地,根据本发明的另一个实施例,提供了一种存储介质,所述存储介质中存储有计算机程序,其中,所述计算机程序被设置为运行时执行 上述方法。
可选地,根据本发明的另一个实施例,提供了一种电子装置,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为运行所述计算机程序以执行上述方法。
通过本发明,根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。因此,可以解决相关技术中流表的匹配流程灵活性较低的问题,提高了流表的匹配流程的灵活性,从而降低了开发新的转发芯片或对芯片进行扩展的所需的成本。
附图说明
此处所说明的附图用来提供对本发明的进一步理解,构成本申请的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:
图1为根据本发明实施例的流表的匹配方法的流程图;
图2为根据本发明另一实施例的流表的匹配方法的流程图;
图3为根据本发明一实施例的字段信息选择方法的流程图;
图4中是根据本发明实施例中的独立表项的内存存储方法的示意图;
图5中是根据本发明实施例中的共享表项的内存存储方法的示意图;
图6是根据本发明实施例的流表的匹配装置的结构框图。
具体实施方式
下文中将参考附图并结合实施例来详细说明本发明。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。
需要说明的是,本发明的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。
实施例1
本发明实施例提供了一种流表的匹配方法。图1为根据本发明实施例的流表的匹配方法的流程图,如图1所示,包括:
步骤S102,根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;
步骤S104,确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;
步骤S106,确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;
步骤S108,根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。
通过本发明,根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。因此,可以解决相关技术中流表的匹配流程灵活性较低的问题,提高了流表的匹配流程的灵活性,从而降低了开发新的转发芯片或对芯片进行扩展的所需的成本。
需要说明的是,在上述实施例中,由于可以根据指示信息选择出用于进行流表匹配的第一信息和第二信息,即流表的匹配流程可以根据指示信息的指示进行选择,从而可以根据需要选择使用哪些信息来进行流表匹配流程,而不是仅仅根据转发芯片中固化的匹配使用固定的信息来执行流表 的匹配过程,从而提高了流表匹配流程的灵活性。
可选地,所述报文所属的虚拟路由转发实例包括所述报文所属的虚拟路由转发实例(Virtual Routing&Forwarding,简称为VRF)的id。
需要说明的是,所述根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,包括:
解析所述报文得到所述报文头信息,并根据所述报文确定所述第三信息;将所述报文头信息存储到第一存储位置,以及将所述第三信息存储到第二存储位置;根据所述指示信息,从所述第一存储位置中获取所述第一信息,以及从所述第二存储位置中获取所述第二信息。
在上述实施例中,通过对报文进行解释得到报文头信息,例如:报文的源Mac地址,目的Mac地址,虚拟局域网实例id(即VlanId),以太网类型,目的ip地址,源ip地址等信息中的至少之一。
基于上述实施例,作为一种可选的实施方式,所述第三信息包括以下至少之一:所述报文的入端口,所述报文所属的虚拟路由转发实例以及三层接口。所述根据所述报文确定所述第三信息,包括:根据所述报文确定所述报文的入端口,所述报文所属的虚拟路由转发实例以及三层接口。
在本发明的一可选实施例中,所述根据所述指示信息,从所述第一存储位置中获取所述第一信息,以及从所述第二存储位置中获取所述第二信息,包括:根据所述指示信息确定所述第一信息的第一宽度以及所述第二信息的第二宽度;确定所述第一信息在所述第一存储位置中的第一目标位置,以及所述第二信息在所述第二存储位置中的第二目标位置;在所述第一目标位置处使用第一选择器获取所述第一信息,以及在所述第二目标位置处使用第二选择器获取所述第二信息,其中,所述第一选择器的宽度为所述第一宽度,所述第二选择器的宽度为所述第二宽度。
其中,在上述实施例中,宽度指的是比特数或字节数。例如,第一信息的第一宽度指的是第一信息的比特数或字节数。
通过上述实施例,由于待获取的信息的宽度确定所使用的选择器,并 使用相应的选择器从目标位置处获取信息,从而实现了从存储位置中获取信息的准确性。
在本发明的一可选实施例中,在所述根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息之前,所述方法还包括:根据所述指示信息确定内存的存储策略,其中,所述存储策略包括以下之一:将所述内存的存储空间划分为多个存储单元,在所述内存中存储第一宽度的多个第二表项,其中,所述第一宽度为所述待匹配项的宽度,所述第二表项包括所述第一表项,每个所述第二表项在所述存储空间中占用一个所述存储单元;将所述内存的存储空间划分为所述多个存储单元,在所述内存中使用第一数量的存储单元存储所述第一宽度的表项,以及使用第二数量的存储单元存储第二宽度的第二表项,其中,所述第二宽度与所述第一宽度不同。
基于上述实施例,提供了两种内存存储策略,即在第一种存储策略中,一块内存仅存储相同宽度的表项,即这块内存仅用于匹配单一宽度的表项,以及在第二种存储策略中,一块内存可以存储不同宽度的表项,即不同宽度的表项可以共享该内存块,从而提高了表项存储的灵活性。
在本发明的一可选实施例中,所述根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项,包括:在所述目标流表中查找与所述哈希值匹配的第三表项;将所述待匹配表项中的所述第一关键字、所述第一流表编号与所述第三表项中的第二关键字和第二流表编号进行比较;在所述第一关键字与所述第二关键字相同以及所述第一流表编号与所述第二流表编号相同的情况下,确定所述第三表项为所述第一表项。
需要说明的是,在上述实施例中,将待匹配表项中的第一关键字、第一流表编号分别与查找到的第三表项的第二关键字和第二流表编号进行比较,在所述第一关键字与所述第二关键字相同以及所述第一流表编号与所述第二流表编号相同的情况下,确定所述第三表项为与所述待匹配表项匹配的表项,从而确保了流表匹配的准确性。
在本发明的一可选实施例中,在所述根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项之后,所述方法还包括:根据所述第一表项中的动作转发所述报文;获取所述报文的出端口,并将所述出端口添加到所述第三信息中。
基于上述实施例,在根据第一表项中的动作对报文进行转发后,将报文的出端口添加到第三信息中,从而可以用于下一级的流表匹配。
以下结合一示例对上述的流表的匹配方法进行解释说明,但不用于限定本发明实施例的技术方案。图2为根据本发明另一实施例的流表的匹配方法的流程图。下面结合图2所示的流程图对本发明示例的技术方案进行详细说明,本发明示例的技术方案如下:
步骤1、信息获取。从转发芯片的端口上接收到报文后,先经过报文解析器把报文的字段(即上述实施例中的报文头信息)解析出来,比如解析出以态网报文的MacDa,MacSa,VlanId,EtherType,IpDa,IpSa(即分别对应于上述实施例中的报文的目的Mac地址,源Mac地址,虚拟局域网实例id,以太网类型,目的ip地址,源ip地址)等,将解析结果存储到ParserResult(ParserResult为上述实施例中的第一存储位置所对应的存储空间)中。同时获取报文的入端口、vrf、三层接口等中间信息(即对应于上述实施例中的第三信息),并存储到PaketInfo(PaketInfo为上述实施例中的第二存储位置所对应的存储空间)中;
需要说明的是,PaketInfo中存储的信息可以看作是芯片处理的中间信息。
步骤2、字段信息选择。从PacketInfo和ParserReulst里选择用于进行查表的匹配关键字。比如指示信息中指示将入端口和vlanid作为匹配关键字,则在该字段信息选择步骤中,从PacketInfo里选择入端口,从ParserResult里选择出vlanid,并把选择的字段组成匹配关键字,并获取该匹配关键字对应的流表编号,以及将匹配关键字和流表编号组成一个匹配字段{tblid,port,vlanid}(即上述实施例中的待匹配项),并通过散列算法 (又称为hash算法)得到一个hash索引(即上述实施例中的哈希值);
作为一种可选的实施方式,步骤2可以由字段信息选择模块执行。图3为根据本发明一实施例的字段信息选择方法的流程图。如图3所示,在从PacketInfo和ParserReulst里选择匹配关键字时,字段信息选择模块通过执行以下步骤来实现:
步骤2-1:将ParserResult中存储的信息(即报文解析结果)和PacketInfo中存储的信息(即芯片处理的中间信息)组成一个组合信息。字段信息选择模块由多个字段选择器组成,例如有2、4、8、16、32比特(bits)选择器;
步骤2-2:字段信息选择模块根据指示信息中指示的待匹配项的结构中各个字段的宽度确定选择器,并使用确定的选择器从组合信息中获取对应的字段内容。例如,待匹配项的关键字是{port,vlanid},由于port是16bits,vlanid是12bits,则使用一个16bits选择器从组合信息里选择port字段,使用一个8bit选择器和4bit选择器从组合信息中选取vlanid字段。需要说明的是,由于组合信息中各个字段在该组合信息的置是固定的,比如port在组合信息中的位置是从128bit开始第128bit至133bit,则从组合信息中获取port时,使用16bits的选择器将组合信息中位于第128bit至133bit之间(即[128:133])的内容提取出来得到port。
步骤3、查表。将步骤2中得到的hash索引与内存存储的流表中的表项的hash值进行比较,找到第三表项,并进一步比较匹配字段{tblid,port,vlanid}中的匹配关键字(即{tport,vlanid})与第三表中的关键字是否相同,以及匹配字段中的流表编号tblid与第三表项中的流表编号是否相同,在均相同的情况下,表示匹配成功并确认第三表项是与匹配字段匹配的表项;
步骤4、根据第三表项中的action动作对报文进行处理。可选地,根据第三表项中的action动作对报文进行处理包括:根据第三表项中的action动作对报文进行转发。在对报文进行处理后,处理结果的信息,比如出端口也放入packetInfo里,用于下一级查表。
可选地,基于上述实施例,在需要对报文进行下一级查表时,重复执行上述步骤1至步骤4即可。
在上述实施例中,用户可以根据需求自定义需要匹配字段,并使用hash算法进行查找和匹配流表,相对于相关技术中仅能使用固定的字段进行流表匹配,提高了流表匹配的灵活性。
相关技术中,转发芯片的内存(即memory)存储大多分为两类,即TCAM和随机存取存储器(又称为RAM)。其中,TCAM有掩码匹配功能,但价格比较昂贵,同时占用芯片面积和功耗较大,并且所能存储的表项数量较少(即表项规格较小)。对于RAM,在表项规格需要较大时多采用hash索引来存储。而目前芯片的hash方案多采用固定key(即关键字)表,即流表中的匹配字段的匹配关键字是固定的,进而根据该固定的匹配关键字得到hash索引。比如主机路由表的匹配关键字由{ipda,vrf}组成,其中ipda,vrf分别为32比特、16比特,即RAM中存储的流表的hash索引是根据ipda,vrf得到的(也即RAM中的流表仅支持对于ipda,vrf字段的匹配)。
可见相关技术中,一旦芯片生产出来,该芯片中的流表所支持的匹配字段就已经固定,同时流表中所存储的表项的宽度也是固定的。在根据报文查找表项时,如果所涉及到的匹配字段比较少而且匹配字段的宽度较小,例如仅匹配只占12bits的vlanid,而该芯片就无法满足这种匹配设置,如果要满足,则需要使用TCAM表项来代替。即在TCAM表项中,把其它字段掩码(即mask)掉。但是,由于TCAM比较昂贵,从而TCAM中存储的表项规格会受到限制,并且使用TCAM表项也无法应对网络协议的变化。
因此,在本发明的实施例中,提供了两种内存的存储策略。在第一中存储策略中,提出了独立表项,即一块内存只用于一种表项,内存中存储的表项的大小由匹配字段的宽度决定。在第二中存储策略中,提出了共享表项,即一块内存可以用于匹配多种表项。
图4中是根据本发明实施例中的独立表项的内存存储方法的示意图。如图4所示,在该内存中存储了多个具有相同宽度的表项(即表1至表n),并且内存中存储的表项的宽度由匹配字段的总宽度决定。作为一种可选的实施方式,例如,当匹配字段的关键字是由{port,vlanid}组成时,流表编号tblid采用4bits,由于port是16bits,vlanid是12bits,tblid为4bits,则匹配字段的总宽度是32bits。则根据内存大小以及匹配字段的总宽度,能够得到该内存中最多能够存储多少表项(即得到了表项规格)。因此,采用独立表项的内存的优点是当匹配字段的总宽度越小,表项规格越大,从而采用独立表项的内存能够支持较大的表项规格。
图5中是根据本发明实施例中的共享表项的内存存储方法的示意图。如图5所示,对于以下4种表项:
表1中的匹配关键字为{port[15:0],vlanid[11:0]},即匹配关键字的宽度为28bits(即将16bits的端口以及12bits的vlanid作为匹配关键字的),以及流表编号1占用4bits,从而表1的匹配字段的总宽度为32bits;
表2中的匹配关键字为{ipda[31:0],vrf[15:0]},匹配关键字的宽度为48bits(即将32bits的目的ip地址以及16bits的vfr作为匹配关键字的),因此表2的匹配字段的总宽度为36bits;
表3中的匹配关键字为{port[15:0],vlan[11:0],macSa[47:0]},匹配关键字的宽度为76bits,因此表3的匹配字段的总宽度为40bits;
表4中的匹配关键字为{ipv6Da[127:0],vrf[15:0]},匹配关键字的宽度为144bits,因此表4的匹配字段的总宽度为148bits;
在共享表项的存储过程中,将内存细分为小的存储单元(cell)。每个cell由4bits的流表编号tbl id和32bits的匹配关键字组成,其中4bits的tbl id用来区分不同的表项,从而防止误匹配;32bits的匹配关键字用来存储组成匹配关键字的字段。如果一个表的匹配关键字的大小大于32bits,则会占用多个cell。图5所示,表1占1个cell,表2占2个cell,表3占4个cell,表4用8个cell。
采用共享表项的方式进行存储的优点是内存可以支持多种表项,并且多种表项共享一块内存,即实现了资源共享。需要说明的是,上层应用可以根据需要(例如,表项应用策略)选择使用哪个内存存储策略,例如表项功能比较独立同时表项规格要求较大,则可以选择独立表项内存策略;如果表项功能混合,则可以选择共享表项内存策略。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到根据上述实施例的方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。
实施例2
根据本发明的另一个实施例,提供了一种流表的匹配装置,该装置用于实现上述实施例及优选实施方式,已经进行过说明的不再赘述。如以下所使用的,术语“模块”可以实现预定功能的软件和/或硬件的组合。尽管以下实施例所描述的装置较佳地以软件来实现,但是硬件,或者软件和硬件的组合的实现也是可能并被构想的。
图6是根据本发明实施例的流表的匹配装置的结构框图,该装置包括:
选择模块62,设置为根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;
第一确定模块64,设置为确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;
第二确定模块66,设置为确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;
匹配模块68,设置为根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。
通过本发明,根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。因此,可以解决相关技术中流表的匹配流程灵活性较低的问题,提高了流表的匹配流程的灵活性,从而降低了开发新的转发芯片或对芯片进行扩展的所需的成本。
在本发明的一可选实施例中,所述选择模块62,还设置为:解析所述报文得到所述报文头信息,并根据所述报文确定所述第三信息;将所述报文头信息存储到第一存储位置,以及将所述第三信息存储到第二存储位置;根据所述指示信息,从所述第一存储位置中获取所述第一信息,以及从所述第二存储位置中获取所述第二信息。
在本发明的一可选实施例中,所述第三信息包括以下至少之一:所述报文的入端口,所述报文所属的虚拟路由转发实例以及三层接口。
在本发明的一可选实施例中,所述选择模块62,还设置为:根据所述指示信息确定所述第一信息的第一宽度以及所述第二信息的第二宽度;确定所述第一信息在所述第一存储位置中的第一目标位置,以及所述第二信息在所述第二存储位置中的第二目标位置;在所述第一目标位置处使用第一选择器获取所述第一信息,以及在所述第二目标位置处使用第二选择器获取所述第二信息,其中,所述第一选择器的宽度为所述第一宽度,所述第二选择器的宽度为所述第二宽度。
在本发明的一可选实施例中,所述装置还包括第三确定模块,设置为:根据所述指示信息确定内存的存储策略,其中,所述存储策略包括以下之一:将所述内存的存储空间划分为多个存储单元,在所述内存中存储第一 宽度的多个第二表项,其中,所述第一宽度为所述待匹配项的宽度,所述第二表项包括所述第一表项,每个所述第二表项在所述存储空间中占用一个所述存储单元;将所述内存的存储空间划分为所述多个存储单元,在所述内存中使用第一数量的存储单元存储所述第一宽度的表项,以及使用第二数量的存储单元存储第二宽度的第二表项,其中,所述第二宽度与所述第一宽度不同。
在本发明的一可选实施例中,所述匹配模块68还设置为:在所述目标流表中查找与所述哈希值匹配的第三表项;将所述待匹配表项中的所述第一关键字、所述第一流表编号与所述第三表项中的第二关键字和第二流表编号进行比较;在所述第一关键字与所述第二关键字相同以及所述第一流表编号与所述第二流表编号相同的情况下,确定所述第三表项为所述第一表项。
在本发明的一可选实施例中,所述装置还包括处理模块,设置为:根据所述第一表项中的动作转发所述报文;获取所述报文的出端口,并将所述出端口添加到所述第三信息中。
实施例3
本发明的实施例还提供了一种存储介质,该存储介质包括存储的程序,其中,上述程序运行时执行上述任一项的方法。
可选地,在本实施例中,上述存储介质可以被设置为存储用于执行以下步骤的程序代码:
S1,根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;
S2,确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;
S3,确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;
S4,根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。
可选地,在本实施例中,上述存储介质可以包括但不限于:U盘、只读存储器(Read-Only Memory,简称为ROM)、随机存取存储器(Random Access Memory,简称为RAM)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
可选地,本实施例中的具体示例可以参考上述实施例及可选实施方式中所描述的示例,本实施例在此不再赘述。
实施例4
本发明的实施例还提供了一种电子装置,包括存储器和处理器,该存储器中存储有计算机程序,该处理器被设置为运行计算机程序以执行上述任一项方法实施例中的步骤。
可选地,上述电子装置还可以包括传输设备以及输入输出设备,其中,该传输设备和上述处理器连接,该输入输出设备和上述处理器连接。
可选地,在本实施例中,上述处理器可以被设置为通过计算机程序执行以下步骤:
S1,根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;
S2,确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;
S3,确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;
S4,根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。
可选地,本实施例中的具体示例可以参考上述实施例及可选实施方式 中所描述的示例,本实施例在此不再赘述。
显然,本领域的技术人员应该明白,上述的本发明的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本发明不限制于任何特定的硬件和软件结合。
以上所述仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。
工业实用性
通过本发明,根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。因此,可以解决相关技术中流表的匹配流程灵活性较低的问题,提高了流表的匹配流程的灵活性,从而降低了开发新的转发芯片或对芯片进行扩展的所需的成本。

Claims (14)

  1. 一种流表的匹配方法,包括:
    根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;
    确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;
    确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;
    根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。
  2. 根据权利要求1所述的方法,其中,所述根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,包括:
    解析所述报文得到所述报文头信息,并根据所述报文确定所述第三信息;
    将所述报文头信息存储到第一存储位置,以及将所述第三信息存储到第二存储位置;
    根据所述指示信息,从所述第一存储位置中获取所述第一信息,以及从所述第二存储位置中获取所述第二信息。
  3. 根据权利要求1所述的方法,其中,所述第三信息包括以下至少之一:所述报文的入端口,所述报文所属的虚拟路由转发实例以及三层接口。
  4. 根据权利要求2所述的方法,其中,所述根据所述指示信息,从所述第一存储位置中获取所述第一信息,以及从所述第二存储位置中获取所述第二信息,包括:
    根据所述指示信息确定所述第一信息的第一宽度以及所述第二信息的第二宽度;
    确定所述第一信息在所述第一存储位置中的第一目标位置,以及所述第二信息在所述第二存储位置中的第二目标位置;
    在所述第一目标位置处使用第一选择器获取所述第一信息,以及在所述第二目标位置处使用第二选择器获取所述第二信息,其中,所述第一选择器的宽度为所述第一宽度,所述第二选择器的宽度为所述第二宽度。
  5. 根据权利要求1所述的方法,其中,在所述根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息之前,所述方法还包括:根据所述指示信息确定内存的存储策略,其中,所述存储策略包括以下之一:
    将所述内存的存储空间划分为多个存储单元,在所述内存中存储第一宽度的多个第二表项,其中,所述第一宽度为所述待匹配项的宽度,所述第二表项包括所述第一表项,每个所述第二表项在所述存储空间中占用一个所述存储单元;
    将所述内存的存储空间划分为所述多个存储单元,在所述内存中使用第一数量的存储单元存储所述第一宽度的表项,以及使用第二数量的存储单元存储第二宽度的第二表项,其中,所述第二宽度与所述第一宽度不同。
  6. 根据权利要求1所述的方法,其中,所述根据所述哈希值在 目标流表中查找与所述待匹配项匹配的第一表项,包括:
    在所述目标流表中查找与所述哈希值匹配的第三表项;
    将所述待匹配表项中的所述第一关键字、所述第一流表编号与所述第三表项中的第二关键字和第二流表编号进行比较;
    在所述第一关键字与所述第二关键字相同以及所述第一流表编号与所述第二流表编号相同的情况下,确定所述第三表项为所述第一表项。
  7. 根据权利要求1所述的方法,其中,在所述根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项之后,所述方法还包括:
    根据所述第一表项中的动作转发所述报文;
    获取所述报文的出端口,并将所述出端口添加到所述第三信息中。
  8. 一种流表的匹配装置,包括:
    选择模块,设置为根据指示信息从报文的报文头信息中选择第一信息,以及从第三信息中选择第二信息,其中,所述第三信息是用于指示所述报文的转发的信息;
    第一确定模块,设置为确定由所述第一信息和所述第二信息组成的第一关键字,以及与所述第一关键字对应的第一流表编号;
    第二确定模块,设置为确定由所述第一关键字和所述第一流表编号组成的待匹配项的哈希值;
    匹配模块,设置为根据所述哈希值在目标流表中查找与所述待匹配项匹配的第一表项。
  9. 根据权利要求8所述的装置,其中,所述选择模块,还设置为:
    解析所述报文得到所述报文头信息,并根据所述报文确定所述第三信息;
    将所述报文头信息存储到第一存储位置,以及将所述第三信息存储到第二存储位置;
    根据所述指示信息,从所述第一存储位置中获取所述第一信息,以及从所述第二存储位置中获取所述第二信息。
  10. 根据权利要求8所述的装置,其中,所述第三信息包括以下至少之一:所述报文的入端口,所述报文所属的虚拟路由转发实例以及三层接口。
  11. 根据权利要求9所述的装置,其中,所述选择模块,还设置为:
    根据所述指示信息确定所述第一信息的第一宽度以及所述第二信息的第二宽度;
    确定所述第一信息在所述第一存储位置中的第一目标位置,以及所述第二信息在所述第二存储位置中的第二目标位置;
    在所述第一目标位置处使用第一选择器获取所述第一信息,以及在所述第二目标位置处使用第二选择器获取所述第二信息,其中,所述第一选择器的宽度为所述第一宽度,所述第二选择器的宽度为所述第二宽度。
  12. 根据权利要求8所述的装置,其中,所述装置还包括第三确定模块,设置为:根据所述指示信息确定内存的存储策略,其中,所 述存储策略包括以下之一:
    将所述内存的存储空间划分为多个存储单元,在所述内存中存储第一宽度的多个第二表项,其中,所述第一宽度为所述待匹配项的宽度,所述第二表项包括所述第一表项,每个所述第二表项在所述存储空间中占用一个所述存储单元;
    将所述内存的存储空间划分为所述多个存储单元,在所述内存中使用第一数量的存储单元存储所述第一宽度的表项,以及使用第二数量的存储单元存储第二宽度的第二表项,其中,所述第二宽度与所述第一宽度不同。
  13. 根据权利要求8所述的装置,其中,所述匹配模块还设置为:
    在所述目标流表中查找与所述哈希值匹配的第三表项;
    将所述待匹配表项中的所述第一关键字、所述第一流表编号与所述第三表项中的第二关键字和第二流表编号进行比较;
    在所述第一关键字与所述第二关键字相同以及所述第一流表编号与所述第二流表编号相同的情况下,确定所述第三表项为所述第一表项。
  14. 根据权利要求8所述的装置,其中,所述装置还包括处理模块,设置为:
    根据所述第一表项中的动作转发所述报文;
    获取所述报文的出端口,并将所述出端口添加到所述第三信息中。
PCT/CN2020/120429 2019-12-31 2020-10-12 流表的匹配方法及装置 WO2021135491A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911419921.0A CN111131050A (zh) 2019-12-31 2019-12-31 流表的匹配方法及装置
CN201911419921.0 2019-12-31

Publications (1)

Publication Number Publication Date
WO2021135491A1 true WO2021135491A1 (zh) 2021-07-08

Family

ID=70507254

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/120429 WO2021135491A1 (zh) 2019-12-31 2020-10-12 流表的匹配方法及装置

Country Status (2)

Country Link
CN (1) CN111131050A (zh)
WO (1) WO2021135491A1 (zh)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111131050A (zh) * 2019-12-31 2020-05-08 盛科网络(苏州)有限公司 流表的匹配方法及装置
CN111865812B (zh) * 2020-07-06 2023-04-07 北京合众方达科技有限公司 一种分布式网络中sdn支撑高性能业务混传的方法
CN111953609B (zh) * 2020-08-07 2022-10-11 平安科技(深圳)有限公司 基于ovs的数据包处理方法及相关设备
CN114448891B (zh) * 2022-01-26 2024-01-02 深圳星云智联科技有限公司 流表同步方法、装置、设备和介质
CN117640513A (zh) * 2022-08-15 2024-03-01 华为技术有限公司 一种数据处理方法、装置和系统

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150304212A1 (en) * 2012-12-28 2015-10-22 Huawei Technologies Co., Ltd. Method and apparatus for matching flow table, and switch
CN107682266A (zh) * 2017-09-12 2018-02-09 杭州迪普科技股份有限公司 流表项的匹配方法及装置、计算机可读存储介质
CN109600313A (zh) * 2017-09-30 2019-04-09 迈普通信技术股份有限公司 报文转发方法及装置
CN110324245A (zh) * 2018-03-31 2019-10-11 华为技术有限公司 一种基于集成流表转发报文的方法及装置
CN111131050A (zh) * 2019-12-31 2020-05-08 盛科网络(苏州)有限公司 流表的匹配方法及装置

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8711860B2 (en) * 2011-12-22 2014-04-29 Telefonaktiebolaget L M Ericsson (Publ) Controller for flexible and extensible flow processing in software-defined networks
US8718064B2 (en) * 2011-12-22 2014-05-06 Telefonaktiebolaget L M Ericsson (Publ) Forwarding element for flexible and extensible flow processing software-defined networks
US9363178B2 (en) * 2013-12-18 2016-06-07 Telefonaktiebolaget L M Ericsson (Publ) Method, apparatus, and system for supporting flexible lookup keys in software-defined networks
KR101886291B1 (ko) * 2014-06-30 2018-09-06 후아웨이 테크놀러지 컴퍼니 리미티드 흐름 엔트리 구성 방법, 장치, 및 시스템
CN104168203A (zh) * 2014-09-03 2014-11-26 上海斐讯数据通信技术有限公司 一种基于流表的处理方法及系统
US9917769B2 (en) * 2014-11-17 2018-03-13 Telefonaktiebolaget Lm Ericsson (Publ) Method and system for virtualizing flow tables in a software-defined networking (SDN) system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150304212A1 (en) * 2012-12-28 2015-10-22 Huawei Technologies Co., Ltd. Method and apparatus for matching flow table, and switch
CN107682266A (zh) * 2017-09-12 2018-02-09 杭州迪普科技股份有限公司 流表项的匹配方法及装置、计算机可读存储介质
CN109600313A (zh) * 2017-09-30 2019-04-09 迈普通信技术股份有限公司 报文转发方法及装置
CN110324245A (zh) * 2018-03-31 2019-10-11 华为技术有限公司 一种基于集成流表转发报文的方法及装置
CN111131050A (zh) * 2019-12-31 2020-05-08 盛科网络(苏州)有限公司 流表的匹配方法及装置

Also Published As

Publication number Publication date
CN111131050A (zh) 2020-05-08

Similar Documents

Publication Publication Date Title
US11102120B2 (en) Storing keys with variable sizes in a multi-bank database
WO2021135491A1 (zh) 流表的匹配方法及装置
US10389633B2 (en) Hash-based address matching
US7313667B1 (en) Methods and apparatus for mapping fields of entries into new values and combining these mapped values into mapped entries for use in lookup operations such as for packet processing
US9794263B2 (en) Technologies for access control
CN111937360B (zh) 最长前缀匹配
US20030225881A1 (en) Efficient cascaded lookups at a network node
CN112425131B (zh) 一种acl的规则分类方法、查找方法和装置
US8923298B2 (en) Optimized trie-based address lookup
EP3292659B1 (en) Multicast data packet forwarding
CN107547407B (zh) 报文传输方法、装置和实现装置
US20090282167A1 (en) Method and apparatus for bridging
US20180107759A1 (en) Flow classification method and device and storage medium
US20060248095A1 (en) Efficient RAM lookups by means of compressed keys
WO2021104393A1 (zh) 多规则流分类的实现方法、设备和存储介质
US20060233173A1 (en) Policy-based processing of packets
EP2953302B1 (en) Service packet processing method, apparatus and system
CN112929281B (zh) 基于fpga的网络设备的报文处理方法、装置及设备
US10193804B2 (en) Method of forwarding data packets, method of creating merged FIB key entry and method of creating a search key
US12132653B2 (en) Method and device for processing routing table entries
WO2014201902A1 (zh) 基于tcam的查表处理方法及装置
US20230367720A1 (en) Data search method and apparatus, and integrated circuit
US7551609B2 (en) Data structure for storing and accessing multiple independent sets of forwarding information
US9088476B2 (en) Network communication system with packet forwarding and method of operation thereof
US7773590B2 (en) Combined interface and non-interface specific associative memory lookup operations for processing of packets

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20909379

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20909379

Country of ref document: EP

Kind code of ref document: A1