| 1 |
/* |
| 2 |
* Cisco router simulation platform. |
| 3 |
* Copyright (c) 2006 Christophe Fillot ([email protected]) |
| 4 |
* |
| 5 |
* Hypervisor routines. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef __HYPERVISOR_H__ |
| 9 |
#define __HYPERVISOR_H__ |
| 10 |
|
| 11 |
/* Default TCP port */ |
| 12 |
#define HYPERVISOR_TCP_PORT 7200 |
| 13 |
|
| 14 |
/* Maximum listening socket number */ |
| 15 |
#define HYPERVISOR_MAX_FD 10 |
| 16 |
|
| 17 |
/* Maximum tokens per line */ |
| 18 |
#define HYPERVISOR_MAX_TOKENS 16 |
| 19 |
|
| 20 |
/* Hypervisor status codes */ |
| 21 |
#define HSC_INFO_OK 100 /* ok */ |
| 22 |
#define HSC_INFO_MSG 101 /* informative message */ |
| 23 |
#define HSC_INFO_DEBUG 102 /* debugging message */ |
| 24 |
#define HSC_ERR_PARSING 200 /* parse error */ |
| 25 |
#define HSC_ERR_UNK_MODULE 201 /* unknown module */ |
| 26 |
#define HSC_ERR_UNK_CMD 202 /* unknown command */ |
| 27 |
#define HSC_ERR_BAD_PARAM 203 /* bad number of parameters */ |
| 28 |
#define HSC_ERR_INV_PARAM 204 /* invalid parameter */ |
| 29 |
#define HSC_ERR_BINDING 205 /* binding error */ |
| 30 |
#define HSC_ERR_CREATE 206 /* unable to create object */ |
| 31 |
#define HSC_ERR_DELETE 207 /* unable to delete object */ |
| 32 |
#define HSC_ERR_UNK_OBJ 208 /* unknown object */ |
| 33 |
#define HSC_ERR_START 209 /* unable to start object */ |
| 34 |
#define HSC_ERR_STOP 210 /* unable to stop object */ |
| 35 |
#define HSC_ERR_FILE 211 /* file error */ |
| 36 |
#define HSC_ERR_BAD_OBJ 212 /* Bad object */ |
| 37 |
#define HSC_ERR_RENAME 213 /* unable to rename object */ |
| 38 |
#define HSC_ERR_NOT_FOUND 214 /* not found (generic) */ |
| 39 |
#define HSC_ERR_UNSPECIFIED 215 /* unspecified error (generic) */ |
| 40 |
|
| 41 |
typedef struct hypervisor_conn hypervisor_conn_t; |
| 42 |
typedef struct hypervisor_cmd hypervisor_cmd_t; |
| 43 |
typedef struct hypervisor_module hypervisor_module_t; |
| 44 |
|
| 45 |
/* Hypervisor connection */ |
| 46 |
struct hypervisor_conn { |
| 47 |
pthread_t tid; /* Thread identifier */ |
| 48 |
volatile int active; /* Connection is active ? */ |
| 49 |
int client_fd; /* Client FD */ |
| 50 |
FILE *in,*out; /* I/O buffered streams */ |
| 51 |
hypervisor_module_t *cur_module; /* Module of current command */ |
| 52 |
hypervisor_conn_t *next,**pprev; |
| 53 |
}; |
| 54 |
|
| 55 |
/* Hypervisor command handler */ |
| 56 |
typedef int (*hypervisor_cmd_handler)(hypervisor_conn_t *conn,int argc, |
| 57 |
char *argv[]); |
| 58 |
|
| 59 |
/* Hypervisor command */ |
| 60 |
struct hypervisor_cmd { |
| 61 |
char *name; |
| 62 |
int min_param,max_param; |
| 63 |
hypervisor_cmd_handler handler; |
| 64 |
hypervisor_cmd_t *next; |
| 65 |
}; |
| 66 |
|
| 67 |
/* Hypervisor module */ |
| 68 |
struct hypervisor_module { |
| 69 |
char *name; |
| 70 |
void *opt; |
| 71 |
hypervisor_cmd_t *cmd_list; |
| 72 |
hypervisor_module_t *next; |
| 73 |
}; |
| 74 |
|
| 75 |
/* Hypervisor NIO initialization */ |
| 76 |
extern int hypervisor_nio_init(void); |
| 77 |
|
| 78 |
/* Hypervisor NIO bridge initialization */ |
| 79 |
extern int hypervisor_nio_bridge_init(void); |
| 80 |
|
| 81 |
/* Hypervisor Frame-Relay switch initialization */ |
| 82 |
extern int hypervisor_frsw_init(void); |
| 83 |
|
| 84 |
/* Hypervisor ATM switch initialization */ |
| 85 |
extern int hypervisor_atmsw_init(void); |
| 86 |
|
| 87 |
/* Hypervisor ATM bridge initialization */ |
| 88 |
extern int hypervisor_atm_bridge_init(void); |
| 89 |
|
| 90 |
/* Hypervisor Ethernet switch initialization */ |
| 91 |
extern int hypervisor_ethsw_init(void); |
| 92 |
|
| 93 |
/* Hypervisor VM initialization */ |
| 94 |
extern int hypervisor_vm_init(void); |
| 95 |
|
| 96 |
/* Hypervisor VM debugging initialization */ |
| 97 |
extern int hypervisor_vm_debug_init(void); |
| 98 |
|
| 99 |
/* Hypervisor store initialization */ |
| 100 |
extern int hypervisor_store_init(void); |
| 101 |
|
| 102 |
/* Send a reply */ |
| 103 |
int hypervisor_send_reply(hypervisor_conn_t *conn,int code,int done, |
| 104 |
char *format,...); |
| 105 |
|
| 106 |
/* Find a module */ |
| 107 |
hypervisor_module_t *hypervisor_find_module(char *name); |
| 108 |
|
| 109 |
/* Find a command in a module */ |
| 110 |
hypervisor_cmd_t *hypervisor_find_cmd(hypervisor_module_t *module,char *name); |
| 111 |
|
| 112 |
/* Find an object in the registry */ |
| 113 |
void *hypervisor_find_object(hypervisor_conn_t *conn,char *name,int obj_type); |
| 114 |
|
| 115 |
/* Find a VM in the registry */ |
| 116 |
void *hypervisor_find_vm(hypervisor_conn_t *conn,char *name); |
| 117 |
|
| 118 |
/* Register a module */ |
| 119 |
hypervisor_module_t *hypervisor_register_module(char *name,void *opt); |
| 120 |
|
| 121 |
/* Register a list of commands */ |
| 122 |
int hypervisor_register_cmd_list(hypervisor_module_t *module, |
| 123 |
hypervisor_cmd_t *cmd_list); |
| 124 |
|
| 125 |
/* Register an array of commands */ |
| 126 |
int hypervisor_register_cmd_array(hypervisor_module_t *module, |
| 127 |
hypervisor_cmd_t *cmd_array); |
| 128 |
|
| 129 |
/* Stop hypervisor from sighandler */ |
| 130 |
int hypervisor_stopsig(void); |
| 131 |
|
| 132 |
/* Hypervisor TCP server */ |
| 133 |
int hypervisor_tcp_server(char *ip_addr,int tcp_port); |
| 134 |
|
| 135 |
#endif |