/[dynamips]/trunk/hypervisor.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/hypervisor.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.5/hypervisor.c revision 1 by dpavlin, Sat Oct 6 16:01:44 2007 UTC upstream/dynamips-0.2.7/hypervisor.c revision 10 by dpavlin, Sat Oct 6 16:29:14 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   * Cisco 7200 (Predator) simulation platform.   * Cisco router simulation platform.
3   * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)   * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4   *   *
5   * Hypervisor routines.   * Hypervisor routines.
# Line 32  Line 32 
32  #include "parser.h"  #include "parser.h"
33  #include "net.h"  #include "net.h"
34  #include "registry.h"  #include "registry.h"
35  #include "mips64.h"  #include "cpu.h"
36    #include "vm.h"
37  #include "dynamips.h"  #include "dynamips.h"
38  #include "dev_c7200.h"  #include "dev_c7200.h"
39  #include "dev_c3600.h"  #include "dev_c3600.h"
40    #include "dev_c2691.h"
41    #include "dev_c3725.h"
42    #include "dev_c3745.h"
43    #include "dev_c2600.h"
44  #include "hypervisor.h"  #include "hypervisor.h"
45  #include "net_io.h"  #include "net_io.h"
46  #include "net_io_bridge.h"  #include "net_io_bridge.h"
# Line 58  static int cmd_version(hypervisor_conn_t Line 63  static int cmd_version(hypervisor_conn_t
63     return(0);     return(0);
64  }  }
65    
66    /* Parser test */
67    static int cmd_parser_test(hypervisor_conn_t *conn,int argc,char *argv[])
68    {
69       int i;
70    
71       for(i=0;i<argc;i++)
72          hypervisor_send_reply(conn,HSC_INFO_MSG,0,
73                                "arg %d (len %u): \"%s\"",
74                                i,strlen(argv[i]),argv[i]);
75    
76       hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
77       return(0);
78    }
79    
80  /* Show hypervisor module list */  /* Show hypervisor module list */
81  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[])
82  {  {
# Line 119  static int cmd_save_config(hypervisor_co Line 138  static int cmd_save_config(hypervisor_co
138     netio_bridge_save_config_all(fd);     netio_bridge_save_config_all(fd);
139     c7200_save_config_all(fd);     c7200_save_config_all(fd);
140     c3600_save_config_all(fd);     c3600_save_config_all(fd);
141       c2691_save_config_all(fd);
142       c3725_save_config_all(fd);
143       c3745_save_config_all(fd);
144       c2600_save_config_all(fd);
145    
146     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
147     return(0);     return(0);
# Line 151  static int cmd_stop(hypervisor_conn_t *c Line 174  static int cmd_stop(hypervisor_conn_t *c
174  /* Hypervisor commands */  /* Hypervisor commands */
175  static hypervisor_cmd_t hypervisor_cmd_array[] = {  static hypervisor_cmd_t hypervisor_cmd_array[] = {
176     { "version", 0, 0, cmd_version, NULL },     { "version", 0, 0, cmd_version, NULL },
177       { "parser_test", 0, 10, cmd_parser_test, NULL },
178     { "module_list", 0, 0, cmd_mod_list, NULL },     { "module_list", 0, 0, cmd_mod_list, NULL },
179     { "cmd_list", 1, 1, cmd_modcmd_list, NULL },     { "cmd_list", 1, 1, cmd_modcmd_list, NULL },
180     { "working_dir", 1, 1, cmd_set_working_dir, NULL },     { "working_dir", 1, 1, cmd_set_working_dir, NULL },
# Line 325  static int hypervisor_exec_cmd(hyperviso Line 349  static int hypervisor_exec_cmd(hyperviso
349  static void *hypervisor_thread(void *arg)  static void *hypervisor_thread(void *arg)
350  {    {  
351     hypervisor_conn_t *conn = arg;     hypervisor_conn_t *conn = arg;
352     char buffer[4096],**tokens;     char buffer[512],**tokens;
353     parser_token_t *tok_list;     parser_context_t ctx;
354     int res,tok_count;     int res;
355        
356       tokens = NULL;
357       parser_context_init(&ctx);
358    
359     while(conn->active) {     while(conn->active) {
360        if (!m_fgets(buffer,sizeof(buffer),conn->in))        if (!fgets(buffer,sizeof(buffer),conn->in))
361           break;           break;
362        
363        if (!*buffer)        if (!*buffer)
364           continue;           continue;
365    
366        /* Tokenize command line */        /* Tokenize command line */
367        tokens = NULL;        res = parser_scan_buffer(&ctx,buffer,strlen(buffer));
       res = parser_tokenize(buffer,&tok_list,&tok_count);  
368    
369        if (res != 0) {        if (res != 0) {  
370           hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"Parse error: %s",           tokens = NULL;
                                parser_strerror(res));  
          continue;  
       }  
371    
372        if (tok_count < 2) {           if (ctx.error != 0) {
373           hypervisor_send_reply(conn,HSC_ERR_PARSING,1,              hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"Parse error: %s",
374                                 "At least a module and a command "                                    parser_strerror(&ctx));
375                                 "must be specified");              goto free_tokens;
376           goto free_tokens;           }
377        }  
378             if (ctx.tok_count < 2) {
379                hypervisor_send_reply(conn,HSC_ERR_PARSING,1,
380                                      "At least a module and a command "
381                                      "must be specified");
382                goto free_tokens;
383             }
384    
385        /* Map token list to an array */           /* Map token list to an array */
386        tokens = parser_map_array(tok_list,tok_count);           tokens = parser_map_array(&ctx);
387                
388        if (!tokens) {           if (!tokens) {
389           hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"No memory");              hypervisor_send_reply(conn,HSC_ERR_PARSING,1,"No memory");
390           goto free_tokens;              goto free_tokens;
391        }           }
392    
393        /* Execute command */           /* Execute command */
394        m_log("hypervisor_exec","%s\n",buffer);           //m_log("hypervisor_exec","%s\n",buffer);
395        hypervisor_exec_cmd(conn,tokens[0],tokens[1],tok_count-2,&tokens[2]);           hypervisor_exec_cmd(conn,tokens[0],tokens[1],ctx.
396                                 tok_count-2,&tokens[2]);
397                
398     free_tokens:        free_tokens:
399        free(tokens);           free(tokens);
400        parser_free_tokens(tok_list);           tokens = NULL;
401             parser_context_free(&ctx);
402          }
403     }     }
404    
405       free(tokens);
406       parser_context_free(&ctx);
407     return NULL;     return NULL;
408  }  }
409    
# Line 518  int hypervisor_tcp_server(int tcp_port) Line 552  int hypervisor_tcp_server(int tcp_port)
552     hypervisor_atmsw_init();     hypervisor_atmsw_init();
553     hypervisor_ethsw_init();     hypervisor_ethsw_init();
554     hypervisor_vm_init();     hypervisor_vm_init();
555       hypervisor_vm_debug_init();
556     hypervisor_c7200_init();     hypervisor_c7200_init();
557     hypervisor_c3600_init();     hypervisor_c3600_init();
558       hypervisor_c2691_init();
559       hypervisor_c3725_init();
560       hypervisor_c3745_init();
561       hypervisor_c2600_init();
562    
563     signal(SIGPIPE,sigpipe_handler);     signal(SIGPIPE,sigpipe_handler);
564    
# Line 534  int hypervisor_tcp_server(int tcp_port) Line 573  int hypervisor_tcp_server(int tcp_port)
573     }     }
574    
575     /* Start accepting connections */     /* Start accepting connections */
576     printf("Hypervisor TCP control server started.\n");     printf("Hypervisor TCP control server started (port %d).\n",tcp_port);
577     hypervisor_running = TRUE;     hypervisor_running = TRUE;
578    
579     while(hypervisor_running) {     while(hypervisor_running) {

Legend:
Removed from v.1  
changed lines
  Added in v.10

  ViewVC Help
Powered by ViewVC 1.1.26