Debian Codegraph @

common/hv_c1700.c

raw
1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2006 Christophe Fillot ([email protected])
4 *
5 * Hypervisor C1700 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_c1700.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 ((c1700_mainboard_set_type(VM_C1700(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 static int cmd_set_system_id(hypervisor_conn_t *conn,int argc,char *argv[])
80 {
81 vm_instance_t *vm;
82
83 if (!(vm = hypervisor_find_vm(conn,argv[0])))
84 return(-1);
85
86 if (( c1700_set_system_id(VM_C1700(vm),argv[1])) == -1) {
87 vm_release(vm);
88 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
89 "unable to set the system id for router '%s'",
90 argv[0]);
91 return(-1);
92 }
93
94 vm_release(vm);
95 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
96 return(0);
97 }
98
99 /* Get the base MAC address for the chassis */
100 static int cmd_get_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[])
101 {
102 vm_instance_t *vm;
103 c1700_t *router;
104
105 if (!(vm = hypervisor_find_vm(conn,argv[0])))
106 return(-1);
107
108 router = VM_C1700(vm);
109 hypervisor_send_reply(conn,HSC_INFO_OK,1,
110 "%2.2x%2.2x.%2.2x%2.2x.%2.2x%2.2x",
111 router->mac_addr.eth_addr_byte[0],
112 router->mac_addr.eth_addr_byte[1],
113 router->mac_addr.eth_addr_byte[2],
114 router->mac_addr.eth_addr_byte[3],
115 router->mac_addr.eth_addr_byte[4],
116 router->mac_addr.eth_addr_byte[5]);
117
118 vm_release(vm);
119 return(0);
120 }
121
122 /* Set the base MAC address for the chassis */
123 static int cmd_set_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[])
124 {
125 vm_instance_t *vm;
126
127 if (!(vm = hypervisor_find_vm(conn,argv[0])))
128 return(-1);
129
130 if ((c1700_chassis_set_mac_addr(VM_C1700(vm),argv[1])) == -1) {
131 vm_release(vm);
132 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
133 "unable to set MAC address for router '%s'",
134 argv[0]);
135 return(-1);
136 }
137
138 vm_release(vm);
139 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
140 return(0);
141 }
142
143 /* Show C1700 hardware */
144 static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[])
145 {
146 vm_instance_t *vm;
147 c1700_t *router;
148
149 if (!(vm = hypervisor_find_vm(conn,argv[0])))
150 return(-1);
151
152 router = VM_C1700(vm);
153 c1700_show_hardware(router);
154
155 vm_release(vm);
156 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
157 return(0);
158 }
159
160 /* Show info about C1700 object */
161 static void cmd_show_c1700_list(registry_entry_t *entry,void *opt,int *err)
162 {
163 hypervisor_conn_t *conn = opt;
164 vm_instance_t *vm = entry->data;
165
166 if (vm->platform == conn->cur_module->opt)
167 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
168 }
169
170 /* C1700 List */
171 static int cmd_c1700_list(hypervisor_conn_t *conn,int argc,char *argv[])
172 {
173 int err = 0;
174 registry_foreach_type(OBJ_TYPE_VM,cmd_show_c1700_list,conn,&err);
175 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
176 return(0);
177 }
178
179 /* C1700 commands */
180 static hypervisor_cmd_t c1700_cmd_array[] = {
181 { "set_chassis", 2, 2, cmd_set_chassis, NULL },
182 { "set_iomem", 2, 2, cmd_set_iomem, NULL },
183 { "get_mac_addr", 1, 1, cmd_get_mac_addr, NULL },
184 { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL },
185 { "set_system_id", 2, 2, cmd_set_system_id, NULL },
186 { "show_hardware", 1, 1, cmd_show_hardware, NULL },
187 { "list", 0, 0, cmd_c1700_list, NULL },
188 { NULL, -1, -1, NULL, NULL },
189 };
190
191 /* Hypervisor C1700 initialization */
192 int hypervisor_c1700_init(vm_platform_t *platform)
193 {
194 hypervisor_module_t *module;
195
196 module = hypervisor_register_module(platform->name,platform);
197 assert(module != NULL);
198
199 hypervisor_register_cmd_array(module,c1700_cmd_array);
200 return(0);
201 }