📄 dynamips.c
字号:
/* Config Register */ case 'c': vm->conf_reg_setup = strtol(optarg, NULL, 0); printf("Config. Register set to 0x%x.\n",vm->conf_reg_setup); break; /* IOS configuration file */ case 'C': vm_ios_set_config(vm,optarg); break; /* Use physical memory to emulate RAM (no-mapped file) */ case 'X': vm->ram_mmap = 0; break; /* Use a ghost file to simulate RAM */ case 'G': vm->ghost_ram_filename = strdup(optarg); vm->ghost_status = VM_GHOST_RAM_USE; break; /* Generate a ghost RAM image */ case 'g': vm->ghost_ram_filename = strdup(optarg); vm->ghost_status = VM_GHOST_RAM_GENERATE; break; /* Alternate ROM */ case 'R': vm->rom_filename = optarg; break; /* Idle PC */ case OPT_IDLE_PC: vm->idle_pc = strtoull(optarg,NULL,0); printf("Idle PC set to 0x%llx.\n",vm->idle_pc); break; /* Timer IRQ check interval */ case OPT_TIMER_ITV: vm->timer_irq_check_itv = atoi(optarg); break; /* Clock divisor */ case 'k': vm->clock_divisor = atoi(optarg); if (!vm->clock_divisor) { fprintf(stderr,"Invalid Clock Divisor specified!\n"); exit(EXIT_FAILURE); } printf("Using a clock divisor of %d.\n",vm->clock_divisor); break; /* Disable JIT */ case 'j': vm->jit_use = FALSE; break; /* VM debug level */ case OPT_VM_DEBUG: vm->debug_level = atoi(optarg); break; /* Log file */ case 'l': if (!(log_file_name = strdup(optarg))) { fprintf(stderr,"Unable to set log file name.\n"); exit(EXIT_FAILURE); } printf("Log file: writing to %s\n",log_file_name); break;#if DEBUG_SYM_TREE /* Symbol file */ case 'S': vm->sym_filename = strdup(optarg); break;#endif /* TCP server for Console Port */ case 'T': vm->vtty_con_type = VTTY_TYPE_TCP; vm->vtty_con_tcp_port = atoi(optarg); break; /* Serial interface for Console port */ case 'U': vm->vtty_con_type = VTTY_TYPE_SERIAL; if (vtty_parse_serial_option(&vm->vtty_con_serial_option,optarg)) { fprintf(stderr, "Invalid Console serial interface descriptor!\n"); exit(EXIT_FAILURE); } break; /* TCP server for AUX Port */ case 'A': vm->vtty_aux_type = VTTY_TYPE_TCP; vm->vtty_aux_tcp_port = atoi(optarg); break; /* Serial interface for AUX port */ case 'B': vm->vtty_aux_type = VTTY_TYPE_SERIAL; if (vtty_parse_serial_option(&vm->vtty_aux_serial_option,optarg)) { fprintf(stderr,"Invalid AUX serial interface descriptor!\n"); exit(EXIT_FAILURE); } break; /* Virtual ATM switch */ case 'a': if (atmsw_start(optarg) == -1) exit(EXIT_FAILURE); break; /* Virtual Frame-Relay switch */ case 'f': if (frsw_start(optarg) == -1) exit(EXIT_FAILURE); break; /* Virtual Ethernet switch */ case 'E': if (ethsw_start(optarg) == -1) exit(EXIT_FAILURE); break; /* Virtual bridge */ case 'b': if (netio_bridge_start(optarg) == -1) exit(EXIT_FAILURE); break;#ifdef GEN_ETH /* Ethernet device list */ case 'e': gen_eth_show_dev_list(); exit(EXIT_SUCCESS); #endif /* Oops ! */ case '?': show_usage(argc,argv,*platform); exit(EXIT_FAILURE); /* Parse options specific to the platform */ default: res = 0; switch(vm->type) { case VM_TYPE_C7200: res = cli_parse_c7200_options(vm,option); break; case VM_TYPE_C3600: res = cli_parse_c3600_options(vm,option); break; case VM_TYPE_C2691: res = cli_parse_c2691_options(vm,option); break; case VM_TYPE_C3725: res = cli_parse_c3725_options(vm,option); break; case VM_TYPE_C3745: res = cli_parse_c3745_options(vm,option); break; } if (res == -1) exit(EXIT_FAILURE); } } /* Last argument, this is the IOS filename */ if (optind == (argc - 1)) { /* setting IOS image file */ vm_ios_set_image(vm,argv[optind]); printf("IOS image file: %s\n\n",vm->ios_image); } else { /* IOS missing */ fprintf(stderr,"Please specify an IOS image filename\n"); show_usage(argc,argv,*platform); exit(EXIT_FAILURE); } vm_release(vm); return(0);}/* * Run in hypervisor mode with a config file if the "-H" option * is present in command line. */static int run_hypervisor(int argc,char *argv[]){ char *options_list = "H:l:hN:"; int i,option; for(i=1;i<argc;i++) if (!strcmp(argv[i],"-H")) { hypervisor_mode = 1; break; } /* standard mode with one instance */ if (!hypervisor_mode) return(FALSE); opterr = 0; while((option = getopt(argc,argv,options_list)) != -1) { switch(option) { /* Hypervisor TCP port */ case 'H': hypervisor_tcp_port = atoi(optarg); break; /* Log file */ case 'l': if (!(log_file_name = malloc(strlen(optarg)+1))) { fprintf(stderr,"Unable to set log file name.\n"); exit(EXIT_FAILURE); } strcpy(log_file_name, optarg); printf("Log file: writing to %s\n",log_file_name); break; /* VM file naming type */ case 'N': vm_file_naming_type = atoi(optarg); break; /* Oops ! */ case '?': show_usage(argc,argv,VM_TYPE_C7200); exit(EXIT_FAILURE); } } return(TRUE);}/* Delete all objects */void dynamips_reset(void){ printf("Shutdown in progress...\n"); /* Delete all virtual router instances */ c7200_delete_all_instances(); c3600_delete_all_instances(); c2691_delete_all_instances(); c3725_delete_all_instances(); c3745_delete_all_instances(); /* Delete ATM and Frame-Relay switches + bridges */ netio_bridge_delete_all(); atmsw_delete_all(); frsw_delete_all(); ethsw_delete_all(); /* Delete all NIO descriptors */ netio_delete_all(); printf("Shutdown completed.\n");}int main(int argc,char *argv[]){ vm_instance_t *vm; int platform,res; /* Default emulation: Cisco 7200 */ platform = VM_TYPE_C7200;#ifdef PROFILE atexit(profiler_savestat);#endif printf("Cisco 7200 Simulation Platform (version %s)\n",sw_version); printf("Copyright (c) 2005,2006 Christophe Fillot.\n"); printf("Build date: %s %s\n\n",__DATE__,__TIME__); /* Initialize timers */ timer_init(); /* Initialize object registry */ registry_init(); /* Initialize ATM module (for HEC checksums) */ atm_init(); /* Initialize CRC functions */ crc_init(); /* Initialize NetIO code */ netio_rxl_init(); /* Initialize NetIO packet filters */ netio_filter_load_all(); /* Initialize VTTY code */ vtty_init(); /* Parse standard command line */ if (!run_hypervisor(argc,argv)) parse_std_cmd_line(argc,argv,&platform); /* Create general log file */ create_log_file(); /* Periodic tasks initialization */ if (ptask_init(0) == -1) exit(EXIT_FAILURE); /* Create instruction lookup tables */ mips64_jit_create_ilt(); mips64_exec_create_ilt(); setup_signals(); if (!hypervisor_mode) { /* Initialize the default instance */ vm = vm_acquire("default"); assert(vm != NULL); switch(platform) { case VM_TYPE_C7200: res = c7200_init_instance(VM_C7200(vm)); break; case VM_TYPE_C3600: res = c3600_init_instance(VM_C3600(vm)); break; case VM_TYPE_C2691: res = c2691_init_instance(VM_C2691(vm)); break; case VM_TYPE_C3725: res = c3725_init_instance(VM_C3725(vm)); break; case VM_TYPE_C3745: res = c3745_init_instance(VM_C3745(vm)); break; default: res = -1; } if (res == -1) { fprintf(stderr,"Unable to initialize router instance.\n"); exit(EXIT_FAILURE); }#if DEBUG_PERF_COUNTER { m_uint64_t prev = 0,delta; while(vm->status == VM_STATUS_RUNNING) { delta = vm->boot_cpu->perf_counter - prev; prev = vm->boot_cpu->perf_counter; printf("delta = %llu\n",delta); sleep(1); } }#else /* Start instance monitoring */ vm_monitor(vm);#endif /* Free resources used by instance */ vm_release(vm); } else { hypervisor_tcp_server(hypervisor_tcp_port); } dynamips_reset(); close_log_file(); return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -