36 |
#include "dynamips.h" |
#include "dynamips.h" |
37 |
#include "dev_c7200.h" |
#include "dev_c7200.h" |
38 |
#include "dev_c3600.h" |
#include "dev_c3600.h" |
39 |
|
#include "dev_c2691.h" |
40 |
|
#include "dev_c3725.h" |
41 |
|
#include "dev_c3745.h" |
42 |
#include "hypervisor.h" |
#include "hypervisor.h" |
43 |
#include "net_io.h" |
#include "net_io.h" |
44 |
#include "net_io_bridge.h" |
#include "net_io_bridge.h" |
61 |
return(0); |
return(0); |
62 |
} |
} |
63 |
|
|
64 |
|
/* Parser test */ |
65 |
|
static int cmd_parser_test(hypervisor_conn_t *conn,int argc,char *argv[]) |
66 |
|
{ |
67 |
|
int i; |
68 |
|
|
69 |
|
for(i=0;i<argc;i++) |
70 |
|
hypervisor_send_reply(conn,HSC_INFO_MSG,0, |
71 |
|
"arg %d (len %u): \"%s\"", |
72 |
|
i,strlen(argv[i]),argv[i]); |
73 |
|
|
74 |
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
75 |
|
return(0); |
76 |
|
} |
77 |
|
|
78 |
/* Show hypervisor module list */ |
/* Show hypervisor module list */ |
79 |
static int cmd_mod_list(hypervisor_conn_t *conn,int argc,char *argv[]) |
static int cmd_mod_list(hypervisor_conn_t *conn,int argc,char *argv[]) |
80 |
{ |
{ |
136 |
netio_bridge_save_config_all(fd); |
netio_bridge_save_config_all(fd); |
137 |
c7200_save_config_all(fd); |
c7200_save_config_all(fd); |
138 |
c3600_save_config_all(fd); |
c3600_save_config_all(fd); |
139 |
|
c2691_save_config_all(fd); |
140 |
|
c3725_save_config_all(fd); |
141 |
|
c3745_save_config_all(fd); |
142 |
|
|
143 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
144 |
return(0); |
return(0); |
171 |
/* Hypervisor commands */ |
/* Hypervisor commands */ |
172 |
static hypervisor_cmd_t hypervisor_cmd_array[] = { |
static hypervisor_cmd_t hypervisor_cmd_array[] = { |
173 |
{ "version", 0, 0, cmd_version, NULL }, |
{ "version", 0, 0, cmd_version, NULL }, |
174 |
|
{ "parser_test", 0, 10, cmd_parser_test, NULL }, |
175 |
{ "module_list", 0, 0, cmd_mod_list, NULL }, |
{ "module_list", 0, 0, cmd_mod_list, NULL }, |
176 |
{ "cmd_list", 1, 1, cmd_modcmd_list, NULL }, |
{ "cmd_list", 1, 1, cmd_modcmd_list, NULL }, |
177 |
{ "working_dir", 1, 1, cmd_set_working_dir, NULL }, |
{ "working_dir", 1, 1, cmd_set_working_dir, NULL }, |
346 |
static void *hypervisor_thread(void *arg) |
static void *hypervisor_thread(void *arg) |
347 |
{ |
{ |
348 |
hypervisor_conn_t *conn = arg; |
hypervisor_conn_t *conn = arg; |
349 |
char buffer[4096],**tokens; |
char buffer[512],**tokens; |
350 |
parser_token_t *tok_list; |
parser_context_t ctx; |
351 |
int res,tok_count; |
int res; |
352 |
|
|
353 |
|
tokens = NULL; |
354 |
|
parser_context_init(&ctx); |
355 |
|
|
356 |
while(conn->active) { |
while(conn->active) { |
357 |
if (!m_fgets(buffer,sizeof(buffer),conn->in)) |
if (!fgets(buffer,sizeof(buffer),conn->in)) |
358 |
break; |
break; |
359 |
|
|
360 |
if (!*buffer) |
if (!*buffer) |
361 |
continue; |
continue; |
362 |
|
|
363 |
/* Tokenize command line */ |
/* Tokenize command line */ |
364 |
tokens = NULL; |
res = parser_scan_buffer(&ctx,buffer,strlen(buffer)); |
|
res = parser_tokenize(buffer,&tok_list,&tok_count); |
|
365 |
|
|
366 |
if (res != 0) { |
if (res != 0) { |
367 |
hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"Parse error: %s", |
tokens = NULL; |
|
parser_strerror(res)); |
|
|
continue; |
|
|
} |
|
368 |
|
|
369 |
if (tok_count < 2) { |
if (ctx.error != 0) { |
370 |
hypervisor_send_reply(conn,HSC_ERR_PARSING,1, |
hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"Parse error: %s", |
371 |
"At least a module and a command " |
parser_strerror(&ctx)); |
372 |
"must be specified"); |
goto free_tokens; |
373 |
goto free_tokens; |
} |
374 |
} |
|
375 |
|
if (ctx.tok_count < 2) { |
376 |
|
hypervisor_send_reply(conn,HSC_ERR_PARSING,1, |
377 |
|
"At least a module and a command " |
378 |
|
"must be specified"); |
379 |
|
goto free_tokens; |
380 |
|
} |
381 |
|
|
382 |
/* Map token list to an array */ |
/* Map token list to an array */ |
383 |
tokens = parser_map_array(tok_list,tok_count); |
tokens = parser_map_array(&ctx); |
384 |
|
|
385 |
if (!tokens) { |
if (!tokens) { |
386 |
hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"No memory"); |
hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"No memory"); |
387 |
goto free_tokens; |
goto free_tokens; |
388 |
} |
} |
389 |
|
|
390 |
/* Execute command */ |
/* Execute command */ |
391 |
m_log("hypervisor_exec","%s\n",buffer); |
//m_log("hypervisor_exec","%s\n",buffer); |
392 |
hypervisor_exec_cmd(conn,tokens[0],tokens[1],tok_count-2,&tokens[2]); |
hypervisor_exec_cmd(conn,tokens[0],tokens[1],ctx. |
393 |
|
tok_count-2,&tokens[2]); |
394 |
|
|
395 |
free_tokens: |
free_tokens: |
396 |
free(tokens); |
free(tokens); |
397 |
parser_free_tokens(tok_list); |
tokens = NULL; |
398 |
|
parser_context_free(&ctx); |
399 |
|
} |
400 |
} |
} |
401 |
|
|
402 |
|
free(tokens); |
403 |
|
parser_context_free(&ctx); |
404 |
return NULL; |
return NULL; |
405 |
} |
} |
406 |
|
|
549 |
hypervisor_atmsw_init(); |
hypervisor_atmsw_init(); |
550 |
hypervisor_ethsw_init(); |
hypervisor_ethsw_init(); |
551 |
hypervisor_vm_init(); |
hypervisor_vm_init(); |
552 |
|
hypervisor_vm_debug_init(); |
553 |
hypervisor_c7200_init(); |
hypervisor_c7200_init(); |
554 |
hypervisor_c3600_init(); |
hypervisor_c3600_init(); |
555 |
|
hypervisor_c2691_init(); |
556 |
|
hypervisor_c3725_init(); |
557 |
|
hypervisor_c3745_init(); |
558 |
|
|
559 |
signal(SIGPIPE,sigpipe_handler); |
signal(SIGPIPE,sigpipe_handler); |
560 |
|
|
569 |
} |
} |
570 |
|
|
571 |
/* Start accepting connections */ |
/* Start accepting connections */ |
572 |
printf("Hypervisor TCP control server started.\n"); |
printf("Hypervisor TCP control server started (port %d).\n",tcp_port); |
573 |
hypervisor_running = TRUE; |
hypervisor_running = TRUE; |
574 |
|
|
575 |
while(hypervisor_running) { |
while(hypervisor_running) { |