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.20 and 1.21

version 1.20, 2007/07/11 04:31:46 version 1.21, 2007/07/12 16:40:13
Line 13 Line 13
 #define snprintf   _snprintf  #define snprintf   _snprintf
 #endif  #endif
   
   #define clear(a) a[0]=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 REDUNDANCY (4*(100/percent))
   
 int count_char(char*,char);  
   
 typedef struct flow {  typedef struct flow {
     int duration;      int duration;
     int weight;      int weight;
Line 26  typedef struct flow {  Line 26  typedef struct flow { 
     struct flow *next, *last;      struct flow *next, *last;
 } flow_t;  } flow_t;
   
   typedef struct int_pair_t { int i; int o; } int_pair;
   
   int_pair process_neighbor_list(char*);
   
 int num, peers, limit, maxload;  int num, peers, limit, maxload;
 swaplinks_p swp;  swaplinks_p swp;
 FILE *f = NULL, *s = NULL, *g = NULL;  FILE *f = NULL, *s = NULL, *g = NULL;
Line 103  void *recvthread(void *arg) {  Line 107  void *recvthread(void *arg) { 
      fprintf(s,"        %d rejected flow, load too high: %d <= %d\n",num,maxload,load+newflow->weight);       fprintf(s,"        %d rejected flow, load too high: %d <= %d\n",num,maxload,load+newflow->weight);
      swaplinks_update_walk_length(swp,1);       swaplinks_update_walk_length(swp,1);
      snprintf(msg,64,"%d;%d;%d;",newflow->duration,newflow->weight,exts+1);       snprintf(msg,64,"%d;%d;%d;",newflow->duration,newflow->weight,exts+1);
    swaplinks_sendtoany(swp,msg,strlen(msg)+1,0);     swaplinks_sendtoany(swp,msg,strlenn(msg)+1,0);
      swaplinks_update_walk_length(swp,peers);       swaplinks_update_walk_length(swp,peers);
       }        }
       else        else
Line 127  int main(int argc, char **argv) {  Line 131  int main(int argc, char **argv) { 
     struct sockaddr_ns reg;      struct sockaddr_ns reg;
     char tmp[256], nbrs[4096];      char tmp[256], nbrs[4096];
     int time = 0, duration, weight, percent, sendcount = 0;      int time = 0, duration, weight, percent, sendcount = 0;
       int_pair p;
     pthread_t tid;      pthread_t tid;
   
     if (argc > 6) {      if (argc > 6) {
Line 144  int main(int argc, char **argv) {  Line 149  int main(int argc, char **argv) { 
     }      }
   
     snprintf(tmp, sizeof(tmp), "test%d", num);      snprintf(tmp, sizeof(tmp), "test%d", num);
   nutss_config_set(NUTSS_CONFIG_USERNAME, tmp, strlen(tmp));    nutss_config_set(NUTSS_CONFIG_USERNAME, tmp, strlenn(tmp));
   nutss_config_set(NUTSS_CONFIG_PROXYUSERNAME, tmp, strlen(tmp));    nutss_config_set(NUTSS_CONFIG_PROXYUSERNAME, tmp, strlenn(tmp));
   nutss_config_set(NUTSS_CONFIG_PROXYPASSWORD, tmp, strlen(tmp));    nutss_config_set(NUTSS_CONFIG_PROXYPASSWORD, tmp, strlenn(tmp));
     strncpy(tmp, "nutss.net", sizeof(tmp));      strncpy(tmp, "nutss.net", sizeof(tmp));
   nutss_config_set(NUTSS_CONFIG_DOMAINNAME, tmp, strlen(tmp));    nutss_config_set(NUTSS_CONFIG_DOMAINNAME, tmp, strlenn(tmp));
     strncpy(tmp, "sip.nutss.net:5060", sizeof(tmp));      strncpy(tmp, "sip.nutss.net:5060", sizeof(tmp));
   nutss_config_set(NUTSS_CONFIG_SIGPROXY, tmp, strlen(tmp));    nutss_config_set(NUTSS_CONFIG_SIGPROXY, tmp, strlenn(tmp));
   
     sprintf(tmp, "output/data_node%d.txt", num); f = fopen(tmp,"w");      sprintf(tmp, "output/data_node%d.txt", num); f = fopen(tmp,"w");
 //    sprintf(tmp, "output/output_node%d.txt", num); s = fopen(tmp,"w");  //    sprintf(tmp, "output/output_node%d.txt", num); s = fopen(tmp,"w");
Line 179  int main(int argc, char **argv) {  Line 184  int main(int argc, char **argv) { 
   
     snprintf(tmp, sizeof(tmp), "%d;%d;0;", duration, weight);      snprintf(tmp, sizeof(tmp), "%d;%d;0;", duration, weight);
   
   while (time++ < REDUNDANCY*limit) { // (i-- != 0) {    while (time++ < REDUNDANCY*limit) {
       if(randint(100) < percent) swaplinks_sendtoany(swp, tmp, strlen(tmp)+1, 0);        if(randint(100) < percent) 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);
       if(g) fprintf(g,"%d\n",count_char(nbrs,','));        p = process_neighbor_list(nbrs);
       nbrs[0] = 0;        if(g) fprintf(g,"%d%d\n",p.i,p.o);
         clear(nbrs);
         sleep(1);          sleep(1);
     }      }
   
Line 198  int main(int argc, char **argv) {  Line 204  int main(int argc, char **argv) { 
     return 0;      return 0;
 }  }
   
int count_char(char *s, char h) { int_pair process_neighbor_list(char *s) {
   inti, l = strlen(s), c = 0;    int_pair p;
   for(i = 0; i < l; i++)    char *t,*v;
       if(s[i] ==h) c++;    t = strtok(s,",");
   returnc;    do {
         s += strlenn(t)+1;
         v = strtok(t,":");
         t += strlenn(v)+1;
         if(*t =='i') p.i++;
         else if(t && *t == 'o') p.o++;
     } while(t = strtok(s,","));
     returnp;
 }  }

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


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