Debian Codegraph @

common/hv_c2600.c

raw
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 <signal.h>
15 #include <fcntl.h>
16 #include <errno.h>
17 #include <assert.h>
18 #include <stdarg.h>
19 #include <sys/ioctl.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <arpa/inet.h>
23 #include <pthread.h>
24
25 #include "cpu.h"
26 #include "vm.h"
27 #include "device.h"
28 #include "dev_c2600.h"
29 #include "dev_vtty.h"
30 #include "utils.h"
31 #include "net.h"
32 #include "atm.h"
33 #include "frame_relay.h"
34 #include "crc.h"
35 #include "net_io.h"
36 #include "net_io_bridge.h"
37 #ifdef GEN_ETH
38 #include "gen_eth.h"
39 #endif
40 #include "registry.h"
41 #include "hypervisor.h"
42
43 /* Set the chassis type */
44 static int cmd_set_chassis(hypervisor_conn_t *conn,int argc,char *argv[])
45 {
46 vm_instance_t *vm;
47
48 if (!(vm = hypervisor_find_vm(conn,argv[0])))
49 return(-1);
50
51 if ((c2600_mainboard_set_type(VM_C2600(vm),argv[1])) == -1) {
52 vm_release(vm);
53 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
54 "unable to set Chassis type for router '%s'",
55 argv[0]);
56 return(-1);
57 }
58
59 vm_release(vm);
60 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
61 return(0);
62 }
63
64 /* Set the I/O mem size */
65 static int cmd_set_iomem(hypervisor_conn_t *conn,int argc,char *argv[])
66 {
67 vm_instance_t *vm;
68
69 if (!(vm = hypervisor_find_vm(conn,argv[0])))
70 return(-1);
71
72 vm->nm_iomem_size = 0x8000 | atoi(argv[1]);
73
74 vm_release(vm);
75 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
76 return(0);
77 }
78
79 /* Set the system id */
80 static int cmd_set_system_id(hypervisor_conn_t *conn,int argc,char *argv[])
81 {
82 vm_instance_t *vm;
83
84 if (!(vm = hypervisor_find_vm(conn,argv[0])))
85 return(-1);
86
87 if (( c2600_set_system_id(VM_C2600(vm),argv[1])) == -1) {
88 vm_release(vm);
89 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
90 "unable to set the system id for router '%s'",
91 argv[0]);
92 return(-1);
93 }
94
95 vm_release(vm);
96 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
97 return(0);
98 }
99
100 /* Get the base MAC address for the chassis */
101 static int cmd_get_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[])
102 {
103 vm_instance_t *vm;
104 c2600_t *router;
105
106 if (!(vm = hypervisor_find_vm(conn,argv[0])))
107 return(-1);
108
109 router = VM_C2600(vm);
110 hypervisor_send_reply(conn,HSC_INFO_OK,1,
111 "%2.2x%2.2x.%2.2x%2.2x.%2.2x%2.2x",
112 router->mac_addr.eth_addr_byte[0],
113 router->mac_addr.eth_addr_byte[1],
114 router->mac_addr.eth_addr_byte[2],
115 router->mac_addr.eth_addr_byte[3],
116 router->mac_addr.eth_addr_byte[4],
117 router->mac_addr.eth_addr_byte[5]);
118
119 vm_release(vm);
120 return(0);
121 }
122
123 /* Set the base MAC address for the chassis */
124 static int cmd_set_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[])
125 {
126 vm_instance_t *vm;
127
128 if (!(vm = hypervisor_find_vm(conn,argv[0])))
129 return(-1);
130
131 if ((c2600_chassis_set_mac_addr(VM_C2600(vm),argv[1])) == -1) {
132 vm_release(vm);
133 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
134 "unable to set MAC address for router '%s'",
135 argv[0]);
136 return(-1);
137 }
138
139 vm_release(vm);
140 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
141 return(0);
142 }
143
144 /* Show C2600 hardware */
145 static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[])
146 {
147 vm_instance_t *vm;
148 c2600_t *router;
149
150 if (!(vm = hypervisor_find_vm(conn,argv[0])))
151 return(-1);
152
153 router = VM_C2600(vm);
154 c2600_show_hardware(router);
155
156 vm_release(vm);
157 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
158 return(0);
159 }
160
161 /* Show info about C2600 object */
162 static void cmd_show_c2600_list(registry_entry_t *entry,void *opt,int *err)
163 {
164 hypervisor_conn_t *conn = opt;
165 vm_instance_t *vm = entry->data;
166
167 if (vm->platform == conn->cur_module->opt)
168 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
169 }
170
171 /* C2600 List */
172 static int cmd_c2600_list(hypervisor_conn_t *conn,int argc,char *argv[])
173 {
174 int err = 0;
175 registry_foreach_type(OBJ_TYPE_VM,cmd_show_c2600_list,conn,&err);
176 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
177 return(0);
178 }
179
180 /* C2600 commands */
181 static hypervisor_cmd_t c2600_cmd_array[] = {
182 { "set_chassis", 2, 2, cmd_set_chassis, NULL },
183 { "set_iomem", 2, 2, cmd_set_iomem, NULL },
184 { "get_mac_addr", 1, 1, cmd_get_mac_addr, NULL },
185 { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL },
186 { "set_system_id", 2, 2, cmd_set_system_id, NULL },
187 { "show_hardware", 1, 1, cmd_show_hardware, NULL },
188 { "list", 0, 0, cmd_c2600_list, NULL },
189 { NULL, -1, -1, NULL, NULL },
190 };
191
192 /* Hypervisor C2600 initialization */
193 int hypervisor_c2600_init(vm_platform_t *platform)
194 {
195 hypervisor_module_t *module;
196
197 module = hypervisor_register_module(platform->name,platform);
198 assert(module != NULL);
199
200 hypervisor_register_cmd_array(module,c2600_cmd_array);
201 return(0);
202 }