/[dynamips]/upstream/dynamips-0.2.6-RC1/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 /upstream/dynamips-0.2.6-RC1/hv_frsw.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Sat Oct 6 16:03:58 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 3888 byte(s)
import dynamips-0.2.6-RC1

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

  ViewVC Help
Powered by ViewVC 1.1.26