~didier-barvaux/+junk/rohc-tcp

« back to all changes in this revision

Viewing changes to app/performance/test_performance.c

  • Committer: Didier Barvaux
  • Date: 2013-03-17 22:28:37 UTC
  • mfrom: (535.1.165 rohc-main)
  • Revision ID: didier@barvaux.org-20130317222837-i0bj1drr62octy8m
Sync with main branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
static int tune_env_for_perfs(double *coef_nanosec);
132
132
 
133
133
static int test_compression_perfs(char *filename,
 
134
                                  const int use_large_cid,
 
135
                                  const unsigned int max_contexts,
134
136
                                  double coef_nanosec,
135
137
                                  unsigned long *packet_count,
136
138
                                  unsigned long *overflows,
144
146
                                unsigned long long *time_elapsed);
145
147
 
146
148
static int test_decompression_perfs(char *filename,
 
149
                                    const int use_large_cid,
 
150
                                    const unsigned int max_contexts,
147
151
                                    double coef_nanosec,
148
152
                                    unsigned long *packet_count,
149
153
                                    unsigned long *overflows,
180
184
 */
181
185
int main(int argc, char *argv[])
182
186
{
 
187
        int max_contexts = ROHC_SMALL_CID_MAX + 1;
 
188
        char *cid_type = NULL;
183
189
        char *test_type = NULL; /* the name of the test to perform */
184
190
        char *filename = NULL; /* the name of the PCAP capture used as input */
 
191
        bool use_large_cid;
185
192
#if __i386__
186
193
        unsigned long packet_count = 0;
187
194
        unsigned long overflows = 0;
222
229
                        /* enable verbose mode */
223
230
                        is_verbose = 1;
224
231
                }
 
232
                else if(!strcmp(*argv, "--max-contexts"))
 
233
                {
 
234
                        /* get the maximum number of contexts the test should use */
 
235
                        max_contexts = atoi(argv[1]);
 
236
                        argv++;
 
237
                        argc--;
 
238
                }
225
239
                else if(test_type == 0)
226
240
                {
227
241
                        /* get the name of the test */
228
242
                        test_type = argv[0];
229
243
                }
 
244
                else if(cid_type == NULL)
 
245
                {
 
246
                        /* get the type of CID to use within the ROHC library */
 
247
                        cid_type = argv[0];
 
248
                }
230
249
                else if(filename == NULL)
231
250
                {
232
251
                        /* get the name of the file that contains the IP packets
248
267
                goto error;
249
268
        }
250
269
 
 
270
        /* check CID type */
 
271
        if(!strcmp(cid_type, "smallcid"))
 
272
        {
 
273
                use_large_cid = false;
 
274
 
 
275
                /* the maximum number of ROHC contexts should be valid */
 
276
                if(max_contexts < 1 || max_contexts > (ROHC_SMALL_CID_MAX + 1))
 
277
                {
 
278
                        fprintf(stderr, "the maximum number of ROHC contexts should be "
 
279
                                "between 1 and %u\n\n", ROHC_SMALL_CID_MAX + 1);
 
280
                        usage();
 
281
                        goto error;
 
282
                }
 
283
        }
 
284
        else if(!strcmp(cid_type, "largecid"))
 
285
        {
 
286
                use_large_cid = true;
 
287
 
 
288
                /* the maximum number of ROHC contexts should be valid */
 
289
                if(max_contexts < 1 || max_contexts > (ROHC_LARGE_CID_MAX + 1))
 
290
                {
 
291
                        fprintf(stderr, "the maximum number of ROHC contexts should be "
 
292
                                "between 1 and %u\n\n", ROHC_LARGE_CID_MAX + 1);
 
293
                        usage();
 
294
                        goto error;
 
295
                }
 
296
        }
 
297
        else
 
298
        {
 
299
                fprintf(stderr, "invalid CID type '%s', only 'smallcid' and 'largecid' "
 
300
                        "expected\n", cid_type);
 
301
                usage();
 
302
                goto error;
 
303
        }
 
304
 
251
305
#if !__i386__
252
306
        /* skip test because the test uses x86 ASM */
253
307
        status = 77;
264
318
        if(strcmp(test_type, "compression") == 0)
265
319
        {
266
320
                /* test ROHC compression with the packets from the capture */
267
 
                ret = test_compression_perfs(filename, coef_nanosec,
 
321
                ret = test_compression_perfs(filename, use_large_cid, max_contexts,
 
322
                                             coef_nanosec,
268
323
                                             &packet_count, &overflows, &time_elapsed);
269
324
        }
270
325
        else if(strcmp(test_type, "decompression") == 0)
271
326
        {
272
327
                /* test ROHC decompression with the packets from the capture */
273
 
                ret = test_decompression_perfs(filename, coef_nanosec,
 
328
                ret = test_decompression_perfs(filename, use_large_cid, max_contexts,
 
329
                                               coef_nanosec,
274
330
                                               &packet_count, &overflows, &time_elapsed);
275
331
        }
276
332
        else
321
377
static void usage(void)
322
378
{
323
379
        fprintf(stderr,
324
 
                "ROHC performance test: test the performance of the ROHC library\n"
325
 
                "                       with a flow of IP packets\n\n"
326
 
                "usage: test_performance [-h|--help] [-v|--version] [de]compression flow\n"
327
 
                "  --version        print version information and exit\n"
328
 
                "  -v\n"
329
 
                "  --verbose        tell the application to be more verbose\n"
330
 
                "  --help           print application usage and exit\n"
331
 
                "  -h\n"
332
 
                "  flow  flow of Ethernet frames to (de)compress (PCAP format)\n");
 
380
                "ROHC performance test: test the performance of the ROHC library\n"
 
381
                "                       with a flow of IP packets\n"
 
382
                "\n"
 
383
                "usage: test_performance [-h|--help] [-v|--version] [de]compression (small|large)cid flow\n"
 
384
                "\n"
 
385
                "  --version               Print version information and exit\n"
 
386
                "  -v\n"
 
387
                "  --verbose               Tell the application to be more verbose\n"
 
388
                "  --help                  Print application usage and exit\n"
 
389
                "  -h\n"
 
390
                "  --max-contexts NUM      The maximum number of ROHC contexts to\n"
 
391
                "                          simultaneously use during the test\n"
 
392
                "\n"
 
393
                "  flow  flow of Ethernet frames to (de)compress (PCAP format)\n");
333
394
}
334
395
 
335
396
 
350
411
#if HAVE_SCHED_H == 1 && SCHED_SETSCHEDULER_PARAMS == 3
351
412
        struct sched_param param;
352
413
#endif
 
414
        const unsigned int nr_tests = 3;
 
415
        const unsigned long test_duration = 10;
353
416
        unsigned long long tics1;
354
417
        unsigned long long tics2;
355
418
        unsigned int i;
398
461
#endif
399
462
 
400
463
        /* determine CPU tics to nanoseconds coefficient */
 
464
        fprintf(stderr, "estimate CPU frequency (%u tests of %lu seconds)... ",
 
465
                nr_tests, test_duration);
 
466
        fflush(stderr);
401
467
        *coef_nanosec = 0;
402
 
        for(i = 0; i < 10; i++)
 
468
        for(i = 0; i < nr_tests; i++)
403
469
        {
404
470
                GET_CPU_TICS(tics1);
405
 
                usleep(10e6);
 
471
                usleep(test_duration * 1e6);
406
472
                GET_CPU_TICS(tics2);
407
 
                *coef_nanosec += 1.e9 / (tics2 - tics1);
 
473
                *coef_nanosec += (test_duration * 1.e9) / (tics2 - tics1);
 
474
                fprintf(stderr, "%.6fGHz ", 1. / ((*coef_nanosec) / (i + 1)));
 
475
                fflush(stderr);
408
476
        }
409
 
        *coef_nanosec /= 10;
410
 
        fprintf(stderr, "CPU frequency estimated to %.6f GHz\n",
 
477
        *coef_nanosec /= nr_tests;
 
478
        fprintf(stderr, "\nCPU frequency estimated to %.6f GHz\n",
411
479
                1. / (*coef_nanosec));
412
480
 
413
481
        return 0;
424
492
 *        with a flow of IP packets
425
493
 *
426
494
 * @param filename      The name of the PCAP file that contains the IP packets
 
495
 * @param use_large_cid Whether the compressor shall use large CIDs
 
496
 * @param max_contexts  The maximum number of ROHC contexts to use
427
497
 * @param coef_nanosec  The coefficient to convert from CPU tics to nanoseconds
428
498
 * @param packet_count  OUT: the number of compressed packets, undefined if
429
499
 *                      compression failed
432
502
 * @return              0 in case of success, 1 otherwise
433
503
 */
434
504
static int test_compression_perfs(char *filename,
 
505
                                  const int use_large_cid,
 
506
                                  const unsigned int max_contexts,
435
507
                                  double coef_nanosec,
436
508
                                  unsigned long *packet_count,
437
509
                                  unsigned long *overflows,
452
524
        const unsigned int rtp_ports[NB_RTP_PORTS] =
453
525
                { 1234, 36780, 33238, 5020, 5002 };
454
526
 
 
527
        assert(max_contexts > 0);
 
528
 
455
529
        /* open the PCAP file that contains the stream */
456
530
        handle = pcap_open_offline(filename, errbuf);
457
531
        if(handle == NULL)
486
560
        }
487
561
 
488
562
        /* create ROHC compressor */
489
 
        comp = rohc_alloc_compressor(ROHC_SMALL_CID_MAX, 0, 0, 0);
 
563
        comp = rohc_alloc_compressor(max_contexts - 1, 0, 0, 0);
490
564
        if(comp == NULL)
491
565
        {
492
566
                fprintf(stderr, "cannot create the ROHC compressor\n");
515
589
        rohc_activate_profile(comp, ROHC_PROFILE_UDPLITE);
516
590
        rohc_activate_profile(comp, ROHC_PROFILE_ESP);
517
591
        rohc_activate_profile(comp, ROHC_PROFILE_TCP);
 
592
        rohc_c_set_large_cid(comp, use_large_cid);
518
593
 
519
594
        /* reset list of RTP ports */
520
595
        if(!rohc_comp_reset_rtp_ports(comp))
533
608
                }
534
609
        }
535
610
 
 
611
        fflush(stderr);
 
612
 
536
613
        /* for each packet in the dump */
537
614
        *packet_count = 0;
538
615
        *time_elapsed = 0;
542
619
                unsigned long long packet_time_elapsed = 0;
543
620
 
544
621
                (*packet_count)++;
 
622
                if((*packet_count) != 0 && ((*packet_count) % 50000) == 0)
 
623
                {
 
624
                        fprintf(stderr, "packet #%lu\n", *packet_count);
 
625
                        fflush(stderr);
 
626
                }
545
627
 
546
628
                /* compress the IP packet */
547
629
                ret = time_compress_packet(comp, *packet_count,
695
777
 *        with a flow of IP packets
696
778
 *
697
779
 * @param filename      The name of the PCAP file that contains the ROHC packets
 
780
 * @param use_large_cid Whether the decompressor shall use large CIDs
 
781
 * @param max_contexts  The maximum number of ROHC contexts to use
698
782
 * @param coef_nanosec  The coefficient to convert from CPU tics to nanoseconds
699
783
 * @param packet_count  OUT: the number of decompressed packets, undefined if
700
784
 *                      decompression failed
703
787
 * @return              0 in case of success, 1 otherwise
704
788
 */
705
789
static int test_decompression_perfs(char *filename,
 
790
                                    const int use_large_cid,
 
791
                                    const unsigned int max_contexts,
706
792
                                    double coef_nanosec,
707
793
                                    unsigned long *packet_count,
708
794
                                    unsigned long *overflows,
718
804
        int is_failure = 1;
719
805
        int ret;
720
806
 
 
807
        assert(max_contexts > 0);
 
808
 
721
809
        /* open the PCAP file that contains the stream */
722
810
        handle = pcap_open_offline(filename, errbuf);
723
811
        if(handle == NULL)
763
851
        if(!rohc_decomp_set_traces_cb(decomp, print_rohc_traces))
764
852
        {
765
853
                fprintf(stderr, "cannot set trace callback for decompressor\n");
766
 
                goto free_decompresssor;
767
 
        }
 
854
                goto free_decompressor;
 
855
        }
 
856
 
 
857
        /* set CID type and MAX_CID for decompressor 1 */
 
858
        if(use_large_cid)
 
859
        {
 
860
                if(!rohc_decomp_set_cid_type(decomp, ROHC_LARGE_CID))
 
861
                {
 
862
                        fprintf(stderr, "failed to set CID type to large CIDs for "
 
863
                                "decompressor\n");
 
864
                        goto free_decompressor;
 
865
                }
 
866
                if(!rohc_decomp_set_max_cid(decomp, max_contexts - 1))
 
867
                {
 
868
                        fprintf(stderr, "failed to set MAX_CID to %d for decompressor\n",
 
869
                                ROHC_LARGE_CID_MAX);
 
870
                        goto free_decompressor;
 
871
                }
 
872
        }
 
873
        else
 
874
        {
 
875
                if(!rohc_decomp_set_cid_type(decomp, ROHC_SMALL_CID))
 
876
                {
 
877
                        fprintf(stderr, "failed to set CID type to small CIDs for "
 
878
                                "decompressor\n");
 
879
                        goto free_decompressor;
 
880
                }
 
881
                if(!rohc_decomp_set_max_cid(decomp, max_contexts - 1))
 
882
                {
 
883
                        fprintf(stderr, "failed to set MAX_CID to %d for decompressor\n",
 
884
                                ROHC_SMALL_CID_MAX);
 
885
                        goto free_decompressor;
 
886
                }
 
887
        }
 
888
 
 
889
        fflush(stderr);
768
890
 
769
891
        /* for each packet in the dump */
770
892
        *packet_count = 0;
775
897
                unsigned long long packet_time_elapsed = 0;
776
898
 
777
899
                (*packet_count)++;
 
900
                if((*packet_count) != 0 && ((*packet_count) % 50000) == 0)
 
901
                {
 
902
                        fprintf(stderr, "packet #%lu\n", *packet_count);
 
903
                        fflush(stderr);
 
904
                }
778
905
 
779
906
                /* decompress the ROHC packet */
780
907
                ret = time_decompress_packet(decomp, *packet_count,
784
911
                {
785
912
                        fprintf(stderr, "packet %lu: performance test failed\n",
786
913
                                *packet_count);
787
 
                        goto free_decompresssor;
 
914
                        goto free_decompressor;
788
915
                }
789
916
 
790
917
                if((*time_elapsed) > (0xffffffff - packet_time_elapsed))
802
929
        /* everything went fine */
803
930
        is_failure = 0;
804
931
 
805
 
free_decompresssor:
 
932
free_decompressor:
806
933
        rohc_free_decompressor(decomp);
807
934
close_input:
808
935
        pcap_close(handle);