OSDN Git Service

Add session_thread_pool_size option for l7vsadm and l7directord.
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / include / virtualservice_element.h
1 /*!
2  * @file  virtualservice_element.h
3  * @brief use l7vscommand virtualservice_data prototype
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2009  NTT COMWARE Corporation.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  **********************************************************************/
24
25 #ifndef VIRTUALSERVICE_ELEMENT_H
26 #define VIRTUALSERVICE_ELEMENT_H
27
28 #include <vector>
29 #include <boost/foreach.hpp>
30 #include <boost/serialization/string.hpp>
31 #include <boost/serialization/vector.hpp>
32 #include <boost/serialization/list.hpp>
33 #include <boost/serialization/map.hpp>
34 #include <boost/algorithm/string.hpp>
35 #include <boost/format.hpp>
36 #include "realserver_element.h"
37 #include "endpoint.h"
38
39 namespace l7vs
40 {
41
42 // virtual service element includes.
43 class virtualservice_element
44 {
45 public:
46         typedef std::pair<std::string, std::string> access_log_rotate_arguments_pair_type;
47         typedef std::map<std::string, std::string> access_log_rotate_arguments_map_type;
48         enum SORRYSERVER_FWDMODE_TAG {
49                 FWD_NONE = 0,
50                 FWD_MASQ,
51                 FWD_TPROXY,
52         };
53
54         bool udpmode;
55         boost::asio::ip::tcp::endpoint tcp_accept_endpoint;
56         boost::asio::ip::udp::endpoint udp_recv_endpoint;
57         std::vector<realserver_element> realserver_vector;
58         std::string protocol_module_name;
59         std::vector<std::string> protocol_args;
60         std::string schedule_module_name;
61
62         long long sorry_maxconnection;
63         boost::asio::ip::tcp::endpoint sorry_endpoint;
64         int sorry_flag;
65         SORRYSERVER_FWDMODE_TAG sorry_fwdmode;
66
67         unsigned long long qos_upstream;
68         unsigned long long qos_downstream;
69         unsigned long long throughput_upstream;
70         unsigned long long throughput_downstream;
71         unsigned long long session_thread_pool_size;
72
73         std::string ssl_file_name;
74
75         int access_log_flag;
76         std::string access_log_file_name;
77         access_log_rotate_arguments_map_type access_log_rotate_arguments;
78         std::string access_log_rotate_key_info;
79         std::string access_log_rotate_verbose_info;
80
81         std::string protocol_module_for_indication_options;
82
83         int socket_option_tcp_defer_accept;
84         int socket_option_tcp_nodelay;
85         int socket_option_tcp_cork;
86         int socket_option_tcp_quickack;
87         std::string socket_option_string;
88
89         unsigned long long    http_total_count;
90         unsigned long long    http_get_count;
91         unsigned long long    http_post_count;
92
93         // constructor
94         virtualservice_element()
95                 :  udpmode(false),
96                    sorry_maxconnection(0LL),
97                    sorry_flag(0),
98                    sorry_fwdmode(FWD_NONE),
99                    qos_upstream(0ULL),
100                    qos_downstream(0ULL),
101                    throughput_upstream(0ULL),
102                    throughput_downstream(0ULL),
103                    session_thread_pool_size(0),
104                    access_log_flag(0),
105                    socket_option_tcp_defer_accept(0),
106                    socket_option_tcp_nodelay(0),
107                    socket_option_tcp_cork(0),
108                    socket_option_tcp_quickack(0),
109                    http_total_count(0ULL),
110                    http_get_count(0ULL),
111                    http_post_count(0ULL) {}
112
113         virtualservice_element(const virtualservice_element &in)
114                 :  udpmode(in.udpmode),
115                    tcp_accept_endpoint(in.tcp_accept_endpoint),
116                    udp_recv_endpoint(in.udp_recv_endpoint),
117                    protocol_module_name(in.protocol_module_name),
118                    schedule_module_name(in.schedule_module_name),
119                    sorry_maxconnection(in.sorry_maxconnection),
120                    sorry_endpoint(in.sorry_endpoint),
121                    sorry_flag(in.sorry_flag),
122                    sorry_fwdmode(in.sorry_fwdmode),
123                    qos_upstream(in.qos_upstream),
124                    qos_downstream(in.qos_downstream),
125                    throughput_upstream(in.throughput_upstream),
126                    throughput_downstream(in.throughput_downstream),
127                    session_thread_pool_size(in.session_thread_pool_size),
128                    ssl_file_name(in.ssl_file_name),
129                    access_log_flag(in.access_log_flag),
130                    access_log_file_name(in.access_log_file_name),
131                    access_log_rotate_key_info(in.access_log_rotate_key_info),
132                    access_log_rotate_verbose_info(in.access_log_rotate_verbose_info),
133                    protocol_module_for_indication_options(in.protocol_module_for_indication_options),
134                    socket_option_tcp_defer_accept(in.socket_option_tcp_defer_accept),
135                    socket_option_tcp_nodelay(in.socket_option_tcp_nodelay),
136                    socket_option_tcp_cork(in.socket_option_tcp_cork),
137                    socket_option_tcp_quickack(in.socket_option_tcp_quickack),
138                    socket_option_string(in.socket_option_string),
139                    http_total_count(in.http_total_count),
140                    http_get_count(in.http_get_count),
141                    http_post_count(in.http_post_count) {
142                 protocol_args.clear();
143                 BOOST_FOREACH(std::string str, in.protocol_args) {
144                         protocol_args.push_back(str);
145                 }
146                 realserver_vector.clear();
147                 BOOST_FOREACH(realserver_element elem, in.realserver_vector) {
148                         realserver_vector.push_back(elem);
149                 }
150                 access_log_rotate_arguments.clear();
151                 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, in.access_log_rotate_arguments) {
152                         access_log_rotate_arguments.insert(pair);
153                 }
154         }
155
156         virtualservice_element &operator=(const virtualservice_element &in) {
157                 udpmode = in.udpmode;
158                 tcp_accept_endpoint = in.tcp_accept_endpoint;
159                 udp_recv_endpoint = in.udp_recv_endpoint;
160                 protocol_module_name = in.protocol_module_name;
161                 schedule_module_name = in.schedule_module_name;
162                 sorry_maxconnection = in.sorry_maxconnection;
163                 sorry_endpoint = in.sorry_endpoint;
164                 sorry_flag = in.sorry_flag;
165                 sorry_fwdmode = in.sorry_fwdmode;
166                 qos_upstream = in.qos_upstream;
167                 qos_downstream = in.qos_downstream;
168                 throughput_upstream = in.throughput_upstream;
169                 throughput_downstream = in.throughput_downstream;
170                 session_thread_pool_size = in.session_thread_pool_size;
171                 access_log_flag = in.access_log_flag;
172                 ssl_file_name = in.ssl_file_name;
173                 access_log_file_name = in.access_log_file_name;
174                 protocol_module_for_indication_options = in.protocol_module_for_indication_options;
175                 access_log_rotate_key_info = in.access_log_rotate_key_info;
176                 access_log_rotate_verbose_info = in.access_log_rotate_verbose_info;
177                 socket_option_tcp_defer_accept = in.socket_option_tcp_defer_accept;
178                 socket_option_tcp_nodelay = in.socket_option_tcp_nodelay;
179                 socket_option_tcp_cork = in.socket_option_tcp_cork;
180                 socket_option_tcp_quickack = in.socket_option_tcp_quickack;
181                 socket_option_string = in.socket_option_string;
182                 http_total_count = in.http_total_count;
183                 http_get_count = in.http_get_count;
184                 http_post_count = in.http_post_count;
185                 protocol_args.clear();
186                 BOOST_FOREACH(std::string str, in.protocol_args) {
187                         protocol_args.push_back(str);
188                 }
189                 realserver_vector.clear();
190                 BOOST_FOREACH(realserver_element elem, in.realserver_vector) {
191                         realserver_vector.push_back(elem);
192                 }
193                 access_log_rotate_arguments.clear();
194                 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, in.access_log_rotate_arguments) {
195                         access_log_rotate_arguments.insert(pair);
196                 }
197                 return *this;
198         }
199
200         friend bool operator==(const virtualservice_element &elem1, const virtualservice_element &elem2) {
201                 if (elem1.udpmode == elem2.udpmode &&
202                     elem1.tcp_accept_endpoint == elem2.tcp_accept_endpoint &&
203                     elem1.udp_recv_endpoint == elem2.udp_recv_endpoint &&
204                     elem1.protocol_module_name == elem2.protocol_module_name &&
205                     elem1.sorry_maxconnection == elem2.sorry_maxconnection &&
206                     elem1.sorry_flag == elem2.sorry_flag &&
207                     elem1.sorry_fwdmode == elem2.sorry_fwdmode &&
208                     elem1.qos_upstream == elem2.qos_upstream &&
209                     elem1.qos_downstream == elem2.qos_downstream &&
210                     elem1.throughput_upstream == elem2.throughput_upstream &&
211                     elem1.throughput_downstream == elem2.throughput_downstream &&
212                     elem1.session_thread_pool_size == elem2.session_thread_pool_size &&
213                     elem1.access_log_flag == elem2.access_log_flag &&
214                     elem1.ssl_file_name == elem2.ssl_file_name &&
215                     elem1.access_log_file_name == elem2.access_log_file_name &&
216                     elem1.protocol_module_for_indication_options == elem2.protocol_module_for_indication_options &&
217                     elem1.access_log_rotate_key_info == elem2.access_log_rotate_key_info &&
218                     elem1.access_log_rotate_verbose_info == elem2.access_log_rotate_verbose_info &&
219                     elem1.socket_option_tcp_defer_accept == elem2.socket_option_tcp_defer_accept &&
220                     elem1.socket_option_tcp_nodelay == elem2.socket_option_tcp_nodelay &&
221                     elem1.socket_option_tcp_cork == elem2.socket_option_tcp_cork &&
222                     elem1.socket_option_tcp_quickack == elem2.socket_option_tcp_quickack &&
223                     elem1.socket_option_string == elem2.socket_option_string &&
224                     elem1.http_total_count == elem2.http_total_count &&
225                     elem1.http_get_count == elem2.http_get_count &&
226                     elem1.http_post_count == elem2.http_post_count) {
227
228                         if (elem1.realserver_vector.size() != elem2.realserver_vector.size()) {
229                                 return false;
230                         }
231                         for (unsigned int i = 0; i < elem1.realserver_vector.size(); ++i) {
232                                 if (elem1.realserver_vector[i] != elem2.realserver_vector[i]) {
233                                         return false;
234                                 }
235                         }
236                         if (elem1.protocol_args.size() != elem2.protocol_args.size()) {
237                                 return false;
238                         }
239                         for (unsigned int i = 0; i < elem1.protocol_args.size(); ++i) {
240                                 if (elem1.protocol_args[i] != elem2.protocol_args[i]) {
241                                         return false;
242                                 }
243                         }
244                         if (elem1.access_log_rotate_arguments.size() != elem2.access_log_rotate_arguments.size()) {
245                                 return false;
246                         }
247                         BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, elem1.access_log_rotate_arguments) {
248                                 access_log_rotate_arguments_map_type::const_iterator it = elem2.access_log_rotate_arguments.find(pair.first);
249                                 if (elem2.access_log_rotate_arguments.end() == it) {
250                                         return false;
251                                 }
252                                 if (it->second != pair.second) {
253                                         return false;
254                                 }
255                         }
256                         return true;
257                 }
258                 return false;
259         }
260
261         friend bool operator!=(const virtualservice_element &elem1, const virtualservice_element &elem2) {
262                 if (elem1.udpmode == elem2.udpmode &&
263                     elem1.tcp_accept_endpoint == elem2.tcp_accept_endpoint &&
264                     elem1.udp_recv_endpoint == elem2.udp_recv_endpoint &&
265                     elem1.protocol_module_name == elem2.protocol_module_name &&
266                     elem1.sorry_maxconnection == elem2.sorry_maxconnection &&
267                     elem1.sorry_flag == elem2.sorry_flag &&
268                     elem1.sorry_fwdmode == elem2.sorry_fwdmode &&
269                     elem1.qos_upstream == elem2.qos_upstream &&
270                     elem1.qos_downstream == elem2.qos_downstream &&
271                     elem1.throughput_upstream == elem2.throughput_upstream &&
272                     elem1.throughput_downstream == elem2.throughput_downstream &&
273                     elem1.session_thread_pool_size == elem2.session_thread_pool_size &&
274                     elem1.access_log_flag == elem2.access_log_flag &&
275                     elem1.ssl_file_name == elem2.ssl_file_name &&
276                     elem1.access_log_file_name == elem2.access_log_file_name &&
277                     elem1.protocol_module_for_indication_options == elem2.protocol_module_for_indication_options &&
278                     elem1.access_log_rotate_key_info == elem2.access_log_rotate_key_info &&
279                     elem1.access_log_rotate_verbose_info == elem2.access_log_rotate_verbose_info &&
280                     elem1.socket_option_tcp_defer_accept == elem2.socket_option_tcp_defer_accept &&
281                     elem1.socket_option_tcp_nodelay == elem2.socket_option_tcp_nodelay &&
282                     elem1.socket_option_tcp_cork == elem2.socket_option_tcp_cork &&
283                     elem1.socket_option_tcp_quickack == elem2.socket_option_tcp_quickack &&
284                     elem1.socket_option_string == elem2.socket_option_string &&
285                     elem1.http_total_count == elem2.http_total_count &&
286                     elem1.http_get_count == elem2.http_get_count &&
287                     elem1.http_post_count == elem2.http_post_count) {
288
289                         if (elem1.realserver_vector.size() != elem2.realserver_vector.size()) {
290                                 return true;
291                         }
292                         for (unsigned int i = 0; i < elem1.realserver_vector.size(); ++i) {
293                                 if (elem1.realserver_vector[i] != elem2.realserver_vector[i]) {
294                                         return true;
295                                 }
296                         }
297                         if (elem1.protocol_args.size() != elem2.protocol_args.size()) {
298                                 return true;
299                         }
300                         for (unsigned int i = 0; i < elem1.protocol_args.size(); ++i) {
301                                 if (elem1.protocol_args[i] != elem2.protocol_args[i]) {
302                                         return true;
303                                 }
304                         }
305                         if (elem1.access_log_rotate_arguments.size() != elem2.access_log_rotate_arguments.size()) {
306                                 return true;
307                         }
308                         BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, elem1.access_log_rotate_arguments) {
309                                 access_log_rotate_arguments_map_type::const_iterator it = elem2.access_log_rotate_arguments.find(pair.first);
310                                 if (elem2.access_log_rotate_arguments.end() == it) {
311                                         return true;
312                                 }
313                                 if (it->second != pair.second) {
314                                         return true;
315                                 }
316                         }
317                         return false;
318                 }
319                 return true;
320         }
321
322         friend bool operator<(const virtualservice_element &elem1, const virtualservice_element &elem2) {
323                 if (!elem1.udpmode && !elem2.udpmode) {
324                         return elem1.tcp_accept_endpoint < elem2.tcp_accept_endpoint;
325                 } else if (elem1.udpmode && elem2.udpmode) {
326                         return elem1.udp_recv_endpoint < elem2.udp_recv_endpoint;
327                 }
328                 return false;
329         }
330
331         template <typename Elem, typename Traits>
332         friend std::basic_ostream<Elem, Traits>& operator<<(std::basic_ostream<Elem, Traits>& os, const virtualservice_element &elem) {
333                 os << "virtualservice_element={";
334                 os << boost::format("udpmode=%s, "
335                                     "tcp_accept_endpoint=%s, "
336                                     "udp_recv_endpoint=%s, ")
337                    % elem.udpmode
338                    % elem.tcp_accept_endpoint
339                    % elem.udp_recv_endpoint;
340
341                 {
342                         unsigned int i = 0;
343                         BOOST_FOREACH(realserver_element rs_elem, elem.realserver_vector) {
344                                 os << boost::format("realserver_vector[%d]=") % i;
345                                 os << rs_elem;
346                                 os << ", ";
347                                 ++i;
348                         }
349                 }
350
351                 os << boost::format("protocol_module_name=%s, "
352                                     "schedule_module_name=%s, ")
353                    % elem.protocol_module_name
354                    % elem.schedule_module_name;
355
356                 std::stringstream access_log_rotate_arguments_stream;
357                 {
358                         unsigned int i = 0;
359                         BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, elem.access_log_rotate_arguments) {
360                                 access_log_rotate_arguments_stream << boost::format("access_log_rotate_arguments[%d]=") % i;
361                                 access_log_rotate_arguments_stream << boost::format("{key=%s, value=%s}") % pair.first % pair.second;
362                                 access_log_rotate_arguments_stream << ", ";
363                                 ++i;
364                         }
365                 }
366
367                 std::string args = boost::algorithm::join(elem.protocol_args, " ");
368                 os << boost::format("protocol_args=%s, "
369                                     "sorry_maxconnection=%d, "
370                                     "sorry_endpoint=%s, "
371                                     "sorry_flag=%d, "
372                                     "sorry_fwdmode=%d, "
373                                     "qos_upstream=%d, "
374                                     "qos_downstream=%d, "
375                                     "throughput_upstream=%d, "
376                                     "throughput_downstream=%d, "
377                                     "session_thread_pool_size=%d, "
378                                     "access_log_flag=%d, "
379                                     "ssl_file_name=%s, "
380                                     "access_log_file_name=%s, "
381                                     "access_log_rotate_arguments=%s, "
382                                     "protocol_module_for_indication_options=%s, "
383                                     "access_log_rotate_key_info=%s, "
384                                     "access_log_rotate_verbose_info=%s, "
385                                     "socket_option_tcp_defer_accept=%d, "
386                                     "socket_option_tcp_nodelay=%d, "
387                                     "socket_option_tcp_cork=%d, "
388                                     "socket_option_tcp_quickack=%d, "
389                                     "socket_option_string=%s; "
390                                     "http_total_count=%d; "
391                                     "http_get_count=%d; "
392                                     "http_post_count=%d; }")
393                    % args
394                    % elem.sorry_maxconnection
395                    % elem.sorry_endpoint
396                    % elem.sorry_flag
397                    % elem.sorry_fwdmode
398                    % elem.qos_upstream
399                    % elem.qos_downstream
400                    % elem.throughput_upstream
401                    % elem.throughput_downstream
402                    % elem.session_thread_pool_size
403                    % elem.access_log_flag
404                    % elem.ssl_file_name
405                    % elem.access_log_file_name
406                    % access_log_rotate_arguments_stream.str()
407                    % elem.protocol_module_for_indication_options
408                    % elem.access_log_rotate_key_info
409                    % elem.access_log_rotate_verbose_info
410                    % elem.socket_option_tcp_defer_accept
411                    % elem.socket_option_tcp_nodelay
412                    % elem.socket_option_tcp_cork
413                    % elem.socket_option_tcp_quickack
414                    % elem.socket_option_string
415                    % elem.http_total_count
416                    % elem.http_get_count
417                    % elem.http_post_count;
418
419                 return os;
420         }
421
422         const std::string get_fwdmode_str() {
423                 return sorry_fwdmode == FWD_MASQ   ? "Masq"
424                        : sorry_fwdmode == FWD_TPROXY ? "Tproxy"
425                        : "Unknown";
426         }
427
428 private:
429         friend class boost::serialization::access; //! friend boost serializable class
430         //! serializable
431         //! @brief using boost serializable. class serializable function.
432         //! @param[in] archive
433         //! @param[in] version
434         template <class Archive>
435         void serialize(Archive &ar, const unsigned int version) {
436                 ar &udpmode;
437                 ar &tcp_accept_endpoint;
438                 ar &udp_recv_endpoint;
439                 ar &realserver_vector;
440                 ar &protocol_module_name;
441                 ar &schedule_module_name;
442                 ar &protocol_args;
443                 ar &sorry_maxconnection;
444                 ar &sorry_endpoint;
445                 ar &sorry_flag;
446                 ar &sorry_fwdmode;
447                 ar &qos_upstream;
448                 ar &qos_downstream;
449                 ar &throughput_upstream;
450                 ar &throughput_downstream;
451                 ar &session_thread_pool_size;
452                 ar &access_log_flag;
453                 ar &ssl_file_name;
454                 ar &access_log_file_name;
455                 ar &access_log_rotate_arguments;
456                 ar &protocol_module_for_indication_options;
457                 ar &access_log_rotate_key_info;
458                 ar &access_log_rotate_verbose_info;
459                 ar &socket_option_tcp_defer_accept;
460                 ar &socket_option_tcp_nodelay;
461                 ar &socket_option_tcp_cork;
462                 ar &socket_option_tcp_quickack;
463                 ar &socket_option_string;
464                 ar &http_total_count;
465                 ar &http_get_count;
466                 ar &http_post_count;
467         }
468 };
469
470 } //namespace l7vsd
471 #endif //L7VS_VIRTUALSERVICE_ELEMENT_H