|
|
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: 1.1.1.4 ! root 107: /* ! 108: * Set temperature for a DS1620 sensor. ! 109: * This can be used to simulate environmental problems (overheat) ! 110: */ ! 111: static int cmd_set_temp_sensor(hypervisor_conn_t *conn,int argc,char *argv[]) 1.1 root 112: { 113: vm_instance_t *vm; 114: c7200_t *router; 1.1.1.4 ! root 115: u_int index; ! 116: int temp; 1.1 root 117: 1.1.1.3 root 118: if (!(vm = hypervisor_find_vm(conn,argv[0]))) 1.1 root 119: return(-1); 120: 121: router = VM_C7200(vm); 122: 1.1.1.4 ! root 123: index = atoi(argv[1]); ! 124: temp = atoi(argv[2]); ! 125: ! 126: if (index < C7200_TEMP_SENSORS) ! 127: ds1620_set_temp(&router->ds1620_sensors[index],temp); 1.1 root 128: 129: vm_release(vm); 130: hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); 131: return(0); 132: } 133: 1.1.1.4 ! root 134: /* ! 135: * Set power supply status. ! 136: * This can be used to simulate environmental problems (power loss) ! 137: */ ! 138: static int cmd_set_power_supply(hypervisor_conn_t *conn,int argc,char *argv[]) ! 139: { 1.1 root 140: vm_instance_t *vm; 141: c7200_t *router; 1.1.1.4 ! root 142: u_int index; ! 143: int status; 1.1 root 144: 1.1.1.3 root 145: if (!(vm = hypervisor_find_vm(conn,argv[0]))) 1.1 root 146: return(-1); 147: 148: router = VM_C7200(vm); 149: 1.1.1.4 ! root 150: index = atoi(argv[1]); ! 151: status = atoi(argv[2]); ! 152: ! 153: if (status) ! 154: router->ps_status |= 1 << index; ! 155: else ! 156: router->ps_status &= ~(1 << index); ! 157: ! 158: /* only 2 power supplies */ ! 159: router->ps_status &= 0x03; 1.1 root 160: 161: vm_release(vm); 162: hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); 163: return(0); 164: } 165: 166: /* Show C7200 hardware */ 167: static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[]) 168: { 169: vm_instance_t *vm; 170: c7200_t *router; 171: 1.1.1.3 root 172: if (!(vm = hypervisor_find_vm(conn,argv[0]))) 1.1 root 173: return(-1); 174: 175: router = VM_C7200(vm); 176: c7200_show_hardware(router); 177: 178: vm_release(vm); 179: hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); 180: return(0); 181: } 182: 183: /* Show info about C7200 object */ 184: static void cmd_show_c7200_list(registry_entry_t *entry,void *opt,int *err) 185: { 186: hypervisor_conn_t *conn = opt; 187: vm_instance_t *vm = entry->data; 188: 1.1.1.3 root 189: if (vm->platform == conn->cur_module->opt) 1.1 root 190: hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name); 191: } 192: 193: /* C7200 List */ 194: static int cmd_c7200_list(hypervisor_conn_t *conn,int argc,char *argv[]) 195: { 196: int err = 0; 197: registry_foreach_type(OBJ_TYPE_VM,cmd_show_c7200_list,conn,&err); 198: hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); 199: return(0); 200: } 201: 202: /* C7200 commands */ 203: static hypervisor_cmd_t c7200_cmd_array[] = { 204: { "set_npe", 2, 2, cmd_set_npe, NULL }, 205: { "set_midplane", 2, 2, cmd_set_midplane, NULL }, 206: { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL }, 1.1.1.4 ! root 207: { "set_temp_sensor", 3, 3, cmd_set_temp_sensor, NULL }, ! 208: { "set_power_supply", 3, 3, cmd_set_power_supply, NULL }, 1.1 root 209: { "show_hardware", 1, 1, cmd_show_hardware, NULL }, 210: { "list", 0, 0, cmd_c7200_list, NULL }, 211: { NULL, -1, -1, NULL, NULL }, 212: }; 213: 214: /* Hypervisor C7200 initialization */ 1.1.1.3 root 215: int hypervisor_c7200_init(vm_platform_t *platform) 1.1 root 216: { 217: hypervisor_module_t *module; 218: 1.1.1.3 root 219: module = hypervisor_register_module(platform->name,platform); 1.1 root 220: assert(module != NULL); 221: 222: hypervisor_register_cmd_array(module,c7200_cmd_array); 223: return(0); 224: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.