Network performance test method, electronic equipment and storage medium
By calling SNMP query to obtain the bandwidth value of the target device and dynamically adjusting the Netperf test parameters, combining Netperf and SNMP, the problem of difficulty in obtaining real-time performance data and network device status information in the existing technology is solved, and a more comprehensive network view and more accurate performance testing are achieved.
Patent Information
- Application Number
- CN202510517914.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-24
- Publication Date
- 2025-05-23
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When measuring network performance, it is difficult to obtain real-time performance data and network device status information at the same time, resulting in a lack of a comprehensive network view.
Get the bandwidth value of the target device by calling SNMP query, and dynamically adjust the Netperf test parameters according to the bandwidth value, using Netperf and SNMP to obtain a more comprehensive network view.
The combination of obtaining real-time performance data and network device status information is realized, the accuracy of network performance testing is improved, and the test duration is reasonably arranged to avoid excessive consumption of network resources.
Smart Images

Figure CN120034459A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of network testing, and in particular to a network performance testing method, electronic equipment and storage medium. Background Art
[0002] Netperf is a network performance measurement tool, mainly for transmission based on TCP (Transmission Control Protocol) or UDP (User Datagram Protocol). SNMP (Simple Network Management Protocol) is an application layer protocol used to manage and monitor network devices in IP networks. Netperf is mainly used to measure key performance indicators such as network bandwidth and latency. However, it does not provide information about the status of network devices (such as CPU utilization, memory usage, etc.). In contrast, SNMP focuses on collecting and monitoring information about the status of network devices, but SNMP is not as accurate and detailed as dedicated performance testing tools such as Netperf in obtaining real-time performance data (such as throughput, latency, etc.). Summary of the invention
[0003] The present invention provides a network performance testing method, an electronic device and a storage medium, aiming to solve at least one of the technical problems existing in the prior art.
[0004] The technical solution of the present invention is a network performance testing method, comprising:
[0005] Call SNMP query to get the bandwidth value of the target device;
[0006] Dynamically adjust Netperf test parameters according to the bandwidth value;
[0007] The Netperf performance test is performed using the adjusted Netperf test parameters.
[0008] According to some embodiments of the present invention, the SNMP query includes:
[0009] Define object identifier variables, community string variables, and address variables;
[0010] Using the object identifier variable to store the object identifier of the target device to obtain the number of received bytes of the target interface;
[0011] Set the community string variable to public to access SNMP data;
[0012] Using the address variable to store the IP address of the target device;
[0013] By using the snmpget function, a request is sent to the target device according to the object identifier variable, the community string variable and the address variable to obtain the bandwidth value of the target device.
[0014] According to some embodiments of the present invention, after calling the SNMP query to obtain the bandwidth value of the target device, the network performance testing method further includes:
[0015] Convert the bandwidth value from bytes to megabits per second.
[0016] According to some embodiments of the present invention, the Netperf test parameters include Netperf test duration and number of flows;
[0017] Dynamically adjust Netperf test parameters according to the bandwidth value, including:
[0018] If the bandwidth value is less than the first preset bandwidth value, the Netperf test duration is set to the first preset duration, and the number of flows is set to the first preset flow number value; otherwise, the Netperf test duration is set to the second preset duration, and the number of flows is set to the second preset flow number value.
[0019] According to some embodiments of the present invention, performing a Netperf performance test using the adjusted Netperf test parameters includes:
[0020] The Netperf performance test is performed by using the netperf function, by specifying the test type as TCP_STREAM, specifying the Netperf test duration as the first preset duration or the second preset duration, and specifying the number of flows as the first preset flow number value or the second preset flow number value.
[0021] According to some embodiments of the present invention, after calling the SNMP query to obtain the bandwidth value of the target device, the network performance testing method further includes:
[0022] Performing an encryption operation on the bandwidth value to obtain a bandwidth encryption value;
[0023] Storing the bandwidth encryption value;
[0024] The bandwidth encryption value is obtained, and a decryption operation is performed on the bandwidth encryption value to restore the bandwidth value.
[0025] According to some embodiments of the present invention, performing an encryption operation on the bandwidth value includes:
[0026] Define the number of encryption rounds;
[0027] Initialize the size of the S-box array to 256;
[0028] For each round, a round number is obtained according to the number of encryption rounds, and a subkey of a corresponding byte of the corresponding round is generated by performing an XOR operation on each byte of the original key and the round number;
[0029] The encryption operation is performed on the bandwidth value using the subkey and the S-box array.
[0030] According to some embodiments of the present invention, the encryption operation includes one or more combinations of XOR operation, non-linear substitution and data replacement;
[0031] Performing the encryption operation on the bandwidth value using the subkey and the S-box array includes:
[0032] For each round, performing an XOR operation on each byte of the bandwidth value and the subkey of the corresponding byte of the corresponding round;
[0033] Perform nonlinear replacement on each byte of the bandwidth value after XOR operation through the S-box array;
[0034] For each byte of the bandwidth value after nonlinear replacement, the permute function is called to perform data replacement.
[0035] The technical solution of the present invention also relates to an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor implements the network performance testing method as described above when executing the computer program.
[0036] The technical solution of the present invention also relates to a storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the network performance testing method as described above is implemented.
[0037] The beneficial effects of the present invention include: calling SNMP query to obtain the bandwidth value of the target device, then dynamically adjusting the Netperf test parameters according to the bandwidth value, and using the adjusted Netperf test parameters to perform Netperf performance testing. Combining Netperf and SNMP can obtain a more comprehensive network view, including both real-time performance data and network device status information. Reasonable arrangement of Netperf test duration is conducive to avoiding excessive consumption of network resources while ensuring sufficient monitoring coverage. In addition, using the adjusted Netperf test parameters to perform Netperf performance testing can improve the accuracy of Netperf performance testing.
[0038] In addition, additional aspects and advantages of the present invention will be given in part in the following description, and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 It is an optional flow chart of a network performance testing method in an embodiment of the present invention.
[0040] Figure 2 This is an optional flow chart of SNMP query in an embodiment of the present invention.
[0041] Figure 3 This is an optional flow chart for dynamically adjusting Netperf test parameters according to bandwidth values in an embodiment of the present invention. DETAILED DESCRIPTION
[0042] The following will be combined with the embodiments and drawings to clearly and completely describe the concept, specific structure and technical effects of the present invention, so as to fully understand the purpose, scheme and effect of the present invention. It should be noted that the embodiments and features in the embodiments of this application can be combined with each other without conflict.
[0043] It should be noted that, unless otherwise specified, when a feature is referred to as being "fixed" or "connected" to another feature, it may be directly fixed or connected to the other feature, or it may be indirectly fixed or connected to the other feature. In addition, the descriptions of up, down, left, right, top, bottom, etc. used in the present invention are only relative to the relative positional relationship of the components of the present invention in the drawings.
[0044] In addition, unless otherwise defined, all technical and scientific terms used herein have the same meaning as those generally understood by those skilled in the art. The terms used in this specification are only for describing specific embodiments, not for limiting the present invention. The term "and / or" used herein includes any combination of one or more related listed items.
[0045] It should be understood that although the terms first, second, third, etc. may be used to describe various elements in the present invention, these elements should not be limited to these terms. These terms are only used to distinguish elements of the same type from each other. For example, without departing from the scope of the present invention, the first element may also be referred to as the second element, and similarly, the second element may also be referred to as the first element.
[0046] Reference Figures 1 to 3 In some embodiments, the technical solution of the present invention is a network performance testing method, including but not limited to steps 101 to 103. Each step is introduced in turn below.
[0047] Step 101: Call SNMP query to obtain the bandwidth value of the target device.
[0048] In some embodiments, before calling SNMP query to obtain the bandwidth value of the target device, the network performance test method further includes installing a dependent library. It should be noted that the network performance test method can be applied to a Linux platform or a Windows platform.
[0049] Specifically, for Linux, install the snmp package on Linux for the existence of snmp-related commands in the command line, and the build-essential package is an integrated compilation package for compiling subsequent netperf source code. In the Ubuntu operating system, install the dependent library, as shown in the following example:
[0050] sudo apt-get update
[0051] sudo apt-get install snmp build-essential
[0052] Specifically, for Windows, download the snmpget.exe tool from SNMP Tools for Windows, or use other third-party SNMP tools such as SoftPerfect Network Scanner.
[0053] It should be noted that the bandwidth value indicates the current bandwidth usage.
[0054] In some embodiments, reference Figure 2 , SNMP query includes but is not limited to the following steps 201 to 205.
[0055] Step 201: Define object identifier variables, community string variables, and address variables.
[0056] Step 202: Use the object identifier variable to store the object identifier of the target device to obtain the number of received bytes of the target interface.
[0057] Step 203: Set the community string variable to public to access SNMP data.
[0058] Step 204: Use the address variable to store the IP address of the target device.
[0059] Step 205: Using the snmpget function, according to the object identifier variable, the community string variable and the address variable, a request is sent to the target device to obtain the bandwidth value of the target device.
[0060] It should be noted that the Internet Protocol (IP) is the basic communication protocol used for data transmission between devices in computer networks.
[0061] In some embodiments, after calling the SNMP query to obtain the bandwidth value of the target device, the network performance test method further includes: converting the bandwidth value from bytes to megabits per second. It should be noted that the bandwidth value obtained by calling the SNMP query is in bytes, and the bandwidth value is converted from bytes to megabits per second (Mbps).
[0062] In a specific embodiment, a snmp query script is written, the Linux script is snmp_query.sh, and the Windows script is snmp_query.ps1.
[0063] Specifically, SNMP_OID (i.e. the aforementioned object identifier variable), SNMP_COMMUNITY (i.e. the aforementioned community string variable) and TARGET_IP (i.e. the aforementioned address variable) are defined, where SNMP_OID stores the object identifier of the target query object and points to the information of the number of bytes received by the target interface. SNMP_COMMUNITY is the community string used to access SNMP data.
[0064] Specifically, the snmpget function sends a request to the target device by specifying the version (-v 2c), community string (-c $SNMP_COMMUNITY) and target IP address, and obtains the number of received bytes of the target interface through the provided object identifier. The output of the snmpget function is processed using the awk function, and the actual numerical value is extracted and stored in the RAW_BANDWIDTH variable.
[0065] Specifically, use the bc command to calculate the bandwidth value. First, convert the number of bytes of the obtained bandwidth value to kilobits (Kbps), that is, RAW_BANDWIDTH*8 / 1000. Then, use the bc command again to convert Kbps to Mbps (megabits per second), that is, $KBPS / 1000, and set the decimal point to retain two digits (scale=2). Among them, 1 byte (Bytes) is equal to 8 bits.
[0066] Specifically, the converted bandwidth value is outputted through the echo function and displayed to the target object in Mbps, wherein the target object is the user.
[0067] Write an SNMP query script. The Linux example is as follows:
[0068] #! / bin / bash
[0069] # SNMP query script example
[0070] # Query the bandwidth information of the interface and convert it to Mbps
[0071] SNMP_OID="1.3.6.1.2.1.2.2.1.10.2" # Interface received bytes OID example
[0072] SNMP_COMMUNITY="public" # SNMP community string
[0073] TARGET_IP="192.168.43.6" # Target device IP address
[0074] # Get the bandwidth information of the device (unit: Bytes)
[0075] RAW_BANDWIDTH=$(snmpget -v 2c -c $SNMP_COMMUNITY $TARGET_IP $SNMP_OID| awk -F ": " '{print $2}')
[0076] # Convert Bytes to Mbps
[0077] KBPS=$(echo "$RAW_BANDWIDTH * 8 / 1000" | bc)
[0078] Mbps=$(echo "scale=2; $KBPS / 1000" | bc)
[0079] echo "Device Bandwidth: $Mbps Mbps"
[0080] Write an SNMP query script. The Windows example is as follows:
[0081] # SNMP query script example
[0082] # Query the bandwidth information of the interface and convert it to Mbps
[0083] $SNMP_OID = "1.3.6.1.2.1.2.2.1.10.2" # Interface receive bytes OID
[0084] $SNMP_COMMUNITY = "public" # SNMP community string
[0085] $TARGET_IP = "192.168.43.6" # Target device IP address
[0086] # Get the bandwidth information of the device (unit: Bytes)
[0087] $RAW_BANDWIDTH = snmpget -v 2c -c $SNMP_COMMUNITY $TARGET_IP $SNMP_OID | Select-Object -Skip 1 | ForEach-Object { $_.Trim()}
[0088] # Convert Bytes to Mbps
[0089] $KBPS = [math]::Round([double]($RAW_BANDWIDTH) * 8 / 1000, 2)
[0090] $Mbps = [math]::Round($KBPS / 1000, 2)
[0091] Write-Host "Device Bandwidth: $Mbps Mbps"
[0092] It should be noted that "1.3.6.1.2.1.2.2.1.10.2" is the identifier of a specific object in the MIB (Management Information Base). Looking at "1.3.6.1.2.1.2.2.1.10.2" from left to right, "1.3.6.1.2.1" is the common part of MIB-II, which is a widely used standard MIB that contains basic management information of network devices. "2.2" represents the interface part. "1" represents an interface item in the interface table (each interface has a unique index in the table). "10" represents the "number of bytes received (ifInOctets)" in the statistics of a specific interface (i.e., the target interface mentioned above). "2" is the index number of the interface, which points to a specific interface; for example, the first Ethernet interface, the second serial interface, etc., depending on the configuration of the target device and how the object identifier is used. It should be understood that "2" here is just an example value, and it needs to be determined according to the interface configuration of the specific target device in actual use.
[0093] Step 102: Dynamically adjust Netperf test parameters according to the bandwidth value.
[0094] In some embodiments, the Netperf test parameters include the Netperf test duration and the number of flows; Figure 3 , dynamically adjust Netperf test parameters according to the bandwidth value, including but not limited to the following steps 301 to 302.
[0095] Step 301: If the bandwidth value is less than the first preset bandwidth value, the Netperf test duration is set to the first preset duration, and the number of flows is set to the first preset number of flows.
[0096] Step 302: Otherwise, the Netperf test duration is set to the second preset duration, and the number of flows is set to the second preset number of flows.
[0097] In a specific embodiment, an if statement is used. If the bandwidth value is less than the first preset bandwidth value, the Netperf test duration is set to the first preset duration, and the number of flows is set to the first preset flow number value; otherwise, the Netperf test duration is set to the second preset duration, and the number of flows is set to the second preset flow number value.
[0098] It should be noted that the first preset bandwidth value may be 100 Mbps, the first preset duration may be 30 seconds, the first preset number of streams value may be 1, the second preset duration may be 60 seconds, and the second preset number of streams value may be 4. The first preset bandwidth value, the first preset duration, the first preset number of streams value, the second preset duration, and the second preset number of streams value are set according to actual conditions, and the present invention does not specifically limit them. For example, the first preset bandwidth value may also be other values close to 100, such as the first preset bandwidth value may be 99 Mbps.
[0099] It should be noted that the number of streams refers to the number of concurrently transmitted streams. Each "stream" represents an independent, concurrent network connection, such as a TCP connection or a UDP session. Setting the number of streams to 1 means that the Netperf test uses a single network connection to transmit data. Setting the number of streams to 4 means that the Netperf test uses 4 independent network connections to transmit data at the same time.
[0100] Specifically, TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are core protocols in the Internet protocol suite (TCP / IP protocol family) and are used to transmit data in the network.
[0101] In a specific embodiment, SNMP query is integrated into Netperf source code. Specifically, first download Netperf source code from Netperf official GitHub. Download it from https: / / github.com / HewlettPackard / netperf.git to the local computer, and enter this folder directory by running cd netperf. The sample code does not need to distinguish between Linux and Windows, and the example is as follows:
[0102] git clone https: / / github.com / HewlettPackard / netperf.git
[0103] cd netperf
[0104] Next, modify the netperf source code. Integrate the SNMP query logic in the src / netperf.c file. The sample code does not need to distinguish between Linux and Windows. The example is as follows:
[0105] #include<stdio.h>
[0106] #include<stdlib.h>
[0107] #include<net-snmp / net-snmp-config.h>
[0108] #include<net-snmp / net-snmp-includes.h>
[0109] / / SNMP query function
[0110] int snmp_query(char *host, char *community, char *oid) {
[0111] netsnmp_session session;
[0112] netsnmp_pdu *pdu, *response;
[0113] snmp_sess_init(&session);
[0114] session.peername = strdup(host);
[0115] session.community = strdup(community);
[0116] session.community_len = strlen(community);
[0117] pdu = snmp_pdu_create(SNMP_MSG_GET);
[0118] snmp_add_var(pdu, oid, strlen(oid), NULL, 0);
[0119] int status = snmp_synch_response(&session, pdu, &response);
[0120] if (status != SNMP_ERR_NOERROR) {
[0121] return -1;
[0122] }
[0123] / / Extract query result
[0124] char *value = NULL;
[0125] if (response->variables->name && response->variables->type ==ASN_COUNTER) {
[0126] value = response->variables->val.counter;
[0127] } else {
[0128] return -1;
[0129] }
[0130] / / Convert to Mbps
[0131] long long bytes = atoll(value);
[0132] double Mbps = (bytes * 8.0) / 1000000; / / Bytes to Mbps
[0133] return (int)Mbps;
[0134] }
[0135] / / SNMP query called in the main function
[0136] int main(int argc, char **argv) {
[0137] char *snmp_host = "192.168.43.6";
[0138] char *snmp_community = "public";
[0139] char *snmp_oid = "1.3.6.1.2.1.2.2.1.10.2";
[0140] int bandwidth = snmp_query(snmp_host, snmp_community, snmp_oid);
[0141] if (bandwidth < 0) {
[0142] fprintf(stderr, "SNMP Query Failed\n");
[0143] return 1;
[0144] }
[0145] int test_duration;
[0146] int stream_count;
[0147] / / Dynamically adjust Netperf parameters
[0148] if (bandwidth < 100) {
[0149] test_duration = 30;
[0150] stream_count = 1;
[0151] } else {
[0152] test_duration = 60;
[0153] stream_count = 4;
[0154] }
[0155] / / Call Netperf test function
[0156] run_netperf_test(test_duration, stream_count);
[0157] return 0;
[0158] }
[0159] / / Netperf test function
[0160] void run_netperf_test(int duration, int stream_count) {
[0161] printf("Running Netperf Test with Duration: %d seconds, Streams:%d\n",
[0162] duration, stream_count);
[0163] / / In actual applications, the underlying function of Netperf will be called here to perform the test
[0164] }
[0165] Among them, use<stdio.h> ,<stdlib.h> The header files related to the Net-SNMP library provide the basic functions and SNMP operation capabilities required for the program to run. Define a function named snmp_query to implement the SNMP query function. The snmp_query function receives the target host address (host), community string (community), and object identifier (oid) as input parameters. Inside the snmp_query function, first initialize an SNMP session (netsnmp_sessionsession) and set the target host name and community string; create a PDU (protocol data unit) and add variable bindings to specify the OID to be queried; call the snmp_synch_response function to send a request and wait for a response synchronously; if the request fails, return -1 to indicate an error; after successfully obtaining the response, check whether the response type is a counter type (ASN_COUNTER) and extract its value; convert the number of bytes to Mbps units and return the converted bandwidth value.
[0166] In the main function, define the target SNMP host address (snmp_host), community string (snmp_community), and OID to be queried (snmp_oid). Call the snmp_query function to query the bandwidth value. If the query fails, output an error message and exit the program. Dynamically adjust the Netperf test parameters according to the queried bandwidth value: if the bandwidth value is less than 100Mbps, set the Netperf test duration to 30 seconds and the number of streams to 1; otherwise, set the Netperf test duration to 60 seconds and the number of streams to 4. Call the run_netperf_test function to perform the actual network performance test, passing in the previously calculated Netperf test duration and number of streams.
[0167] Then, use make to compile the source code. In the netperf source code file, use make to compile the source code. The example is as follows:
[0168] . / configure
[0169] make
[0170] sudo make install
[0171] Step 103: Execute the Netperf performance test using the adjusted Netperf test parameters.
[0172] In some embodiments, performing a Netperf performance test using the adjusted Netperf test parameters includes:
[0173] Use the netperf function to perform a Netperf performance test by specifying the test type as TCP_STREAM, specifying the Netperf test duration as a first preset duration or a second preset duration, and specifying the number of flows as a first preset flow number value or a second preset flow number value.
[0174] Specifically, TCP_STREAM represents a TCP stream throughput test.
[0175] In some embodiments, after invoking SNMP query to obtain the bandwidth value of the target device, the network performance testing method further includes:
[0176] Performing encryption operation on the bandwidth value to obtain a bandwidth encryption value;
[0177] The encrypted value of bandwidth is stored;
[0178] The encrypted bandwidth value is obtained, and a decryption operation is performed on the encrypted bandwidth value to restore the bandwidth value.
[0179] It should be noted that the encrypted bandwidth value is stored in a database or log file. Data security is of vital importance. Encrypting the bandwidth value before storing it can avoid plaintext leakage and improve data security.
[0180] In some embodiments, performing an encryption operation on the bandwidth value includes:
[0181] Define the number of encryption rounds;
[0182] Initialize the size of the S-box array to 256;
[0183] Use a for loop to obtain the round number for each round according to the number of encryption rounds, and generate the subkey of the corresponding byte of the corresponding round by performing an XOR operation on each byte of the original key and the round number;
[0184] The bandwidth value is encrypted using the subkey and the S-box array.
[0185] It should be noted that the S-box (Substitution-box) is the basic structure for the symmetric key algorithm to perform substitution calculations. The size of the S-box array is initialized to 256, indicating that the number of elements in the S-box array is 256.
[0186] In some embodiments, the encryption operation includes one or more combinations of XOR operations, non-linear substitutions, and data replacements;
[0187] The bandwidth value is encrypted using the subkey and the S-box array, including:
[0188] For each round, each byte of the bandwidth value is XORed with the subkey of the corresponding byte of the corresponding round;
[0189] Each byte of the bandwidth value after XOR operation is nonlinearly replaced by the S-box array;
[0190] For each byte of the bandwidth value after nonlinear replacement, call the permute function to perform data replacement.
[0191] It should be noted that nonlinear substitution is a nonlinear transformation in encryption algorithms. It is a key operation used to destroy the linear structure of data, making the encryption process difficult to crack through mathematical analysis (such as linear algebra attacks). Nonlinear transformation is implemented through S-boxes, which are predefined substitution tables that map each input byte to a random output byte. Even if an attacker knows part of the plaintext and ciphertext, he cannot infer the key or the pattern of the S-box.
[0192] In some embodiments, the decryption operation is the inverse operation of the encryption operation.
[0193] In a specific embodiment, encryption and decryption algorithms are written. The sample code does not need to distinguish between Linux and Windows, and the example is as follows:
[0194] #include<stdio.h>
[0195] #include<stdint.h>
[0196] #include<string.h>
[0197] #include<stdlib.h>
[0198] #define KEY_SIZE 16 / / Key length
[0199] #define ROUND_COUNT 10 / / Number of encryption rounds
[0200] uint8_t s_box
[256] = { 0x63, 0x7C, 0x77, 0x7B, 0xF0, 0xF6, 0x2F,0x87,
[0201] 0xA4, 0x2C, 0xAA, 0xF0, 0xB5, 0xB1, 0x7E, 0x0E,
[0202] / / Omit the remaining 256 -16 values
[0203] };
[0204] void key_expansion(const uint8_t *key, uint8_t round_keys[ROUND_COUNT][KEY_SIZE]) {
[0205] for (int i = 0; i < ROUND_COUNT; i++) {
[0206] for (int j = 0; j < KEY_SIZE; j++) {
[0207] round_keys[i][j] = key[j] ^ (i + 1);
[0208] }
[0209] }
[0210] }
[0211] void permute(uint8_t *data, int len) {
[0212] for (int i = 0; i < len / 2; i++) {
[0213] uint8_t temp = data[i];
[0214] data[i] = data[len - i - 1];
[0215] data[len - i - 1] = temp;
[0216] }
[0217] }
[0218] void custom_encrypt(const uint8_t *input, uint8_t *output, size_tlen, const uint8_t *key) {
[0219] uint8_t round_keys[ROUND_COUNT][KEY_SIZE];
[0220] key_expansion(key, round_keys);
[0221] for (size_t i = 0; i < len; i++) {
[0222] uint8_t data = input[i];
[0223] for (int round = 0; round < ROUND_COUNT; round++) {
[0224] data ^= round_keys[round][i % KEY_SIZE];
[0225] data = s_box[data];
[0226] permute(&data, 1);
[0227] }
[0228] output[i] = data;
[0229] }
[0230] }
[0231] void custom_decrypt(const uint8_t *input, uint8_t *output, size_tlen, const uint8_t *key) {
[0232] uint8_t round_keys[ROUND_COUNT][KEY_SIZE];
[0233] key_expansion(key, round_keys);
[0234] for (size_t i = 0; i < len; i++) {
[0235] uint8_t data = input[i];
[0236] for (int round = ROUND_COUNT - 1; round >= 0; round--) {
[0237] permute(&data, 1);
[0238] data = s_box[data];
[0239] data ^= round_keys[round][i % KEY_SIZE];
[0240] }
[0241] output[i] = data;
[0242] }
[0243] }
[0244] int main() {
[0245] uint8_t key[KEY_SIZE] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0x4b,0x67, 0x33,
[0246] 0x88, 0x17, 0x94, 0x4f, 0x35, 0x11,0x6e, 0x44};
[0247] uint8_t data[] = "SNMP query result";
[0248] size_t len = strlen((char *)data);
[0249] uint8_t encrypted_data[len];
[0250] uint8_t decrypted_data[len];
[0251] custom_encrypt(data, encrypted_data, len, key);
[0252] printf("Encrypted data (hex): ");
[0253] for (size_t i = 0; i < len; i++) {
[0254] printf("%02x ", encrypted_data[i]);
[0255] }
[0256] printf("\n");
[0257] custom_decrypt(encrypted_data, decrypted_data, len, key);
[0258] printf("Decrypted data: %s\n", decrypted_data);
[0259] return 0;
[0260] }
[0261] Among them, use<stdio.h> ,<stdint.h> ,<string.h> and<stdlib.h> To provide the basic functions and type definitions required for the program to run. Define the key length KEY_SIZE of the original key as 16 bytes and the number of encryption rounds ROUND_COUNT as 10. Initialize an S-box array s_box of size 256 for performing nonlinear substitution operations.
[0262] The key_expansion function is used to generate the subkey used in each round based on the input original key. The key_expansion function receives the original key and a two-dimensional array round_keys as parameters, and each element in the two-dimensional array round_keys is a subkey. For each round, the subkey is generated by performing an XOR operation on the original key and the round number.
[0263] The permute function is used to perform data permutation operation on the data. Specifically, the permute function receives the data pointer and length as parameters and exchanges the positions of the first half and the second half of the data.
[0264] The custom_encrypt function is used to implement data encryption. The custom_encrypt function receives input data, output buffer, data length, and original key as parameters. First, the key_expansion function is called to generate the subkey for each round. Then, for each byte of the input data, the following operations are performed in sequence: XOR operation with the subkey of the current round; nonlinear replacement through the S box; and permute function is called to replace the data.
[0265] The custom_decrypt function is used to implement the data decryption function. The custom_decrypt function receives the input data, output buffer, data length, and original key as parameters. First, the key_expansion function is called to generate the subkey for each round. Then, for each byte of the input data, the following reverse operations are performed in sequence: calling the permute function to permute the data; performing reverse nonlinear replacement through the S box; and performing an XOR operation with the subkey of the current round.
[0266] In the main function, a 16-byte original key and a piece of plain text data "SNMPquery result" are defined. The custom_encrypt function and custom_decrypt function are called to perform encryption and decryption operations respectively, and the encrypted data (hexadecimal representation) and the decrypted plain text data are printed out.
[0267] Then, compile the encryption program. You will get the crypt.exe file in Windows and the crypt file in Linux. The example is as follows:
[0268] gcc -o crypt crypt.c
[0269] In a specific embodiment, SNMP query and Netperf test are integrated. Specifically, a script run_netperf.sh is created to combine SNMP query and Netperf test and perform encryption and decryption processing.
[0270] Integrate SNMP query and Netperf test, Linux example is as follows:
[0271] #! / bin / bash
[0272] SNMP_QUERY_SCRIPT=". / snmp_query.sh"
[0273] CRYPT_BINARY=". / crypt"
[0274] KEY_FILE="encryption_key.bin"
[0275] # Call SNMP query script
[0276] echo "Executing SNMP Query..."
[0277] BANDWIDTH=$(. / snmp_query.sh)
[0278] echo "SNMP Query Result: $BANDWIDTH Mbps"
[0279] # Encrypt query results
[0280] echo "Encrypting Bandwidth Data..."
[0281] ENCRYPTED_DATA=$(echo $BANDWIDTH | . / crypt encrypt $KEY_FILE)
[0282] echo "Encrypted Data: $ENCRYPTED_DATA"
[0283] # Decrypt data
[0284] echo "Decrypting Bandwidth Data..."
[0285] DECRYPTED_BANDWIDTH=$(echo $ENCRYPTED_DATA | . / crypt decrypt $KEY_FILE)
[0286] echo "Decrypted Bandwidth: $DECRYPTED_BANDWIDTH Mbps"
[0287] # Adjust Netperf parameters
[0288] if [ "$DECRYPTED_BANDWIDTH" -lt 100 ]; then
[0289] TEST_TIME=30
[0290] TEST_STREAM=1
[0291] else
[0292] TEST_TIME=60
[0293] TEST_STREAM=4
[0294] fi
[0295] # Run Netperf test
[0296] echo "Executing Netperf Test..."
[0297] netperf -H server_ip -l $TEST_TIME -t TCP_STREAM -s $TEST_STREAM
[0298] Integrate SNMP query and Netperf test, Windows example is as follows:
[0299] # Define variables
[0300] $SNMP_QUERY_SCRIPT = ".\snmp_query.ps1"
[0301] $CRYPT_BINARY = ".\crypt.exe"
[0302] $KEY_FILE = "encryption_key.bin"
[0303] # Call SNMP query script
[0304] Write-Output "Executing SNMP Query..."
[0305] $BANDWIDTH = & $SNMP_QUERY_SCRIPT
[0306] Write-Output "SNMP Query Result: ${BANDWIDTH} Mbps"
[0307] # Encrypt the query result
[0308] Write-Output "Encrypting Bandwidth Data..."
[0309] $ENCRYPTED_DATA = ($BANDWIDTH | & $CRYPT_BINARY encrypt $KEY_FILE)
[0310] Write-Output "Encrypted Data: ${ENCRYPTED_DATA}"
[0311] # Decrypt the data
[0312] Write-Output "Decrypting Bandwidth Data..."
[0313] $DECRYPTED_BANDWIDTH = ($ENCRYPTED_DATA | & $CRYPT_BINARY decrypt $KEY_FILE)
[0314] Write-Output "Decrypted Bandwidth: ${DECRYPTED_BANDWIDTH} Mbps"
[0315] # Adjust Netperf parameters
[0316] if ([double]$DECRYPTED_BANDWIDTH -lt 100) {
[0317] $TEST_TIME = 30
[0318] $TEST_STREAM = 1
[0319] } else {
[0320] $TEST_TIME = 60
[0321] $TEST_STREAM = 4
[0322] }
[0323] # Execute Netperf
[0324] Write-Output "Executing Netperf Test..."
[0325] netperf -H server_ip -l $TEST_TIME -t TCP_STREAM -s $TEST_STREAM
[0326] The . / snmp_query.sh script is used to perform an SNMP query (Simple Network Management Protocol) to obtain the current bandwidth usage. The echo command is used here to output a message indicating that the SNMP query is being performed. The results are stored in the variable BANDWIDTH, and the echo command is used again to output the results to the console, displaying "SNMPQuery Result: X Mbps", where X is the actual bandwidth value obtained by the query.
[0327] The bandwidth value obtained from the SNMP query is encrypted using a binary file called crypt. This is done by calling . / crypt encrypt $KEY_FILE, where $KEY_FILE points to the file path containing the encryption key. The encrypted data is stored in the variable ENCRYPTED_DATA and is output via the echo command.
[0328] The decryption function is called using the crypt binary tool, i.e. . / crypt decrypt $KEY_FILE. The decrypted bandwidth value is stored in the variable DECRYPTED_BANDWIDTH and printed out using the echo command.
[0329] The specific configuration of the Netperf test is determined based on the decrypted bandwidth value. If the decrypted bandwidth value is less than 100Mbps, TEST_TIME is set to 30 seconds and only one stream (TEST_STREAM=1) is used for testing; conversely, if the bandwidth value is greater than or equal to 100Mbps, TEST_TIME is set to 60 seconds and four streams (TEST_STREAM=4) are used for testing. The conditional statement if [ "$DECRYPTED_BANDWIDTH" -lt 100 ] is used here to implement the selection of logical branches.
[0330] The netperf command line tool is used to perform a network performance test on the specified server IP address (server_ip). The test type is TCP_STREAM, the Netperf test duration is $TEST_TIME seconds, and the number of streams used is specified as $TEST_STREAM.
[0331] In a specific embodiment, after executing the Netperf performance test, the network performance test method further includes saving the Netperf performance test result into a CSV file, and generating a chart using Gnuplot to generate a visual report.
[0332] It should be noted that Comma-Separated Values (CSV) is a commonly used text file format for storing tabular data, such as spreadsheets or databases. Gnuplot is a command-driven interactive function plotting program. Gnuplot supports the drawing of two-dimensional and three-dimensional graphics, and can convert data and mathematical functions into easy-to-observe flat or three-dimensional graphics.
[0333] Specifically, first save the Netperf performance test results.
[0334] Save the Netperf performance test results. The Linux example is as follows:
[0335] netperf -H server_ip -l 60 -t TCP_STREAM -s 4 -O rtt,throughput -oresults.csv
[0336] Save the Netperf performance test results. The Windows example is as follows:
[0337] Netperf.exe -H server_ip -l 60 -t TCP_STREAM -s 4 -O rtt,throughput -o results.csv
[0338] Next, use Gnuplot to draw the graph.
[0339] Read data from a file named results.csv and generate two line charts with titles based on the specified columns. The Linux example is as follows:
[0340] gnuplot -e "set datafile separator ','; plot 'results.csv' using 1:2with lines title 'Throughput', 'results.csv' using 1:4 with lines title 'RTT'"
[0341] The Windows example is as follows:
[0342] Gnuplot.exe -e "set datafile separator ','; plot 'results.csv' using1:2 with lines title 'Throughput', 'results.csv' using 1:4 with lines title 'RTT'"
[0343] Then, use gnuplot plot_results.gp to get the png image.
[0344] It is understandable that by combining Netperf and SNMP to obtain real-time performance data and network device status information, it is easier to identify performance bottlenecks or failure points by comprehensively analyzing the data from these two tools, so as to take corresponding measures. In addition, a solution for running Windows and Linux at the same time is proposed, which realizes cross-platform and can cover most server system test scenarios.
[0345] It can be seen that the bandwidth value of the target device is obtained by calling SNMP query, the Netperf test parameters are dynamically adjusted according to the bandwidth value, and the Netperf performance test is performed using the adjusted Netperf test parameters. The combination of Netperf and SNMP can obtain a more comprehensive network view, including both real-time performance data and network device status information. Reasonable arrangement of Netperf test duration is conducive to avoiding excessive consumption of network resources while ensuring sufficient monitoring coverage. In addition, using the adjusted Netperf test parameters to perform Netperf performance tests can improve the accuracy of Netperf performance tests.
[0346] The embodiment of the present invention further provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned network performance testing method when executing the computer program. The electronic device can be any intelligent terminal including a computer.
[0347] An embodiment of the present invention further provides a storage medium storing a computer program, and when the computer program is executed by a processor, the above-mentioned network performance testing method is implemented.
[0348] It should be appreciated that the method steps in the embodiments of the present invention can be implemented or implemented by computer hardware, a combination of hardware and software, or by computer instructions stored in a non-transitory computer readable memory. The method can use standard programming techniques. Each program can be implemented in a high-level process or object-oriented programming language to communicate with a computer system. However, if necessary, the program can be implemented in an assembly or machine language. In any case, the language can be a compiled or interpreted language. In addition, the program can be run on a programmed ASIC for this purpose.
[0349] In addition, the operations of the processes described herein may be performed in any suitable order unless otherwise indicated herein or otherwise clearly contradicted by context. The processes described herein (or variations and / or combinations thereof) may be performed under the control of one or more computer systems configured with executable instructions, and may be implemented as code (e.g., executable instructions, one or more computer programs, or one or more applications) that is executed collectively on one or more processors, by hardware, or a combination thereof. The computer program includes a plurality of instructions that may be executed by one or more processors.
[0350] Further, the method can be implemented in any type of computing platform that is operably connected to a suitable computer, including but not limited to a personal computer, a minicomputer, a mainframe, a workstation, a network or distributed computing environment, a separate or integrated computer platform, or in communication with a charged particle tool or other imaging device, etc. Various aspects of the present invention can be implemented in machine-readable code stored on a non-transitory storage medium or device, whether removable or integrated into a computing platform, such as a hard disk, an optical read and / or write storage medium, a RAM, a ROM, etc., so that it can be read by a programmable computer, and when the storage medium or device is read by the computer, it can be used to configure and operate the computer to perform the process described herein. In addition, the machine-readable code, or portions thereof, can be transmitted via a wired or wireless network. When such media includes instructions or programs that implement the steps described above in conjunction with a microprocessor or other data processor, the invention described herein includes these and other different types of non-transitory computer-readable storage media. When programmed according to the methods and techniques of the present invention, the present invention can also include the computer itself.
[0351] The computer program can be applied to input data to perform the functions described herein, thereby converting the input data to generate output data stored in a non-volatile memory. The output information can also be applied to one or more output devices such as a display. In a preferred embodiment of the present invention, the converted data represents physical and tangible objects, including specific visual depictions of physical and tangible objects produced on the display.
[0352] The above is only a preferred embodiment of the present invention. The present invention is not limited to the above implementation. As long as the technical effect of the present invention is achieved by the same means, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the scope of protection of the present invention. Within the scope of protection of the present invention, its technical scheme and / or implementation method may have various modifications and changes.
Claims
1. A network performance testing method, characterized in that: include: Call SNMP query to get the bandwidth value of the target device; Dynamically adjust Netperf test parameters according to the bandwidth value; The Netperf performance test is performed using the adjusted Netperf test parameters.
2. A network performance testing method according to claim 1, characterized in that: The SNMP query includes: Define object identifier variables, community string variables, and address variables; Using the object identifier variable to store the object identifier of the target device to obtain the number of received bytes of the target interface; Set the community string variable to public to access SNMP data; Using the address variable to store the IP address of the target device; By using the snmpget function, a request is sent to the target device according to the object identifier variable, the community string variable and the address variable to obtain the bandwidth value of the target device.
3. A network performance testing method according to claim 1, characterized in that: After calling the SNMP query to obtain the bandwidth value of the target device, the network performance testing method further includes: Convert the bandwidth value from bytes to megabits per second.
4. A network performance testing method according to claim 1, characterized in that: The Netperf test parameters include Netperf test duration and number of flows; Dynamically adjust Netperf test parameters according to the bandwidth value, including: If the bandwidth value is less than the first preset bandwidth value, setting the Netperf test duration to the first preset duration, and setting the number of flows to the first preset number of flows; Otherwise, the Netperf test duration is set to the second preset duration, and the number of flows is set to the second preset number of flows value.
5. A network performance testing method according to claim 4, characterized in that: The method of performing a Netperf performance test using the adjusted Netperf test parameters includes: The Netperf performance test is performed by using the netperf function, by specifying the test type as TCP_STREAM, specifying the Netperf test duration as the first preset duration or the second preset duration, and specifying the number of flows as the first preset flow number value or the second preset flow number value.
6. A network performance testing method according to claim 1, characterized in that: After calling the SNMP query to obtain the bandwidth value of the target device, the network performance testing method further includes: Performing an encryption operation on the bandwidth value to obtain a bandwidth encryption value; Storing the bandwidth encryption value; The bandwidth encryption value is obtained, and a decryption operation is performed on the bandwidth encryption value to restore the bandwidth value.
7. A network performance testing method according to claim 6, characterized in that: The encryption operation is performed on the bandwidth value, including: Define the number of encryption rounds; Initialize the size of the S-box array to 256; For each round, a round number is obtained according to the number of encryption rounds, and a subkey of a corresponding byte of the corresponding round is generated by performing an XOR operation on each byte of the original key and the round number; The encryption operation is performed on the bandwidth value using the subkey and the S-box array.
8. A network performance testing method according to claim 7, characterized in that: The encryption operation includes one or more combinations of XOR operation, non-linear replacement and data replacement; Performing the encryption operation on the bandwidth value using the subkey and the S-box array includes: For each round, performing an XOR operation on each byte of the bandwidth value and the subkey of the corresponding byte of the corresponding round; Perform nonlinear replacement on each byte of the bandwidth value after XOR operation through the S-box array; The permute function is called to perform data replacement on each byte of the bandwidth value after nonlinear replacement.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements a network performance testing method as described in any one of claims 1 to 8 when executing the computer program.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, a network performance testing method as described in any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Basic-level medical internet-of-things remote monitoring method based on SNMP
CN104301157A
Shell-based network bandwidth testing method under cluster environment
CN104618190A
Method for server cluster system network test
CN104639402A
method for automatically testing the performance of a network card by using netperf under Linux
CN109522168A
Automatic test system for limit performance of network card
CN116032805A