⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hv_vm.c

📁 思科路由器仿真器,用来仿7200系列得,可以在电脑上模拟路由器-Cisco router simulator, used to fake a 7200 series can be simulated
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Cisco 7200 (Predator) simulation platform. * Copyright (c) 2006 Christophe Fillot (cf@utc.fr) * * Hypervisor generic VM routines. */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/mman.h>#include <signal.h>#include <fcntl.h>#include <errno.h>#include <assert.h>#include <stdarg.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/socket.h>#include <arpa/inet.h>#include <pthread.h>#include "mips64.h"#include "cp0.h"#include "dynamips.h"#include "device.h"#include "dev_c7200.h"#include "dev_vtty.h"#include "utils.h"#include "base64.h"#include "net.h"#include "atm.h"#include "frame_relay.h"#include "crc.h"#include "net_io.h"#include "net_io_bridge.h"#ifdef GEN_ETH#include "gen_eth.h"#endif#include "registry.h"#include "hypervisor.h"/* Find the specified CPU */static cpu_mips_t *find_cpu(hypervisor_conn_t *conn,vm_instance_t *vm,                            u_int cpu_id){   cpu_mips_t *cpu;   cpu = cpu_group_find_id(vm->cpu_group,cpu_id);   if (!cpu) {      vm_release(vm);      hypervisor_send_reply(conn,HSC_ERR_BAD_OBJ,1,"Bad CPU specified");      return NULL;   }      return cpu;}/* Set debugging level */static int cmd_set_debug_level(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   vm->debug_level = atoi(argv[1]);   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"O",argv[0]);   return(0);}/* Set IOS image filename */static int cmd_set_ios(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   if (vm_ios_set_image(vm,argv[1]) == -1) {      vm_release(vm);      hypervisor_send_reply(conn,HSC_ERR_CREATE,1,                            "unable to store IOS image name for router '%s'",                            argv[0]);      return(-1);   }   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"IOS image set for '%s'",argv[0]);   return(0);}/* Set IOS configuration filename to load at startup */static int cmd_set_config(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   if (vm_ios_set_config(vm,argv[1]) == -1) {      vm_release(vm);      hypervisor_send_reply(conn,HSC_ERR_CREATE,1,                            "unable to store IOS config for router '%s'",                            argv[0]);      return(-1);   }   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"IOS config file set for '%s'",                         argv[0]);   return(0);}/* Set RAM size */static int cmd_set_ram(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   vm->ram_size = atoi(argv[1]);   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Set NVRAM size */static int cmd_set_nvram(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   vm->nvram_size = atoi(argv[1]);   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Enable/disable use of a memory-mapped file to simulate RAM */static int cmd_set_ram_mmap(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   vm->ram_mmap = atoi(argv[1]);   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Set the clock divisor */static int cmd_set_clock_divisor(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   u_int clock_div;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   if ((clock_div = atoi(argv[1])) != 0)      vm->clock_divisor = clock_div;   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Set the idle PC */static int cmd_set_idle_pc(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   vm->idle_pc = strtoull(argv[1],NULL,0);   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Set the idle PC value when the CPU is online */static int cmd_set_idle_pc_online(hypervisor_conn_t *conn,                                  int argc,char *argv[]){   vm_instance_t *vm;   cpu_mips_t *cpu;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))      return(-1);   cpu->idle_pc = strtoull(argv[2],NULL,0);   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Get the idle PC proposals */static int cmd_get_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]){     vm_instance_t *vm;   cpu_mips_t *cpu;   int i;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))      return(-1);   mips64_get_idling_pc(cpu);   for(i=0;i<cpu->idle_pc_prop_count;i++) {      hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]",                            cpu->idle_pc_prop[i].pc,                            cpu->idle_pc_prop[i].count);   }   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Dump the idle PC proposals */static int cmd_show_idle_pc_prop(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   cpu_mips_t *cpu;   int i;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))      return(-1);   for(i=0;i<cpu->idle_pc_prop_count;i++) {      hypervisor_send_reply(conn,HSC_INFO_MSG,0,"0x%llx [%d]",                            cpu->idle_pc_prop[i].pc,                            cpu->idle_pc_prop[i].count);   }   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Set CPU idle max value */static int cmd_set_idle_max(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   cpu_mips_t *cpu;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))      return(-1);   cpu->idle_max = atoi(argv[2]);   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Set CPU idle sleep time value */static int cmd_set_idle_sleep_time(hypervisor_conn_t *conn,                                   int argc,char *argv[]){   vm_instance_t *vm;   cpu_mips_t *cpu;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))      return(-1);   cpu->idle_sleep_time = atoi(argv[2]);   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Show info about potential timer drift */static int cmd_show_timer_drift(hypervisor_conn_t *conn,                                int argc,char *argv[]){   vm_instance_t *vm;   cpu_mips_t *cpu;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   if (!(cpu = find_cpu(conn,vm,atoi(argv[1]))))      return(-1);   hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Timer Drift: %u",                         cpu->timer_drift);   hypervisor_send_reply(conn,HSC_INFO_MSG,0,"Pending Timer IRQ: %u",                         cpu->timer_irq_pending);         vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");   return(0);}/* Set the exec area size */static int cmd_set_exec_area(hypervisor_conn_t *conn,int argc,char *argv[]){   vm_instance_t *vm;   if (!(vm = hypervisor_find_object(conn,argv[0],OBJ_TYPE_VM)))      return(-1);   vm->exec_area_size = atoi(argv[1]);   vm_release(vm);   hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -