]> git.proxmox.com Git - mirror_kronosnet.git/commitdiff
[test] add packet verification option to knet_bench
authorFabio M. Di Nitto <fdinitto@redhat.com>
Wed, 16 Oct 2019 06:10:23 +0000 (08:10 +0200)
committerFabio M. Di Nitto <fdinitto@redhat.com>
Wed, 16 Oct 2019 06:10:23 +0000 (08:10 +0200)
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
libknet/tests/knet_bench.c

index 14dcb55bb8977e27dd2650a0e0659f7816fd2c0d..ed28b63623a208659bbb4c0e823a03e187ad9e93 100644 (file)
@@ -46,6 +46,7 @@ static char *compresscfg = NULL;
 static char *cryptocfg = NULL;
 static int machine_output = 0;
 static int use_access_lists = 0;
+static int use_pckt_verification = 0;
 
 static int bench_shutdown_in_progress = 0;
 static pthread_mutex_t shutdown_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -75,6 +76,11 @@ struct node {
        struct sockaddr_storage address[KNET_MAX_LINK];
 };
 
+struct pckt_ver {
+       uint32_t len;
+       uint32_t chksum;
+};
+
 static void print_help(void)
 {
        printf("knet_bench usage:\n");
@@ -116,6 +122,7 @@ static void print_help(void)
        printf("                                           1: show handle stats, 2: show summary link stats\n");
        printf("                                           3: show detailed link stats\n");
        printf(" -a                                        enable machine parsable output (default: off).\n");
+       printf(" -v                                        enable packet verification for performance tests (default: off).\n");
 }
 
 static void parse_nodes(char *nodesinfo[MAX_NODES], int onidx, int port, struct node nodes[MAX_NODES], int *thisidx)
@@ -252,7 +259,7 @@ static void setup_knet(int argc, char *argv[])
 
        memset(nodes, 0, sizeof(nodes));
 
-       while ((rv = getopt(argc, argv, "aCT:S:s:ldfom:wb:t:n:c:p:x:X::P:z:h")) != EOF) {
+       while ((rv = getopt(argc, argv, "aCT:S:s:lvdfom:wb:t:n:c:p:x:X::P:z:h")) != EOF) {
                switch(rv) {
                        case 'h':
                                print_help();
@@ -410,11 +417,14 @@ static void setup_knet(int argc, char *argv[])
                                break;
                        case 'x':
                                force_packet_size = (uint32_t)atoi(optarg);
-                               if ((force_packet_size < 1) || (force_packet_size > 65536)) {
-                                       printf("Unsupported packet size %u (accepted 1 - 65536)\n", force_packet_size);
+                               if ((force_packet_size < 64) || (force_packet_size > 65536)) {
+                                       printf("Unsupported packet size %u (accepted 64 - 65536)\n", force_packet_size);
                                        exit(FAIL);
                                }
                                break;
+                       case 'v':
+                               use_pckt_verification = 1;
+                               break;
                        case 'C':
                                continous = 1;
                                break;
@@ -653,6 +663,24 @@ static void setup_knet(int argc, char *argv[])
        }
 }
 
+/*
+ * calculate weak chksum (stole from corosync for debugging purposes)
+ */
+static uint32_t compute_chsum(const unsigned char *data, uint32_t data_len)
+{
+       unsigned int i;
+       unsigned int checksum = 0;
+
+       for (i = 0; i < data_len; i++) {
+               if (checksum & 1) {
+                       checksum |= 0x10000;
+               }
+
+               checksum = ((checksum >> 1) + (unsigned char)data[i]) & 0xffff;
+       }
+       return (checksum);
+}
+
 static void *_rx_thread(void *args)
 {
        int rx_epoll;
@@ -765,6 +793,20 @@ static void *_rx_thread(void *args)
                                                        }
                                                        continue;
                                                }
+                                               if (use_pckt_verification) {
+                                                       struct pckt_ver *recv_pckt = (struct pckt_ver *)msg[i].msg_hdr.msg_iov->iov_base;
+                                                       uint32_t chksum;
+
+                                                       if (msg[i].msg_len != recv_pckt->len) {
+                                                               printf("Wrong packet len received: %u expected: %u!\n", msg[i].msg_len, recv_pckt->len);
+                                                               exit(FAIL);
+                                                       }
+                                                       chksum = compute_chsum((const unsigned char *)msg[i].msg_hdr.msg_iov->iov_base + sizeof(struct pckt_ver), msg[i].msg_len - sizeof(struct pckt_ver));
+                                                       if (recv_pckt->chksum != chksum){
+                                                               printf("Wrong packet checksum received: %u expected: %u!\n", recv_pckt->chksum, chksum);
+                                                               exit(FAIL);
+                                                       }
+                                               }
                                                rx_pkts++;
                                                rx_bytes = rx_bytes + msg[i].msg_len;
                                                current_pckt_size = msg[i].msg_len;
@@ -912,6 +954,11 @@ static void send_perf_data_by_size(void)
                }
                for (i = 0; i < PCKT_FRAG_MAX; i++) {
                        iov_out[i].iov_len = packetsize;
+                       if (use_pckt_verification) {
+                               struct pckt_ver *tx_pckt = (struct pckt_ver *)&iov_out[i].iov_base;
+                               tx_pckt->len = iov_out[i].iov_len;
+                               tx_pckt->chksum = compute_chsum((const unsigned char *)iov_out[i].iov_base + sizeof(struct pckt_ver), iov_out[i].iov_len - sizeof(struct pckt_ver));
+                       }
                }
 
                total_pkts_to_tx = perf_by_size_size / packetsize;
@@ -1195,6 +1242,11 @@ static void send_perf_data_by_time(void)
                }
                for (i = 0; i < PCKT_FRAG_MAX; i++) {
                        iov_out[i].iov_len = packetsize;
+                       if (use_pckt_verification) {
+                               struct pckt_ver *tx_pckt = (struct pckt_ver *)iov_out[i].iov_base;
+                               tx_pckt->len = iov_out[i].iov_len;
+                               tx_pckt->chksum = compute_chsum((const unsigned char *)iov_out[i].iov_base + sizeof(struct pckt_ver), iov_out[i].iov_len - sizeof(struct pckt_ver));
+                       }
                }
                printf("[info]: testing with %u bytes packet size for %" PRIu64 " seconds.\n", packetsize, perf_by_time_secs);