/[dynamips]/upstream/dynamips-0.2.8-RC1/hv_c3725.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 /upstream/dynamips-0.2.8-RC1/hv_c3725.c

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

upstream/dynamips-0.2.7/hv_c3725.c revision 10 by dpavlin, Sat Oct 6 16:29:14 2007 UTC upstream/dynamips-0.2.8-RC1/hv_c3725.c revision 11 by dpavlin, Sat Oct 6 16:33:40 2007 UTC
# Line 41  Line 41 
41  #include "registry.h"  #include "registry.h"
42  #include "hypervisor.h"  #include "hypervisor.h"
43    
 /* Create a C3725 instance */  
 static int cmd_create(hypervisor_conn_t *conn,int argc,char *argv[])  
 {  
    c3725_t *router;  
   
    if (!(router = c3725_create_instance(argv[0],atoi(argv[1])))) {  
       hypervisor_send_reply(conn,HSC_ERR_CREATE,1,  
                             "unable to create C3725 instance '%s'",  
                             argv[0]);  
       return(-1);  
    }  
   
    router->vm->vtty_con_type = VTTY_TYPE_NONE;  
    router->vm->vtty_aux_type = VTTY_TYPE_NONE;  
     
    vm_release(router->vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"C3725 '%s' created",argv[0]);  
    return(0);  
 }  
   
 /* Delete a C3725 instance */  
 static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[])  
 {  
    int res;  
   
    res = c3725_delete_instance(argv[0]);  
   
    if (res == 1) {  
       hypervisor_send_reply(conn,HSC_INFO_OK,1,"C3725 '%s' deleted",argv[0]);  
    } else {  
       hypervisor_send_reply(conn,HSC_ERR_DELETE,1,  
                             "unable to delete C3725 '%s'",argv[0]);  
    }  
   
    return(res);  
 }  
   
44  /* Set the I/O mem size */  /* Set the I/O mem size */
45  static int cmd_set_iomem(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_set_iomem(hypervisor_conn_t *conn,int argc,char *argv[])
46  {  {
47     vm_instance_t *vm;     vm_instance_t *vm;
48    
49     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))     if (!(vm = hypervisor_find_vm(conn,argv[0])))
50        return(-1);        return(-1);
51    
52     VM_C3725(vm)->nm_iomem_size = 0x8000 | atoi(optarg);     vm->nm_iomem_size = 0x8000 | atoi(argv[1]);
53    
54     vm_release(vm);     vm_release(vm);
55     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
# Line 98  static int cmd_set_mac_addr(hypervisor_c Line 61  static int cmd_set_mac_addr(hypervisor_c
61  {  {
62     vm_instance_t *vm;     vm_instance_t *vm;
63    
64     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))     if (!(vm = hypervisor_find_vm(conn,argv[0])))
65        return(-1);        return(-1);
66    
67     if ((c3725_chassis_set_mac_addr(VM_C3725(vm),argv[1])) == -1) {     if ((c3725_chassis_set_mac_addr(VM_C3725(vm),argv[1])) == -1) {
# Line 114  static int cmd_set_mac_addr(hypervisor_c Line 77  static int cmd_set_mac_addr(hypervisor_c
77     return(0);     return(0);
78  }  }
79    
 /* Start a C3725 instance */  
 static int cmd_start(hypervisor_conn_t *conn,int argc,char *argv[])  
 {  
    vm_instance_t *vm;  
    c3725_t *router;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
   
    if (router->vm->vtty_con_type == VTTY_TYPE_NONE) {  
       hypervisor_send_reply(conn,HSC_INFO_MSG,0,  
                             "Warning: no console port defined for "  
                             "C3725 '%s'",argv[0]);  
    }  
   
    if (c3725_init_instance(router) == -1) {  
       vm_release(vm);  
       hypervisor_send_reply(conn,HSC_ERR_START,1,  
                             "unable to start instance '%s'",  
                             argv[0]);  
       return(-1);  
    }  
     
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"C3725 '%s' started",argv[0]);  
    return(0);  
 }  
   
 /* Stop a C3725 instance */  
 static int cmd_stop(hypervisor_conn_t *conn,int argc,char *argv[])  
 {  
    vm_instance_t *vm;  
    c3725_t *router;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
   
    if (c3725_stop_instance(router) == -1) {  
       vm_release(vm);  
       hypervisor_send_reply(conn,HSC_ERR_STOP,1,  
                             "unable to stop instance '%s'",  
                             argv[0]);  
       return(-1);  
    }  
     
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"C3725 '%s' stopped",argv[0]);  
    return(0);  
 }  
   
 /* Show NM bindings */  
 static int cmd_nm_bindings(hypervisor_conn_t *conn,int argc,char *argv[])  
 {  
    vm_instance_t *vm;  
    c3725_t *router;  
    char *nm_type;  
    int i;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
   
    for(i=0;i<C3725_MAX_NM_BAYS;i++) {  
       nm_type = c3725_nm_get_type(router,i);  
       if (nm_type)  
          hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u: %s",i,nm_type);  
    }  
     
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");  
    return(0);  
 }  
   
 /* Show NM NIO bindings */  
 static int cmd_nm_nio_bindings(hypervisor_conn_t *conn,int argc,char *argv[])  
 {  
    struct c3725_nio_binding *nb;  
    struct c3725_nm_bay *bay;  
    vm_instance_t *vm;  
    c3725_t *router;  
    u_int nm_bay;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
    nm_bay = atoi(argv[1]);  
   
    if (!(bay = c3725_nm_get_info(router,nm_bay))) {  
       vm_release(vm);  
       hypervisor_send_reply(conn,HSC_ERR_UNK_OBJ,1,"Invalid slot %u",nm_bay);  
       return(-1);  
    }  
   
    for(nb=bay->nio_list;nb;nb=nb->next)  
       hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u: %s",  
                             nb->port_id,nb->nio->name);  
     
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");  
    return(0);  
 }  
   
 /* Add a NM binding for the specified slot */  
 static int cmd_add_nm_binding(hypervisor_conn_t *conn,int argc,char *argv[])  
 {    
    vm_instance_t *vm;  
    c3725_t *router;  
    u_int nm_bay;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
    nm_bay = atoi(argv[1]);  
   
    if (c3725_nm_add_binding(router,argv[2],nm_bay) == -1) {  
       vm_release(vm);  
       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,  
                             "C3725 %s: unable to add NM binding for slot %u",  
                             argv[0],nm_bay);  
       return(-1);  
    }  
   
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");  
    return(0);  
 }  
   
 /* Remove a NM binding for the specified slot */  
 static int cmd_remove_nm_binding(hypervisor_conn_t *conn,int argc,char *argv[])  
 {  
    vm_instance_t *vm;  
    c3725_t *router;  
    u_int nm_bay;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
    nm_bay = atoi(argv[1]);  
   
    if (c3725_nm_remove_binding(router,nm_bay) == -1) {  
       vm_release(vm);  
       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,  
                             "C3725 %s: unable to remove NM binding for "  
                             "slot %u",argv[0],nm_bay);  
       return(-1);  
    }  
   
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");  
    return(0);  
 }  
   
 /* Add a NIO binding to the specified slot/port */  
 static int cmd_add_nio_binding(hypervisor_conn_t *conn,int argc,char *argv[])  
 {    
    u_int nm_bay,port_id;  
    vm_instance_t *vm;  
    c3725_t *router;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
   
    nm_bay = atoi(argv[1]);  
    port_id = atoi(argv[2]);  
   
    if (c3725_nm_add_nio_binding(router,nm_bay,port_id,argv[3]) == -1) {  
       vm_release(vm);  
       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,  
                             "C3725 %s: unable to add NIO binding for "  
                             "interface %u/%u",argv[0],nm_bay,port_id);  
       return(-1);  
    }  
   
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");  
    return(0);  
 }  
   
 /* Remove a NIO binding from the specified slot/port */  
 static int cmd_remove_nio_binding(hypervisor_conn_t *conn,  
                                   int argc,char *argv[])  
 {  
    u_int nm_bay,port_id;  
    vm_instance_t *vm;  
    c3725_t *router;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
   
    nm_bay = atoi(argv[1]);  
    port_id = atoi(argv[2]);  
   
    if (c3725_nm_remove_nio_binding(router,nm_bay,port_id) == -1) {  
       vm_release(vm);  
       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,  
                             "C3725 %s: unable to remove NIO binding for "  
                             "interface %u/%u",argv[0],nm_bay,port_id);  
       return(-1);  
    }  
   
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");  
    return(0);  
 }  
   
 /* Enable NIO of the specified slot/port */  
 static int cmd_nm_enable_nio(hypervisor_conn_t *conn,int argc,char *argv[])  
 {    
    u_int nm_bay,port_id;  
    vm_instance_t *vm;  
    c3725_t *router;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
   
    nm_bay = atoi(argv[1]);  
    port_id = atoi(argv[2]);  
   
    if (c3725_nm_enable_nio(router,nm_bay,port_id) == -1) {  
       vm_release(vm);  
       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,  
                             "C3725 %s: unable to enable NIO for "  
                             "interface %u/%u",argv[0],nm_bay,port_id);  
       return(-1);  
    }  
   
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");  
    return(0);  
 }  
   
 /* Disable NIO of the specified slot/port */  
 static int cmd_nm_disable_nio(hypervisor_conn_t *conn,int argc,char *argv[])  
 {    
    u_int nm_bay,port_id;  
    vm_instance_t *vm;  
    c3725_t *router;  
   
    if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))  
       return(-1);  
   
    router = VM_C3725(vm);  
   
    nm_bay = atoi(argv[1]);  
    port_id = atoi(argv[2]);  
   
    if (c3725_nm_disable_nio(router,nm_bay,port_id) == -1) {  
       vm_release(vm);  
       hypervisor_send_reply(conn,HSC_ERR_BINDING,1,  
                             "C3725 %s: unable to unset NIO for "  
                             "interface %u/%u",  
                             argv[0],nm_bay,port_id);  
       return(-1);  
    }  
   
    vm_release(vm);  
    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");  
    return(0);  
 }  
   
80  /* Show C3725 hardware */  /* Show C3725 hardware */
81  static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[])  static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[])
82  {  {
83     vm_instance_t *vm;     vm_instance_t *vm;
84     c3725_t *router;     c3725_t *router;
85    
86     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C3725)))     if (!(vm = hypervisor_find_vm(conn,argv[0])))
87        return(-1);        return(-1);
88    
89     router = VM_C3725(vm);     router = VM_C3725(vm);
# Line 411  static void cmd_show_c3725_list(registry Line 100  static void cmd_show_c3725_list(registry
100     hypervisor_conn_t *conn = opt;     hypervisor_conn_t *conn = opt;
101     vm_instance_t *vm = entry->data;     vm_instance_t *vm = entry->data;
102    
103     if (vm->type == VM_TYPE_C3725)     if (vm->platform == conn->cur_module->opt)
104        hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);        hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
105  }  }
106    
# Line 426  static int cmd_c3725_list(hypervisor_con Line 115  static int cmd_c3725_list(hypervisor_con
115    
116  /* C3725 commands */  /* C3725 commands */
117  static hypervisor_cmd_t c3725_cmd_array[] = {  static hypervisor_cmd_t c3725_cmd_array[] = {
    { "create", 2, 2, cmd_create, NULL },  
    { "delete", 1, 1, cmd_delete, NULL },  
118     { "set_iomem", 2, 2, cmd_set_iomem, NULL },     { "set_iomem", 2, 2, cmd_set_iomem, NULL },
119     { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL },     { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL },
    { "start", 1, 1, cmd_start, NULL },  
    { "stop", 1, 1, cmd_stop, NULL },  
    { "nm_bindings", 1, 1, cmd_nm_bindings, NULL },  
    { "nm_nio_bindings", 2, 2, cmd_nm_nio_bindings, NULL },  
    { "add_nm_binding", 3, 3, cmd_add_nm_binding, NULL },  
    { "remove_nm_binding", 2, 2, cmd_remove_nm_binding, NULL },  
    { "add_nio_binding", 4, 4, cmd_add_nio_binding, NULL },  
    { "remove_nio_binding", 3, 3, cmd_remove_nio_binding, NULL },  
    { "nm_enable_nio", 3, 3, cmd_nm_enable_nio, NULL },  
    { "nm_disable_nio", 3, 3, cmd_nm_disable_nio, NULL },  
120     { "show_hardware", 1, 1, cmd_show_hardware, NULL },     { "show_hardware", 1, 1, cmd_show_hardware, NULL },
121     { "list", 0, 0, cmd_c3725_list, NULL },     { "list", 0, 0, cmd_c3725_list, NULL },
122     { NULL, -1, -1, NULL, NULL },     { NULL, -1, -1, NULL, NULL },
123  };  };
124    
125  /* Hypervisor C3725 initialization */  /* Hypervisor C3725 initialization */
126  int hypervisor_c3725_init(void)  int hypervisor_c3725_init(vm_platform_t *platform)
127  {  {
128     hypervisor_module_t *module;     hypervisor_module_t *module;
129    
130     module = hypervisor_register_module("c3725");     module = hypervisor_register_module(platform->name,platform);
131     assert(module != NULL);     assert(module != NULL);
132    
133     hypervisor_register_cmd_array(module,c3725_cmd_array);     hypervisor_register_cmd_array(module,c3725_cmd_array);

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

  ViewVC Help
Powered by ViewVC 1.1.26