Annotation of cf/hv_c7200.c, revision 1.1.1.3

1.1       root        1: /*
1.1.1.2   root        2:  * Cisco router simulation platform.
1.1       root        3:  * Copyright (c) 2006 Christophe Fillot ([email protected])
                      4:  *
                      5:  * Hypervisor C7200 routines.
                      6:  */
                      7: 
                      8: #include <stdio.h>
                      9: #include <stdlib.h>
                     10: #include <unistd.h>
                     11: #include <string.h>
                     12: #include <sys/types.h>
                     13: #include <sys/stat.h>
                     14: #include <sys/mman.h>
                     15: #include <signal.h>
                     16: #include <fcntl.h>
                     17: #include <errno.h>
                     18: #include <assert.h>
                     19: #include <stdarg.h>
                     20: #include <sys/ioctl.h>
                     21: #include <sys/types.h>
                     22: #include <sys/socket.h>
                     23: #include <arpa/inet.h>
                     24: #include <pthread.h>
                     25: 
1.1.1.2   root       26: #include "cpu.h"
                     27: #include "vm.h"
1.1       root       28: #include "device.h"
                     29: #include "dev_c7200.h"
                     30: #include "dev_vtty.h"
                     31: #include "utils.h"
                     32: #include "net.h"
                     33: #include "atm.h"
                     34: #include "frame_relay.h"
                     35: #include "crc.h"
                     36: #include "net_io.h"
                     37: #include "net_io_bridge.h"
                     38: #ifdef GEN_ETH
                     39: #include "gen_eth.h"
                     40: #endif
                     41: #include "registry.h"
                     42: #include "hypervisor.h"
                     43: 
                     44: /* Set the NPE type */
                     45: static int cmd_set_npe(hypervisor_conn_t *conn,int argc,char *argv[])
                     46: {
                     47:    vm_instance_t *vm;
                     48: 
1.1.1.3 ! root       49:    if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1       root       50:       return(-1);
                     51: 
                     52:    if ((c7200_npe_set_type(VM_C7200(vm),argv[1])) == -1) {
                     53:       vm_release(vm);
                     54:       hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
                     55:                             "unable to set NPE type for router '%s'",
                     56:                             argv[0]);
                     57:       return(-1);
                     58:    }
                     59: 
                     60:    vm_release(vm);
                     61:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
                     62:    return(0);
                     63: }
                     64: 
                     65: /* Set the Midplane type */
                     66: static int cmd_set_midplane(hypervisor_conn_t *conn,int argc,char *argv[])
                     67: {
                     68:    vm_instance_t *vm;
                     69: 
1.1.1.3 ! root       70:    if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1       root       71:       return(-1);
                     72: 
                     73:    if ((c7200_midplane_set_type(VM_C7200(vm),argv[1])) == -1) {
                     74:       vm_release(vm);
                     75:       hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
                     76:                             "unable to set Midplane type for router '%s'",
                     77:                             argv[0]);
                     78:       return(-1);
                     79:    }
                     80: 
                     81:    vm_release(vm);
                     82:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
                     83:    return(0);
                     84: }
                     85: 
                     86: /* Set the base MAC address for the chassis */
                     87: static int cmd_set_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[])
                     88: {
                     89:    vm_instance_t *vm;
                     90: 
1.1.1.3 ! root       91:    if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1       root       92:       return(-1);
                     93: 
                     94:    if ((c7200_midplane_set_mac_addr(VM_C7200(vm),argv[1])) == -1) {
                     95:       vm_release(vm);
                     96:       hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
                     97:                             "unable to set MAC address for router '%s'",
                     98:                             argv[0]);
                     99:       return(-1);
                    100:    }
                    101: 
                    102:    vm_release(vm);
                    103:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
                    104:    return(0);
                    105: }
                    106: 
                    107: /* Initialize a PA while the router is running */
                    108: static int cmd_pa_init_online(hypervisor_conn_t *conn,int argc,char *argv[])
                    109: {
                    110:    vm_instance_t *vm;
                    111:    c7200_t *router;
                    112:    u_int pa_bay;
                    113: 
1.1.1.3 ! root      114:    if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1       root      115:       return(-1);
                    116: 
                    117:    router = VM_C7200(vm);
                    118: 
                    119:    pa_bay = atoi(argv[1]);
                    120:    c7200_pa_init_online(router,pa_bay);
                    121: 
                    122:    vm_release(vm);
                    123:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
                    124:    return(0);
                    125: }
                    126: 
                    127: /* Stop a PA while the router is running */
                    128: static int cmd_pa_stop_online(hypervisor_conn_t *conn,int argc,char *argv[])
                    129: {     
                    130:    vm_instance_t *vm;
                    131:    c7200_t *router;
                    132:    u_int pa_bay;
                    133: 
1.1.1.3 ! root      134:    if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1       root      135:       return(-1);
                    136: 
                    137:    router = VM_C7200(vm);
                    138: 
                    139:    pa_bay = atoi(argv[1]);
                    140:    c7200_pa_stop_online(router,pa_bay);
                    141: 
                    142:    vm_release(vm);
                    143:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
                    144:    return(0);
                    145: }
                    146: 
                    147: /* Show C7200 hardware */
                    148: static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[])
                    149: {
                    150:    vm_instance_t *vm;
                    151:    c7200_t *router;
                    152: 
1.1.1.3 ! root      153:    if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1       root      154:       return(-1);
                    155: 
                    156:    router = VM_C7200(vm);
                    157:    c7200_show_hardware(router);
                    158: 
                    159:    vm_release(vm);
                    160:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
                    161:    return(0);
                    162: }
                    163: 
                    164: /* Show info about C7200 object */
                    165: static void cmd_show_c7200_list(registry_entry_t *entry,void *opt,int *err)
                    166: {
                    167:    hypervisor_conn_t *conn = opt;
                    168:    vm_instance_t *vm = entry->data;
                    169: 
1.1.1.3 ! root      170:    if (vm->platform == conn->cur_module->opt)
1.1       root      171:       hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
                    172: }
                    173: 
                    174: /* C7200 List */
                    175: static int cmd_c7200_list(hypervisor_conn_t *conn,int argc,char *argv[])
                    176: {
                    177:    int err = 0;
                    178:    registry_foreach_type(OBJ_TYPE_VM,cmd_show_c7200_list,conn,&err);
                    179:    hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
                    180:    return(0);
                    181: }
                    182: 
                    183: /* C7200 commands */
                    184: static hypervisor_cmd_t c7200_cmd_array[] = {
                    185:    { "set_npe", 2, 2, cmd_set_npe, NULL },
                    186:    { "set_midplane", 2, 2, cmd_set_midplane, NULL },
                    187:    { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL },
                    188:    { "pa_init_online", 2, 2, cmd_pa_init_online, NULL },
                    189:    { "pa_stop_online", 2, 2, cmd_pa_stop_online, NULL },
                    190:    { "show_hardware", 1, 1, cmd_show_hardware, NULL },
                    191:    { "list", 0, 0, cmd_c7200_list, NULL },
                    192:    { NULL, -1, -1, NULL, NULL },
                    193: };
                    194: 
                    195: /* Hypervisor C7200 initialization */
1.1.1.3 ! root      196: int hypervisor_c7200_init(vm_platform_t *platform)
1.1       root      197: {
                    198:    hypervisor_module_t *module;
                    199: 
1.1.1.3 ! root      200:    module = hypervisor_register_module(platform->name,platform);
1.1       root      201:    assert(module != NULL);
                    202: 
                    203:    hypervisor_register_cmd_array(module,c7200_cmd_array);
                    204:    return(0);
                    205: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.