1 |
dpavlin |
4 |
/* |
2 |
dpavlin |
7 |
* Cisco router simulation platform. |
3 |
dpavlin |
4 |
* Copyright (c) 2006 Christophe Fillot (cf@utc.fr) |
4 |
|
|
* |
5 |
|
|
* Hypervisor C2691 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 |
dpavlin |
7 |
#include "cpu.h" |
27 |
|
|
#include "vm.h" |
28 |
dpavlin |
4 |
#include "device.h" |
29 |
|
|
#include "dev_c2691.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 |
dpavlin |
11 |
if (!(vm = hypervisor_find_vm(conn,argv[0]))) |
50 |
dpavlin |
4 |
return(-1); |
51 |
|
|
|
52 |
dpavlin |
11 |
vm->nm_iomem_size = 0x8000 | atoi(argv[1]); |
53 |
dpavlin |
4 |
|
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 |
dpavlin |
11 |
if (!(vm = hypervisor_find_vm(conn,argv[0]))) |
65 |
dpavlin |
4 |
return(-1); |
66 |
|
|
|
67 |
|
|
if ((c2691_chassis_set_mac_addr(VM_C2691(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 C2691 hardware */ |
81 |
|
|
static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[]) |
82 |
|
|
{ |
83 |
|
|
vm_instance_t *vm; |
84 |
|
|
c2691_t *router; |
85 |
|
|
|
86 |
dpavlin |
11 |
if (!(vm = hypervisor_find_vm(conn,argv[0]))) |
87 |
dpavlin |
4 |
return(-1); |
88 |
|
|
|
89 |
|
|
router = VM_C2691(vm); |
90 |
|
|
c2691_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 C2691 object */ |
98 |
|
|
static void cmd_show_c2691_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 |
dpavlin |
11 |
if (vm->platform == conn->cur_module->opt) |
104 |
dpavlin |
4 |
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
/* C2691 List */ |
108 |
|
|
static int cmd_c2691_list(hypervisor_conn_t *conn,int argc,char *argv[]) |
109 |
|
|
{ |
110 |
|
|
int err = 0; |
111 |
|
|
registry_foreach_type(OBJ_TYPE_VM,cmd_show_c2691_list,conn,&err); |
112 |
|
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
113 |
|
|
return(0); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
/* C2691 commands */ |
117 |
|
|
static hypervisor_cmd_t c2691_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_c2691_list, NULL }, |
122 |
|
|
{ NULL, -1, -1, NULL, NULL }, |
123 |
|
|
}; |
124 |
|
|
|
125 |
|
|
/* Hypervisor C2691 initialization */ |
126 |
dpavlin |
11 |
int hypervisor_c2691_init(vm_platform_t *platform) |
127 |
dpavlin |
4 |
{ |
128 |
|
|
hypervisor_module_t *module; |
129 |
|
|
|
130 |
dpavlin |
11 |
module = hypervisor_register_module(platform->name,platform); |
131 |
dpavlin |
4 |
assert(module != NULL); |
132 |
|
|
|
133 |
|
|
hypervisor_register_cmd_array(module,c2691_cmd_array); |
134 |
|
|
return(0); |
135 |
|
|
} |