--- upstream/dynamips-0.2.5/hypervisor.c 2007/10/06 16:01:44 1 +++ upstream/dynamips-0.2.8-RC1/hypervisor.c 2007/10/06 16:33:40 11 @@ -1,5 +1,5 @@ /* - * Cisco 7200 (Predator) simulation platform. + * Cisco router simulation platform. * Copyright (c) 2006 Christophe Fillot (cf@utc.fr) * * Hypervisor routines. @@ -32,10 +32,16 @@ #include "parser.h" #include "net.h" #include "registry.h" -#include "mips64.h" +#include "cpu.h" +#include "vm.h" #include "dynamips.h" #include "dev_c7200.h" #include "dev_c3600.h" +#include "dev_c2691.h" +#include "dev_c3725.h" +#include "dev_c3745.h" +#include "dev_c2600.h" +#include "dev_c1700.h" #include "hypervisor.h" #include "net_io.h" #include "net_io_bridge.h" @@ -58,6 +64,20 @@ return(0); } +/* Parser test */ +static int cmd_parser_test(hypervisor_conn_t *conn,int argc,char *argv[]) +{ + int i; + + for(i=0;icur_module->opt; vm_instance_t *vm; if (!(vm = vm_acquire(name))) { @@ -229,11 +250,11 @@ return NULL; } - if (vm->type != vm_type) { + if (vm->platform != platform) { vm_release(vm); hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1, - "VM '%s' is not a VM type %d", - name,vm_type); + "VM '%s' is not a VM type %s", + name,platform->name); return NULL; } @@ -241,7 +262,7 @@ } /* Register a module */ -hypervisor_module_t *hypervisor_register_module(char *name) +hypervisor_module_t *hypervisor_register_module(char *name,void *opt) { hypervisor_module_t *m; @@ -256,6 +277,7 @@ } m->name = name; + m->opt = opt; m->cmd_list = NULL; m->next = module_list; @@ -318,6 +340,8 @@ return(-1); } + conn->cur_module = module; + return(cmd->handler(conn,argc,argv)); } @@ -325,51 +349,61 @@ static void *hypervisor_thread(void *arg) { hypervisor_conn_t *conn = arg; - char buffer[4096],**tokens; - parser_token_t *tok_list; - int res,tok_count; + char buffer[512],**tokens; + parser_context_t ctx; + int res; + tokens = NULL; + parser_context_init(&ctx); + while(conn->active) { - if (!m_fgets(buffer,sizeof(buffer),conn->in)) + if (!fgets(buffer,sizeof(buffer),conn->in)) break; if (!*buffer) continue; /* Tokenize command line */ - tokens = NULL; - res = parser_tokenize(buffer,&tok_list,&tok_count); + res = parser_scan_buffer(&ctx,buffer,strlen(buffer)); - if (res != 0) { - hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"Parse error: %s", - parser_strerror(res)); - continue; - } + if (res != 0) { + tokens = NULL; - if (tok_count < 2) { - hypervisor_send_reply(conn,HSC_ERR_PARSING,1, - "At least a module and a command " - "must be specified"); - goto free_tokens; - } + if (ctx.error != 0) { + hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"Parse error: %s", + parser_strerror(&ctx)); + goto free_tokens; + } + + if (ctx.tok_count < 2) { + hypervisor_send_reply(conn,HSC_ERR_PARSING,1, + "At least a module and a command " + "must be specified"); + goto free_tokens; + } - /* Map token list to an array */ - tokens = parser_map_array(tok_list,tok_count); + /* Map token list to an array */ + tokens = parser_map_array(&ctx); - if (!tokens) { - hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"No memory"); - goto free_tokens; - } - - /* Execute command */ - m_log("hypervisor_exec","%s\n",buffer); - hypervisor_exec_cmd(conn,tokens[0],tokens[1],tok_count-2,&tokens[2]); + if (!tokens) { + hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"No memory"); + goto free_tokens; + } + + /* Execute command */ + //m_log("hypervisor_exec","%s\n",buffer); + hypervisor_exec_cmd(conn,tokens[0],tokens[1],ctx. + tok_count-2,&tokens[2]); - free_tokens: - free(tokens); - parser_free_tokens(tok_list); + free_tokens: + free(tokens); + tokens = NULL; + parser_context_free(&ctx); + } } + free(tokens); + parser_context_free(&ctx); return NULL; } @@ -383,7 +417,7 @@ { hypervisor_module_t *module; - module = hypervisor_register_module("hypervisor"); + module = hypervisor_register_module("hypervisor",NULL); assert(module != NULL); hypervisor_register_cmd_array(module,hypervisor_cmd_array); @@ -501,7 +535,7 @@ } /* Hypervisor TCP server */ -int hypervisor_tcp_server(int tcp_port) +int hypervisor_tcp_server(char *ip_addr,int tcp_port) { int fd_array[HYPERVISOR_MAX_FD]; struct sockaddr_storage remote_addr; @@ -518,15 +552,15 @@ hypervisor_atmsw_init(); hypervisor_ethsw_init(); hypervisor_vm_init(); - hypervisor_c7200_init(); - hypervisor_c3600_init(); + hypervisor_vm_debug_init(); signal(SIGPIPE,sigpipe_handler); if (!tcp_port) tcp_port = HYPERVISOR_TCP_PORT; - fd_count = ip_listen(tcp_port,SOCK_STREAM,HYPERVISOR_MAX_FD,fd_array); + fd_count = ip_listen(ip_addr,tcp_port,SOCK_STREAM, + HYPERVISOR_MAX_FD,fd_array); if (fd_count <= 0) { fprintf(stderr,"Hypervisor: unable to create TCP sockets.\n"); @@ -534,7 +568,7 @@ } /* Start accepting connections */ - printf("Hypervisor TCP control server started.\n"); + printf("Hypervisor TCP control server started (port %d).\n",tcp_port); hypervisor_running = TRUE; while(hypervisor_running) {