|
|
1.1 root 1: /*
2: * Cisco router simulation platform.
3: * Copyright (c) 2006 Christophe Fillot ([email protected])
4: *
5: * Hypervisor C2600 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:
26: #include "cpu.h"
27: #include "vm.h"
28: #include "device.h"
29: #include "dev_c2600.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 chassis type */
45: static int cmd_set_chassis(hypervisor_conn_t *conn,int argc,char *argv[])
46: {
47: vm_instance_t *vm;
48:
1.1.1.2 ! root 49: if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1 root 50: return(-1);
51:
52: if ((c2600_mainboard_set_type(VM_C2600(vm),argv[1])) == -1) {
53: vm_release(vm);
54: hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
55: "unable to set Chassis 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 I/O mem size */
66: static int cmd_set_iomem(hypervisor_conn_t *conn,int argc,char *argv[])
67: {
68: vm_instance_t *vm;
69:
1.1.1.2 ! root 70: if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1 root 71: return(-1);
72:
1.1.1.2 ! root 73: vm->nm_iomem_size = 0x8000 | atoi(argv[1]);
1.1 root 74:
75: vm_release(vm);
76: hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
77: return(0);
78: }
79:
80: /* Set the base MAC address for the chassis */
81: static int cmd_set_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[])
82: {
83: vm_instance_t *vm;
84:
1.1.1.2 ! root 85: if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1 root 86: return(-1);
87:
88: if ((c2600_chassis_set_mac_addr(VM_C2600(vm),argv[1])) == -1) {
89: vm_release(vm);
90: hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
91: "unable to set MAC address for router '%s'",
92: argv[0]);
93: return(-1);
94: }
95:
96: vm_release(vm);
97: hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
98: return(0);
99: }
100:
101: /* Show C2600 hardware */
102: static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[])
103: {
104: vm_instance_t *vm;
105: c2600_t *router;
106:
1.1.1.2 ! root 107: if (!(vm = hypervisor_find_vm(conn,argv[0])))
1.1 root 108: return(-1);
109:
110: router = VM_C2600(vm);
111: c2600_show_hardware(router);
112:
113: vm_release(vm);
114: hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
115: return(0);
116: }
117:
118: /* Show info about C2600 object */
119: static void cmd_show_c2600_list(registry_entry_t *entry,void *opt,int *err)
120: {
121: hypervisor_conn_t *conn = opt;
122: vm_instance_t *vm = entry->data;
123:
1.1.1.2 ! root 124: if (vm->platform == conn->cur_module->opt)
1.1 root 125: hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
126: }
127:
128: /* C2600 List */
129: static int cmd_c2600_list(hypervisor_conn_t *conn,int argc,char *argv[])
130: {
131: int err = 0;
132: registry_foreach_type(OBJ_TYPE_VM,cmd_show_c2600_list,conn,&err);
133: hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
134: return(0);
135: }
136:
137: /* C2600 commands */
138: static hypervisor_cmd_t c2600_cmd_array[] = {
139: { "set_chassis", 2, 2, cmd_set_chassis, NULL },
140: { "set_iomem", 2, 2, cmd_set_iomem, NULL },
141: { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL },
142: { "show_hardware", 1, 1, cmd_show_hardware, NULL },
143: { "list", 0, 0, cmd_c2600_list, NULL },
144: { NULL, -1, -1, NULL, NULL },
145: };
146:
147: /* Hypervisor C2600 initialization */
1.1.1.2 ! root 148: int hypervisor_c2600_init(vm_platform_t *platform)
1.1 root 149: {
150: hypervisor_module_t *module;
151:
1.1.1.2 ! root 152: module = hypervisor_register_module(platform->name,platform);
1.1 root 153: assert(module != NULL);
154:
155: hypervisor_register_cmd_array(module,c2600_cmd_array);
156: return(0);
157: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.