1 |
/* |
2 |
* Cisco 3745 simulation platform. |
3 |
* Copyright (c) 2006 Christophe Fillot (cf@utc.fr) |
4 |
* |
5 |
* Hypervisor C3745 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_c3745.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 I/O mem size */ |
45 |
static int cmd_set_iomem(hypervisor_conn_t *conn,int argc,char *argv[]) |
46 |
{ |
47 |
vm_instance_t *vm; |
48 |
|
49 |
if (!(vm = hypervisor_find_vm(conn,argv[0]))) |
50 |
return(-1); |
51 |
|
52 |
vm->nm_iomem_size = 0x8000 | atoi(argv[1]); |
53 |
|
54 |
vm_release(vm); |
55 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
56 |
return(0); |
57 |
} |
58 |
|
59 |
/* Set the base MAC address for the chassis */ |
60 |
static int cmd_set_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[]) |
61 |
{ |
62 |
vm_instance_t *vm; |
63 |
|
64 |
if (!(vm = hypervisor_find_vm(conn,argv[0]))) |
65 |
return(-1); |
66 |
|
67 |
if ((c3745_chassis_set_mac_addr(VM_C3745(vm),argv[1])) == -1) { |
68 |
vm_release(vm); |
69 |
hypervisor_send_reply(conn,HSC_ERR_CREATE,1, |
70 |
"unable to set MAC address for router '%s'", |
71 |
argv[0]); |
72 |
return(-1); |
73 |
} |
74 |
|
75 |
vm_release(vm); |
76 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
77 |
return(0); |
78 |
} |
79 |
|
80 |
/* Show C3745 hardware */ |
81 |
static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[]) |
82 |
{ |
83 |
vm_instance_t *vm; |
84 |
c3745_t *router; |
85 |
|
86 |
if (!(vm = hypervisor_find_vm(conn,argv[0]))) |
87 |
return(-1); |
88 |
|
89 |
router = VM_C3745(vm); |
90 |
c3745_show_hardware(router); |
91 |
|
92 |
vm_release(vm); |
93 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
94 |
return(0); |
95 |
} |
96 |
|
97 |
/* Show info about C3745 object */ |
98 |
static void cmd_show_c3745_list(registry_entry_t *entry,void *opt,int *err) |
99 |
{ |
100 |
hypervisor_conn_t *conn = opt; |
101 |
vm_instance_t *vm = entry->data; |
102 |
|
103 |
if (vm->platform == conn->cur_module->opt) |
104 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name); |
105 |
} |
106 |
|
107 |
/* C3745 List */ |
108 |
static int cmd_c3745_list(hypervisor_conn_t *conn,int argc,char *argv[]) |
109 |
{ |
110 |
int err = 0; |
111 |
registry_foreach_type(OBJ_TYPE_VM,cmd_show_c3745_list,conn,&err); |
112 |
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
113 |
return(0); |
114 |
} |
115 |
|
116 |
/* C3745 commands */ |
117 |
static hypervisor_cmd_t c3745_cmd_array[] = { |
118 |
{ "set_iomem", 2, 2, cmd_set_iomem, NULL }, |
119 |
{ "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL }, |
120 |
{ "show_hardware", 1, 1, cmd_show_hardware, NULL }, |
121 |
{ "list", 0, 0, cmd_c3745_list, NULL }, |
122 |
{ NULL, -1, -1, NULL, NULL }, |
123 |
}; |
124 |
|
125 |
/* Hypervisor C3745 initialization */ |
126 |
int hypervisor_c3745_init(vm_platform_t *platform) |
127 |
{ |
128 |
hypervisor_module_t *module; |
129 |
|
130 |
module = hypervisor_register_module(platform->name,platform); |
131 |
assert(module != NULL); |
132 |
|
133 |
hypervisor_register_cmd_array(module,c3745_cmd_array); |
134 |
return(0); |
135 |
} |