/[dynamips]/upstream/dynamips-0.2.6-RC3/hv_c3600.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-RC3/hv_c3600.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Sat Oct 6 16:03:58 2007 UTC (16 years, 5 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.6-RC1/hv_c3600.c
File MIME type: text/plain
File size: 12701 byte(s)
import dynamips-0.2.6-RC1

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

  ViewVC Help
Powered by ViewVC 1.1.26