/* * void * handle_stdin * * Handle the standard input from the user and call the appropriate * functions */ void handle_stdin(char buff[80]) { char c; int i; /* If only one character is present */ if(sscanf(buff, "%c", &c) == 1) { switch(buff[0]) { case 'N': print_neighbors(); return; case 'T': print_routing_table(); return; case 'p': print_router(); return; } } /* To send messages */ if(sscanf(buff, "%d", &i) == 1) { if(i >= 0 && i<=19) send_msg(i); return; } /* Reject policy */ if(sscanf(buff, "R %d", &i) == 1) { if(i < 0 || i > 19) printf("Invalid router ID specified."); else if(router.is_border_router == FALSE) { printf("Reject commands can be run only on border routers.\n"); } else { printf("Router rejected: %d.", i); reject(i); } printf("\n\n"); fflush(stdout); return; } /* Prefer policy */ if(buff[0] == 'P') { if(router.is_border_router == FALSE) { printf("Commands to set preferred paths can be run only on \ border routers.\n\n"); fflush(stdout); return; } set_prefer_policy(buff); return; }
void print_routers(ccir_topo_t *topo) { uint32_t i = 0; debug(RDB_TOPO, "%s: count = %u", __func__, topo->num_routers); for (i = 0; i < topo->num_routers; i++) print_router(topo->routers[i]); return; }
int main(int argc, char *argv[]) { FILE* fwrite = fopen("topology","w+"); FILE* fdraw = fopen("draw_combine.dot","w+"); struct dirent *pDirEntry = NULL; DIR *pDir = NULL; if( (pDir = opendir("./")) == NULL ) { printf("opendir failed!\n"); return 1; } else { while( pDirEntry = readdir(pDir) ) { if ( strstr(pDirEntry->d_name, "out") && pDirEntry->d_name[0]=='o' && pDirEntry->d_name[1]=='u' && pDirEntry->d_name[2]=='t') { printf("输入文件:%s \n",pDirEntry->d_name); load_edge(pDirEntry->d_name); printf("------------------------------------\n"); } } closedir(pDir); } fprintf(fdraw, "digraph G {\n\t rankdir=LR;\n"); display_table(fwrite,fdraw); print_router(fdraw); fprintf(fdraw, "}"); fclose(fwrite); fclose(fdraw); cluster(); return 0; }