/* ** Author: Krishna Puttaswamy ** This test is to measure the throughput of chimera by pumping message continuously between two nodes in a netwrok of ** nodes in the hosts file */ #include #include #include #include #include "message.h" #include "log.h" #include "key.h" #include "jrb.h" #include "jval.h" #include "semaphore.h" #include "network.h" #include "dtime.h" #include "dht.h" extern char *optarg; #define OPTSTR "f:" #define USAGE "btest" int announced; void *sem; Key current; ChimeraState *state; typedef struct { char *hnp; char *name; int port; Key key; int pid; } Host; JRB read_hosts (char *fn, int *nhosts) { FILE *fp; char s[256]; char hn[128]; Key key; JRB hosts; Host *host; char keyinput[64]; int port = 0; char pp[100]; fp = fopen (fn, "r"); if (fp == NULL) { perror (fn); exit (1); } hosts = make_jrb (); *nhosts = 0; while (fgets (s, 256, fp) != NULL) { sscanf (s, "%s %s %s", hn, pp, keyinput); port = atoi(pp); //fprintf(stderr, "read host %s pp %s portnumber %d key %s\n", hn, pp, port, keyinput); host = (Host *) malloc (sizeof (Host)); host->name = strdup (hn); host->port = port; str_to_key (keyinput, &key); key_assign (&(host->key), key); sprintf (s, "%s:%d", hn, port); host->hnp = strdup (s); host->pid = 0; jrb_insert_str (hosts, strdup (s), new_jval_v (host)); *nhosts++; } fclose (fp); return (hosts); } void hello (ChimeraState * chstate, Message * msg) { fprintf (stderr, "hello: %s\n", msg->payload); announced++; sema_v (sem); } void start_host (Host * host, Host * join) { char port[16], key[160]; char ssh[100] = "ssh"; memset (port, 0, 16); memset (key, 0, 160); char *arg[9]; int i; char currentHost[256]; gethostname(currentHost, 100); // get the currenthostname //fprintf(stderr, "The hostname is %s \n", currentHost); sprintf (port, "%d", host->port); sprintf (key, "%s", host->key.keystr); // arg[0] = "ssh"; // arg[1] = host->name; char sshcommand[1000]; arg[0] = "./blue"; //arg[0] = "valgrind --leak-check=full --error-limit=no --log-file=vallogs/cashlog ./blue"; if (join != NULL) { arg[1] = "-j"; arg[2] = join->hnp; arg[3] = port; arg[4] = key; arg[5] = NULL; sprintf(sshcommand, "%s %s %s %s %s", arg[0], arg[1], arg[2], arg[3], arg[4]); } else { arg[1] = port; arg[2] = key; arg[3] = NULL; sprintf(sshcommand, "%s %s %s", arg[0], arg[1], arg[2]); } // fprintf(stderr, "nodehost is %s and currenthost is %s \n", host->name, currentHost); if (strcmp(host->name, "localhost")==0 || strcmp(host->name, currentHost) == 0) { } else { arg[0] = ssh; arg[1] = host->name; arg[2] = sshcommand; arg[3] = NULL; // fprintf(stderr, "Ssh command is %s \n", sshcommand); } host->pid = fork (); if (host->pid == 0) { if (strcmp(arg[0], "ssh") == 0) { // fprintf(stderr, "The ssh command to be executed on %s is %s \n", arg[1], arg[2]); execvp("/usr/bin/ssh", arg); } else { //fprintf(stderr, "The command to be executed is %s %s %s \n", arg[0], arg[1], arg[2]); execvp ("./blue", arg); //execvp ("valgrind --leak-check=full --error-limit=no --log-file=vallogs/cashlog ./blue", arg); } fprintf(stderr, "ERROR ERROR ERROR!!!! THE EXECVP RETURNED in the driver \n"); perror ("./blue"); exit (1); } sema_p (sem, 0.0); } void key_rand (Key * key) { int i; for (i = 0; i < 5; i++) { key->t[i] = rand (); } key_to_str (key); } int main (int argc, char **argv) { int opt; char *configfile = "hosts"; JRB hosts, node, node2; Host *host, *join, *me; int nhosts; int i, j; Message *m; char dest[160]; char msg[256]; Key tmp; ChimeraHost ch; double start; while ((opt = getopt (argc, argv, OPTSTR)) != EOF) { switch ((char) opt) { case 'f': configfile = optarg; break; default: fprintf (stderr, "invalid option %c\n", (char) opt); fprintf (stderr, "usage: %s\n", USAGE); exit (1); } } sem = sema_create (0); state = (ChimeraState *) malloc (sizeof (ChimeraState)); hosts = read_hosts (configfile, &nhosts); state->log = log_init (); log_direct (state->log, LOG_ERROR, stderr); log_direct (state->log, LOG_WARN, stderr); key_init (); state->message = message_init (state, 11110); message_handler (state, HELLO_MESSAGE, hello, 1); message_handler (state, SEND_MESSAGE, hello, 1); srand (time (NULL)); /* This part runs blue in different hosts */ announced = 0; jrb_traverse (node, hosts) { if (announced == 0) { join = NULL; } else { i = (rand () % announced) + 1; jrb_traverse (node2, hosts) { i--; if (i == 0) break; } join = (Host *) node2->val.v; } host = (Host *) node->val.v; start_host (host, join); dsleep (0.05); } sleep(20); char temp[1000]; strcpy(temp, "hello"); printf("Read %s \n", temp); int jj = 0; while(jj < 1) { fprintf (stderr, "beginning of loop %d \n", jj); jj++; i = (rand() % announced) + 1; jrb_traverse (node, hosts) { i--; if (i == 0) break; } host = (Host *) node->val.v; ch.name = host->name; ch.address = network_address (state->network, host->name); ch.port = host->port; key_assign (&ch.key, host->key); fprintf (stderr, "sending send order to %s:%s\n", ch.name, ch.key.keystr); m = message_create (ch.key, SEND_MESSAGE, strlen (temp) + 1, temp); message_send (state, &ch, m, TRUE); fprintf (stderr, "sent \n"); sleep(50); } printf ("outside the LOOOOOP \n"); while(1) sleep(1000); }