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.
10 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
11 * Copyright (C) 2005 NTT COMWARE Corporation.
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.
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.
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
28 **********************************************************************/
29 #ifndef L7VS_SERVICE_H
30 #define L7VS_SERVICE_H
34 #include "l7vs_conn.h"
38 struct l7vs_scheduler;
43 typedef uint32_t handle_t;
45 #define TEMP_SERVICEHANDLE UINT32_MAX
46 #define BPS_DEFAULT_INTERVAL 1000000ULL
48 // virtual service definition datatype
50 handle_t handle; //! l7vs_service_handle
51 struct l7vs_lsock* lsock; //! listen socket struct pointer
52 GList* dest_list; //! real server 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
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
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)
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
89 char protomod[L7VS_MODNAME_LEN]; //! protocol module name
90 char schedmod[L7VS_MODNAME_LEN]; //! scheduler
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
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
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];
113 struct l7vs_service_repdata{
114 struct sockaddr_in addr; //! server address
115 uint8_t proto; //! server transport protocol
117 char protomod[L7VS_MODNAME_LEN]; //! protocol module name
118 char protomod_arg[L7VS_PROTOMOD_MAX_SERVICE_ARG];
120 int sorry_cc; //! sorry connection count limit
121 struct sockaddr_storage sorry_addr; //! sorry-server address
122 int sorry_flag; //! sorry flag
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
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 *);
153 * make l7vs_service struct dump string
154 * @param[out] retstr char pointer
155 * @param[in] srv l7vs_service struct pointer
158 l7vs_service_c_str( char* retstr, struct l7vs_service* srv )
161 snprintf(retstr, DEBUG_STR_LEN, "NULL");
164 sprintf( retstr, "%s handle = %d", retstr, srv->handle );
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 );
174 sprintf( retstr, "%s reschedule = %d", retstr, srv->reschedule );
176 sprintf( retstr, "%s sorry conn count limit = %d", retstr, srv->sorry_cc );
177 sprintf( retstr, "%s sorry flag = %d", retstr, srv->sorry_flag );
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 );
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 ){
187 sprintf( retstr, "%s socket family = AF_UNIX(PF_UNIX)", retstr );
190 sprintf( retstr, "%s socket family = AF_INET(PF_INET)", retstr );
193 sprintf( retstr, "%s socket family = %d", retstr, srv->sorry_dest->addr.sin_family );
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 ) );
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 );
210 * make l7vs_service_arg struct dump string
211 * @param[out] retstr char pointer
212 * @param[in] srv_arg l7vs_service_arg struct pointer
215 l7vs_service_arg_c_str( char* retstr, struct l7vs_service_arg* srv_arg )
217 if (srv_arg == NULL) {
218 snprintf(retstr, DEBUG_STR_LEN, "NULL");
221 sprintf( retstr, "%s struct data length = %zu", retstr, srv_arg->len );
222 //service address dump
223 switch( srv_arg->addr.sin_family ){
225 sprintf( retstr, "%s socket family = AF_UNIX(PF_UNIX)", retstr );
228 sprintf( retstr, "%s socket family = AF_INET(PF_INET)", retstr );
231 sprintf( retstr, "%s socket family = %d", retstr, srv_arg->addr.sin_family );
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 ) );
236 switch( srv_arg->proto ){
238 sprintf( retstr, "%s proto = IPPROTO_TCP", retstr );
241 sprintf( retstr, "%s proto = IPPROTO_UDP", retstr );
244 sprintf( retstr, "%s proto = %d", retstr, ntohs( srv_arg->proto ) );
247 sprintf( retstr, "%s proto = %d", retstr, srv_arg->proto );
249 sprintf( retstr, "%s backlog = %d", retstr, srv_arg->backlog );
251 sprintf( retstr, "%s protomod name = %s", retstr, srv_arg->protomod );
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 );
259 sprintf( retstr, "%s backlog = %d", retstr, srv_arg->reschedule );
261 sprintf( retstr, "%s sorry conn count limit = %d", retstr, srv_arg->sorry_cc );
263 struct sockaddr_in* sorryaddr = (struct sockaddr_in*)&(srv_arg->sorry_addr);
264 if( NULL != sorryaddr ){
265 switch( sorryaddr->sin_family ){
267 sprintf( retstr, "%s sorry server socket family = AF_UNIX(PF_UNIX)", retstr );
270 sprintf( retstr, "%s sorry server socket family = AF_INET(PF_INET)", retstr );
273 sprintf( retstr, "%s sorry server socket family = %d", retstr, sorryaddr->sin_family );
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 ) );
279 sprintf( retstr, "%s sorry flag = %d", retstr, srv_arg->sorry_flag );
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 );
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 );
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
295 l7vs_service_arg_multi_c_str( char* retstr, struct l7vs_service_arg_multi* srv_arg_multi )
297 if (srv_arg_multi == NULL) {
298 snprintf(retstr, DEBUG_STR_LEN, "NULL");
301 l7vs_service_arg_c_str( retstr, &srv_arg_multi->srv_arg );
303 sprintf( retstr, "%s protomod args = %s", retstr, srv_arg_multi->protomod_arg );
308 * make l7vs_service_repdata struct dump string
309 * @param[out] retstr char pointer
310 * @param[in] srv_repdata l7vs_service_repdata struct pointer
313 l7vs_service_repdata_c_str( char* retstr, struct l7vs_service_repdata* srv_repdata )
315 if (srv_repdata == NULL) {
316 snprintf(retstr, DEBUG_STR_LEN, "NULL");
319 switch( srv_repdata->addr.sin_family ){
321 sprintf( retstr, "%s socket family = AF_UNIX(PF_UNIX)", retstr );
324 sprintf( retstr, "%s socket family = AF_INET(PF_INET)", retstr );
327 sprintf( retstr, "%s socket family = %d", retstr, srv_repdata->addr.sin_family );
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 ) );
332 switch( srv_repdata->proto ){
334 sprintf( retstr, "%s proto = IPPROTO_TCP", retstr );
337 sprintf( retstr, "%s proto = IPPROTO_UDP", retstr );
340 sprintf( retstr, "%s proto = %d", retstr, ntohs( srv_repdata->proto ) );
342 //protocol module name
343 sprintf( retstr, "%s protomod name = %s", retstr, srv_repdata->protomod );
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 );
349 struct sockaddr_in* sorryaddr = (struct sockaddr_in*)&(srv_repdata->sorry_addr);
350 switch( sorryaddr->sin_family ){
352 sprintf( retstr, "%s socket family = AF_UNIX(PF_UNIX)", retstr );
355 sprintf( retstr, "%s socket family = AF_INET(PF_INET)", retstr );
358 sprintf( retstr, "%s socket family = %d", retstr, sorryaddr->sin_family );
360 sprintf( retstr, "%s port no = %d", retstr, ntohs( sorryaddr->sin_port ) );
361 sprintf( retstr, "%s address = %s", retstr, inet_ntoa( sorryaddr->sin_addr ) );
363 sprintf( retstr, "%s sorry flag = %d", retstr, srv_repdata->sorry_flag );
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 );
370 #endif //L7VS_SERVICE_H