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.11 and 1.12

version 1.11, 2007/06/04 23:04:00 version 1.12, 2007/06/29 17:19:44
Line 22  typedef struct flow { Line 22  typedef struct flow {
     struct flow *next, *last;      struct flow *next, *last;
 } flow_t;  } flow_t;
   
int num,limit;int num,peers, limit, maxload;
 swaplinks_p swp;
 FILE *f = NULL, *s = NULL;  FILE *f = NULL, *s = NULL;
   
 void *recvthread(void *arg) {  void *recvthread(void *arg) {
Line 30  void *recvthread(void *arg) { Line 31  void *recvthread(void *arg) {
     struct sockaddr_ns peer;      struct sockaddr_ns peer;
     socklen_t len = sizeof(peer);      socklen_t len = sizeof(peer);
     flow_t *flows = NULL, *newflow = NULL, *ptr = NULL, *axe = NULL;      flow_t *flows = NULL, *newflow = NULL, *ptr = NULL, *axe = NULL;
   chartmp[128], buf[2048];    charmsg[64], tmp[128], buf[2048];
   int time = 0, load = 0, busy = 0,delta, expiration;    int time = 0, load = 0, busy = 0,exts, delta, expiration;
   
     buf[0] = 0;      buf[0] = 0;
   
     while(time < limit) {      while(time < limit) {
         sleep(1);          sleep(1);
         if(busy++ > limit*3) {          if(busy++ > limit*3) {
           if(s) fprintf(s,"%d HALTING RECEIVING. TOO MUCH WAITING.\n",num);            if(s) fprintf(s,"%d HALTING RECEPTION. TOO MUCH WAITING.\n",num);
             pthread_exit(NULL);              pthread_exit(NULL);
         }          }
         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,"\t\tTIME at node %d: %d\n",num,time);            if(s) fprintf(s,"\t\tTIME at node %d: %d\n",num,time);
             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,";"));
           strncpy(newflow->source,peer.user+4,sizeof(newflow->source));            exts = atoi(strtok(NULL,";"));
           snprintf(buf,2048,"->%d:%d<->",newflow->duration,newflow->weight);            if(load < maxload) {
           for(ptr = flows; ptr;) {           strncpy(newflow->source,peer.user+4,sizeof(newflow->source));
      sprintf(buf,"%s%d:%d<->",buf,ptr->duration,ptr->weight);                    snprintf(buf,2048,"->%d:%d<->",newflow->duration,newflow->weight);
      expiration = 0; axe = NULL;           for(ptr = flows; ptr;) {
               if(--ptr->duration == 0) {      sprintf(buf,"%s%d:%d<->",buf,ptr->duration,ptr->weight);
          axe = ptr;      expiration = 0; axe = NULL;
                   load -= ptr->weight;                        if(--ptr->duration == 0) {
                   delta -= ptr->weight;          axe = ptr;
                           load -= ptr->weight;
          if(ptr->last && ptr->next) {                            delta -= ptr->weight;
     assert(flows != ptr);
     ptr->last->next = ptr->next;          if(ptr->last && ptr->next) {
     ptr->next->last = ptr->last;     assert(flows != ptr);
          }     ptr->last->next = ptr->next;
          else if(ptr->next) {     ptr->next->last = ptr->last;
     assert(flows == ptr);          }
     flows = ptr->next;          else if(ptr->next) {
     if(flows) flows->last = NULL;     assert(flows == ptr);
          }     flows = ptr->next;
          else if(ptr->last) {     if(flows) flows->last = NULL;
     assert(flows != ptr);          }
     ptr->last->next = NULL;          else if(ptr->last) {
          }     assert(flows != ptr);
          else {     ptr->last->next = NULL;
     assert(flows == ptr);          }
     flows = NULL;          else {
          }     assert(flows == ptr);
    flows = NULL;
       //if(s) fprintf(s,"%d EXPIRED FLOW from %s:d%d/w%d\n",num,ptr->source,ptr->duration,ptr->weight);          }
          expiration = 1;
               }        //if(s) fprintf(s,"%d EXPIRED FLOW from %s:d%d/w%d\n",num,ptr->source,ptr->duration,ptr->weight);
      ptr = ptr->next;          expiration = 1;
      if(expiration) free(axe);                        }
     ptr = ptr->next;
           }      if(expiration) free(axe);
           sprintf(buf,"%s||\n",buf);
                   }
   //if(s) fprintf(s,"%d ACCEPTED FLOW from %s:d%d/w%d\n",num,newflow->source,newflow->duration,newflow->weight);           sprintf(buf,"%s||\n",buf);
         if(s) fprintf(s,"%s",buf);
       //if(s) fprintf(s,"%d ACCEPTED FLOW from %s:d%d/w%d\n",num,newflow->source,newflow->duration,newflow->weight);
           load += newflow->weight;         if(s) fprintf(s,"%s",buf);
           delta += newflow->weight;
           newflow->next = flows;                    load += newflow->weight;
           if(newflow->next) newflow->next->last = newflow;           delta += newflow->weight;
           flows = newflow;           newflow->next = flows;
           if(f) fprintf(f,"%d\n",load);           if(newflow->next) newflow->next->last = newflow;
       }           flows = newflow;
                     if(f) fprintf(f,"%d\n",load);
                 }
 // ADMISSION CONTROL
        // if we're overloaded, drop it or pass this on to a neighbor, mark it as such
        else if(exts < 5) {
       swaplinks_update_walk_length(swp,1);
       snprintf(msg,64,"%d;%d;%d;",newflow->duration,newflow->weight,exts+1);
       swaplinks_sendtoany(swp,msg,strlen(msg)+1,0);
       swaplinks_update_walk_length(swp,peers);
        }
         }
     }      }
     if(s) fprintf(s,"%d DONE RECEIVING\n",num);      if(s) fprintf(s,"%d DONE RECEIVING\n",num);
   
Line 103  void *recvthread(void *arg) { Line 115  void *recvthread(void *arg) {
   
 int main(int argc, char **argv) {  int main(int argc, char **argv) {
     struct sockaddr_ns reg;      struct sockaddr_ns reg;
     swaplinks_p swp;  
     char tmp[256];      char tmp[256];
   int time = 0, peers, duration, weight, sendcount = 0;    int time = 0, duration, weight, sendcount = 0;
     pthread_t tid;      pthread_t tid;
   
   if (argc >5) {    if (argc >6) {
         num = atoi(argv[1]);          num = atoi(argv[1]);
         peers = atoi(argv[2]);          peers = atoi(argv[2]);
         limit = atoi(argv[3]);          limit = atoi(argv[3]);
         duration = atoi(argv[4]);          duration = atoi(argv[4]);
         weight = atoi(argv[5]);          weight = atoi(argv[5]);
           maxload = atoi(argv[6]);
     }      }
     else {      else {
       printf("Usage:\n  slinks_variable_load node_number peers_number time_limit flow_duration flow_weight\n");        printf("Usage:\n  slinks_variable_load node_number peers_number time_limit flow_duration flow_weightmax_load\n");
         exit(1);          exit(1);
     }      }
   
Line 150  int main(int argc, char **argv) { Line 162  int main(int argc, char **argv) {
   
     sleep(1);      sleep(1);
   
   snprintf(tmp, sizeof(tmp), "%d;%d;", duration, weight);    snprintf(tmp, sizeof(tmp), "%d;%d;0;", duration, weight);
   
     while (time++ < 2*limit) { // (i-- != 0) {      while (time++ < 2*limit) { // (i-- != 0) {
         swaplinks_sendtoany(swp, tmp, strlen(tmp)+1, 0);          swaplinks_sendtoany(swp, tmp, strlen(tmp)+1, 0);

Removed from v.1.11  
changed lines
  Added in v.1.12


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