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

Contents of /upstream/dynamips-0.2.6-RC3/hv_c7200.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations)
Sat Oct 6 16:06:49 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 13935 byte(s)
dynamips-0.2.6-RC3

1 /*
2 * Cisco 7200 (Predator) simulation platform.
3 * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4 *
5 * Hypervisor C7200 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_c7200.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 C7200 instance */
45 static int cmd_create(hypervisor_conn_t *conn,int argc,char *argv[])
46 {
47 c7200_t *router;
48
49 if (!(router = c7200_create_instance(argv[0],atoi(argv[1])))) {
50 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
51 "unable to create C7200 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,"C7200 '%s' created",argv[0]);
61 return(0);
62 }
63
64 /* Delete a C7200 instance */
65 static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[])
66 {
67 int res;
68
69 res = c7200_delete_instance(argv[0]);
70
71 if (res == 1) {
72 hypervisor_send_reply(conn,HSC_INFO_OK,1,"C7200 '%s' deleted",argv[0]);
73 } else {
74 hypervisor_send_reply(conn,HSC_ERR_DELETE,1,
75 "unable to delete C7200 '%s'",argv[0]);
76 }
77
78 return(res);
79 }
80
81 /* Set the NPE type */
82 static int cmd_set_npe(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_C7200)))
87 return(-1);
88
89 if ((c7200_npe_set_type(VM_C7200(vm),argv[1])) == -1) {
90 vm_release(vm);
91 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
92 "unable to set NPE 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 Midplane type */
103 static int cmd_set_midplane(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_C7200)))
108 return(-1);
109
110 if ((c7200_midplane_set_type(VM_C7200(vm),argv[1])) == -1) {
111 vm_release(vm);
112 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
113 "unable to set Midplane type 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 /* 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],VM_TYPE_C7200)))
129 return(-1);
130
131 if ((c7200_midplane_set_mac_addr(VM_C7200(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 /* Start a C7200 instance */
145 static int cmd_start(hypervisor_conn_t *conn,int argc,char *argv[])
146 {
147 vm_instance_t *vm;
148 c7200_t *router;
149
150 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
151 return(-1);
152
153 router = VM_C7200(vm);
154
155 if (router->vm->vtty_con_type == VTTY_TYPE_NONE) {
156 hypervisor_send_reply(conn,HSC_INFO_MSG,0,
157 "Warning: no console port defined for "
158 "C7200 '%s'",argv[0]);
159 }
160
161 if (c7200_init_instance(router) == -1) {
162 vm_release(vm);
163 hypervisor_send_reply(conn,HSC_ERR_START,1,
164 "unable to start instance '%s'",
165 argv[0]);
166 return(-1);
167 }
168
169 vm_release(vm);
170 hypervisor_send_reply(conn,HSC_INFO_OK,1,"C7200 '%s' started",argv[0]);
171 return(0);
172 }
173
174 /* Stop a C7200 instance */
175 static int cmd_stop(hypervisor_conn_t *conn,int argc,char *argv[])
176 {
177 vm_instance_t *vm;
178 c7200_t *router;
179
180 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
181 return(-1);
182
183 router = VM_C7200(vm);
184
185 if (c7200_stop_instance(router) == -1) {
186 vm_release(vm);
187 hypervisor_send_reply(conn,HSC_ERR_STOP,1,
188 "unable to stop instance '%s'",
189 argv[0]);
190 return(-1);
191 }
192
193 vm_release(vm);
194 hypervisor_send_reply(conn,HSC_INFO_OK,1,"C7200 '%s' stopped",argv[0]);
195 return(0);
196 }
197
198 /* Show PA bindings */
199 static int cmd_pa_bindings(hypervisor_conn_t *conn,int argc,char *argv[])
200 {
201 vm_instance_t *vm;
202 c7200_t *router;
203 char *pa_type;
204 int i;
205
206 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
207 return(-1);
208
209 router = VM_C7200(vm);
210
211 for(i=0;i<C7200_MAX_PA_BAYS;i++) {
212 pa_type = c7200_pa_get_type(router,i);
213 if (pa_type)
214 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u: %s",i,pa_type);
215 }
216
217 vm_release(vm);
218 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
219 return(0);
220 }
221
222 /* Show PA NIO bindings */
223 static int cmd_pa_nio_bindings(hypervisor_conn_t *conn,int argc,char *argv[])
224 {
225 struct c7200_nio_binding *nb;
226 struct c7200_pa_bay *bay;
227 vm_instance_t *vm;
228 c7200_t *router;
229 u_int pa_bay;
230
231 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
232 return(-1);
233
234 router = VM_C7200(vm);
235 pa_bay = atoi(argv[1]);
236
237 if (!(bay = c7200_pa_get_info(router,pa_bay))) {
238 vm_release(vm);
239 hypervisor_send_reply(conn,HSC_ERR_UNK_OBJ,1,"Invalid slot %u",pa_bay);
240 return(-1);
241 }
242
243 for(nb=bay->nio_list;nb;nb=nb->next)
244 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%u: %s",
245 nb->port_id,nb->nio->name);
246
247 vm_release(vm);
248 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
249 return(0);
250 }
251
252 /* Add a PA binding for the specified slot */
253 static int cmd_add_pa_binding(hypervisor_conn_t *conn,int argc,char *argv[])
254 {
255 vm_instance_t *vm;
256 c7200_t *router;
257 u_int pa_bay;
258
259 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
260 return(-1);
261
262 router = VM_C7200(vm);
263 pa_bay = atoi(argv[1]);
264
265 if (c7200_pa_add_binding(router,argv[2],pa_bay) == -1) {
266 vm_release(vm);
267 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
268 "C7200 %s: unable to add PA binding for slot %u",
269 argv[0],pa_bay);
270 return(-1);
271 }
272
273 vm_release(vm);
274 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
275 return(0);
276 }
277
278 /* Remove a PA binding for the specified slot */
279 static int cmd_remove_pa_binding(hypervisor_conn_t *conn,int argc,char *argv[])
280 {
281 vm_instance_t *vm;
282 c7200_t *router;
283 u_int pa_bay;
284
285 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
286 return(-1);
287
288 router = VM_C7200(vm);
289 pa_bay = atoi(argv[1]);
290
291 if (c7200_pa_remove_binding(router,pa_bay) == -1) {
292 vm_release(vm);
293 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
294 "C7200 %s: unable to remove PA binding for "
295 "slot %u",argv[0],pa_bay);
296 return(-1);
297 }
298
299 vm_release(vm);
300 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
301 return(0);
302 }
303
304 /* Add a NIO binding to the specified slot/port */
305 static int cmd_add_nio_binding(hypervisor_conn_t *conn,int argc,char *argv[])
306 {
307 u_int pa_bay,port_id;
308 vm_instance_t *vm;
309 c7200_t *router;
310
311 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
312 return(-1);
313
314 router = VM_C7200(vm);
315
316 pa_bay = atoi(argv[1]);
317 port_id = atoi(argv[2]);
318
319 if (c7200_pa_add_nio_binding(router,pa_bay,port_id,argv[3]) == -1) {
320 vm_release(vm);
321 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
322 "C7200 %s: unable to add NIO binding for "
323 "interface %u/%u",argv[0],pa_bay,port_id);
324 return(-1);
325 }
326
327 vm_release(vm);
328 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
329 return(0);
330 }
331
332 /* Remove a NIO binding from the specified slot/port */
333 static int cmd_remove_nio_binding(hypervisor_conn_t *conn,
334 int argc,char *argv[])
335 {
336 u_int pa_bay,port_id;
337 vm_instance_t *vm;
338 c7200_t *router;
339
340 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
341 return(-1);
342
343 router = VM_C7200(vm);
344
345 pa_bay = atoi(argv[1]);
346 port_id = atoi(argv[2]);
347
348 if (c7200_pa_remove_nio_binding(router,pa_bay,port_id) == -1) {
349 vm_release(vm);
350 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
351 "C7200 %s: unable to remove NIO binding for "
352 "interface %u/%u",argv[0],pa_bay,port_id);
353 return(-1);
354 }
355
356 vm_release(vm);
357 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
358 return(0);
359 }
360
361 /* Enable NIO of the specified slot/port */
362 static int cmd_pa_enable_nio(hypervisor_conn_t *conn,int argc,char *argv[])
363 {
364 u_int pa_bay,port_id;
365 vm_instance_t *vm;
366 c7200_t *router;
367
368 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
369 return(-1);
370
371 router = VM_C7200(vm);
372
373 pa_bay = atoi(argv[1]);
374 port_id = atoi(argv[2]);
375
376 if (c7200_pa_enable_nio(router,pa_bay,port_id) == -1) {
377 vm_release(vm);
378 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
379 "C7200 %s: unable to enable NIO for "
380 "interface %u/%u",argv[0],pa_bay,port_id);
381 return(-1);
382 }
383
384 vm_release(vm);
385 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
386 return(0);
387 }
388
389 /* Disable NIO of the specified slot/port */
390 static int cmd_pa_disable_nio(hypervisor_conn_t *conn,int argc,char *argv[])
391 {
392 u_int pa_bay,port_id;
393 vm_instance_t *vm;
394 c7200_t *router;
395
396 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
397 return(-1);
398
399 router = VM_C7200(vm);
400
401 pa_bay = atoi(argv[1]);
402 port_id = atoi(argv[2]);
403
404 if (c7200_pa_disable_nio(router,pa_bay,port_id) == -1) {
405 vm_release(vm);
406 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
407 "C7200 %s: unable to unset NIO for "
408 "interface %u/%u",
409 argv[0],pa_bay,port_id);
410 return(-1);
411 }
412
413 vm_release(vm);
414 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
415 return(0);
416 }
417
418 /* Initialize a PA while the router is running */
419 static int cmd_pa_init_online(hypervisor_conn_t *conn,int argc,char *argv[])
420 {
421 vm_instance_t *vm;
422 c7200_t *router;
423 u_int pa_bay;
424
425 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
426 return(-1);
427
428 router = VM_C7200(vm);
429
430 pa_bay = atoi(argv[1]);
431 c7200_pa_init_online(router,pa_bay);
432
433 vm_release(vm);
434 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
435 return(0);
436 }
437
438 /* Stop a PA while the router is running */
439 static int cmd_pa_stop_online(hypervisor_conn_t *conn,int argc,char *argv[])
440 {
441 vm_instance_t *vm;
442 c7200_t *router;
443 u_int pa_bay;
444
445 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
446 return(-1);
447
448 router = VM_C7200(vm);
449
450 pa_bay = atoi(argv[1]);
451 c7200_pa_stop_online(router,pa_bay);
452
453 vm_release(vm);
454 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
455 return(0);
456 }
457
458 /* Show C7200 hardware */
459 static int cmd_show_hardware(hypervisor_conn_t *conn,int argc,char *argv[])
460 {
461 vm_instance_t *vm;
462 c7200_t *router;
463
464 if (!(vm = hypervisor_find_vm(conn,argv[0],VM_TYPE_C7200)))
465 return(-1);
466
467 router = VM_C7200(vm);
468 c7200_show_hardware(router);
469
470 vm_release(vm);
471 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
472 return(0);
473 }
474
475 /* Show info about C7200 object */
476 static void cmd_show_c7200_list(registry_entry_t *entry,void *opt,int *err)
477 {
478 hypervisor_conn_t *conn = opt;
479 vm_instance_t *vm = entry->data;
480
481 if (vm->type == VM_TYPE_C7200)
482 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
483 }
484
485 /* C7200 List */
486 static int cmd_c7200_list(hypervisor_conn_t *conn,int argc,char *argv[])
487 {
488 int err = 0;
489 registry_foreach_type(OBJ_TYPE_VM,cmd_show_c7200_list,conn,&err);
490 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
491 return(0);
492 }
493
494 /* C7200 commands */
495 static hypervisor_cmd_t c7200_cmd_array[] = {
496 { "create", 2, 2, cmd_create, NULL },
497 { "delete", 1, 1, cmd_delete, NULL },
498 { "set_npe", 2, 2, cmd_set_npe, NULL },
499 { "set_midplane", 2, 2, cmd_set_midplane, NULL },
500 { "set_mac_addr", 2, 2, cmd_set_mac_addr, NULL },
501 { "start", 1, 1, cmd_start, NULL },
502 { "stop", 1, 1, cmd_stop, NULL },
503 { "pa_bindings", 1, 1, cmd_pa_bindings, NULL },
504 { "pa_nio_bindings", 2, 2, cmd_pa_nio_bindings, NULL },
505 { "add_pa_binding", 3, 3, cmd_add_pa_binding, NULL },
506 { "remove_pa_binding", 2, 2, cmd_remove_pa_binding, NULL },
507 { "add_nio_binding", 4, 4, cmd_add_nio_binding, NULL },
508 { "remove_nio_binding", 3, 3, cmd_remove_nio_binding, NULL },
509 { "pa_enable_nio", 3, 3, cmd_pa_enable_nio, NULL },
510 { "pa_disable_nio", 3, 3, cmd_pa_disable_nio, NULL },
511 { "pa_init_online", 2, 2, cmd_pa_init_online, NULL },
512 { "pa_stop_online", 2, 2, cmd_pa_stop_online, NULL },
513 { "show_hardware", 1, 1, cmd_show_hardware, NULL },
514 { "list", 0, 0, cmd_c7200_list, NULL },
515 { NULL, -1, -1, NULL, NULL },
516 };
517
518 /* Hypervisor C7200 initialization */
519 int hypervisor_c7200_init(void)
520 {
521 hypervisor_module_t *module;
522
523 module = hypervisor_register_module("c7200");
524 assert(module != NULL);
525
526 hypervisor_register_cmd_array(module,c7200_cmd_array);
527 return(0);
528 }

  ViewVC Help
Powered by ViewVC 1.1.26