Log In
New Account
  
 
Home My Page Project Tree Code Snippets Project Openings NUTSS
 
 
Summary Tracker Lists CVS Files
 

CVS | Administration

Diff for /libnutss/examples/slinks_variable_load.c between versions 1.18 and 1.19

version 1.18, 2007/07/03 16:45:11 version 1.19, 2007/07/10 03:21:17
Line 13 Line 13
 #define snprintf   _snprintf  #define snprintf   _snprintf
 #endif  #endif
   
   #define randint(N) ((int)(rand() / (((double)RAND_MAX + 1) / (N))))
 #define assert(p) if(!(p)) { printf("Assertion '%s' FAILED!\n", #p); exit(1); }  #define assert(p) if(!(p)) { printf("Assertion '%s' FAILED!\n", #p); exit(1); }
   #define redundancy 5
   
 typedef struct flow {  typedef struct flow {
     int duration;      int duration;
Line 40  void *recvthread(void *arg) {  Line 42  void *recvthread(void *arg) { 
        sleep(1);         sleep(1);
        if(swaplinks_recvfrom(swp, tmp, sizeof(tmp), 0, &peer, &len) > 0) {         if(swaplinks_recvfrom(swp, tmp, sizeof(tmp), 0, &peer, &len) > 0) {
       time++; delta = 0;        time++; delta = 0;
       if(s) fprintf(s,"      %d recvd request %d\n",num,time);  
       // parse new flow        // parse new flow
       newflow = (flow_t*)calloc(1,sizeof(flow_t));        newflow = (flow_t*)calloc(1,sizeof(flow_t));
       newflow->duration = atoi(strtok(tmp,";"));        newflow->duration = atoi(strtok(tmp,";"));
       newflow->weight = atoi(strtok(NULL,";"));        newflow->weight = atoi(strtok(NULL,";"));
       exts = atoi(strtok(NULL,";"));        exts = atoi(strtok(NULL,";"));
       strncpy(newflow->source,peer.user+4,sizeof(newflow->source));        strncpy(newflow->source,peer.user+4,sizeof(newflow->source));
         if(s) fprintf(s,"      %d recvd request #%d from %s - w:%d d:%d\n",
              num,time,newflow->source,newflow->weight,newflow->duration);
       snprintf(buf,2048,"->%d:%d:%s<->",newflow->duration,newflow->weight,newflow->source);        snprintf(buf,2048,"->%d:%d:%s<->",newflow->duration,newflow->weight,newflow->source);
       // run through flows, decrementing duration, cleaning any expired flows        // run through flows, decrementing duration, cleaning any expired flows
       for(ptr = flows; ptr;) {        for(ptr = flows; ptr;) {
Line 102  void *recvthread(void *arg) {  Line 105  void *recvthread(void *arg) { 
      swaplinks_sendtoany(swp,msg,strlen(msg)+1,0);       swaplinks_sendtoany(swp,msg,strlen(msg)+1,0);
      swaplinks_update_walk_length(swp,peers);       swaplinks_update_walk_length(swp,peers);
       }        }
         else
        fprintf(s,"        %d retired unserviceable request\n",num);
   
       if(f) fprintf(f,"%d\n",load);        if(f) fprintf(f,"%d\n",load);
     if(s) fprintf(s,"%s",buf);      if(s) fprintf(s,"%s",buf);
        }         }
Line 157  int main(int argc, char **argv) {  Line 163  int main(int argc, char **argv) { 
     strncpy(reg.service, "swaplinksd", sizeof(reg.service));      strncpy(reg.service, "swaplinksd", sizeof(reg.service));
   
     swaplinks_init();      swaplinks_init();
   
       sleep(randint(10));
   
     swp = swaplinks_new("cloud9", &reg, peers, peers);      swp = swaplinks_new("cloud9", &reg, peers, peers);
   
     // let swaplinks get going.      // let swaplinks get going.
Line 164  int main(int argc, char **argv) {  Line 173  int main(int argc, char **argv) { 
   
     pthread_create(&tid, NULL, recvthread, swp);      pthread_create(&tid, NULL, recvthread, swp);
   
   sleep(1);    sleep(2);
   
     snprintf(tmp, sizeof(tmp), "%d;%d;0;", duration, weight);      snprintf(tmp, sizeof(tmp), "%d;%d;0;", duration, weight);
   
   while (time++ <2.5*limit) { // (i-- != 0) {    while (time++ <redundancy*limit) { // (i-- != 0) {
         swaplinks_sendtoany(swp, tmp, strlen(tmp)+1, 0);          swaplinks_sendtoany(swp, tmp, strlen(tmp)+1, 0);
 //        if(s) fprintf(s,"   %d sent request %d\n",num,time);  //        if(s) fprintf(s,"   %d sent request %d\n",num,time);
         swaplinks_get_neighbors(swp, nbrs, 4096);          swaplinks_get_neighbors(swp, nbrs, 4096);

Removed from v.1.18  
changed lines
  Added in v.1.19


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
 

GForge.cis.cornell.edu is brought to you by

Cornell Computing and Information Science


Powered By GForge Collaborative Development Environment