1 |
dpavlin |
1 |
/* |
2 |
dpavlin |
7 |
* Cisco router simulation platform. |
3 |
dpavlin |
1 |
* Copyright (c) 2006 Christophe Fillot (cf@utc.fr) |
4 |
|
|
* |
5 |
|
|
* Hypervisor ATM switch 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 "atm.h" |
29 |
|
|
#include "frame_relay.h" |
30 |
|
|
#include "crc.h" |
31 |
|
|
#include "net_io.h" |
32 |
|
|
#include "registry.h" |
33 |
|
|
#include "hypervisor.h" |
34 |
|
|
|
35 |
|
|
/* Create a new ATMSW object */ |
36 |
|
|
static int cmd_create(hypervisor_conn_t *conn,int argc,char *argv[]) |
37 |
|
|
{ |
38 |
|
|
atmsw_table_t *t; |
39 |
|
|
|
40 |
|
|
if (!(t = atmsw_create_table(argv[0]))) { |
41 |
|
|
hypervisor_send_reply(conn,HSC_ERR_CREATE,1, |
42 |
|
|
"unable to create ATM switch '%s'", |
43 |
|
|
argv[0]); |
44 |
|
|
return(-1); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
atmsw_release(argv[0]); |
48 |
|
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"ATMSW '%s' created",argv[0]); |
49 |
|
|
return(0); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
/* Delete an ATM switch */ |
53 |
|
|
static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[]) |
54 |
|
|
{ |
55 |
|
|
int res; |
56 |
|
|
|
57 |
|
|
res = atmsw_delete(argv[0]); |
58 |
|
|
|
59 |
|
|
if (res == 1) { |
60 |
|
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"ATMSW '%s' deleted",argv[0]); |
61 |
|
|
} else { |
62 |
|
|
hypervisor_send_reply(conn,HSC_ERR_DELETE,1, |
63 |
|
|
"unable to delete ATMSW '%s'",argv[0]); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
return(res); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
/* |
70 |
|
|
* Create a Virtual Path Connection |
71 |
|
|
* |
72 |
|
|
* Parameters: <atmsw_name> <input_nio> <input_vpi> <output_nio> <output_vpi> |
73 |
|
|
*/ |
74 |
|
|
static int cmd_create_vpc(hypervisor_conn_t *conn,int argc,char *argv[]) |
75 |
|
|
{ |
76 |
|
|
atmsw_table_t *t; |
77 |
|
|
|
78 |
|
|
if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATMSW))) |
79 |
|
|
return(-1); |
80 |
|
|
|
81 |
|
|
/* create the connection */ |
82 |
|
|
if (atmsw_create_vpc(t,argv[1],atoi(argv[2]),argv[3],atoi(argv[4])) == -1) { |
83 |
|
|
atmsw_release(argv[0]); |
84 |
|
|
hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to create VPC"); |
85 |
|
|
return(-1); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
atmsw_release(argv[0]); |
89 |
|
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"VPC created"); |
90 |
|
|
return(0); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/* |
94 |
|
|
* Delete a Virtual Path Connection |
95 |
|
|
* |
96 |
|
|
* Parameters: <atmsw_name> <input_nio> <input_vpi> <output_nio> <output_vpi> |
97 |
|
|
*/ |
98 |
|
|
static int cmd_delete_vpc(hypervisor_conn_t *conn,int argc,char *argv[]) |
99 |
|
|
{ |
100 |
|
|
atmsw_table_t *t; |
101 |
|
|
|
102 |
|
|
if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATMSW))) |
103 |
|
|
return(-1); |
104 |
|
|
|
105 |
|
|
/* delete the connection */ |
106 |
|
|
if (atmsw_delete_vpc(t,argv[1],atoi(argv[2]),argv[3],atoi(argv[4])) == -1) { |
107 |
|
|
atmsw_release(argv[0]); |
108 |
|
|
hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to delete VPC"); |
109 |
|
|
return(-1); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
atmsw_release(argv[0]); |
113 |
|
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"VPC deleted"); |
114 |
|
|
return(0); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
/* |
118 |
|
|
* Create a Virtual Circuit Connection |
119 |
|
|
* |
120 |
|
|
* Parameters: <atmsw_name> <input_nio> <input_vpi> <input_vci> |
121 |
|
|
* <output_nio> <output_vpi> <output_vci> |
122 |
|
|
*/ |
123 |
|
|
static int cmd_create_vcc(hypervisor_conn_t *conn,int argc,char *argv[]) |
124 |
|
|
{ |
125 |
|
|
atmsw_table_t *t; |
126 |
|
|
|
127 |
|
|
if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATMSW))) |
128 |
|
|
return(-1); |
129 |
|
|
|
130 |
|
|
/* create the connection */ |
131 |
|
|
if (atmsw_create_vcc(t,argv[1],atoi(argv[2]),atoi(argv[3]), |
132 |
|
|
argv[4],atoi(argv[5]),atoi(argv[6])) == -1) |
133 |
|
|
{ |
134 |
|
|
atmsw_release(argv[0]); |
135 |
|
|
hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to create VCC"); |
136 |
|
|
return(-1); |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
atmsw_release(argv[0]); |
140 |
|
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"VCC created"); |
141 |
|
|
return(0); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
/* |
145 |
|
|
* Delete a Virtual Circuit Connection |
146 |
|
|
* |
147 |
|
|
* Parameters: <atmsw_name> <input_nio> <input_vpi> <input_vci> |
148 |
|
|
* <output_nio> <output_vpi> <output_vci> |
149 |
|
|
*/ |
150 |
|
|
static int cmd_delete_vcc(hypervisor_conn_t *conn,int argc,char *argv[]) |
151 |
|
|
{ |
152 |
|
|
atmsw_table_t *t; |
153 |
|
|
|
154 |
|
|
if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATMSW))) |
155 |
|
|
return(-1); |
156 |
|
|
|
157 |
|
|
/* create the connection */ |
158 |
|
|
if (atmsw_delete_vcc(t,argv[1],atoi(argv[2]),atoi(argv[3]), |
159 |
|
|
argv[4],atoi(argv[5]),atoi(argv[6])) == -1) |
160 |
|
|
{ |
161 |
|
|
atmsw_release(argv[0]); |
162 |
|
|
hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to delete VCC"); |
163 |
|
|
return(-1); |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
atmsw_release(argv[0]); |
167 |
|
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"VCC deleted"); |
168 |
|
|
return(0); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
/* Show info about a ATM switch object */ |
172 |
|
|
static void cmd_show_list(registry_entry_t *entry,void *opt,int *err) |
173 |
|
|
{ |
174 |
|
|
hypervisor_conn_t *conn = opt; |
175 |
|
|
hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name); |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
/* ATM switch List */ |
179 |
|
|
static int cmd_list(hypervisor_conn_t *conn,int argc,char *argv[]) |
180 |
|
|
{ |
181 |
|
|
int err = 0; |
182 |
|
|
registry_foreach_type(OBJ_TYPE_ATMSW,cmd_show_list,conn,&err); |
183 |
|
|
hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK"); |
184 |
|
|
return(0); |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
/* ATMSW commands */ |
188 |
|
|
static hypervisor_cmd_t atmsw_cmd_array[] = { |
189 |
|
|
{ "create", 1, 1, cmd_create, NULL }, |
190 |
|
|
{ "delete", 1, 1, cmd_delete, NULL }, |
191 |
|
|
{ "create_vpc", 5, 5, cmd_create_vpc, NULL }, |
192 |
|
|
{ "delete_vpc", 5, 5, cmd_delete_vpc, NULL }, |
193 |
|
|
{ "create_vcc", 7, 7, cmd_create_vcc, NULL }, |
194 |
|
|
{ "delete_vcc", 7, 7, cmd_delete_vcc, NULL }, |
195 |
|
|
{ "list", 0, 0, cmd_list, NULL }, |
196 |
|
|
{ NULL, -1, -1, NULL, NULL }, |
197 |
|
|
}; |
198 |
|
|
|
199 |
|
|
/* Hypervisor ATM switch initialization */ |
200 |
|
|
int hypervisor_atmsw_init(void) |
201 |
|
|
{ |
202 |
|
|
hypervisor_module_t *module; |
203 |
|
|
|
204 |
|
|
module = hypervisor_register_module("atmsw"); |
205 |
|
|
assert(module != NULL); |
206 |
|
|
|
207 |
|
|
hypervisor_register_cmd_array(module,atmsw_cmd_array); |
208 |
|
|
return(0); |
209 |
|
|
} |