signbenchtest.c

Go to the documentation of this file.
00001 /**
00002  * @file signbenchtest.c
00003  * 
00004  * A simple test program to benchmark signing performance.
00005  *
00006  * Copyright (C) 2009 Palo Alto Research Center, Inc.
00007  *
00008  * This work is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License version 2 as published by the
00010  * Free Software Foundation.
00011  * This work is distributed in the hope that it will be useful, but WITHOUT ANY
00012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00014  * for more details. You should have received a copy of the GNU General Public
00015  * License along with this program; if not, write to the
00016  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019  #include <stdlib.h>
00020 #include <stdint.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <ccn/ccn.h>
00024 #include <ccn/charbuf.h>
00025 #include <ccn/keystore.h>
00026 #include <time.h>
00027 #include <sys/time.h>
00028 
00029 #define FRESHNESS 10 
00030 #define COUNT 3000
00031 #define PAYLOAD_SIZE 51
00032 
00033 int
00034 main(int argc, char **argv)
00035 {
00036 
00037   struct ccn_keystore *keystore = NULL;
00038   int res = 0;
00039   struct ccn_charbuf *signed_info = ccn_charbuf_create();
00040   int i;
00041   int sec, usec;
00042   char msgbuf[PAYLOAD_SIZE];
00043   struct timeval start, end;
00044   struct ccn_charbuf *message = ccn_charbuf_create();
00045   struct ccn_charbuf *path = ccn_charbuf_create();
00046   struct ccn_charbuf *seq = ccn_charbuf_create();
00047 
00048   struct ccn_charbuf *temp = ccn_charbuf_create();
00049   keystore = ccn_keystore_create();
00050   ccn_charbuf_putf(temp, "%s/.ccnx/.ccnx_keystore", getenv("HOME"));
00051   res = ccn_keystore_init(keystore,
00052                           ccn_charbuf_as_string(temp),
00053                           "Th1s1sn0t8g00dp8ssw0rd.");
00054   if (res != 0) {
00055     printf("Failed to initialize keystore %s\n", ccn_charbuf_as_string(temp));
00056     exit(1);
00057   }
00058   ccn_charbuf_destroy(&temp);
00059   
00060   res = ccn_signed_info_create(signed_info,
00061                                /* pubkeyid */ ccn_keystore_public_key_digest(keystore),
00062                                /* publisher_key_id_size */ ccn_keystore_public_key_digest_length(keystore),
00063                                /* datetime */ NULL,
00064                                /* type */ CCN_CONTENT_DATA,
00065                                /* freshness */ FRESHNESS,
00066                                /*finalblockid*/ NULL,
00067                                /* keylocator */ NULL);
00068 
00069   srandom(time(NULL));
00070   for (i=0; i<PAYLOAD_SIZE; i++) {
00071     msgbuf[i] = random();
00072   }
00073 
00074   printf("Generating %d signed ContentObjects (one . per 100)\n", COUNT);
00075   gettimeofday(&start, NULL);
00076 
00077   for (i=0; i<COUNT; i++) {
00078     
00079     if (i>0 && (i%100) == 0) {
00080       printf(".");
00081       fflush(stdout);
00082     }
00083     ccn_name_init(path);
00084     ccn_name_append_str(path, "rtp");
00085     ccn_name_append_str(path, "protocol");
00086     ccn_name_append_str(path, "13.2.117.34");
00087     ccn_name_append_str(path, "domain");
00088     ccn_name_append_str(path, "smetters");
00089     ccn_name_append_str(path, "principal");
00090     ccn_name_append_str(path, "2021915340");
00091     ccn_name_append_str(path, "id");
00092     ccn_charbuf_putf(seq, "%u", i);
00093     ccn_name_append(path, seq->buf, seq->length);
00094     ccn_name_append_str(path, "seq");
00095   
00096     res = ccn_encode_ContentObject(/* out */ message,
00097                                    path, signed_info, 
00098                                    msgbuf, PAYLOAD_SIZE,
00099                                    /* digest_algorithm */ NULL, 
00100                                    ccn_keystore_private_key(keystore));
00101 
00102     ccn_charbuf_reset(message);
00103     ccn_charbuf_reset(path);
00104     ccn_charbuf_reset(seq);
00105   }
00106   gettimeofday(&end, NULL);
00107   sec = end.tv_sec - start.tv_sec;
00108   usec = (int)end.tv_usec - (int)start.tv_usec;
00109   while (usec < 0) {
00110     sec--;
00111     usec += 1000000;
00112   }
00113 
00114   printf("\nComplete in %d.%06d secs\n", sec, usec);
00115 
00116   return(0);
00117 }

Generated on Thu Feb 16 00:44:00 2012 for Content-Centric Networking in C by  doxygen 1.5.6