|
|
1.1 root 1: /*
2: * Cisco router simulation platform.
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_bridge.h"
29: #include "crc.h"
30: #include "net_io.h"
31: #include "registry.h"
32: #include "hypervisor.h"
33:
34: /* Create a new ATM bridge object */
35: static int cmd_create(hypervisor_conn_t *conn,int argc,char *argv[])
36: {
37: atm_bridge_t *t;
38:
39: if (!(t = atm_bridge_create(argv[0]))) {
40: hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
41: "unable to create ATM bridge '%s'",
42: argv[0]);
43: return(-1);
44: }
45:
46: atm_bridge_release(argv[0]);
47: hypervisor_send_reply(conn,HSC_INFO_OK,1,"ATM bridge '%s' created",argv[0]);
48: return(0);
49: }
50:
51: /* Delete an ATM bridge */
52: static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[])
53: {
54: int res;
55:
56: res = atm_bridge_delete(argv[0]);
57:
58: if (res == 1) {
59: hypervisor_send_reply(conn,HSC_INFO_OK,1,
60: "ATM bridge '%s' deleted",argv[0]);
61: } else {
62: hypervisor_send_reply(conn,HSC_ERR_DELETE,1,
63: "unable to delete ATM bridge '%s'",argv[0]);
64: }
65:
66: return(res);
67: }
68:
69: /*
70: * Configure an ATM bridge
71: *
72: * Parameters: <atmbr_name> <eth_nio> <atm_nio> <vpi> <vci>
73: */
74: static int cmd_configure(hypervisor_conn_t *conn,int argc,char *argv[])
75: {
76: atm_bridge_t *t;
77:
78: if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATM_BRIDGE)))
79: return(-1);
80:
81: /* create the connection */
82: if (atm_bridge_configure(t,argv[1],argv[2],
83: atoi(argv[3]),atoi(argv[4])) == -1)
84: {
85: atm_bridge_release(argv[0]);
86: hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
87: "unable to configure bridge");
88: return(-1);
89: }
90:
91: atm_bridge_release(argv[0]);
92: hypervisor_send_reply(conn,HSC_INFO_OK,1,"ATM bridge configured");
93: return(0);
94: }
95:
96: /*
97: * Unconfigure a bridge
98: */
99: static int cmd_unconfigure(hypervisor_conn_t *conn,int argc,char *argv[])
100: {
101: atm_bridge_t *t;
102:
103: if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_ATM_BRIDGE)))
104: return(-1);
105:
106: if (atm_bridge_unconfigure(t) == -1) {
107: atm_bridge_release(argv[0]);
108: hypervisor_send_reply(conn,HSC_ERR_BINDING,1,
109: "unable to unconfigure bridge");
110: return(-1);
111: }
112:
113: atm_bridge_release(argv[0]);
114: hypervisor_send_reply(conn,HSC_INFO_OK,1,"ATM bridge unconfigured");
115: return(0);
116: }
117:
118: /* Show info about a ATM bridge object */
119: static void cmd_show_list(registry_entry_t *entry,void *opt,int *err)
120: {
121: hypervisor_conn_t *conn = opt;
122: hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
123: }
124:
125: /* ATM bridge List */
126: static int cmd_list(hypervisor_conn_t *conn,int argc,char *argv[])
127: {
128: int err = 0;
129: registry_foreach_type(OBJ_TYPE_ATM_BRIDGE,cmd_show_list,conn,&err);
130: hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
131: return(0);
132: }
133:
134: /* ATM Bridge commands */
135: static hypervisor_cmd_t atmbr_cmd_array[] = {
136: { "create", 1, 1, cmd_create, NULL },
137: { "delete", 1, 1, cmd_delete, NULL },
138: { "configure", 5, 5, cmd_configure, NULL },
139: { "unconfigure", 1, 1, cmd_unconfigure, NULL },
140: { "list", 0, 0, cmd_list, NULL },
141: { NULL, -1, -1, NULL, NULL },
142: };
143:
144: /* Hypervisor ATM bridge initialization */
145: int hypervisor_atm_bridge_init(void)
146: {
147: hypervisor_module_t *module;
148:
149: module = hypervisor_register_module("atm_bridge",NULL);
150: assert(module != NULL);
151:
152: hypervisor_register_cmd_array(module,atmbr_cmd_array);
153: return(0);
154: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.