OSDN Git Service

Update INSTALL.ja.utf-8 for new release.
[ultramonkey-l7/ultramonkey-l7-v2.git] / include / l7vs_service.h
1 /* 
2  * @file    l7vs_service.h
3  * @bref    service that brings function of l7vsd together.
4  * @bref    It has sets of conn of ther service.
5  * @bref    and sets of read servers.
6  * @bref    and protocol module
7  * @bref    and schedulers.
8  *
9  *
10  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
11  * Copyright (C) 2005  NTT COMWARE Corporation.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this library; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26  * 02110-1301 USA
27  *
28  **********************************************************************/
29 #ifndef L7VS_SERVICE_H
30 #define L7VS_SERVICE_H
31
32 #include <stdint.h>
33 #include <glib.h>
34 #include "l7vs_conn.h"
35 #include "l7vs.h"
36
37 struct l7vs_lsock;
38 struct l7vs_scheduler;
39 struct l7vs_protomod;
40 struct l7vs_dest;
41 struct l7vs_dest_arg;
42
43 typedef uint32_t handle_t;
44
45 #define TEMP_SERVICEHANDLE      UINT32_MAX
46 #define BPS_DEFAULT_INTERVAL    1000000ULL
47
48 // virtual service definition datatype
49 struct l7vs_service{
50     handle_t               handle;     //! l7vs_service_handle
51     struct l7vs_lsock*     lsock;      //! listen socket struct pointer
52     GList*                 dest_list;  //! real server list
53 //    GList*                 conn_list;
54     GHashTable*            conn_hash;  //! connection table
55     struct l7vs_scheduler* scheduler;  //! scheduler pointer
56     void*                  sched_data; //! scheduler data pointer
57     struct l7vs_protomod*  pm;         //! protocol module pointer
58
59     // ...and per-module match-data follows
60     char              protomod_opt_string[L7VS_PROTOMOD_OPT_LEN]; //! protocol module option string
61     char              protomod_key_string[L7VS_PROTOMOD_KEY_LEN]; //! protocol module key string
62     int               reschedule;               //! reschedule flag
63     int               sorry_cc;                 //! sorry connection count limit
64     struct l7vs_dest* sorry_dest;               //! sorry-server destination
65     int               sorry_flag;               //! sorry flag
66
67     unsigned long long qos_threshold_up;            //! QoS threshold value from client to real server (UP Direction)
68     unsigned long long qos_threshold_down;          //! QoS threshold value from real server to client (DOWN Direction)
69     unsigned long long throughput_to_server;        //! Throughput to real server
70     unsigned long long throughput_to_client;        //! Throughput to client
71     size_t             pre_recvsize_from_client;    //! data recive size from client (before 1 sec)
72     size_t             cur_recvsize_from_client;    //! data recive size from client (current)
73     unsigned long long pre_recvtime_from_client;    //! Receiving time from client
74     size_t             pre_recvsize_from_server;    //! data recive size from real server (before 1 sec)
75     size_t             cur_recvsize_from_server;    //! data recive size from real server (current)
76     unsigned long long pre_recvtime_from_server;    //! Receiving time from real server
77     int                qos_up_flag;                 //! QoS to real server intervention flag (UP Direction)
78     int                qos_down_flag;               //! QoS to client intervention flag (DOWN Direction)
79 };
80
81 // virtual service definition, external representation.
82 struct l7vs_service_arg{
83     size_t             len;     //! structure size
84     struct sockaddr_in addr;    //! server address
85     uint8_t            proto;   //! server transport protocol
86     int                persist; //! persistency
87     int                backlog; //! listen(2) backlog length
88
89     char               protomod[L7VS_MODNAME_LEN]; //! protocol module name
90     char               schedmod[L7VS_MODNAME_LEN]; //! scheduler
91
92     // ... and protocol-module defined data follows
93     char                    protomod_opt_string[L7VS_PROTOMOD_OPT_LEN]; //! protocol module option string
94     char                    protomod_key_string[L7VS_PROTOMOD_KEY_LEN]; //! protocol module key string
95     int                     reschedule;               //! reshcedule
96     int                     sorry_cc;                 //! sorry connection count limit
97     struct sockaddr_storage sorry_addr;               //! sorry-server address
98     int                     sorry_flag;               //! sorry flag
99
100     unsigned long long qos_threshold_up;          //! QoS Threshold value from client to real server (UP Direction)
101     unsigned long long qos_threshold_down;        //! QoS Threshold value from real server to client (DOWN Direction)
102     unsigned long long throughput_to_server; //! Throughput to real server
103     unsigned long long throughput_to_client; //! Throughput to client
104 };
105
106 // message of virtual service and protocol module definition, external representation.
107 struct l7vs_service_arg_multi{
108     struct l7vs_service_arg srv_arg;
109     char                    protomod_arg[L7VS_PROTOMOD_MAX_SERVICE_ARG];
110 };
111
112 // replication data
113 struct l7vs_service_repdata{
114     struct sockaddr_in addr;  //! server address
115     uint8_t            proto; //! server transport protocol
116
117     char protomod[L7VS_MODNAME_LEN]; //! protocol module name
118     char protomod_arg[L7VS_PROTOMOD_MAX_SERVICE_ARG];
119
120     int                     sorry_cc;   //! sorry connection count limit
121     struct sockaddr_storage sorry_addr; //! sorry-server address
122     int                     sorry_flag; //! sorry flag
123
124     unsigned long long qos_threshold_up;   //! QoS Threshold value from client to real server
125     unsigned long long qos_threshold_down; //! QoS Threshold value from real server to client
126 };
127
128 //
129 // functions
130 //
131 extern struct l7vs_service* l7vs_service_create( struct l7vs_service_arg_multi*, int* );
132 extern int                  l7vs_service_destroy( struct l7vs_service* );
133 extern struct l7vs_service* l7vs_service_lookup( struct l7vs_service_arg_multi* );
134 extern int                  l7vs_service_add_dest( struct l7vs_service*, struct l7vs_dest_arg* );
135 extern int                  l7vs_service_remove_dest( struct l7vs_service*, struct l7vs_dest_arg* );
136 extern int                  l7vs_service_schedule( struct l7vs_service*, struct l7vs_conn* );
137 extern int                  l7vs_service_establish( struct l7vs_service*, struct l7vs_conn* );
138 extern struct l7vs_dest*    l7vs_service_lookup_dest( struct l7vs_service*, struct sockaddr_in* );
139 extern int                  l7vs_service_list_service_arg( struct l7vs_service_arg_multi**, int* );
140 extern int                  l7vs_service_list_dest_arg( struct l7vs_service*, struct l7vs_dest_arg** );
141 extern int                  l7vs_service_register_conn( struct l7vs_service*, struct l7vs_conn* );
142 extern int                  l7vs_service_remove_conn( struct l7vs_service*, struct l7vs_conn* );
143 extern void                 l7vs_service_flush_all();
144 extern int                  l7vs_service_set_QoS_Threshold( struct l7vs_service*, struct l7vs_service_arg_multi* );
145 extern int                  l7vs_service_set_SorryServer_Values( struct l7vs_service*, struct l7vs_service_arg_multi* );
146 extern unsigned int         l7vs_service_get_VSnum();
147 extern struct l7vs_service* l7vs_service_get_VSInfo_byNum( unsigned int );
148 extern struct l7vs_service* l7vs_service_get_VSInfo_byHandler( const handle_t );
149 extern void                 l7vs_service_update_throughput( struct l7vs_service*, unsigned long long );
150 extern struct l7vs_service_arg_multi * l7vs_service_get_service_arg(struct l7vs_service *);
151
152 /*!
153  * make l7vs_service struct dump string
154  * @param[out] retstr char pointer
155  * @param[in]  srv l7vs_service struct pointer
156  */
157 inline void
158 l7vs_service_c_str( char* retstr, struct l7vs_service* srv )
159 {
160     if (srv == NULL) {
161         snprintf(retstr, DEBUG_STR_LEN, "NULL");
162     }else{
163         //handle
164         sprintf( retstr, "%s handle = %d", retstr, srv->handle );
165         //lsock pointer
166         //scheduler pointer
167         //scheduler data pointer
168         //protocol module pointer
169         //protocol module option string
170         sprintf( retstr, "%s protomod option string = %s", retstr, srv->protomod_opt_string );
171         //protocol module key string
172         sprintf( retstr, "%s protomod key string = %s", retstr, srv->protomod_key_string );
173         //reschedule
174         sprintf( retstr, "%s reschedule = %d", retstr, srv->reschedule );
175         //sorry
176         sprintf( retstr, "%s sorry conn count limit = %d", retstr, srv->sorry_cc );
177         sprintf( retstr, "%s sorry flag = %d", retstr, srv->sorry_flag );
178         //QoS
179         sprintf( retstr, "%s QoS to server = %llu", retstr, srv->qos_threshold_up );
180         sprintf( retstr, "%s QoS to client = %llu", retstr, srv->qos_threshold_down );
181         //throughput
182         sprintf( retstr, "%s Throughput to server = %llu", retstr, srv->throughput_to_server );
183         sprintf( retstr, "%s Throughput to client = %llu", retstr, srv->throughput_to_client );
184         if( NULL != srv->sorry_dest ){
185             switch( srv->sorry_dest->addr.sin_family ){
186             case AF_UNIX:
187                 sprintf( retstr, "%s socket family = AF_UNIX(PF_UNIX)", retstr );
188                 break;
189             case AF_INET:
190                 sprintf( retstr, "%s socket family = AF_INET(PF_INET)", retstr );
191                 break;
192             default:
193                 sprintf( retstr, "%s socket family = %d", retstr, srv->sorry_dest->addr.sin_family );
194             }
195             sprintf( retstr, "%s port no = %d", retstr, ntohs( srv->sorry_dest->addr.sin_port ) );
196             sprintf( retstr, "%s address = %s", retstr, inet_ntoa( srv->sorry_dest->addr.sin_addr ) );
197         }
198         //The last receiving time
199         sprintf( retstr, "%s recv time from client = %llu", retstr, srv->pre_recvtime_from_client );
200         sprintf( retstr, "%s recv time from server = %llu", retstr, srv->pre_recvtime_from_server );
201         //The last receiving size
202         sprintf( retstr, "%s pre recv size from client = %zu", retstr, srv->pre_recvsize_from_client );
203         sprintf( retstr, "%s pre recv size from server = %zu", retstr, srv->pre_recvsize_from_server );
204         sprintf( retstr, "%s recv size from client = %zu", retstr, srv->cur_recvsize_from_client );
205         sprintf( retstr, "%s recv size from server = %zu", retstr, srv->cur_recvsize_from_server );
206     }
207 }
208
209 /*!
210  * make l7vs_service_arg struct dump string
211  * @param[out] retstr  char pointer
212  * @param[in]  srv_arg l7vs_service_arg struct pointer
213  */
214 inline void
215 l7vs_service_arg_c_str( char* retstr, struct l7vs_service_arg* srv_arg )
216 {
217     if (srv_arg == NULL) {
218         snprintf(retstr, DEBUG_STR_LEN, "NULL");
219     }else{
220         //data length
221         sprintf( retstr, "%s struct data length = %zu", retstr, srv_arg->len );
222         //service address dump
223         switch( srv_arg->addr.sin_family ){
224         case AF_UNIX:
225             sprintf( retstr, "%s socket family = AF_UNIX(PF_UNIX)", retstr );
226             break;
227         case AF_INET:
228             sprintf( retstr, "%s socket family = AF_INET(PF_INET)", retstr );
229             break;
230         default:
231             sprintf( retstr, "%s socket family = %d", retstr, srv_arg->addr.sin_family );
232         }
233         sprintf( retstr, "%s port no = %d", retstr, ntohs( srv_arg->addr.sin_port ) );
234         sprintf( retstr, "%s address = %s", retstr, inet_ntoa( srv_arg->addr.sin_addr ) );
235         //proto
236         switch( srv_arg->proto ){
237         case IPPROTO_TCP:
238             sprintf( retstr, "%s proto = IPPROTO_TCP", retstr );
239             break;
240         case IPPROTO_UDP:
241             sprintf( retstr, "%s proto = IPPROTO_UDP", retstr );
242             break;
243         default:
244             sprintf( retstr, "%s proto = %d", retstr, ntohs( srv_arg->proto ) );
245         }
246         //persist
247         sprintf( retstr, "%s proto = %d", retstr, srv_arg->proto );
248         //backlog
249         sprintf( retstr, "%s backlog = %d", retstr, srv_arg->backlog );
250         //protomod name
251         sprintf( retstr, "%s protomod name = %s", retstr, srv_arg->protomod );
252         //scheduler name
253         sprintf( retstr, "%s scheduler name = %s", retstr, srv_arg->schedmod );
254         //protomod option string
255         sprintf( retstr, "%s protomod option string = %s", retstr, srv_arg->protomod_opt_string );
256         //protomod key string
257         sprintf( retstr, "%s protomod key string = %s", retstr, srv_arg->protomod_key_string );
258         //reschedule
259         sprintf( retstr, "%s backlog = %d", retstr, srv_arg->reschedule );
260         //sorry_cc
261         sprintf( retstr, "%s sorry conn count limit = %d", retstr, srv_arg->sorry_cc );
262         //sorry address dump
263         struct sockaddr_in* sorryaddr = (struct sockaddr_in*)&(srv_arg->sorry_addr);
264         if( NULL != sorryaddr ){
265             switch( sorryaddr->sin_family ){
266             case AF_UNIX:
267                 sprintf( retstr, "%s sorry server socket family = AF_UNIX(PF_UNIX)", retstr );
268                 break;
269             case AF_INET:
270                 sprintf( retstr, "%s sorry server socket family = AF_INET(PF_INET)", retstr );
271                 break;
272             default:
273                 sprintf( retstr, "%s sorry server socket family = %d", retstr, sorryaddr->sin_family );
274             }
275             sprintf( retstr, "%s sorry server port no = %d", retstr, ntohs( sorryaddr->sin_port ) );
276             sprintf( retstr, "%s sorry server address = %s", retstr, inet_ntoa( sorryaddr->sin_addr ) );
277         }
278         //sorry_flag
279         sprintf( retstr, "%s sorry flag = %d", retstr, srv_arg->sorry_flag );
280         //QoS setting value
281         sprintf( retstr, "%s QoS control to server = %llu", retstr, srv_arg->qos_threshold_up );
282         sprintf( retstr, "%s QoS control to client = %llu", retstr, srv_arg->qos_threshold_down );
283         //throughput
284         sprintf( retstr, "%s Throughput to server = %llu", retstr, srv_arg->throughput_to_server );
285         sprintf( retstr, "%s Throughput to client = %llu", retstr, srv_arg->throughput_to_client );
286     }
287 }
288
289 /*!
290  * make l7vs_service_arg_multi struct dump string
291  * @param[out] retstr  char pointer
292  * @param[in]  srv_arg_multi l7vs_service_repdata struct pointer
293  */
294 inline void
295 l7vs_service_arg_multi_c_str( char* retstr, struct l7vs_service_arg_multi* srv_arg_multi )
296 {
297     if (srv_arg_multi == NULL) {
298         snprintf(retstr, DEBUG_STR_LEN, "NULL");
299     }else{
300         //service_arg dump
301         l7vs_service_arg_c_str( retstr, &srv_arg_multi->srv_arg );
302         //protomodarg
303         sprintf( retstr, "%s protomod args = %s", retstr, srv_arg_multi->protomod_arg );
304     }
305 }
306
307 /*!
308  * make l7vs_service_repdata struct dump string
309  * @param[out] retstr  char pointer
310  * @param[in]  srv_repdata l7vs_service_repdata struct pointer
311  */
312 inline void
313 l7vs_service_repdata_c_str( char* retstr, struct l7vs_service_repdata* srv_repdata )
314 {
315     if (srv_repdata == NULL) {
316         snprintf(retstr, DEBUG_STR_LEN, "NULL");
317     }else{
318         //addr dump
319         switch( srv_repdata->addr.sin_family ){
320         case AF_UNIX:
321             sprintf( retstr, "%s socket family = AF_UNIX(PF_UNIX)", retstr );
322             break;
323         case AF_INET:
324             sprintf( retstr, "%s socket family = AF_INET(PF_INET)", retstr );
325             break;
326         default:
327             sprintf( retstr, "%s socket family = %d", retstr, srv_repdata->addr.sin_family );
328         }
329         sprintf( retstr, "%s port no = %d", retstr, ntohs( srv_repdata->addr.sin_port ) );
330         sprintf( retstr, "%s address = %s", retstr, inet_ntoa( srv_repdata->addr.sin_addr ) );
331         //proto
332         switch( srv_repdata->proto ){
333         case IPPROTO_TCP:
334             sprintf( retstr, "%s proto = IPPROTO_TCP", retstr );
335             break;
336         case IPPROTO_UDP:
337             sprintf( retstr, "%s proto = IPPROTO_UDP", retstr );
338             break;
339         default:
340             sprintf( retstr, "%s proto = %d", retstr, ntohs( srv_repdata->proto ) );
341         }
342         //protocol module name
343         sprintf( retstr, "%s protomod name = %s", retstr, srv_repdata->protomod );
344         //protomod argument
345         sprintf( retstr, "%s protomod args = %s", retstr, srv_repdata->protomod_arg );
346         //number of connection limit
347         sprintf( retstr, "%s sorry conn count limit = %d", retstr, srv_repdata->sorry_cc );
348         //sorry addr dump
349         struct sockaddr_in* sorryaddr = (struct sockaddr_in*)&(srv_repdata->sorry_addr);
350         switch( sorryaddr->sin_family ){
351         case AF_UNIX:
352             sprintf( retstr, "%s socket family = AF_UNIX(PF_UNIX)", retstr );
353             break;
354         case AF_INET:
355             sprintf( retstr, "%s socket family = AF_INET(PF_INET)", retstr );
356             break;
357         default:
358             sprintf( retstr, "%s socket family = %d", retstr, sorryaddr->sin_family );
359         }
360         sprintf( retstr, "%s port no = %d", retstr, ntohs( sorryaddr->sin_port ) );
361         sprintf( retstr, "%s address = %s", retstr, inet_ntoa( sorryaddr->sin_addr ) );
362         //sorry flag
363         sprintf( retstr, "%s sorry flag = %d", retstr, srv_repdata->sorry_flag );
364         //QoS setting value
365         sprintf( retstr, "%s QoS control to server = %llu", retstr, srv_repdata->qos_threshold_up );
366         sprintf( retstr, "%s QoS control to client = %llu", retstr, srv_repdata->qos_threshold_down );
367     }
368 }
369
370 #endif //L7VS_SERVICE_H