Debian Codegraph @

common/hv_c3745.c

raw
1 /*
2 * Cisco 3745 simulation platform.
3 * Copyright (c) 2006 Christophe Fillot ([email protected])
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 <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_c3745.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 I/O mem size */
44 static int cmd_set_iomem(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 vm->nm_iomem_size = 0x8000 | atoi(argv[1]);
52
53 vm_release(vm);
54 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
55 return(0);
56 }
57
58 /* Set the system id */
59 static int cmd_set_system_id(hypervisor_conn_t *conn,int argc,char *argv[])
60 {
61 vm_instance_t *vm;
62
63 if (!(vm = hypervisor_find_vm(conn,argv[0])))
64 return(-1);
65
66 if (( c3745_set_system_id(VM_C3745(vm),argv[1])) == -1) {
67 vm_release(vm);
68 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
69 "unable to set the system id for router '%s'",
70 argv[0]);
71 return(-1);
72 }
73
74 vm_release(vm);
75 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
76 return(0);
77 }
78
79 /* Get the base MAC address for the chassis */
80 static int cmd_get_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[])
81 {
82 vm_instance_t *vm;
83 c3745_t *router;
84
85 if (!(vm = hypervisor_find_vm(conn,argv[0])))
86 return(-1);
87
88 router = VM_C3745(vm);
89 hypervisor_send_reply(conn,HSC_INFO_OK,1,
90 "%2.2x%2.2x.%2.2x%2.2x.%2.2x%2.2x",
91 router->mac_addr.eth_addr_byte[0],
92 router->mac_addr.eth_addr_byte[1],
93 router->mac_addr.eth_addr_byte[2],
94 router->mac_addr.eth_addr_byte[3],
95 router->mac_addr.eth_addr_byte[4],
96 router->mac_addr.eth_addr_byte[5]);
97
98 vm_release(vm);
99 return(0);
100 }
101
102 /* Set the base MAC address for the chassis */
103 static int cmd_set_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[])
104 {
105 vm_instance_t *vm;
106
107 if (!(vm = hypervisor_find_vm(conn,argv[0])))
108 return(-1);
109
110 if ((c3745_chassis_set_mac_addr(VM_C3745(vm),argv[1])) == -1) {
111 vm_release(vm);
112 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
113 "unable to set MAC address for router '%s'",
114 argv[0]);
115 return(-1);
116 }
117
118 vm_release(vm);
119 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
120 return(0);
121 }
122
123 /* Show C3745 hardware */
124 static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[])
125 {
126 vm_instance_t *vm;
127 c3745_t *router;
128
129 if (!(vm = hypervisor_find_vm(conn,argv[0])))
130 return(-1);
131
132 router = VM_C3745(vm);
133 c3745_show_hardware(router);
134
135 vm_release(vm);
136 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
137 return(0);
138 }
139
140 /* Show info about C3745 object */
141 static void cmd_show_c3745_list(registry_entry_t *entry,void *opt,int *err)
142 {
143 hypervisor_conn_t *conn = opt;
144 vm_instance_t *vm = entry->data;
145
146 if (vm->platform == conn->cur_module->opt)
147 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
148 }
149
150 /* C3745 List */
151 static int cmd_c3745_list(hypervisor_conn_t *conn,int argc,char *argv[])
152 {
153 int err = 0;
154 registry_foreach_type(OBJ_TYPE_VM,cmd_show_c3745_list,conn,&err);
155 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
156 return(0);
157 }
158
159 /* C3745 commands */
160 static hypervisor_cmd_t c3745_cmd_array[] = {
161 { "set_iomem", 2, 2, cmd_set_iomem, NULL },
162 { "get_mac_addr", 1, 1, cmd_get_mac_addr, NULL },
163 { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL },
164 { "set_system_id", 2, 2, cmd_set_system_id, NULL },
165 { "show_hardware", 1, 1, cmd_show_hardware, NULL },
166 { "list", 0, 0, cmd_c3745_list, NULL },
167 { NULL, -1, -1, NULL, NULL },
168 };
169
170 /* Hypervisor C3745 initialization */
171 int hypervisor_c3745_init(vm_platform_t *platform)
172 {
173 hypervisor_module_t *module;
174
175 module = hypervisor_register_module(platform->name,platform);
176 assert(module != NULL);
177
178 hypervisor_register_cmd_array(module,c3745_cmd_array);
179 return(0);
180 }