/* Set IOS image filename */ static int cmd_set_ios(hypervisor_conn_t *conn,int argc,char *argv[]) { vm_instance_t *vm; if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM))) return(-1); if (vm_ios_set_image(vm,argv[1]) == -1) { vm_release(vm); hypervisor_send_reply(conn,HSC_ERR_CREATE,1, "unable to store IOS image name for router '%s'", argv[0]); return(-1); } vm_release(vm); hypervisor_send_reply(conn,HSC_INFO_OK,1,"IOS image set for '%s'",argv[0]); return(0); }
/* Parse the command line */ static int parse_std_cmd_line(int argc,char *argv[]) { char *options_list = "r:o:n:c:m:l:C:i:jt:p:s:k:T:U:A:B:a:f:E:b:S:R:M:eXP:N:G:g:L:Z:"; vm_platform_t *platform; vm_instance_t *vm; int instance_id; int option; char *str; /* Get the instance ID */ instance_id = 0; /* Use the old VM file naming type */ vm_file_naming_type = 1; cli_load_plugins(argc,argv); if ((str = cli_find_option(argc,argv,"-i"))) { instance_id = atoi(str); printf("Instance ID set to %d.\n",instance_id); } if ((str = cli_find_option(argc,argv,"-N"))) vm_file_naming_type = atoi(str); /* Get the platform type */ if (!(platform = cli_get_platform_type(argc,argv))) exit(EXIT_FAILURE); /* Create the default instance */ if (!(vm = cli_create_instance("default",platform->name,instance_id))) exit(EXIT_FAILURE); opterr = 0; while((option = getopt_long(argc,argv,options_list, cmd_line_lopts,NULL)) != -1) { switch(option) { /* Initialize the GDB Stub to handle gdb protocol connections */ case 'Z': vm->gdb_port = strtol(optarg, NULL, 10); vm->gdb_server_running = TRUE; break; /* Instance ID (already managed) */ case 'i': break; /* Platform (already managed) */ case 'P': break; /* RAM size */ case 'r': vm->ram_size = strtol(optarg, NULL, 10); printf("Virtual RAM size set to %d MB.\n",vm->ram_size); break; /* ROM size */ case 'o': vm->rom_size = strtol(optarg, NULL, 10); printf("Virtual ROM size set to %d MB.\n",vm->rom_size); break; /* NVRAM size */ case 'n': vm->nvram_size = strtol(optarg, NULL, 10); printf("NVRAM size set to %d KB.\n",vm->nvram_size); break; /* Execution area size */ case OPT_EXEC_AREA: vm->exec_area_size = atoi(optarg); break; /* PCMCIA disk0 size */ case OPT_DISK0_SIZE: vm->pcmcia_disk_size[0] = atoi(optarg); printf("PCMCIA ATA disk0 size set to %u MB.\n", vm->pcmcia_disk_size[0]); break; /* PCMCIA disk1 size */ case OPT_DISK1_SIZE: vm->pcmcia_disk_size[1] = atoi(optarg); printf("PCMCIA ATA disk1 size set to %u MB.\n", vm->pcmcia_disk_size[1]); break; /* 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; /* Use sparse memory */ case OPT_SPARSE_MEM: vm->sparse_mem = TRUE; 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; /* Port settings */ case 'p': vm_slot_cmd_create(vm,optarg); break; /* NIO settings */ case 's': vm_slot_cmd_add_nio(vm,optarg); 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 /* Load plugin (already handled) */ case 'L': break; /* Oops ! */ case '?': show_usage(vm,argc,argv); exit(EXIT_FAILURE); /* Parse options specific to the platform */ default: if (vm->platform->cli_parse_options != NULL) if (vm->platform->cli_parse_options(vm,option) == -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(vm,argc,argv); exit(EXIT_FAILURE); } vm_release(vm); return(0); }
/* Parse the command line */ static int parse_std_cmd_line(int argc,char *argv[]) { char *options_list = "r:o:n:c:m:l:C:i:jt:p:s:k:T:U:A:B:a:f:E:b:S:R:M:eXP:N:G:g:L:I:"; vm_platform_t *platform; vm_instance_t *vm = NULL; int instance_id; int option; char *str; FILE *pid_file = NULL; // For saving the pid if requested /* Get the instance ID */ instance_id = 0; /* Use the old VM file naming type */ vm_file_naming_type = 1; cli_load_plugins(argc,argv); if ((str = cli_find_option(argc,argv,"-i"))) { instance_id = atoi(str); printf("Instance ID set to %d.\n",instance_id); } if ((str = cli_find_option(argc,argv,"-N"))) vm_file_naming_type = atoi(str); /* Get the platform type */ if (!(platform = cli_get_platform_type(argc,argv))) goto exit_failure; /* Create the default instance */ if (!(vm = cli_create_instance("default",platform->name,instance_id))) goto exit_failure; opterr = 0; vtty_set_ctrlhandler(1); /* By default allow ctrl ] */ vtty_set_telnetmsg(1); /* By default allow telnet message */ while((option = getopt_long(argc,argv,options_list, cmd_line_lopts,NULL)) != -1) { switch(option) { /* Instance ID (already managed) */ case 'i': break; /* Platform (already managed) */ case 'P': break; /* RAM size */ case 'r': vm->ram_size = strtol(optarg, NULL, 10); printf("Virtual RAM size set to %d MB.\n",vm->ram_size); break; /* ROM size */ case 'o': vm->rom_size = strtol(optarg, NULL, 10); printf("Virtual ROM size set to %d MB.\n",vm->rom_size); break; /* NVRAM size */ case 'n': vm->nvram_size = strtol(optarg, NULL, 10); printf("NVRAM size set to %d KB.\n",vm->nvram_size); break; /* PCMCIA disk0 size */ case OPT_DISK0_SIZE: vm->pcmcia_disk_size[0] = atoi(optarg); printf("PCMCIA ATA disk0 size set to %u MB.\n", vm->pcmcia_disk_size[0]); break; /* PCMCIA disk1 size */ case OPT_DISK1_SIZE: vm->pcmcia_disk_size[1] = atoi(optarg); printf("PCMCIA ATA disk1 size set to %u MB.\n", vm->pcmcia_disk_size[1]); break; case OPT_NOCTRL: vtty_set_ctrlhandler(0); /* Ignore ctrl ] */ printf("Block ctrl+] access to monitor console.\n"); break; /* 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 startup configuration file */ case 'C': case OPT_STARTUP_CONFIG_FILE: vm_ios_set_config(vm,optarg,vm->ios_private_config); break; /* IOS private configuration file */ case OPT_PRIVATE_CONFIG_FILE: vm_ios_set_config(vm,vm->ios_startup_config,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': free(vm->ghost_ram_filename); vm->ghost_ram_filename = strdup(optarg); vm->ghost_status = VM_GHOST_RAM_USE; break; /* Generate a ghost RAM image */ case 'g': free(vm->ghost_ram_filename); vm->ghost_ram_filename = strdup(optarg); vm->ghost_status = VM_GHOST_RAM_GENERATE; break; /* Use sparse memory */ case OPT_SPARSE_MEM: vm->sparse_mem = TRUE; break; /* Alternate ROM */ case 'R': vm->rom_filename = optarg; break; case OPT_NOTELMSG: vtty_set_telnetmsg(0); /* disable telnet greeting */ printf("Prevent telnet message on AUX/CONSOLE connecte.\n"); break; case OPT_FILEPID: if ((pid_file = fopen(optarg,"w"))) { fprintf(pid_file,"%d",getpid()); fclose(pid_file); } else { printf("Unable to save to %s.\n",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"); goto 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 = realloc(log_file_name, strlen(optarg)+1))) { fprintf(stderr,"Unable to set log file name.\n"); goto exit_failure; } strcpy(log_file_name, optarg); 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"); goto 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"); goto exit_failure; } break; /* Port settings */ case 'p': vm_slot_cmd_create(vm,optarg); break; /* NIO settings */ case 's': vm_slot_cmd_add_nio(vm,optarg); break; /* Virtual ATM switch */ case 'a': if (atmsw_start(optarg) == -1) goto exit_failure; break; /* Virtual ATM bridge */ case 'M': if (atm_bridge_start(optarg) == -1) goto exit_failure; break; /* Virtual Frame-Relay switch */ case 'f': if (frsw_start(optarg) == -1) goto exit_failure; break; /* Virtual Ethernet switch */ case 'E': if (ethsw_start(optarg) == -1) goto exit_failure; break; /* Virtual bridge */ case 'b': if (netio_bridge_start(optarg) == -1) goto exit_failure; break; #ifdef GEN_ETH /* Ethernet device list */ case 'e': gen_eth_show_dev_list(); goto exit_success; #endif /* Load plugin (already handled) */ case 'L': break; /* Oops ! */ case '?': show_usage(vm,argc,argv); goto exit_failure; /* Parse options specific to the platform */ default: if (vm->platform->cli_parse_options != NULL) /* If you get an option wrong, say which option is was */ /* Wont be pretty for a long option, but it will at least help */ if (vm->platform->cli_parse_options(vm,option) == -1) { printf("Flag not recognised: -%c\n",(char)option); goto 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(vm,argc,argv); goto exit_failure; } vm_release(vm); return(0); exit_success: if (vm) { vm_release(vm); vm_delete_instance("default"); } exit(EXIT_SUCCESS); return(-1); exit_failure: if (vm) { vm_release(vm); vm_delete_instance("default"); } exit(EXIT_FAILURE); return(-1); }