/[dynamips]/upstream/dynamips-0.2.6-RC5/hv_c2691.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /upstream/dynamips-0.2.6-RC5/hv_c2691.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (hide annotations)
Sat Oct 6 16:08:03 2007 UTC (14 years, 8 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.6-RC4/hv_c2691.c
File MIME type: text/plain
File size: 12083 byte(s)
dynamips-0.2.6-RC4

1 dpavlin 4 /*
2     * Cisco 3600 simulation platform.
3     * 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     #include "mips64.h"
27     #include "dynamips.h"
28     #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     /* Create a C2691 instance */
45     static int cmd_create(hypervisor_conn_t *conn,int argc,char *argv[])
46     {
47     c2691_t *router;
48    
49     if (!(router = c2691_create_instance(argv[0],atoi(argv[1])))) {
50     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
51     "unable to create C2691 instance '%s'",
52     argv[0]);
53     return(-1);
54     }
55    
56     router->vm->vtty_con_type = VTTY_TYPE_NONE;
57     router->vm->vtty_aux_type = VTTY_TYPE_NONE;
58    
59     vm_release(router->vm);
60     hypervisor_send_reply(conn,HSC_INFO_OK,1,"C2691 '%s' created",argv[0]);
61     return(0);
62     }
63    
64     /* Delete a C2691 instance */
65     static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[])
66     {
67     int res;
68    
69     res = c2691_delete_instance(argv[0]);
70    
71     if (res == 1) {
72     hypervisor_send_reply(conn,HSC_INFO_OK,1,"C2691 '%s' deleted",argv[0]);
73     } else {
74     hypervisor_send_reply(conn,HSC_ERR_DELETE,1,
75     "unable to delete C2691 '%s'",argv[0]);
76     }
77    
78     return(res);
79     }
80    
81     /* Set the I/O mem size */
82     static int cmd_set_iomem(hypervisor_conn_t *conn,int argc,char *argv[])
83     {
84     vm_instance_t *vm;
85    
86     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
87     return(-1);
88    
89     VM_C2691(vm)->nm_iomem_size = 0x8000 | atoi(optarg);
90    
91     vm_release(vm);
92     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
93     return(0);
94     }
95    
96     /* Set the base MAC address for the chassis */
97     static int cmd_set_mac_addr(hypervisor_conn_t *conn,int argc,char *argv[])
98     {
99     vm_instance_t *vm;
100    
101     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
102     return(-1);
103    
104     if ((c2691_chassis_set_mac_addr(VM_C2691(vm),argv[1])) == -1) {
105     vm_release(vm);
106     hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
107     "unable to set MAC address for router '%s'",
108     argv[0]);
109     return(-1);
110     }
111    
112     vm_release(vm);
113     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
114     return(0);
115     }
116    
117     /* Start a C2691 instance */
118     static int cmd_start(hypervisor_conn_t *conn,int argc,char *argv[])
119     {
120     vm_instance_t *vm;
121     c2691_t *router;
122    
123     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
124     return(-1);
125    
126     router = VM_C2691(vm);
127    
128     if (router->vm->vtty_con_type == VTTY_TYPE_NONE) {
129     hypervisor_send_reply(conn,HSC_INFO_MSG,0,
130     "Warning: no console port defined for "
131     "C2691 '%s'",argv[0]);
132     }
133    
134     if (c2691_init_instance(router) == -1) {
135     vm_release(vm);
136     hypervisor_send_reply(conn,HSC_ERR_START,1,
137     "unable to start instance '%s'",
138     argv[0]);
139     return(-1);
140     }
141    
142     vm_release(vm);
143     hypervisor_send_reply(conn,HSC_INFO_OK,1,"C2691 '%s' started",argv[0]);
144     return(0);
145     }
146    
147     /* Stop a C2691 instance */
148     static int cmd_stop(hypervisor_conn_t *conn,int argc,char *argv[])
149     {
150     vm_instance_t *vm;
151     c2691_t *router;
152    
153     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
154     return(-1);
155    
156     router = VM_C2691(vm);
157    
158     if (c2691_stop_instance(router) == -1) {
159     vm_release(vm);
160     hypervisor_send_reply(conn,HSC_ERR_STOP,1,
161     "unable to stop instance '%s'",
162     argv[0]);
163     return(-1);
164     }
165    
166     vm_release(vm);
167     hypervisor_send_reply(conn,HSC_INFO_OK,1,"C2691 '%s' stopped",argv[0]);
168     return(0);
169     }
170    
171     /* Show NM bindings */
172     static int cmd_nm_bindings(hypervisor_conn_t *conn,int argc,char *argv[])
173     {
174     vm_instance_t *vm;
175     c2691_t *router;
176     char *nm_type;
177     int i;
178    
179     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
180     return(-1);
181    
182     router = VM_C2691(vm);
183    
184     for(i=0;i<C2691_MAX_NM_BAYS;i++) {
185     nm_type = c2691_nm_get_type(router,i);
186     if (nm_type)
187     hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u: %s",i,nm_type);
188     }
189    
190     vm_release(vm);
191     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
192     return(0);
193     }
194    
195     /* Show NM NIO bindings */
196     static int cmd_nm_nio_bindings(hypervisor_conn_t *conn,int argc,char *argv[])
197     {
198     struct c2691_nio_binding *nb;
199     struct c2691_nm_bay *bay;
200     vm_instance_t *vm;
201     c2691_t *router;
202     u_int nm_bay;
203    
204     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
205     return(-1);
206    
207     router = VM_C2691(vm);
208     nm_bay = atoi(argv[1]);
209    
210     if (!(bay = c2691_nm_get_info(router,nm_bay))) {
211     vm_release(vm);
212     hypervisor_send_reply(conn,HSC_ERR_UNK_OBJ,1,"Invalid slot %u",nm_bay);
213     return(-1);
214     }
215    
216     for(nb=bay->nio_list;nb;nb=nb->next)
217     hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u: %s",
218     nb->port_id,nb->nio->name);
219    
220     vm_release(vm);
221     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
222     return(0);
223     }
224    
225     /* Add a NM binding for the specified slot */
226     static int cmd_add_nm_binding(hypervisor_conn_t *conn,int argc,char *argv[])
227     {
228     vm_instance_t *vm;
229     c2691_t *router;
230     u_int nm_bay;
231    
232     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
233     return(-1);
234    
235     router = VM_C2691(vm);
236     nm_bay = atoi(argv[1]);
237    
238     if (c2691_nm_add_binding(router,argv[2],nm_bay) == -1) {
239     vm_release(vm);
240     hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
241     "C2691 %s: unable to add NM binding for slot %u",
242     argv[0],nm_bay);
243     return(-1);
244     }
245    
246     vm_release(vm);
247     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
248     return(0);
249     }
250    
251     /* Remove a NM binding for the specified slot */
252     static int cmd_remove_nm_binding(hypervisor_conn_t *conn,int argc,char *argv[])
253     {
254     vm_instance_t *vm;
255     c2691_t *router;
256     u_int nm_bay;
257    
258     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
259     return(-1);
260    
261     router = VM_C2691(vm);
262     nm_bay = atoi(argv[1]);
263    
264     if (c2691_nm_remove_binding(router,nm_bay) == -1) {
265     vm_release(vm);
266     hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
267     "C2691 %s: unable to remove NM binding for "
268     "slot %u",argv[0],nm_bay);
269     return(-1);
270     }
271    
272     vm_release(vm);
273     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
274     return(0);
275     }
276    
277     /* Add a NIO binding to the specified slot/port */
278     static int cmd_add_nio_binding(hypervisor_conn_t *conn,int argc,char *argv[])
279     {
280     u_int nm_bay,port_id;
281     vm_instance_t *vm;
282     c2691_t *router;
283    
284     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
285     return(-1);
286    
287     router = VM_C2691(vm);
288    
289     nm_bay = atoi(argv[1]);
290     port_id = atoi(argv[2]);
291    
292     if (c2691_nm_add_nio_binding(router,nm_bay,port_id,argv[3]) == -1) {
293     vm_release(vm);
294     hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
295     "C2691 %s: unable to add NIO binding for "
296     "interface %u/%u",argv[0],nm_bay,port_id);
297     return(-1);
298     }
299    
300     vm_release(vm);
301     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
302     return(0);
303     }
304    
305     /* Remove a NIO binding from the specified slot/port */
306     static int cmd_remove_nio_binding(hypervisor_conn_t *conn,
307     int argc,char *argv[])
308     {
309     u_int nm_bay,port_id;
310     vm_instance_t *vm;
311     c2691_t *router;
312    
313     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
314     return(-1);
315    
316     router = VM_C2691(vm);
317    
318     nm_bay = atoi(argv[1]);
319     port_id = atoi(argv[2]);
320    
321     if (c2691_nm_remove_nio_binding(router,nm_bay,port_id) == -1) {
322     vm_release(vm);
323     hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
324     "C2691 %s: unable to remove NIO binding for "
325     "interface %u/%u",argv[0],nm_bay,port_id);
326     return(-1);
327     }
328    
329     vm_release(vm);
330     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
331     return(0);
332     }
333    
334     /* Enable NIO of the specified slot/port */
335     static int cmd_nm_enable_nio(hypervisor_conn_t *conn,int argc,char *argv[])
336     {
337     u_int nm_bay,port_id;
338     vm_instance_t *vm;
339     c2691_t *router;
340    
341     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
342     return(-1);
343    
344     router = VM_C2691(vm);
345    
346     nm_bay = atoi(argv[1]);
347     port_id = atoi(argv[2]);
348    
349     if (c2691_nm_enable_nio(router,nm_bay,port_id) == -1) {
350     vm_release(vm);
351     hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
352     "C2691 %s: unable to enable NIO for "
353     "interface %u/%u",argv[0],nm_bay,port_id);
354     return(-1);
355     }
356    
357     vm_release(vm);
358     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
359     return(0);
360     }
361    
362     /* Disable NIO of the specified slot/port */
363     static int cmd_nm_disable_nio(hypervisor_conn_t *conn,int argc,char *argv[])
364     {
365     u_int nm_bay,port_id;
366     vm_instance_t *vm;
367     c2691_t *router;
368    
369     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
370     return(-1);
371    
372     router = VM_C2691(vm);
373    
374     nm_bay = atoi(argv[1]);
375     port_id = atoi(argv[2]);
376    
377     if (c2691_nm_disable_nio(router,nm_bay,port_id) == -1) {
378     vm_release(vm);
379     hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
380     "C2691 %s: unable to unset NIO for "
381     "interface %u/%u",
382     argv[0],nm_bay,port_id);
383     return(-1);
384     }
385    
386     vm_release(vm);
387     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
388     return(0);
389     }
390    
391     /* Show C2691 hardware */
392     static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[])
393     {
394     vm_instance_t *vm;
395     c2691_t *router;
396    
397     if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C2691)))
398     return(-1);
399    
400     router = VM_C2691(vm);
401     c2691_show_hardware(router);
402    
403     vm_release(vm);
404     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
405     return(0);
406     }
407    
408     /* Show info about C2691 object */
409     static void cmd_show_c2691_list(registry_entry_t *entry,void *opt,int *err)
410     {
411     hypervisor_conn_t *conn = opt;
412     vm_instance_t *vm = entry->data;
413    
414     if (vm->type == VM_TYPE_C2691)
415     hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
416     }
417    
418     /* C2691 List */
419     static int cmd_c2691_list(hypervisor_conn_t *conn,int argc,char *argv[])
420     {
421     int err = 0;
422     registry_foreach_type(OBJ_TYPE_VM,cmd_show_c2691_list,conn,&err);
423     hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
424     return(0);
425     }
426    
427     /* C2691 commands */
428     static hypervisor_cmd_t c2691_cmd_array[] = {
429     { "create", 2, 2, cmd_create, NULL },
430     { "delete", 1, 1, cmd_delete, NULL },
431     { "set_iomem", 2, 2, cmd_set_iomem, NULL },
432     { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL },
433     { "start", 1, 1, cmd_start, NULL },
434     { "stop", 1, 1, cmd_stop, NULL },
435     { "nm_bindings", 1, 1, cmd_nm_bindings, NULL },
436     { "nm_nio_bindings", 2, 2, cmd_nm_nio_bindings, NULL },
437     { "add_nm_binding", 3, 3, cmd_add_nm_binding, NULL },
438     { "remove_nm_binding", 2, 2, cmd_remove_nm_binding, NULL },
439     { "add_nio_binding", 4, 4, cmd_add_nio_binding, NULL },
440     { "remove_nio_binding", 3, 3, cmd_remove_nio_binding, NULL },
441     { "nm_enable_nio", 3, 3, cmd_nm_enable_nio, NULL },
442     { "nm_disable_nio", 3, 3, cmd_nm_disable_nio, NULL },
443     { "show_hardware", 1, 1, cmd_show_hardware, NULL },
444     { "list", 0, 0, cmd_c2691_list, NULL },
445     { NULL, -1, -1, NULL, NULL },
446     };
447    
448     /* Hypervisor C2691 initialization */
449     int hypervisor_c2691_init(void)
450     {
451     hypervisor_module_t *module;
452    
453     module = hypervisor_register_module("c2691");
454     assert(module != NULL);
455    
456     hypervisor_register_cmd_array(module,c2691_cmd_array);
457     return(0);
458     }

  ViewVC Help
Powered by ViewVC 1.1.26