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