Message statistical method, switch chip and switch
By maintaining a configuration table and a logical judgment module in the switching chip, the problems of flexibility and resource waste in the switching chip packet statistics scheme are solved, enabling flexible and precise packet statistics under complex conditions, and improving network monitoring and analysis efficiency.
Patent Information
- Application Number
- CN202511398564.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-28
- Publication Date
- 2025-11-28
AI Technical Summary
Existing switching chip message statistics schemes suffer from problems such as limited statistical dimensions, poor flexibility, serious waste of hardware resources, and inability to support complex combination of conditions for statistics.
By maintaining a configuration table in the switching chip, the lookup module obtains the condition index and target storage location, the logic judgment module determines whether the actual data meets the statistical conditions, and the counting module updates the counter when the conditions are met, thus achieving flexible and precise message statistics.
Without wasting ACL resources, it achieves more flexible, granular, and complex condition matching capabilities for packet statistics, thereby improving the efficiency of network monitoring and analysis.
Smart Images

Figure CN121037299A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of communication, in particular to a message statistics method, a switching chip and a switch. BACKGROUND
[0002] With the continuous expansion of the scale of data center networks, enterprise networks and operator networks and the increasing complexity of services, network traffic monitoring and statistics functions become crucial. Accurate message quantity statistics (Stats) is the basis for realizing network performance monitoring, fault diagnosis, traffic engineering, billing and security analysis.
[0003] Most existing switching chips support basic Stats functions, and the mainstream implementation mechanism thereof relies on inherent hardware entries in the switching chip, mainly the statistics entries in the forwarding table or the ACL (Access Control List) table. An index pointer exists in each statistics entry to indicate the address of the corresponding hardware counter, such as Figure 1 When a message hits a certain statistics entry, the chip automatically increments the counter value pointed to by the index pointer in the statistics entry. For example, in the forwarding table, each egress port is associated with a counter for counting the number of all messages or bytes forwarded by the port; in the ACL table, a counter can be configured for a policy rule to count the number of all messages matching the rule.
[0004] However, the existing statistics scheme has significant limitations: (1) Single statistics dimension, poor flexibility: the existing statistics function is strongly coupled with fixed hardware entries. The dimension of the forwarding table statistics is naturally limited to port, VLAN, destination MAC address or IP network segment, and other forwarding logic related elements. If finer granularity or different dimension statistics (for example, statistics of traffic of a specific TCP port, statistics of traffic of a specific source IP) are to be implemented, the ACL table must be relied on. Although the ACL table can define the statistics condition by configuring the matching rule, it is essentially still a simple "match-count" pipeline. Each statistics must occupy a complete ACL entry, resulting in that the statistics dimension is fixed after configuration and cannot dynamically adjust the statistics object or condition.
[0005] (2) Hardware resource limitation and waste: ACL is a valuable hardware resource in the switching chip, and its entry space is usually very limited. Using a large number of ACL entries for traffic statistics instead of core security policies or QoS policies can easily affect the deployment of security policies of the network device. In addition, to implement a complex statistics target (such as respectively counting voice traffic of different priorities), multiple ACL rules need to be configured, which causes inefficient use and waste of resources.
[0006] (3) Unable to support complex conditional combination statistics: the existing scheme is difficult to efficiently support the statistical scenarios of complex logical judgment on multiple fields of the packet. For example, the user wants to count the packets with TTL value greater than 200 or less than 50, or the abnormal traffic with source IP belonging to a certain range and destination port not being 80. To realize such needs, the only method at present is to configure multiple ACL rules for combination, which not only consumes a large amount of resources, but also is extremely cumbersome to manage, and even becomes infeasible due to the hard limit of the number of ACL entries. Such inflexibility makes many advanced monitoring and analysis scenarios unable to be directly and efficiently implemented in the data plane. SUMMARY
[0007] The purpose of the present application is to provide a packet statistical method, a switching chip and a switch to improve the problems existing in the prior art.
[0008] Embodiments of the present application can be implemented as follows: In a first aspect, the present application provides a packet statistical method applied to a switching chip in a switch, wherein the switching chip maintains a configuration table, and the configuration table includes at least one configuration table entry corresponding to a statistical condition; the switching chip includes a table lookup module, a logical judgment module and a counting module; and the method includes: The table lookup module acquires a condition index and a target storage location from a statistical entry in the ACL table or the forwarding table when the packet information of a current packet matches the statistical entry; The table lookup module determines a target configuration table entry matching the condition index from the configuration table; the target configuration table entry includes a statistical object and control data; The table lookup module acquires actual data corresponding to the statistical object from the packet information; The logical judgment module judges whether the actual data satisfies the statistical condition corresponding to the condition index under the drive of the control data, and outputs a statistical signal; The counting module updates a packet counter of the target storage location when the statistical signal is true.
[0009] In an optional implementation, the logical judgment module includes a first comparison unit, a second comparison unit and an output unit connected to both of them; The statistical object includes a first field and a second field; the actual data includes a first actual value corresponding to the first field and a second actual value corresponding to the second field; the target configuration table entry further includes a first threshold value and a second threshold value, the control data includes a first control data, a second control data and an output control signal; and the statistical condition includes a first condition and a second condition. The logic judging module judges whether the actual data satisfies the statistical condition corresponding to the condition index under the driving of the control data, and outputs a statistical signal, including: The first comparison unit judges whether the first actual value and the first threshold value satisfy the first condition under the driving of the first control data, and obtains a first comparison signal; The second comparison unit judges whether the second actual value and the second threshold value satisfy the second condition under the driving of the second control data, and obtains a second comparison signal; The output unit determines the statistical signal based on the first comparison signal and the second comparison signal under the driving of the output control signal.
[0010] In an optional embodiment, the first control data includes a first control signal, a second control signal and a first selection signal; and the first comparison unit includes a first comparator, a first NOT gate, a first selector, a second selector and a first selection unit. The first comparison unit judges whether the first actual value and the first threshold value satisfy the first condition under the driving of the first control data, and obtains a first comparison signal, including: The first comparator outputs a first signal, a second signal and a third signal based on the first actual value and the first threshold value; the first signal being true represents that the first actual value is less than the first threshold value, the second signal being true represents that the first actual value is greater than the first threshold value, and the third signal being true represents that the first actual value is equal to the first threshold value; The first NOT gate performs a logical NOT operation on the third signal to obtain a fourth signal; the fourth signal being true represents that the first actual value is not equal to the first threshold value; The first selector directly outputs the first signal when the first control signal is 0, or directly outputs the second signal when the first control signal is 1; The second selector directly outputs the third signal when the second control signal is 0, or directly outputs the fourth signal when the second control signal is 1; The first selection unit determines the first comparison signal based on the signal output by the first selector and the signal output by the second selector under the driving of the first selection signal; the first comparison signal being true represents that the first actual value and the first threshold value satisfy the first condition, and the first comparison signal being false represents that the first actual value and the first threshold value do not satisfy the first condition.
[0011] In an optional embodiment, the first selection unit includes a first OR gate and a third selector. The first selection unit determines the first comparison signal based on the signal output by the first selector and the signal output by the second selector under the driving of the first selection signal, and the step includes: The first OR gate performs a logical OR operation on the signal output by the first selector and the signal output by the second selector to obtain a first OR operation signal. The third selector directly outputs the signal output by the first selector as the first comparison signal to the output unit when the first selection signal is 00, directly outputs the first OR operation signal as the first comparison signal to the output unit when the first selection signal is 01, or directly outputs the signal output by the second selector as the first comparison signal to the output unit when the first selection signal is 10.
[0012] In an optional implementation, the second control data includes a third control signal, a fourth control signal, and a second selection signal; and the second comparison unit includes a second comparator, a second NOT gate, a fourth selector, a fifth selector, and a second selection unit. The second comparison unit determines whether the second actual value and the second threshold value satisfy the second condition under the driving of the second control data to obtain a second comparison signal, and the step includes: The second comparator outputs a fifth signal, a sixth signal, and a seventh signal based on the second actual value and the second threshold value; the fifth signal being true represents that the second actual value is less than the second threshold value, the sixth signal being true represents that the second actual value is greater than the second threshold value, and the seventh signal being true represents that the second actual value is equal to the second threshold value. The second NOT gate performs a logical NOT operation on the seventh signal to obtain an eighth signal; the eighth signal being true represents that the second actual value is not equal to the second threshold value. The fourth selector directly outputs the fifth signal when the third control signal is 0, or directly outputs the sixth signal when the third control signal is 1. The fifth selector directly outputs the seventh signal when the fourth control signal is 0, or directly outputs the eighth signal when the fourth control signal is 1. The second selection unit determines the second comparison signal based on the signal output by the fourth selector and the signal output by the fifth selector under the driving of the second selection signal; the second comparison signal being true represents that the second actual value and the second threshold value satisfy the second condition, and the second comparison signal being false represents that the second actual value and the second threshold value do not satisfy the second condition.
[0013] In an optional embodiment, the second selection unit comprises a second OR gate and a sixth selector; The step of determining the second comparison signal based on the signal output by the fourth selector and the signal output by the fifth selector under the driving of the second selection signal comprises: The second OR gate performs logical OR operation on the signal output by the fourth selector and the signal output by the fifth selector to obtain a second OR operation signal; The sixth selector directly outputs the signal output by the fourth selector as the second comparison signal to the output unit when the second selection signal is 00; or directly outputs the second OR operation signal as the second comparison signal to the output unit when the second selection signal is 01; or directly outputs the signal output by the fifth selector as the second comparison signal to the output unit when the second selection signal is 10.
[0014] In an optional embodiment, the output unit comprises a third OR gate, an AND gate and a seventh selector; The step of determining the statistical signal based on the first comparison signal and the second comparison signal under the driving of the output control signal comprises: The third OR gate performs logical OR operation on the first comparison signal and the second comparison signal to obtain a third OR operation signal; The AND gate performs logical AND operation on the first comparison signal and the second comparison signal to obtain an AND operation signal; The seventh selector directly outputs the third OR operation signal as the statistical signal when the output control signal is 0; or directly outputs the AND operation signal as the statistical signal when the output control signal is 1.
[0015] In a second aspect, the present application provides a switching chip, wherein the switching chip maintains a configuration table, and the configuration table comprises at least one configuration table entry corresponding to a statistical condition; the switching chip comprises a lookup table module, a logical judgment module and a counting module; The lookup table module is configured to acquire a condition index and a target storage location from a statistical entry in an ACL table or a forwarding table when the message information of a current message matches the statistical entry; The lookup table module is further configured to determine a target configuration table entry matching the condition index from the configuration table; the target configuration table entry comprises a statistical object and control data; The lookup table module is further configured to acquire actual data corresponding to the statistical object from the message information; The logic judging module is configured to judge whether the actual data satisfies the statistical condition corresponding to the condition index under the driving of the control data, and output a statistical signal; The counting module is configured to update the packet counter of the target storage location when the statistical signal is true.
[0016] In an optional implementation, the statistical object includes a first field and a second field; the actual data includes a first actual value corresponding to the first field and a second actual value corresponding to the second field; the target configuration entry further includes a first threshold value and a second threshold value, the control data includes first control data, second control data and an output control signal; the statistical condition includes a first condition and a second condition; The logic judging module includes a first comparison unit, a second comparison unit and an output unit connected with both of them; wherein: The first comparison unit is configured to judge whether the first actual value and the first threshold value satisfy the first condition under the driving of the first control data, and obtain a first comparison signal; The second comparison unit is configured to judge whether the second actual value and the second threshold value satisfy the second condition under the driving of the second control data, and obtain a second comparison signal; The output unit is configured to determine the statistical signal based on the first comparison signal and the second comparison signal under the driving of the output control signal.
[0017] In a third aspect, the present application provides a switch, including the switch chip as described in the second aspect.
[0018] Compared with the prior art, the embodiment of the present application provides a packet statistical method, a switching chip and a switch. The switching chip maintains a configuration table, and the configuration table includes at least one configuration table item corresponding to a statistical condition. The switching chip includes a table lookup module, a logical judgment module and a counting module. The method is as follows: the table lookup module obtains a condition index and a target storage location from a statistical entry when the packet information of a current packet is looked up in the ACL table or the statistical entry in the forwarding table; the table lookup module determines a target configuration table item matched with the condition index from the configuration table; the target configuration table item includes a statistical object and control data; the table lookup module obtains actual data corresponding to the statistical object from the packet information; the logical judgment module judges whether the actual data satisfies the statistical condition corresponding to the condition index under the driving of the control data, and outputs a statistical signal; and the counting module updates the packet counter of the target storage location when the statistical signal is true. The configuration table item of the statistical condition is recorded by the configuration table, and whether the actual data corresponding to the statistical object satisfies the statistical condition is judged by the logical judgment module. Thus, the packet statistical capability of more flexibility, more fineness and supporting complex condition matching can be realized without wasting a large number of ACL resources. BRIEF DESCRIPTION OF DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some of the embodiments of the present application, and therefore should not be regarded as a limitation to the scope. For those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.
[0020] Figure 1 A schematic diagram of the packet statistical process of the prior art.
[0021] Figure 2 A schematic diagram of the flow of the packet statistical method provided by the embodiment of the present application.
[0022] Figure 3 A schematic diagram of the structure of the logical judgment module provided by the embodiment of the present application.
[0023] Figure 4 A schematic diagram of the structure of the logical judgment module provided by the embodiment of the present application.
[0024] Icon: 100 - first comparison unit; 110 - first comparator; 120 - first NOT gate; 130 - first selector; 140 - second selector; 150 - first selection unit; 151 - first OR gate; 152 - third selector; 200 - second comparison unit; 210 - second comparator; 220 - second NOT gate; 230 - fourth selector; 240 - fifth selector; 250 - second selection unit; 251 - second OR gate; 252 - sixth selector; 300 - output unit; 310 - third OR gate; 320 - AND gate; 330 - seventh selector. DETAILED DESCRIPTION
[0025] In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings can be arranged and designed in various different configurations.
[0026] Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative labor are within the scope of protection of the present application.
[0027] It should be noted that: similar reference numerals and letters represent similar items in the following drawings, therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.
[0028] In addition, if the terms "first", "second" and the like are used, they are only used to distinguish descriptions, and cannot be understood as indicating or implying relative importance.
[0029] It should be noted that: the features in the embodiments of the present application can be combined with each other without conflict.
[0030] Here, first, the key words or key terms related to the present application are introduced: 1. Stats (Statistics) function, that is, statistical function, is a mechanism in network devices (such as switches, routers, chips, etc.) for traffic statistics of specific data packets. It helps network administrators understand the distribution of various traffic in the network, performance indicators, abnormal behavior, etc. by counting or byte number accumulation of data packets hitting specific rules (such as ACL rules or forwarding table entries), which is an important basis for implementing network monitoring, traffic analysis, QoS management, security policy, etc. advanced functions.
[0031] 2. Entry refers to an entry. In this invention, Entry usually refers to an ACL Entry or a Forwarding Entry.
[0032] The packet statistics method provided in this embodiment of the invention can be applied to the switching chip in a switch. The switching chip maintains a configuration table, which includes at least one configuration table entry corresponding to a statistical condition. Each configuration table entry is uniquely identified by a condition index, and the content of the configuration table entry includes the statistical object of a statistical condition, threshold data, and control data.
[0033] Please refer to Figure 2 , Figure 2 This is a flowchart illustrating a message statistics method provided in an embodiment of the present invention. The switching chip includes a table lookup module, a logic judgment module, and a counting module. The method includes the following steps S100~S500: S100: When the message information of the current message matches the statistical entries in the ACL table or forwarding table, the table lookup module obtains the condition index and target storage location from the statistical entries.
[0034] It's understandable that when a switch receives a packet, the switching chip's parsing engine parses the packet to obtain packet information (such as the packet header data). Then, the lookup engine can perform table lookups (routing table, forwarding table, etc.) based on the packet information, while the ACL engine can perform ACL matching based on the packet information. Therefore, the statistical entries matched by the packet information in the ACL table or forwarding table can be ACL entries or forwarding table entries with the stats function enabled.
[0035] For example, when the matched statistical entry is an ACL entry, the index field in the ACL entry is the condition index corresponding to a statistical condition, the address field (StatsPtr field) reflects the target storage address (the target storage address may include an address pointer and an address offset), and the action field is permit and count or refuse and count.
[0036] S200, The table lookup module determines the target configuration table entry that matches the condition index from the configuration table.
[0037] S400, the table lookup module retrieves the actual data corresponding to the statistical object from the message information.
[0038] S400, the logic judgment module, driven by the control data, judges whether the actual data meets the statistical conditions corresponding to the condition index and outputs statistical signals.
[0039] In the embodiment, if the statistical signal is true, it means that the actual data corresponding to the statistical object satisfies the statistical condition corresponding to the target configuration table item; if the statistical signal is false, it means that the actual data corresponding to the statistical object does not satisfy the statistical condition corresponding to the target configuration table item.
[0040] S500, the counting module updates the packet counter of the target storage location when the statistical signal is true.
[0041] In the embodiment, the packet counter of the target storage location is updated only when the statistical signal is true.
[0042] The packet statistical method provided by the embodiment records the configuration table items of a plurality of complex statistical conditions through a configuration table, and judges whether the actual data corresponding to the statistical object satisfies the statistical condition through a logical judgment module, so that complex condition statistics can be realized without wasting a large number of ACL resources.
[0043] Optionally, the statistical object includes a first field and a second field; the actual data includes a first actual value corresponding to the first field and a second actual value corresponding to the second field; the threshold data in the target configuration table item can include a first threshold and a second threshold, and the control data includes a first control data, a second control data and an output control signal.
[0044] The statistical condition can be divided into a first condition corresponding to the first field and a second condition corresponding to the second field, and the first condition and the second condition need to be satisfied at the same time or only one of them is satisfied. The first field and the second field can be the same or different, and the statistical object of the application can involve but is not limited to the following fields in the packet information: (1) Packet TTL field: packet survival time; (2) Discard Type field: indicating the type of the discarded data packet; (3) Packet Length field: indicating the length of the data packet (usually in bytes).
[0045] (4) Source Lport field: indicating the source port number (may be a load balancing or forwarding related port); (5) Color field: used for marking or classifying data packets (for example, 0, 1, 2, 3, etc. are used to represent different QoS priorities or security levels, etc.); (6) Drop Reason field: indicating the specific reason for discarding the data packet; (7) Destination field: target address; (8) Fid field: flow identifier, used for uniquely identifying a data flow.
[0046] For example, the application can determine whether the packet satisfies the complex conditions of TTL∈[100, 200] or TTL<50 and Color=0 based on the logical judgment module without relying on the ACL resource. Taking the statistical condition of TTL∈[100, 200] as an example, the first condition is TTL≥100 and the second condition is TTL≤200, and both conditions need to be satisfied.
[0047] Please refer to Figure 3 The logical judgment module can include a first comparison unit 100, a second comparison unit 200, and an output unit 300 connected with both. Figure 3 The red word in the figure indicates the input data, and the blue word indicates the output. Therefore, in combination with Figure 3 The implementation of the above step S400 can include S410-S430. S410, the first comparison unit 100 determines whether the first actual value and the first threshold value satisfy the first condition under the driving of the first control data, and obtains a first comparison signal; S420, the second comparison unit 200 determines whether the second actual value and the second threshold value satisfy the second condition under the driving of the second control data, and obtains a second comparison signal; S430, the output unit 300 determines a statistical signal based on the first comparison signal and the second comparison signal under the driving of the output control signal.
[0048] Optionally, the first control data includes a first control signal, a second control signal, and a first selection signal; and the second control data includes a third control signal, a fourth control signal, and a second selection signal. Therefore, assuming that the first actual value and the second actual value are represented by A and C respectively, and the first threshold value and the second threshold value are represented by C and D respectively, the English names and explanations of the fields in the configuration table are as follows: 1, condition index: used to uniquely identify a statistical condition; 2, first field and second field: representing the key packet fields involved in the first condition and the second condition respectively; 3, first threshold value and second threshold value: representing the comparison threshold values involved in the first condition and the second condition respectively; 4, first control signal: 0 represents the judgment result of A<B, and 1 represents the judgment result of A>B; 5, second control signal: 0 represents the judgment result of A=B, and 1 represents the judgment result of A≠B; 6, first selection signal: in combination with the first / second control signal, the first selection signal can reflect the specific expression of the first condition, and the value of the first selection signal can be: 00 represents the first condition is AB; 01 represents the first condition is A≤B or A≥B, 10 represents the first condition is A=B or A≠B; 7. The third control signal: 0 represents the output of the judgment result of C 8. The fourth control signal: 0 represents the output of the judgment result of C 9. The second selection signal: in combination with the third / fourth control signal, the second condition can be reflected by the specific expression, and the value of the second selection signal can be: 00 represents that the first condition is C 10. The output control signal: reflecting the satisfaction relationship of the first condition and the second condition, 0 represents that the first condition and the second condition satisfy one, and 1 represents that the first condition and the second condition need to be satisfied at the same time.
[0049] Based on the above, the signal configuration required by the actual value and the threshold value in the six condition judgment cases is shown in Table 1.
[0050] Table 1 Signal configuration required in six condition judgment cases
[0051] The logic judgment module of the present application is a logic circuit driven by control data in a configuration table. Based on the above, the structure and working principle of each part of the logic judgment module will be introduced below. Figure 3 Figure 4
[0052] In an alternative implementation, please refer to Figure 4 , the first comparison unit 100 includes a first comparator 110, a first NOT gate 120, a first selector 130, a second selector 140, and a first selection unit 150. That is, the implementation process of the above step S410 can include S411~S415.
[0053] S411, the first comparator 110 outputs a first signal, a second signal and a third signal based on the first actual value and the first threshold value.
[0054] S412, the first NOT gate 120 performs logical NOT operation on the third signal to obtain a fourth signal.
[0055] Among them, the first signal is true (i.e. y1=1 in Figure 4 ) represents that the first actual value is less than the first threshold value, the second signal is true (i.e. y2=1 in Figure 4 ) represents that the first actual value is greater than the first threshold value, and the third signal is true (i.e. y3=1 in Figure 4 ) represents that the first actual value is equal to the first threshold value; the fourth signal is true (i.e. y4=1 in Figure 4 y4=1) represents that the first actual value is not equal to the first threshold value.
[0056] S413, the first selector 130 directly outputs the first signal when the first control signal is 0, or directly outputs the second signal when the first control signal is 1.
[0057] S414, the second selector 140 directly outputs the third signal when the second control signal is 0, or directly outputs the fourth signal when the second control signal is 1.
[0058] S415, the first selection unit 150 determines the first comparison signal based on the signal output by the first selector 130 and the signal output by the second selector 140 under the driving of the first selection signal.
[0059] Wherein, the first comparison signal is true (i.e. Figure 4 r1=1) reflects that the first actual value and the first threshold value satisfy the first condition, and the first comparison signal is false (i.e. Figure 4 r1=0) reflects that the first actual value and the first threshold value do not satisfy the first condition.
[0060] In an optional implementation, please continue to refer to Figure 4 , the first selection unit 150 includes a first OR gate 151 and a third selector 152. That is, the implementation of step S415 can include S4151~ S4152: S4151, the first OR gate 151 performs logical OR operation on the signal output by the first selector 130 and the signal output by the second selector 140 to obtain a first OR operation signal; S4152, the third selector 152 directly outputs the signal output by the first selector 130 as the first comparison signal to the output unit 300 when the first selection signal is 00, or directly outputs the first OR operation signal as the first comparison signal to the output unit 300 when the first selection signal is 01, or directly outputs the signal output by the second selector 140 as the first comparison signal to the output unit 300 when the first selection signal is 10.
[0061] As Figure 4 , when the first selection signal is 00, the first comparison signal r1= the signal x1 output by the first selector 130; when the first selection signal is 01, the first comparison signal r1= the first OR operation signal m1; when the first selection signal is 10, the first comparison signal r1= the signal x2 output by the second selector 140.
[0062] In an optional implementation, please continue to refer to Figure 4The second comparison unit 200 includes a second comparator 210, a second NOT gate 220, a fourth selector 230, a fifth selector 240, and a second selection unit 250. That is, the implementation of the step S420 can include S421-S425.
[0063] S421, the second comparator 210 outputs a fifth signal, a sixth signal, and a seventh signal based on the second actual value and a second threshold value.
[0064] S422, the second NOT gate 220 performs a logical NOT operation on the seventh signal to obtain an eighth signal.
[0065] Wherein, the fifth signal is true (i.e. y5=1 in the above formula) represents that the second actual value is less than the second threshold value, the sixth signal is true (i.e. y6=1 in the above formula) represents that the second actual value is greater than the second threshold value, and the seventh signal is true (i.e. y7=1 in the above formula) represents that the second actual value is equal to the second threshold value. Figure 4 Figure 4 Figure 4 Figure 4
[0066] S423, the fourth selector 230 directly outputs the fifth signal when the third control signal is 0, or directly outputs the sixth signal when the third control signal is 1.
[0067] S424, the fifth selector 240 directly outputs the seventh signal when the fourth control signal is 0, or directly outputs the eighth signal when the fourth control signal is 1.
[0068] S425, the second selection unit 250 determines a second comparison signal based on the signal output by the fourth selector 230 and the signal output by the fifth selector 240 under the driving of a second selection signal.
[0069] Wherein, the second comparison signal is true (i.e. r2=1 in the above formula) represents that the second actual value and the second threshold value satisfy the second condition, and the second comparison signal is false (i.e. r2=0 in the above formula) represents that the second actual value and the second threshold value do not satisfy the second condition. Figure 4 Figure 4
[0070] In an optional implementation, please continue to refer to Figure 4 The second selection unit 250 includes a second OR gate 251 and a sixth selector 252. That is, the implementation of the step S425 can include S4251-S4252: S4251, the second OR gate 251 performs a logical OR operation on the signal output by the fourth selector 230 and the signal output by the fifth selector 240 to obtain a second OR operation signal; S4252、the sixth selector 252 directly outputs the signal output by the fourth selector 230 as the second comparison signal to the output unit 300 when the second selection signal is 00; or directly outputs the second or operation signal as the second comparison signal to the output unit 300 when the second selection signal is 01; or directly outputs the signal output by the fifth selector 240 as the second comparison signal to the output unit 300 when the second selection signal is 10.
[0071] As Figure 4 When the second selection signal is 00, the second comparison signal r2 = the signal x3 output by the third selector 152; when the second selection signal is 01, the second comparison signal r2 = the second or operation signal m2; when the first selection signal is 10, the second comparison signal r2 = the signal x4 output by the fourth selector 230.
[0072] In an alternative implementation, please continue to refer to Figure 4 The output unit 300 includes a third or gate 310, an and gate 320, and a seventh selector 330. That is, the implementation of the above step S430 can include S431-S433.
[0073] S431, the third or gate 310 performs a logical or operation on the first comparison signal and the second comparison signal to obtain a third or operation signal; S432, the and gate 320 performs a logical and operation on the first comparison signal and the second comparison signal to obtain an and operation signal; S433, the seventh selector 330 directly outputs the third or operation signal as the statistical signal when the output control signal is 0; or directly outputs the and operation signal as the statistical signal when the output control signal is 1.
[0074] In this embodiment, as Figure 4 When the output control signal is 0, the statistical signal s = the third or operation signal n1; when the output control signal is 1, the statistical signal s = the and operation signal n2.
[0075] In combination It can be seen that the first selector 130, the second selector 140, the fourth selector 230, the fifth selector 240, and the seventh selector 330 in the logic judgment module can adopt a 2-to-1 selector, and the third selector 152 and the fourth selector 230 can adopt a 3-to-1 selector or a 4-to-1 selector.
[0076] Therefore, to realize the complex statistical condition judgment for 1 key field or 2 key fields, only the configuration personnel writes the control data corresponding to the statistical condition into the configuration table based on the above table 1, and the present application obtains the target configuration table item in the configuration table pointed by the condition index in the statistical entry after the current packet hits the statistical entry, and finally The logic circuit shown can judge whether the key field in the current packet satisfies the statistical condition under the driving of the control data in the target configuration table item, and the packet counter is updated only when the statistical condition is satisfied, and the packet counter is not updated when the statistical condition is not satisfied.
[0077] Based on the same inventive concept as the above packet statistical method, the embodiment of the present application further provides a switch chip, which maintains a configuration table including at least one configuration table item corresponding to a statistical condition; the switch chip includes a table lookup module, a logic judgment module and a counting module; The table lookup module is used to obtain the condition index and the target storage location from the statistical entry when the packet information of the current packet and the statistical entry in the ACL table or the forwarding table; The table lookup module is further used to determine the target configuration table item matched with the condition index from the configuration table; the target configuration table item includes a statistical object and control data; The table lookup module is further used to obtain the actual data corresponding to the statistical object from the packet information; The logic judgment module is used to judge whether the actual data satisfies the statistical condition corresponding to the condition index under the driving of the control data, and outputs a statistical signal; The counting module is used to update the packet counter of the target storage location when the statistical signal is true.
[0078] It should be noted that the structure and working principle of the logic judgment module in the switch chip are consistent with the content described in the above packet statistical method, and will not be repeated here.
[0079] The embodiment of the present application further provides a switch including the above provided switch chip.
[0080] In summary, the embodiment of the present application provides a packet statistics method, a switching chip and a switch. The switching chip maintains a configuration table, and the configuration table includes at least one configuration table item corresponding to a statistics condition. The switching chip includes a table lookup module, a logical judgment module and a counting module. The method is as follows: the table lookup module obtains a condition index and a target storage location from a statistics entry when the packet information of a current packet is looked up in the ACL table or the forwarding table; the table lookup module determines a target configuration table item matched with the condition index from the configuration table; the target configuration table item includes a statistics object and control data; the table lookup module obtains actual data corresponding to the statistics object from the packet information; the logical judgment module judges whether the actual data satisfies the statistics condition corresponding to the condition index under the drive of the control data, and outputs a statistics signal; and the counting module updates the packet counter of the target storage location when the statistics signal is true. The configuration table item of the statistics condition is recorded by the configuration table, and whether the actual data corresponding to the statistics object satisfies the statistics condition is judged by the logical judgment module. Thus, the complex condition statistics can be realized without wasting a large number of ACL resources.
[0081] The above merely describes the specific embodiments of the present application, but the protection scope of the present application is not limited to this. Any changes or replacements within the technical range disclosed by the present application can be easily thought by those skilled in the art, and should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A message statistics method, characterized in that, A switching chip used in a switch, the switching chip maintaining a configuration table, the configuration table including at least one configuration table entry corresponding to a statistical condition; the switching chip includes a table lookup module, a logical judgment module, and a counting module; the method includes: When the message information of the current message matches the statistical entries in the ACL table or forwarding table, the table lookup module obtains the condition index and target storage location from the statistical entries. The table lookup module determines the target configuration table entry that matches the condition index from the configuration table; the target configuration table entry includes statistical objects and control data. The table lookup module obtains the actual data corresponding to the statistical object from the message information; The logic judgment module, driven by the control data, determines whether the actual data meets the statistical conditions corresponding to the condition index and outputs a statistical signal. The counting module updates the message counter at the target storage location when the statistical signal is true.
2. The message statistics method according to claim 1, characterized in that, The logic judgment module includes a first comparison unit, a second comparison unit, and an output unit connected to both of them; The statistical object includes a first field and a second field; the actual data includes a first actual value corresponding to the first field and a second actual value corresponding to the second field; the target configuration table entry also includes a first threshold and a second threshold; the control data includes first control data, second control data, and output control signals; the statistical conditions include a first condition and a second condition. The step of the logic judgment module determining whether the actual data satisfies the statistical conditions corresponding to the condition index under the drive of the control data and outputting a statistical signal includes: Driven by the first control data, the first comparison unit determines whether the first actual value and the first threshold satisfy the first condition and obtains a first comparison signal; Driven by the second control data, the second comparison unit determines whether the second actual value and the second threshold satisfy the second condition, and obtains a second comparison signal; The output unit determines the statistical signal based on the first comparison signal and the second comparison signal under the drive of the output control signal.
3. The message statistics method according to claim 2, characterized in that, The first control data includes a first control signal, a second control signal, and a first selection signal; the first comparison unit includes a first comparator, a first NOT gate, a first selector, a second selector, and a first selection unit. The step of the first comparison unit determining whether the first actual value and the first threshold satisfy the first condition under the drive of the first control data, and obtaining the first comparison signal, includes: The first comparator outputs a first signal, a second signal, and a third signal based on the first actual value and the first threshold; the first signal being true indicates that the first actual value is less than the first threshold, the second signal being true indicates that the first actual value is greater than the first threshold, and the third signal being true indicates that the first actual value is equal to the first threshold. The first NOT gate performs a logical NOT operation on the third signal to obtain a fourth signal; the fourth signal being true indicates that the first actual value is not equal to the first threshold. When the first control signal is 0, the first selector directly outputs the first signal; or, when the first control signal is 1, it directly outputs the second signal. When the second control signal is 0, the second selector directly outputs the third signal; or, when the second control signal is 1, it directly outputs the fourth signal. Driven by the first selection signal, the first selection unit determines the first comparison signal based on the signal output by the first selector and the signal output by the second selector; if the first comparison signal is true, it reflects that the first actual value and the first threshold satisfy the first condition, and if the first comparison signal is false, it reflects that the first actual value and the first threshold do not satisfy the first condition.
4. The message statistics method according to claim 3, characterized in that, The first selection unit includes a first OR gate and a third selector; The step of determining the first comparison signal by the first selection unit under the drive of the first selection signal, based on the signal output by the first selector and the signal output by the second selector, includes: The first OR gate performs a logical OR operation on the signal output by the first selector and the signal output by the second selector to obtain the first OR operation signal; When the first selection signal is 00, the third selector directly outputs the signal output by the first selector as the first comparison signal to the output unit; or, when the first selection signal is 01, it directly outputs the first OR operation signal as the first comparison signal to the output unit; or, when the first selection signal is 10, it directly outputs the signal output by the second selector as the first comparison signal to the output unit.
5. The message statistics method according to claim 2, characterized in that, The second control data includes a third control signal, a fourth control signal, and a second selection signal; the second comparison unit includes a second comparator, a second NOT gate, a fourth selector, a fifth selector, and a second selection unit. The step of the second comparison unit determining whether the second actual value and the second threshold satisfy the second condition under the drive of the second control data, and obtaining the second comparison signal, includes: The second comparator outputs a fifth signal, a sixth signal, and a seventh signal based on the second actual value and the second threshold; the fifth signal being true indicates that the second actual value is less than the second threshold, the sixth signal being true indicates that the second actual value is greater than the second threshold, and the seventh signal being true indicates that the second actual value is equal to the second threshold. The second NOT gate performs a logical NOT operation on the seventh signal to obtain the eighth signal; the eighth signal being true indicates that the second actual value is not equal to the second threshold. The fourth selector outputs the fifth signal directly when the third control signal is 0; or, when the third control signal is 1, it outputs the sixth signal directly. The fifth selector outputs the seventh signal directly when the fourth control signal is 0; or, when the fourth control signal is 1, it outputs the eighth signal directly. Driven by the second selection signal, the second selection unit determines the second comparison signal based on the signals output by the fourth selector and the fifth selector; if the second comparison signal is true, it reflects that the second actual value and the second threshold satisfy the second condition; if the second comparison signal is false, it reflects that the second actual value and the second threshold do not satisfy the second condition.
6. The message statistics method according to claim 5, characterized in that, The second selection unit includes a second OR gate and a sixth selector; The second selection unit, driven by the second selection signal, determines the second comparison signal based on the signals output by the fourth selector and the fifth selector, including the following steps: The second OR gate performs a logical OR operation on the signal output by the fourth selector and the signal output by the fifth selector to obtain the second OR operation signal; When the second selection signal is 00, the sixth selector directly outputs the signal output by the fourth selector as the second comparison signal to the output unit; or, when the second selection signal is 01, it directly outputs the second OR operation signal as the second comparison signal to the output unit; or, when the second selection signal is 10, it directly outputs the signal output by the fifth selector as the second comparison signal to the output unit.
7. The message statistics method according to claim 2, characterized in that, The output unit includes a third OR gate, an AND gate, and a seventh selector; The step of the output unit determining the statistical signal based on the first comparison signal and the second comparison signal under the drive of the output control signal includes: The third OR gate performs a logical OR operation on the first comparison signal and the second comparison signal to obtain the third OR operation signal; The AND gate performs a logical AND operation on the first comparison signal and the second comparison signal to obtain the AND operation signal; The seventh selector outputs the third OR operation signal as the statistical signal when the output control signal is 0; or, when the output control signal is 1, it outputs the AND operation signal as the statistical signal.
8. A switching chip, characterized in that, The switching chip maintains a configuration table, which includes at least one configuration table entry corresponding to a statistical condition; the switching chip includes a table lookup module, a logic judgment module, and a counting module. The table lookup module is used to obtain the condition index and target storage location from the statistical entries in the ACL table or forwarding table when the message information of the current message is compared with the statistical entries in the ACL table or forwarding table. The table lookup module is also used to determine a target configuration table entry that matches the condition index from the configuration table; the target configuration table entry includes statistical objects and control data. The table lookup module is also used to obtain the actual data corresponding to the statistical object from the message information; The logic judgment module is used to determine whether the actual data meets the statistical conditions corresponding to the condition index under the drive of the control data, and outputs a statistical signal. The counting module is used to update the message counter at the target storage location when the statistical signal is true.
9. The switching chip according to claim 8, characterized in that, The statistical object includes a first field and a second field; the actual data includes a first actual value corresponding to the first field and a second actual value corresponding to the second field; the target configuration table entry also includes a first threshold and a second threshold; the control data includes first control data, second control data, and output control signals; the statistical conditions include a first condition and a second condition. The logic judgment module includes: a first comparison unit, a second comparison unit, and an output unit connected to both; wherein: The first comparison unit is used to determine whether the first actual value and the first threshold satisfy the first condition under the drive of the first control data, and to obtain a first comparison signal; The second comparison unit is used to determine whether the second actual value and the second threshold satisfy the second condition under the drive of the second control data, and to obtain a second comparison signal; The output unit is used to determine the statistical signal based on the first comparison signal and the second comparison signal under the drive of the output control signal.
10. A switch, characterized in that, include: The switching chip as described in any one of claims 8-9.