/* * Switch simulator */ #define ADDRESS_MAX 5 #define NUM_PACKETS 1000 #include #include void create_traffic (void); int main(int argc, char **argv) { FILE *SEG1; FILE *HOSTS; int i,j,to,from,to_tmp,from_tmp,bridge; int (*bridges)[]; /* generates ficticious traffic */ create_traffic(); SEG1 = fopen("switch.dat","r"); HOSTS = fopen("host.conf","r"); for(i=1;i<=NUM_PACKETS;i++) { fscanf(SEG1,"%d %d",&to,&from); while(fscanf(HOSTS,"%d %d %d",&from_tmp,&to_tmp,&bridge) != EOF) { if (to == to_tmp && from == from_tmp) { printf("Traffic from %d to %d routed through %d\n",from,to,bridge); } } rewind(HOSTS); } fclose(SEG1); fclose(HOSTS); return 0; } void create_traffic (void) { FILE *SEG1 = fopen("switch.dat","w"); int i; int num1,num2; for (i=0;i<=NUM_PACKETS;i++) { srand(rand()); num1 = 1 + (rand() % ADDRESS_MAX); num2 = 1 + (rand() % ADDRESS_MAX); while (num2 == num1 || num2 == 0) { num2 = 1 + rand() % ADDRESS_MAX; } (void) fprintf(SEG1,"%d %d\n",num1,num2); fflush(SEG1); } fclose(SEG1); }