/[dynamips]/trunk/hv_nio_bridge.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 /trunk/hv_nio_bridge.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations)
Sat Oct 6 16:45:40 2007 UTC (11 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 3979 byte(s)
make working copy

1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4 *
5 * Hypervisor NIO bridge 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 "utils.h"
27 #include "net.h"
28 #include "crc.h"
29 #include "net_io.h"
30 #include "net_io_bridge.h"
31 #include "registry.h"
32 #include "hypervisor.h"
33
34 /* Create a new NIO bridge */
35 static int cmd_create(hypervisor_conn_t *conn,int argc,char *argv[])
36 {
37 netio_bridge_t *t;
38
39 if (!(t = netio_bridge_create(argv[0]))) {
40 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
41 "unable to create NIO bridge '%s'",
42 argv[0]);
43 return(-1);
44 }
45
46 netio_bridge_release(argv[0]);
47 hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO bridge '%s' created",argv[0]);
48 return(0);
49 }
50
51 /* Delete an NIO bridge */
52 static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[])
53 {
54 int res;
55
56 res = netio_bridge_delete(argv[0]);
57
58 if (res == 1) {
59 hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO bridge '%s' deleted",
60 argv[0]);
61 } else {
62 hypervisor_send_reply(conn,HSC_ERR_DELETE,1,
63 "unable to delete NIO bridge '%s'",argv[0]);
64 }
65
66 return(res);
67 }
68
69 /*
70 * Add a NIO to a bridge
71 *
72 * Parameters: <bridge_name> <nio_name>
73 */
74 static int cmd_add_nio(hypervisor_conn_t *conn,int argc,char *argv[])
75 {
76 netio_bridge_t *t;
77
78 if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_NIO_BRIDGE)))
79 return(-1);
80
81 if (netio_bridge_add_netio(t,argv[1]) == -1) {
82 netio_bridge_release(argv[0]);
83 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
84 "unable to bind NIO '%s' to bridge '%s'",
85 argv[1],argv[0]);
86 return(-1);
87 }
88
89 netio_bridge_release(argv[0]);
90 hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' bound.",argv[1]);
91 return(0);
92 }
93
94 /*
95 * Remove a NIO from a bridge
96 *
97 * Parameters: <bridge_name> <nio_name>
98 */
99 static int cmd_remove_nio(hypervisor_conn_t *conn,int argc,char *argv[])
100 {
101 netio_bridge_t *t;
102
103 if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_NIO_BRIDGE)))
104 return(-1);
105
106 if (netio_bridge_remove_netio(t,argv[1]) == -1) {
107 netio_bridge_release(argv[0]);
108 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
109 "unable to bind NIO '%s' to bridge '%s'",
110 argv[1],argv[0]);
111 return(-1);
112 }
113
114 netio_bridge_release(argv[0]);
115 hypervisor_send_reply(conn,HSC_INFO_OK,1,"NIO '%s' unbound.",argv[1]);
116 return(0);
117 }
118
119 /* Show info about a NIO bridge object */
120 static void cmd_show_list(registry_entry_t *entry,void *opt,int *err)
121 {
122 hypervisor_conn_t *conn = opt;
123 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
124 }
125
126 /* Bridge switch List */
127 static int cmd_list(hypervisor_conn_t *conn,int argc,char *argv[])
128 {
129 int err = 0;
130 registry_foreach_type(OBJ_TYPE_NIO_BRIDGE,cmd_show_list,conn,&err);
131 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
132 return(0);
133 }
134
135 /* NIO bridge commands */
136 static hypervisor_cmd_t nio_bridge_cmd_array[] = {
137 { "create", 1, 1, cmd_create, NULL },
138 { "delete", 1, 1, cmd_delete, NULL },
139 { "add_nio", 2, 2, cmd_add_nio, NULL },
140 { "remove_nio", 2, 2, cmd_remove_nio, NULL },
141 { "list", 0, 0, cmd_list, NULL },
142 { NULL, -1, -1, NULL, NULL },
143 };
144
145 /* Hypervisor NIO bridge initialization */
146 int hypervisor_nio_bridge_init(void)
147 {
148 hypervisor_module_t *module;
149
150 module = hypervisor_register_module("nio_bridge",NULL);
151 assert(module != NULL);
152
153 hypervisor_register_cmd_array(module,nio_bridge_cmd_array);
154 return(0);
155 }

  ViewVC Help
Powered by ViewVC 1.1.26