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.21 and 1.22

version 1.21, 2007/07/12 16:40:13 version 1.22, 2007/07/12 18:52:38
Line 17 Line 17
 #define strlenn(s) (s) ? strlen(s) : 0  #define strlenn(s) (s) ? strlen(s) : 0
 #define randint(N) ((int)(rand() / (((double)RAND_MAX + 1) / (N))))  #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(4*(100/percent)) #define REDUNDANCY4
   
 typedef struct flow {  typedef struct flow {
     int duration;      int duration;
Line 42  void *recvthread(void *arg) {  Line 42  void *recvthread(void *arg) { 
     char msg[64], tmp[128], buf[2048];      char msg[64], tmp[128], buf[2048];
     int time = 0, load = 0, exts, delta, expiration;      int time = 0, load = 0, exts, delta, expiration;
   
   buf[0] = 0;    clear(buf);
   
     while(time < limit) {      while(time < limit) {
        if(swaplinks_recvfrom(swp, tmp, sizeof(tmp), 0, &peer, &len) > 0) {         if(swaplinks_recvfrom(swp, tmp, sizeof(tmp), 0, &peer, &len) > 0) {
Line 82  void *recvthread(void *arg) {  Line 82  void *recvthread(void *arg) { 
    assert(flows == ptr);     assert(flows == ptr);
    flows = NULL;     flows = NULL;
     }      }
      //if(s) fprintf(s,"%d EXPIRED FLOW from %s:d%d/w%d\n",num,ptr->source,ptr->duration,ptr->weight); //if(s) fprintf(s,"%d EXPIRED FLOW from %s:d%d/w%d\n",num,ptr->source,ptr->duration,ptr->weight);
     expiration = 1;      expiration = 1;
      }       }
      ptr = ptr->next;       ptr = ptr->next;
Line 90  void *recvthread(void *arg) {  Line 90  void *recvthread(void *arg) { 
       }        }
       sprintf(buf,"%s||\n",buf);        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); //               if(s) fprintf(s,"%d ACCEPTED FLOW from %s:d%d/w%d\n",num,newflow->source,newflow->duration,newflow->weight);
       // if this flow will not put us overbudget, accept        // if this flow will not put us overbudget, accept
       if(load+newflow->weight <= maxload) {        if(load+newflow->weight <= maxload) {
      load += newflow->weight;       load += newflow->weight;
Line 134  int main(int argc, char **argv) {  Line 134  int main(int argc, char **argv) { 
     int_pair p;      int_pair p;
     pthread_t tid;      pthread_t tid;
   
   if (argc >6) {    if (argc >7) {
         num = atoi(argv[1]);          num = atoi(argv[1]);
         peers = atoi(argv[2]);          peers = atoi(argv[2]);
         limit = atoi(argv[3]);          limit = atoi(argv[3]);
Line 182  int main(int argc, char **argv) {  Line 182  int main(int argc, char **argv) { 
   
 //    sleep(2);  //    sleep(2);
   
     snprintf(tmp, sizeof(tmp), "%d;%d;0;", duration, weight);  
   
     while (time++ < REDUNDANCY*limit) {      while (time++ < REDUNDANCY*limit) {
       if(randint(100) < percent)swaplinks_sendtoany(swp, tmp, strlenn(tmp)+1, 0);        if(randint(100) < percent)snprintf(tmp, sizeof(tmp), "%d;%d;0;", duration, 0);
         else snprintf(tmp, sizeof(tmp), "%d;%d;0;", duration, weight);
         swaplinks_sendtoany(swp, tmp, strlenn(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);
         p = process_neighbor_list(nbrs);          p = process_neighbor_list(nbrs);
Line 205  int main(int argc, char **argv) {  Line 205  int main(int argc, char **argv) { 
 }  }
   
 int_pair process_neighbor_list(char *s) {  int_pair process_neighbor_list(char *s) {
   int_pair p;    int_pair p= { 0, 0 };
     char *t,*v;      char *t,*v;
   t = strtok(s,",");
   do {    if(!s) return p;
       s += strlenn(t)+1;    while(*s) {
       v = strtok(t,":");        if(*s++ == '_') {
       t += strlenn(v)+1;            switch(*s++) {
       if(*t == 'i') p.i++;                case 'i': p.i++;break;
else if(t && *t == 'o') p.o++;                case 'o': p.o++;break;
} while(t = strtok(s,","));                default: exit(s[-1]);
             }
         }
     }
     return p;      return p;
   /*
       if(s) {
           t = strtok(s,",");
           do {
               s += strlenn(t)+1;
               v = strtok(t,":");
               t += strlenn(v)+1;
               if(t && *t == 'i') p.i++;
               else if(t && *t == 'o') p.o++;
           } while(t = strtok(s,","));
       }
   */
 }  }

Removed from v.1.21  
changed lines
  Added in v.1.22


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