Traffic statistics method and device, electronic equipment and readable storage medium
By processing data packet information using a hash algorithm to generate hash values and determine storage addresses, the problem of insufficient traffic statistics in existing technologies is solved, enabling multi-dimensional traffic statistics and more efficient network data management.
Patent Information
- Application Number
- CN202310254419.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-16
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2043-03-16
AI Technical Summary
Current technologies for network data traffic statistics are relatively simple and cannot obtain more detailed traffic statistics information, resulting in poor network data monitoring and management.
By acquiring data packet information, the target data information is processed using a hash algorithm to generate a hash value, and the storage address is determined in the hash table. Then, traffic statistics are performed based on the storage address, supporting multi-dimensional traffic statistics.
It enables multi-dimensional traffic statistics of network data, obtains more detailed traffic statistics information, improves the efficiency of network data monitoring and management, and reduces the storage space requirements of hash tables, thereby reducing hardware costs.
Smart Images

Figure CN116545643B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of network communication, and in particular to a traffic statistics method and device, an electronic device, and a readable storage medium. BACKGROUND
[0002] With the rapid development of information technology such as cloud computing, Internet of Things, and big data, the network data environment is becoming increasingly complex. If there is a lack of monitoring and management of network data, network security problems such as data leakage and Distributed Denial of Service (DDoS) attacks will become increasingly prominent. Statistics and analysis of the traffic of network data can better achieve monitoring and management of network data. However, the current traffic statistics of network data is relatively simple and cannot obtain more detailed traffic statistics information. SUMMARY
[0003] In view of the above problems, embodiments of the present application provide a traffic statistics method and device, an electronic device, and a readable storage medium, to solve the problem that more detailed traffic statistics information cannot be obtained in the related art.
[0004] According to a first aspect of embodiments of the present application, a traffic statistics method is provided, which includes: obtaining data packet information. Processing target data information in the data packet information according to a hash algorithm to obtain a target hash value. According to the target hash value, determining a first storage address corresponding to the target hash value in a hash table stored in a first storage; the hash table is used to store data information corresponding to at least one hash value. According to the target hash value and the first storage address, determining a second storage address in a second storage. According to the second storage address, performing statistics on the traffic of the target data information.
[0005] In an optional manner, according to the target hash value, determining the first storage address corresponding to the target hash value in the hash table stored in the first storage includes: according to the target hash value, determining whether the target data information exists in the hash table; if the target data information exists in the hash table, determining the first storage address based on the storage position of the target data information in the hash table; if the target data information does not exist in the hash table, storing the target data information in the hash table, and determining the first storage address based on the storage position of the target data information in the hash table.
[0006] In an optional manner, according to the target hash value, determining whether the target data information exists in the hash table includes: according to the target hash value, determining a target query position corresponding to the target hash value in the hash table; according to the target query position, determining at least one data information group corresponding to the target query position in the hash table; and determining whether the target data information exists in the at least one data information group.
[0007] In an optional mode, the data information group comprises the identifier information and the query information; and the determining whether the target data information exists in the at least one data information group comprises: determining whether the identifier information in the at least one data information group is valid, and the query information in the at least one data information group matches the target data information.
[0008] In an optional mode, the storing the target data information in the hash table comprises: determining, in the at least one data information group, an idle data information group in which the identifier information is invalid; and writing the target data information into the query information in the idle data information group, and setting the identifier information in the idle data information group as valid.
[0009] In an optional mode, the counting the flow of the target data information according to the second storage address comprises: counting, according to the second storage address, the number of data packets and the number of data packet bytes of the target data information stored in the second storage address.
[0010] In an optional mode, before the processing the target data information in the data message information according to the hash algorithm to obtain the target hash value, the method further comprises: determining whether the data message information needs to be counted; and if the data message information needs to be counted, processing the target data information in the data message information according to the hash algorithm to obtain the target hash value.
[0011] According to a second aspect of the embodiments of the present application, a flow counting device is provided, comprising: an obtaining module, a processing module, a querying module, a determining module and a counting module. The obtaining module is configured to obtain data message information. The processing module is configured to process target data information in the data message information according to a hash algorithm to obtain a target hash value. The querying module is configured to determine, according to the target hash value, a first storage address corresponding to the target hash value in a hash table stored in a first storage. The hash table is used to store data information corresponding to at least one hash value. The determining module is configured to determine, according to the target hash value and the first storage address, a second storage address in a second storage. The counting module is configured to count the flow of the target data information according to the second storage address.
[0012] According to a third aspect of the embodiments of the present application, an electronic device is provided, comprising a processor and a memory. The memory is configured to store executable instructions of the processor; and the processor is configured to execute the operations of the flow counting method according to the first aspect by executing the executable instructions.
[0013] According to a fourth aspect of the embodiments of the present application, a computer readable storage medium is provided, and the storage medium stores at least one executable instruction, and the executable instruction causes a flow statistics device to perform operations of the flow statistics method according to the first aspect.
[0014] According to the embodiments of the present application, the data packet information is acquired, the target data information in the data packet information is processed according to the hash algorithm to obtain a target hash value, then the first storage address corresponding to the target hash value is determined in the hash table stored in the first storage according to the target hash value, then the second storage address in the second storage is determined according to the target hash value and the first storage address, and finally the flow of the target data information is counted according to the second storage address. Since the target data information can be any one or any multiple information in the data packet information (including the input port, the output port, the SMAC, the SIP and the packet length of the packet), the flow statistics of multiple dimensions of the data packet information can be realized by the embodiments of the present application, the classified statistics is realized, and more detailed flow statistics information can be acquired, and the network data monitoring and management is better realized. Meanwhile, the target data information is processed by the hash algorithm, the length of the target data information is reduced, the storage space occupied by the hash table is saved, and the hardware cost is reduced.
[0015] The above description is only a summary of the technical solutions of the embodiments of the present application, in order to more clearly understand the technical means of the embodiments of the present application, the embodiments of the present application can be implemented according to the content of the specification, and in order to make the above and other purposes, characteristics and advantages of the embodiments of the present application more obvious and easy to understand, the specific implementation manner of the present application is described below. BRIEF DESCRIPTION OF DRAWINGS
[0016] The accompanying drawings are only used to show the embodiments, and are not considered as limiting the present application. Moreover, the same reference signs are used to represent the same components throughout the drawings. In the drawings:
[0017] Figure 1 A flowchart of a flow statistics method provided by the embodiments of the present application is shown;
[0018] Figure 2 A flowchart of another flow statistics method provided by the embodiments of the present application is shown;
[0019] Figure 3 A schematic diagram of a flow statistics device provided by the embodiments of the present application is shown;
[0020] Figure 4 A flowchart of another flow statistics method provided by the embodiments of the present application is shown;
[0021] Figure 5Another schematic diagram of a flow statistics device provided by an embodiment of the present application is shown in FIG. 2.
[0022] Figure 6 A structural schematic diagram of an electronic device provided by an embodiment of the present application is shown in FIG. 3. DETAILED DESCRIPTION
[0023] Exemplary embodiments of the present application will be described in detail with reference to the accompanying drawings. Although exemplary embodiments of the present application are shown in the drawings, it is understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein.
[0024] Generally, flow statistics information of network data can be obtained by counting data flow of a certain input port or output port in a network device, but the flow statistics information obtained by using this method is not detailed enough. For example, the data flow to a certain source MAC address (Media Access Control Address, hereinafter referred to as SMAC) cannot be determined in the statistics information obtained by using this method. Therefore, there is a problem of single type of statistics in the related art, and more detailed statistics information cannot be obtained.
[0025] To solve the above problem, an embodiment of the present application provides a flow statistics method, which can realize multi-dimensional flow statistics of network data, and can perform flow statistics on related information of data packet information according to user demand, so that the flow statistics of network data is more detailed, and further facilitates the monitoring and management of network data. For example, the more detailed the flow statistics of network data is, the better the monitoring and management of network data can be achieved.
[0026] Figure 1 A flowchart of a flow statistics method provided by an embodiment of the present application is shown in FIG. 4, and the flow statistics method will be described below in combination with Figure 1 The flow statistics method provided by an embodiment of the present application will be described exemplarily. As shown in FIG. 5, the method includes steps S110 to S150. Figure 1
[0027] Step S110, obtaining data packet information.
[0028] Exemplarily, the flow statistics method provided by an embodiment of the present application can be executed by an electronic device, for example, the flow statistics method can be executed by a switching device. Specifically, obtaining data packet information can include: a target switching device receiving data packet information sent by other switching device (one or more) coupled thereto.
[0029] In some examples, the data packet information can be referred to as packet information or a packet (message), and the data packet information can include an input port of the packet, an output port of the packet, an SMAC in the packet, a source IP address (hereinafter referred to as SIP), a length of the packet, and the like. The input port of the packet can be a port on the target switching device through which the data packet information is input, and the output port of the packet can be a port on the target switching device through which the data packet information is output.
[0030] In step S120, the target data information in the data packet information is processed according to the hash algorithm to obtain a target hash value.
[0031] For example, the target data information can be any one of the information in the data packet information, such as the SMAC. Alternatively, the target data information can be a combination of at least two pieces of information in the data packet information, such as the input port and the SMAC, or the output port and the SIP, and the like. The present application does not make a specific limitation in this regard.
[0032] In some examples, the target data information can be set according to user requirements, for example, according to the type of network data that the user needs to count. For example, when the user needs to count the flow of the SMAC, the target data information can be set as the SMAC.
[0033] In some embodiments, before the target data information in the data packet information is processed according to the hash algorithm to obtain the target hash value, the method further includes: determining whether the data packet information needs to be counted; and if the data packet information needs to be counted, processing the target data information in the data packet information according to the hash algorithm to obtain the target hash value.
[0034] Specifically, after the data packet information is obtained, the data packet information is first analyzed and identified to determine whether the target data information is included in the data packet information. If the target data information is included in the data packet information, it indicates that the data packet information needs to be counted, and then the step of counting the flow of the target data information can be continued. If the target data information is not included in the data packet information, it indicates that the data packet information does not need to be counted, and thus the step of counting the flow of the target data information can be terminated.
[0035] After it is determined that the data packet information needs to be counted, the target data information in the data packet information is processed according to the hash algorithm to obtain the target hash value.
[0036] Exemplarily, the hash algorithm can include a CRC-16 algorithm and a CRC-32 algorithm, and the type of the hash algorithm is not limited in the embodiments of the present application. For example, the type of the hash algorithm can also include a CRC-12 algorithm, etc.
[0037] In some examples, the processing of the target data information by the hash algorithm can realize compression of the length of the target data information. That is, the length (or the number of bits) of the target hash value obtained after the processing of the target data information by the hash algorithm is less than the length (or the number of bits) of the target data information. Specifically, the number of bits of the target hash value obtained by different hash algorithms can be different. For example, taking the target data information as SMAC, the length of the SMAC is 48 bits, when the hash algorithm is a CRC-16 algorithm, the 48-bit SMAC is processed by the hash algorithm CRC-16 algorithm, and the length of the target hash value obtained is 16 bits, that is, the 48-bit SMAC is compressed into a 16-bit target hash value; or when the hash algorithm is a CRC-32 algorithm, the 48-bit SMAC is processed by the hash algorithm CRC-32 algorithm, and the length of the target hash value obtained is 32 bits, that is, the 48-bit SMAC is compressed into a 32-bit target hash value. Therefore, by processing by the hash algorithm, the target data information with a longer length can be compressed into a target hash value with a shorter length, thereby saving storage space.
[0038] In some examples, after obtaining the data packet information, the target data information can be processed by a hash algorithm according to a preset strategy to obtain a target hash value. The preset strategy can be a preconfigured strategy; the preset strategy can be used to determine the target data information in the data packet information and the hash algorithm corresponding to the target data information. That is, the preset strategy can be used to indicate which information in the data packet information is processed by which hash algorithm to obtain the target hash value. For example, the preset strategy can be used to indicate that the SMAC in the data packet information is processed by a CRC-16 algorithm to obtain the target hash value corresponding to the SMAC.
[0039] After obtaining the target hash value corresponding to the target data information, step S130 is continued.
[0040] In step S130, a first storage address corresponding to the target hash value is determined in a hash table stored in a first storage according to the target hash value.
[0041] The first storage can be a random access memory (RAM), which can be a static RAM or a dynamic RAM, and the present application does not limit this.
[0042] In some embodiments, the hash table is used to store data information corresponding to at least one hash value. For example, the hash value can be the target hash value obtained according to step S120, and when the hash value is the target hash value, the data information corresponding to the hash value is the target data information.
[0043] For example, the hash table can include a plurality of hash buckets, and each hash bucket can correspond to a query location, and the corresponding hash bucket can be determined through the query location. Each query location in the hash table can be determined according to the hash value of each data information.
[0044] Since the hash values corresponding to different data information can be the same, the bucket depth of the hash bucket in the hash table can be M, where M is an integer greater than or equal to 1, that is, each hash bucket can have M storage addresses. For example, when M is 4, that is, one query location can correspond to 4 storage addresses.
[0045] In some examples, the hash table can store a plurality of data information groups. For example, in the M storage addresses in each hash bucket, each storage address can store a data information group. That is, in the hash table, one query location can correspond to M data information groups. For example, the M data information groups in each hash bucket can be respectively recorded as data information group 0, data information group 1, data information group 2,..., and data information group M. For example, when M = 4, each hash bucket can include 4 data information groups, which are data information group 0, data information group 1, data information group 2, data information group 3, and data information group 4.
[0046] In some embodiments, each data information group includes identifier information and query information. The identifier information is used to indicate whether the data information group is an idle data information group, that is, whether the query information in the data information group is empty.
[0047] In some examples, the identifier information can be set to valid and invalid. For example, when the identifier information is set to valid, such as setting the identifier information to 1, it is used to indicate that the data information group is a non-idle data information group, that is, the query information in the data information group is not empty. When the identifier information is set to invalid, such as setting the identifier information to 0, it is used to indicate that the data information group is an idle data information group, that is, the query information in the data information group is empty. In some examples, the query information is used to indicate the data information stored in the data information group. For example, when the query information is not empty, it indicates that the data information group stores data information, and when the query information is empty, it indicates that the data information group does not store data information.
[0048] Figure 2 Another flow statistics method provided by the embodiments of the present application is as follows: Figure 2The step S130 can include steps S210-S230 as shown below.
[0049] In step S210, it is determined whether the target data information exists in the hash table according to the target hash value.
[0050] In some embodiments, the determining whether the target data information exists in the hash table according to the target hash value includes: determining a target query position corresponding to the target hash value in the hash table according to the target hash value; determining at least one data information group corresponding to the target query position in the hash table according to the target query position; and determining whether the target data information exists in the at least one data information group.
[0051] Specifically, after the target hash value is obtained, the target query position corresponding to the target hash value can be queried in the hash table according to the target hash value. The target query position can be the same as the target hash value, or the target query position can have a certain mapping relationship with the target hash value. Therefore, after the target hash value is obtained, the target query position can be located in the hash table through the target hash value.
[0052] Since one query position (also referred to as an entry position of the hash table) in the hash table corresponds to one hash bucket, the target hash bucket corresponding to the target query position can be queried in the hash table according to the target query position. The target hash bucket includes M data information groups, and therefore, it can be further determined whether a data information group including the target data information exists in the M data information groups.
[0053] In some embodiments, the data information group includes identifier valid information and query information, and the determining whether the target data information exists in the at least one data information group includes: determining whether a data information group in which the identifier information is valid and the query information matches the target data information exists in the at least one data information group.
[0054] After the M data information groups in the target hash bucket corresponding to the target query position in the hash table are determined according to the target hash value, it can be first determined whether the identifier information in each data information group in the M data information groups is valid, and when a data information group in which the identifier information is valid exists in the M data information groups, it can be further determined whether the query information in the data information group in which the identifier information is valid is consistent with the target data information.
[0055] In step S220, if the target data information exists in the hash table, a first storage address is determined based on a storage position of the target data information in the hash table.
[0056] In some embodiments, the target data information exists in the hash table if the target data information exists in at least one data information group, that is, the identifier information of at least one data information group is valid, and the query information matches the target data information of the data information group.
[0057] In some examples, the target data information exists in the hash table if the target data information exists in at least one data information group, that is, the identifier information of at least one data information group is valid, and the query information matches the target data information of the data information group. Among the M data information groups, the number of data information groups with valid identifier information can be one or more (e.g., less than or equal to M); and the number of data information groups with valid identifier information and matching the target data information can be one.
[0058] In some embodiments, the first storage address is determined according to the storage location of the target data information in the hash table, including: determining the first storage address according to the location of the data information group with valid identifier information and matching the target data information in the hash table.
[0059] Specifically, the first storage address is the storage location of the data information group (which can also be referred to as the target data information group) with valid identifier information and matching the target data information in the first storage (e.g., the hash table). According to the target query location, the target hash bucket can be determined, and according to the target data information, the target data information group can be determined in the target hash bucket, and then the storage location of the target data information group can be determined.
[0060] In some examples, the storage location of each data information group in each hash bucket in the hash table is different. For example, in the target hash bucket, four data information groups are included, and the storage address of each data information group is 2 bits. For example, the storage location corresponding to the data information group 1 can be 00, the storage location corresponding to the data information group 2 can be 01, the storage location corresponding to the data information group 3 can be 10, and the storage location corresponding to the data information group 4 can be 11. When the target data information group is the data information group 3, the first storage address is "10".
[0061] In step S230, if the target data information does not exist in the hash table, the target data information is stored in the hash table, and the first storage address is determined based on the storage location of the target data information in the hash table.
[0062] Exemplarily, the target data information not existing in the hash table includes: according to the target hash value, M data information groups corresponding to the target query position in the hash table are determined, and the query information in the M data information groups with valid marker information is all inconsistent with the target data information; or, according to the target hash value, M data information groups corresponding to the target query position in the hash table are determined, and the marker information of the M data information groups is all invalid; or, according to the target hash value, the target query position in the hash table cannot be determined.
[0063] After determining that the target data information does not exist in the hash table, the target data information is stored in the hash table, and a first storage address is determined based on the storage position of the target data information in the hash table.
[0064] In some embodiments, storing the target data information in the hash table includes: in at least one data information group, determining an idle data information group with invalid marker information; writing the target data information into the query information in the idle data information group, and setting the marker information in the idle data information group to valid.
[0065] In some examples, according to the target hash value, M data information groups corresponding to the target query position in the hash table are determined, and the query information in the M data information groups with valid marker information is all inconsistent with the target data information includes: if the marker information corresponding to the M data information groups is all valid, and the query information in the M data information groups is all inconsistent with the target data information, the target data information does not exist in the hash table; in this case, it is indicated that there is no idle data information group in the target hash bucket, and at this time, the target data information does not need to be counted.
[0066] Or, if the marker information corresponding to m (wherein m is an integer greater than or equal to 1 and less than M) data information groups in the M data information groups is valid, and the query information corresponding to the m data information groups is all inconsistent with the target data information, the target data information does not exist in the hash table; in this case, it is indicated that there are n (wherein n=M-m) idle data information groups in the M data information groups, and therefore, the target data information can be written into the query information in one data information group in the n idle data information groups, the data information group in which the target data information is written can be referred to as a target data information group, and the storage address corresponding to the target data information group is a first storage address.
[0067] The target data information group can be any one of the n idle data information groups, or the target data information group can be a data information group with a relatively earlier storage address among the n idle data information groups. For example, data information group 3 and data information group 4 are idle data information groups among 4 data information groups, and the storage location 10 corresponding to the data information group 3 is earlier than the storage location 11 corresponding to the data information group 4. Therefore, the target data information can be written into the query information in the data information group 3, and the data information group 3 can be referred to as the target data information group.
[0068] In some examples, if M data information groups corresponding to the target query location in the hash table are determined according to the target hash value, and the identifier information of the M data information groups is all invalid, indicating that the M data information groups are all idle data information groups, the target data information can be written into the query information in one of the M data information groups. The data information group can be any one of the M data information groups, or the data information group can be the first data information group (for example, data information group 1) among the M idle data information groups.
[0069] In some examples, if the target query location in the hash table cannot be determined according to the target hash value, that is, there is no hash bucket corresponding to the target hash value in the hash table, a target hash bucket can be created according to the target hash value. The target hash bucket can be set with M data information groups, and the identifier information of the M data information groups is all invalid, that is, the M data information groups are all idle data information groups. At this time, the target data information can be written into the query information in one of the M data information groups. The data information group can be any one of the M data information groups, or the data information group can be the first data information group (for example, data information group 1) among the M idle data information groups.
[0070] For example, after the target data information is written into the query information in the idle data information group, the identifier information in the idle data information group can be set as valid.
[0071] In some examples, the initial hash table stored in the first memory can be an empty table, and the hash table can be generated according to the target hash value determined in step S120 and the target data information corresponding to the target hash value. For example, the target data information can be written into the query information in the idle data information group in the target hash bucket corresponding to the target hash value in the initial hash table according to the above embodiment.
[0072] After the target data information is written into the query information in the idle data information group, the storage location of the idle data information group can be determined as the first storage address.
[0073] Step S140, determining a second storage address in the second memory according to the target hash value and the first storage address.
[0074] After the first storage address corresponding to the target data information in the first memory is determined, the second storage address can be determined according to the target hash value and the first storage address. The second storage address can be a storage address in the second memory. Alternatively, the second storage address can also be determined according to the target query position and the first storage address.
[0075] For example, the target hash value can be used as a high-bit address, and the first storage address can be used as a low-bit address to determine the second storage address. For example, when the length of the target hash value is 8 bits and the length of the first storage address is 2 bits, the length of the second storage address can be 10 bits, of which the first 8 bits are the target hash value and the last 2 bits are the first storage address. The present application is not limited in this regard.
[0076] Step S150, counting the traffic of the target data information according to the second storage address.
[0077] In some examples, the second storage address is also referred to as a statistical address. The second memory stores statistical information corresponding to the statistical address. For example, different second storage addresses can correspond to statistical information of different target data information.
[0078] After the second storage address is determined, it can be queried in the second memory whether the second storage address exists. If the second storage address exists in the second memory, the statistical information of the target data information corresponding to the second storage address is updated. If the second storage address does not exist in the second memory, the second storage address is added, and the statistical information of the target data information is recorded in the second storage address.
[0079] In some embodiments, counting the traffic of the target data information according to the second storage address includes: counting the number of data packets and the number of data packet bytes of the target data information stored in the second storage address according to the second storage address. That is, the statistical information includes the number of data packets and the number of bytes of each data packet.
[0080] For example, if the second storage address exists in the second memory, the number of data packets of the target data information corresponding to the second storage address is incremented by 1, and the number of data packet bytes is correspondingly accumulated. If the second storage address does not exist in the second memory, the number of data packets (such as 1) and the corresponding number of data packet bytes of the target data information are stored in the second storage address, thereby completing the counting of the target data information.
[0081] Therefore, the embodiment of the present application obtains data packet information, and processes target data information in the data packet information according to a hash algorithm to obtain a target hash value. Then, the target hash value is used to determine a first storage address corresponding to the target hash value in a hash table stored in a first memory. Next, the target hash value and the first storage address are used to determine a second storage address in a second memory. Finally, the second storage address is used to count the traffic of the target data information. Since the target data information can be any one or any multiple information in the data packet information (including the input port, the output port, the SMAC, the SIP, and the packet length of the packet), the embodiment of the present application can realize the traffic counting of multiple dimensions of the data packet information, realizes the classified counting, and thus can obtain more detailed traffic counting information, and better realizes the monitoring and management of network data. Meanwhile, the embodiment of the present application processes the target data information by using the hash algorithm, reduces the length of the target data information, saves the storage space occupied by the hash table, and reduces the hardware cost.
[0082] Figure 3 A schematic diagram of a traffic counting device provided by the embodiment of the present application is shown in Figure 3 , which includes a packet receiving module 11, a packet analyzing module 12, a control module 13, a counting module 14, and a querying module 15.
[0083] Figure 4 A schematic diagram of another traffic counting method provided by the embodiment of the present application is shown in Figure 3 , for example, the traffic counting method can be executed by the traffic counting device 10 in Figure 3 and Figure 4 . The traffic counting method provided by the embodiment of the present application is described below. As shown in Figure 4 , the traffic counting method includes steps S401 to S411.
[0084] Step S401, receiving data packet information.
[0085] Referring to Figure 3 , the packet receiving module 11 receives the data packet information, and sends the data packet information to the packet analyzing module 12.
[0086] Step S402, judging whether the data packet information needs to be counted.
[0087] Referring to Figure 3If it is determined that the data packet information does not need to be counted, the packet analysis module 12 sends the data packet information to the control module 13, and step S404 is performed.
[0088] In step S403, the target data information does not need to be counted, and the counting is ended.
[0089] In step S404, the target data information in the data packet information is processed according to a hash algorithm to obtain a target hash value.
[0090] Referring to Figure 3 The control module 13 performs a hash operation on the target data information according to a preset strategy to obtain a target hash value. It should be noted that the specific process of step S404 is similar to step S120 in the above embodiment, and thus is not described herein again to avoid repetition.
[0091] In step S405, it is determined whether the target data information exists in the hash table according to the target hash value.
[0092] Referring to Figure 3 The control module 13 performs a hash operation on the target data information according to a preset strategy to obtain a target hash value. It should be noted that the specific process of step S404 is similar to step S120 in the above embodiment, and thus is not described herein again to avoid repetition.
[0093] It should be noted that the specific process of step S405 is similar to step S210 in the above embodiment, and thus is not described herein again to avoid repetition.
[0094] If it is determined that the target data information does not exist in the hash table, step S406 is performed; if it is determined that the target data information exists in the hash table, step S407 is continuously performed.
[0095] In step S406, it is determined whether there is an idle data information group with invalid marker information.
[0096] If there is an idle data information group with invalid marker information in the M data information groups, step S408 is performed; if there is no idle data information group with invalid marker information, step S403 is performed.
[0097] In step S407, a first storage address is determined according to the position of the data information group with valid marker information and consistent query information and target data information in the hash table.
[0098] Step S408, write the target data information into the query information in the idle data information group, and set the identifier information in the idle data information group as valid.
[0099] Step S409, determine the first storage address based on the storage position of the target data information in the hash table.
[0100] Step S410, determine the second storage address in the second storage according to the target hash value and the first storage address.
[0101] Step S411, according to the second storage address, count the traffic of the target data information.
[0102] Referring to Figure 3 , the control module 13 determines the second storage address according to the target hash value and the first storage address, and updates the statistical information of the target data information in the statistical module 14 according to the second storage address. In some examples, the statistical module 14 can be a dual-port RAM, wherein each address can store the number of data packets and the total byte number information of the target data information, and can be read and written by the host computer 20 and the control module 13.
[0103] For example, Figure 3 The host computer 20 in the statistical module 14 can obtain the statistical information of the target data information in each storage address in the statistical module 14 by reading the statistical module 14; then, read the target data information corresponding to the statistical information in the corresponding address in the query module 15 through the storage address, such as input port, output port, SMAC and SIP, etc.
[0104] It should be noted that steps S410 to S411 are similar to steps S140 to S150 in the above embodiment, and will not be repeated here to avoid repetition.
[0105] Figure 5 Another schematic diagram of a flow statistical device provided by the embodiment of the present application is shown in Figure 5 The flow statistical device 10 includes an acquisition module 101, a processing module 102, a query module 103, a determination module 104 and a statistical module 105.
[0106] The acquisition module 101 is configured to acquire data packet information.
[0107] The processing module 102 is configured to process the target data information in the data packet information according to a hash algorithm to obtain a target hash value.
[0108] The query module 103 is configured to determine, according to the target hash value, a first storage address corresponding to the target hash value in a hash table stored in the first storage; the hash table is used to store data information corresponding to at least one hash value.
[0109] The determination module 104 is configured to determine, according to the target hash value and the first storage address, a second storage address in the second storage.
[0110] The statistics module 105 is configured to perform statistics on the traffic of the target data information according to the second storage address.
[0111] In some embodiments, the query module 103 is specifically configured to determine, according to the target hash value, whether the target data information exists in the hash table; if the target data information exists in the hash table, determine the first storage address based on the storage position of the target data information in the hash table; if the target data information does not exist in the hash table, store the target data information in the hash table, and determine the first storage address based on the storage position of the target data information in the hash table.
[0112] In some embodiments, the query module 103 is specifically configured to determine, according to the target hash value, a target query position corresponding to the target hash value in the hash table; determine, according to the target query position, at least one data information group corresponding to the target query position in the hash table; and determine whether the target data information exists in the at least one data information group.
[0113] In some embodiments, the data information group includes identifier information and query information; the query module 103 is specifically configured to determine whether the at least one data information group includes a data information group in which the identifier information is valid and the query information matches the target data information.
[0114] In some embodiments, the traffic statistics device 10 further includes a write module configured to determine, in the at least one data information group, an idle data information group in which the identifier information is invalid; write the target data information into the query information in the idle data information group, and set the identifier information in the idle data information group to be valid.
[0115] In some embodiments, the statistics module 105 is specifically configured to perform statistics on the number of data packets and the number of data packet bytes of the target data information stored in the second storage address according to the second storage address.
[0116] In some embodiments, the traffic statistics device 10 further includes a judgment module configured to judge whether the data packet information needs to be counted; if the data packet information needs to be counted, the processing module 102 is configured to process the target data information in the data packet information according to the hash algorithm to obtain the target hash value.
[0117] Figure 6 A structural schematic diagram of an electronic device is provided for embodiments of the present application, and embodiments of the present application do not limit the specific implementation of the electronic device. As shown in the figure, the electronic device 1000 can include a processor 1001 and a memory 1002. The electronic device 1000 can also include a communications interface 1003 and a communications bus 1004, for example. Figure 6
[0118] The processor 1001, the memory 1002, and the communications interface 1003 can communicate with each other through the communications bus 1004. The communications interface 1003 is configured to communicate with network elements such as clients or other servers.
[0119] In some embodiments, the processor 1001 is configured to execute the program 1005, and can execute the related steps in the trajectory tracking method embodiments described above. Specifically, the program 1005 can include program code including computer executable instructions.
[0120] The processor 1001 can be a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present application. The one or more processors of the electronic device 1000 can be the same type of processor, such as one or more CPUs; or can be different types of processors, such as one or more CPUs and one or more ASICs.
[0121] In some embodiments, the memory 1002 is configured to store the program 1005. The memory 1002 can include a high-speed RAM memory, and can also include a non-volatile memory (NVM), such as at least one disk memory.
[0122] The program 1005 can be invoked by the processor 1001 to cause the electronic device 1000 to perform the following operations:
[0123] Obtain data message information;
[0124] Process target data information in the data message information according to a hash algorithm to obtain a target hash value;
[0125] Determine a first storage address corresponding to the target hash value in a hash table stored in a first memory according to the target hash value; the hash table is configured to store data information corresponding to at least one hash value;
[0126] determine a second storage address in the second memory according to the target hash value and the first storage address;
[0127] count the flow of the target data information according to the second storage address.
[0128] The embodiment of the present application provides a computer readable storage medium, the storage medium stores at least one executable instruction, and the executable instruction is used for causing the electronic device 1000 to execute the flow counting method in the above embodiment when the electronic device 1000 runs.
[0129] The executable instruction can be specifically used for causing the electronic device 1000 to execute the following operation:
[0130] obtain data message information;
[0131] process target data information in the data message information according to a hash algorithm to obtain a target hash value;
[0132] determine a first storage address corresponding to the target hash value in a hash table stored in the first memory according to the target hash value; the hash table is used for storing data information corresponding to at least one hash value;
[0133] determine a second storage address in the second memory according to the target hash value and the first storage address;
[0134] count the flow of the target data information according to the second storage address.
[0135] The flow counting device, the electronic device and the computer readable storage medium provided by the embodiment of the present application are all used for executing the corresponding flow counting method provided in the above, therefore, the beneficial effects that can be achieved by the flow counting device, the electronic device and the computer readable storage medium can refer to the beneficial effects in the corresponding method provided in the above, and details are not described herein again.
[0136] The algorithms or displays provided herein are not inherently related to any particular computer, virtual system, or other device. Furthermore, embodiments of the present application are not described with reference to any particular programming language.
[0137] In the specification provided herein, a large number of specific details are described. However, it can be understood that the embodiments of the present application can be practiced without these specific details. Similarly, in order to simplify the present application and help understand one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, various features of the embodiments of the present application are sometimes grouped together into a single embodiment, a figure, or a description thereof. Among them, the claims following the specific embodiments are thus explicitly incorporated into the specific embodiments, and each claim itself is a separate embodiment of the present application.
[0138] Those skilled in the art will appreciate that modules in the apparatuses in the embodiments can be adapted and placed in one or more apparatuses other than that in the embodiments. Modules or units or components in the embodiments can be combined into one module or unit or component, and furthermore can be divided into multiple sub-modules or sub-units or sub-components. Except that at least some of such features and / or processes or units are mutually exclusive.
[0139] It should be noted that the above-mentioned embodiments illustrate rather than limit the application, and that those skilled in the art will be able to design many alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word 'comprising' does not exclude the presence of elements or steps other than those listed in a claim. The word 'a' or 'an' preceding an element does not exclude the presence of a plurality of such elements. The application can be implemented by means of both hardware and software, and any combination thereof. In a unit claim, any reference signs placed between parentheses in the claim do not limit the claim. The use of the word 'at least' followed by a list of one or more items does not exclude additional such items. The use of the term 'about' with a reference to a value and / or location and / or time and / or height can include to the reference signed value and / or location and / or time and / or height and to deviations thereof commensurate with experimental error. The word 'first','second', 'third', and the like can not imply any order. The use of the terms 'first','second', 'third', and the like does not limit the scope of the claims, which are to be given their broadest interpretation. The above-mentioned embodiments are to be construed as illustrative and not restrictive. Number of steps in the above-described embodiments is to be understood not as a limitation but as an example.
Claims
1. A method of flow statistics, characterized by, The method comprises: acquiring data message information; determining target data information and a hash algorithm corresponding to the target data information in the data message information according to a preset strategy, and processing the target data information by using the hash algorithm to obtain a target hash value; wherein the target data information is at least one of an input port, an output port, a source MAC, a source IP and a message length of the data message information; determining whether the target data information exists in a hash table stored in a first memory according to the target hash value, and determining a first storage address corresponding to the target hash value based on a storage position of the target data information in the hash table if the target data information exists in the hash table; determining a second storage address in a second memory according to the target hash value and the first storage address; wherein the target hash value is a high-bit address of the second storage address, and the first storage address is a low-bit address of the second storage address; counting a data packet quantity and a data packet byte quantity of the target data information stored in the second memory according to the second storage address.
2. The method of claim 1, wherein, The method further comprises: if the target data information does not exist in the hash table, storing the target data information in the hash table, and determining the first storage address based on a storage position of the target data information in the hash table.
3. The method of claim 2, wherein, The determining whether the target data information exists in the hash table according to the target hash value comprises: determining a target query position corresponding to the target hash value in the hash table according to the target hash value; determining at least one data information group corresponding to the target query position in the hash table according to the target query position; determining whether the target data information exists in the at least one data information group.
4. The method of claim 3, wherein, The data information group comprises identifier information and query information; the determining whether the target data information exists in the at least one data information group comprises: determining whether the identifier information in the at least one data information group is valid, and whether the query information matches the target data information.
5. The method of claim 4, wherein, The storing the target data information in the hash table comprises: determining an idle data information group in which the identifier information is invalid in the at least one data information group; writing the target data information into the query information in the idle data information group, and setting the identifier information in the idle data information group as valid.
6. The method according to any one of claims 1-5, characterized in that, Before the processing the target data information by using the hash algorithm to obtain the target hash value, the method further comprises: determining whether the data message information needs to be counted; if the data message information needs to be counted, processing the target data information in the data message information according to the hash algorithm to obtain the target hash value.
7. A flow metering device, characterized by comprise: an acquisition module configured to acquire data message information; a processing module configured to process target data information in the data message information according to a hash algorithm to obtain a target hash value; The query module is configured to: determine whether the target data information exists in a hash table stored in the first memory according to the target hash value, and if the target data information exists in the hash table, determine the first storage address corresponding to the target hash value based on a storage position of the target data information in the hash table. The determination module is configured to: determine a second storage address in a second memory according to the target hash value and the first storage address. The statistics module is configured to: according to the second storage address, count a data packet quantity and a data packet byte quantity of the target data information stored in the second memory. The device further comprises: The target data information in the data packet information is processed according to a hash algorithm to obtain a target hash value, including: according to a preset strategy, determining target data information and a hash algorithm corresponding to the target data information in the data packet information, and processing the target data information by using the hash algorithm to obtain a target hash value; wherein the target data information is at least one of an input port, an output port, a source MAC, a source IP and a packet length of the data packet information; wherein the target hash value is a high address of the second storage address, and the first storage address is a low address of the second storage address.
8. An electronic device, comprising: Comprise: A processor; And A memory configured to store executable instructions of the processor; Wherein the processor is configured to execute the operations of the traffic statistics method as claimed in any one of claims 1-6 by executing the executable instructions.
9. A computer-readable storage medium, characterized in that, The storage medium has at least one executable instruction stored therein, and the executable instruction, when running on the traffic statistics device, causes the traffic statistics device to perform the operations of the traffic statistics method as claimed in any one of claims 1-6.
Citation Information
Patent Citations
Network flow monitoring method based on Hash compression algorithm
CN105515919A
Hash table processing method, device and equipment and computer readable storage medium
CN115203210A