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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations)
Sat Oct 6 16:24:54 2007 UTC (16 years, 5 months ago) by dpavlin
Original Path: upstream/dynamips-0.2.7-RC2/hv_frsw.c
File MIME type: text/plain
File size: 3837 byte(s)
dynamips-0.2.7-RC2

1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4 *
5 * Hypervisor Frame-Relay 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 "frame_relay.h"
29 #include "crc.h"
30 #include "net_io.h"
31 #include "registry.h"
32 #include "hypervisor.h"
33
34 /* Create a new FRSW object */
35 static int cmd_create(hypervisor_conn_t *conn,int argc,char *argv[])
36 {
37 frsw_table_t *t;
38
39 if (!(t = frsw_create_table(argv[0]))) {
40 hypervisor_send_reply(conn,HSC_ERR_CREATE,1,
41 "unable to create frame-relay switch '%s'",
42 argv[0]);
43 return(-1);
44 }
45
46 frsw_release(argv[0]);
47 hypervisor_send_reply(conn,HSC_INFO_OK,1,"FRSW '%s' created",argv[0]);
48 return(0);
49 }
50
51 /* Delete a Frame-Relay switch */
52 static int cmd_delete(hypervisor_conn_t *conn,int argc,char *argv[])
53 {
54 int res;
55
56 res = frsw_delete(argv[0]);
57
58 if (res == 1) {
59 hypervisor_send_reply(conn,HSC_INFO_OK,1,"FRSW '%s' deleted",argv[0]);
60 } else {
61 hypervisor_send_reply(conn,HSC_ERR_DELETE,1,
62 "unable to delete FRSW '%s'",argv[0]);
63 }
64
65 return(res);
66 }
67
68 /*
69 * Create a Virtual Circuit
70 *
71 * Parameters: <frsw_name> <input_nio> <input_dlci> <output_nio> <output_dlci>
72 */
73 static int cmd_create_vc(hypervisor_conn_t *conn,int argc,char *argv[])
74 {
75 frsw_table_t *t;
76
77 if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_FRSW)))
78 return(-1);
79
80 /* create the connection */
81 if (frsw_create_vc(t,argv[1],atoi(argv[2]),argv[3],atoi(argv[4])) == -1) {
82 frsw_release(argv[0]);
83 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to create VC");
84 return(-1);
85 }
86
87 frsw_release(argv[0]);
88 hypervisor_send_reply(conn,HSC_INFO_OK,1,"VC created");
89 return(0);
90 }
91
92 /*
93 * Delete a Virtual Circuit
94 *
95 * Parameters: <frsw_name> <input_nio> <input_dlci> <output_nio> <output_dlci>
96 */
97 static int cmd_delete_vc(hypervisor_conn_t *conn,int argc,char *argv[])
98 {
99 frsw_table_t *t;
100
101 if (!(t = hypervisor_find_object(conn,argv[0],OBJ_TYPE_FRSW)))
102 return(-1);
103
104 /* delete the connection */
105 if (frsw_delete_vc(t,argv[1],atoi(argv[2]),argv[3],atoi(argv[4])) == -1) {
106 frsw_release(argv[0]);
107 hypervisor_send_reply(conn,HSC_ERR_BINDING,1,"unable to delete VC");
108 return(-1);
109 }
110
111 frsw_release(argv[0]);
112 hypervisor_send_reply(conn,HSC_INFO_OK,1,"VC deleted");
113 return(0);
114 }
115
116 /* Show info about a FRSW object */
117 static void cmd_show_list(registry_entry_t *entry,void *opt,int *err)
118 {
119 hypervisor_conn_t *conn = opt;
120 hypervisor_send_reply(conn,HSC_INFO_MSG,0,"%s",entry->name);
121 }
122
123 /* Frame-Relay switch List */
124 static int cmd_list(hypervisor_conn_t *conn,int argc,char *argv[])
125 {
126 int err = 0;
127 registry_foreach_type(OBJ_TYPE_FRSW,cmd_show_list,conn,&err);
128 hypervisor_send_reply(conn,HSC_INFO_OK,1,"OK");
129 return(0);
130 }
131
132 /* FRSW commands */
133 static hypervisor_cmd_t frsw_cmd_array[] = {
134 { "create", 1, 1, cmd_create, NULL },
135 { "delete", 1, 1, cmd_delete, NULL },
136 { "create_vc", 5, 5, cmd_create_vc, NULL },
137 { "delete_vc", 5, 5, cmd_delete_vc, NULL },
138 { "list", 0, 0, cmd_list, NULL },
139 { NULL, -1, -1, NULL, NULL },
140 };
141
142 /* Hypervisor Frame-Relay switch initialization */
143 int hypervisor_frsw_init(void)
144 {
145 hypervisor_module_t *module;
146
147 module = hypervisor_register_module("frsw");
148 assert(module != NULL);
149
150 hypervisor_register_cmd_array(module,frsw_cmd_array);
151 return(0);
152 }

  ViewVC Help
Powered by ViewVC 1.1.26