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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Sat Oct 6 16:01:44 2007 UTC (12 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 4025 byte(s)
import 0.2.5 from upstream

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

  ViewVC Help
Powered by ViewVC 1.1.26