2 * @file virtualservice_element.h
3 * @brief use l7vscommand virtualservice_data prototype
5 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6 * Copyright (C) 2009 NTT COMWARE Corporation.
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.
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.
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
23 **********************************************************************/
25 #ifndef VIRTUALSERVICE_ELEMENT_H
26 #define VIRTUALSERVICE_ELEMENT_H
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"
42 // virtual service element includes.
43 class virtualservice_element
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 {
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;
62 long long sorry_maxconnection;
63 boost::asio::ip::tcp::endpoint sorry_endpoint;
65 SORRYSERVER_FWDMODE_TAG sorry_fwdmode;
67 unsigned long long qos_upstream;
68 unsigned long long qos_downstream;
69 unsigned long long throughput_upstream;
70 unsigned long long throughput_downstream;
72 std::string ssl_file_name;
75 std::string access_log_file_name;
76 access_log_rotate_arguments_map_type access_log_rotate_arguments;
77 std::string access_log_rotate_key_info;
78 std::string access_log_rotate_verbose_info;
80 std::string protocol_module_for_indication_options;
82 int socket_option_tcp_defer_accept;
83 int socket_option_tcp_nodelay;
84 int socket_option_tcp_cork;
85 int socket_option_tcp_quickack;
86 std::string socket_option_string;
88 unsigned long long http_total_count;
89 unsigned long long http_get_count;
90 unsigned long long http_post_count;
93 virtualservice_element()
95 sorry_maxconnection(0LL),
97 sorry_fwdmode(FWD_NONE),
100 throughput_upstream(0ULL),
101 throughput_downstream(0ULL),
103 socket_option_tcp_defer_accept(0),
104 socket_option_tcp_nodelay(0),
105 socket_option_tcp_cork(0),
106 socket_option_tcp_quickack(0),
107 http_total_count(0ULL),
108 http_get_count(0ULL),
109 http_post_count(0ULL) {}
111 virtualservice_element(const virtualservice_element &in)
112 : udpmode(in.udpmode),
113 tcp_accept_endpoint(in.tcp_accept_endpoint),
114 udp_recv_endpoint(in.udp_recv_endpoint),
115 protocol_module_name(in.protocol_module_name),
116 schedule_module_name(in.schedule_module_name),
117 sorry_maxconnection(in.sorry_maxconnection),
118 sorry_endpoint(in.sorry_endpoint),
119 sorry_flag(in.sorry_flag),
120 sorry_fwdmode(in.sorry_fwdmode),
121 qos_upstream(in.qos_upstream),
122 qos_downstream(in.qos_downstream),
123 throughput_upstream(in.throughput_upstream),
124 throughput_downstream(in.throughput_downstream),
125 ssl_file_name(in.ssl_file_name),
126 access_log_flag(in.access_log_flag),
127 access_log_file_name(in.access_log_file_name),
128 access_log_rotate_key_info(in.access_log_rotate_key_info),
129 access_log_rotate_verbose_info(in.access_log_rotate_verbose_info),
130 protocol_module_for_indication_options(in.protocol_module_for_indication_options),
131 socket_option_tcp_defer_accept(in.socket_option_tcp_defer_accept),
132 socket_option_tcp_nodelay(in.socket_option_tcp_nodelay),
133 socket_option_tcp_cork(in.socket_option_tcp_cork),
134 socket_option_tcp_quickack(in.socket_option_tcp_quickack),
135 socket_option_string(in.socket_option_string),
136 http_total_count(in.http_total_count),
137 http_get_count(in.http_get_count),
138 http_post_count(in.http_post_count)
140 protocol_args.clear();
141 BOOST_FOREACH(std::string str, in.protocol_args) {
142 protocol_args.push_back(str);
144 realserver_vector.clear();
145 BOOST_FOREACH(realserver_element elem, in.realserver_vector) {
146 realserver_vector.push_back(elem);
148 access_log_rotate_arguments.clear();
149 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, in.access_log_rotate_arguments) {
150 access_log_rotate_arguments.insert(pair);
154 virtualservice_element &operator=(const virtualservice_element &in)
156 udpmode = in.udpmode;
157 tcp_accept_endpoint = in.tcp_accept_endpoint;
158 udp_recv_endpoint = in.udp_recv_endpoint;
159 protocol_module_name = in.protocol_module_name;
160 schedule_module_name = in.schedule_module_name;
161 sorry_maxconnection = in.sorry_maxconnection;
162 sorry_endpoint = in.sorry_endpoint;
163 sorry_flag = in.sorry_flag;
164 sorry_fwdmode = in.sorry_fwdmode;
165 qos_upstream = in.qos_upstream;
166 qos_downstream = in.qos_downstream;
167 throughput_upstream = in.throughput_upstream;
168 throughput_downstream = in.throughput_downstream;
169 access_log_flag = in.access_log_flag;
170 ssl_file_name = in.ssl_file_name;
171 access_log_file_name = in.access_log_file_name;
172 protocol_module_for_indication_options = in.protocol_module_for_indication_options;
173 access_log_rotate_key_info = in.access_log_rotate_key_info;
174 access_log_rotate_verbose_info = in.access_log_rotate_verbose_info;
175 socket_option_tcp_defer_accept = in.socket_option_tcp_defer_accept;
176 socket_option_tcp_nodelay = in.socket_option_tcp_nodelay;
177 socket_option_tcp_cork = in.socket_option_tcp_cork;
178 socket_option_tcp_quickack = in.socket_option_tcp_quickack;
179 socket_option_string = in.socket_option_string;
180 http_total_count = in.http_total_count;
181 http_get_count = in.http_get_count;
182 http_post_count = in.http_post_count;
183 protocol_args.clear();
184 BOOST_FOREACH(std::string str, in.protocol_args) {
185 protocol_args.push_back(str);
187 realserver_vector.clear();
188 BOOST_FOREACH(realserver_element elem, in.realserver_vector) {
189 realserver_vector.push_back(elem);
191 access_log_rotate_arguments.clear();
192 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, in.access_log_rotate_arguments) {
193 access_log_rotate_arguments.insert(pair);
198 friend bool operator==(const virtualservice_element &elem1, const virtualservice_element &elem2)
200 if (elem1.udpmode == elem2.udpmode &&
201 elem1.tcp_accept_endpoint == elem2.tcp_accept_endpoint &&
202 elem1.udp_recv_endpoint == elem2.udp_recv_endpoint &&
203 elem1.protocol_module_name == elem2.protocol_module_name &&
204 elem1.sorry_maxconnection == elem2.sorry_maxconnection &&
205 elem1.sorry_flag == elem2.sorry_flag &&
206 elem1.sorry_fwdmode == elem2.sorry_fwdmode &&
207 elem1.qos_upstream == elem2.qos_upstream &&
208 elem1.qos_downstream == elem2.qos_downstream &&
209 elem1.throughput_upstream == elem2.throughput_upstream &&
210 elem1.throughput_downstream == elem2.throughput_downstream &&
211 elem1.access_log_flag == elem2.access_log_flag &&
212 elem1.ssl_file_name == elem2.ssl_file_name &&
213 elem1.access_log_file_name == elem2.access_log_file_name &&
214 elem1.protocol_module_for_indication_options == elem2.protocol_module_for_indication_options &&
215 elem1.access_log_rotate_key_info == elem2.access_log_rotate_key_info &&
216 elem1.access_log_rotate_verbose_info == elem2.access_log_rotate_verbose_info &&
217 elem1.socket_option_tcp_defer_accept == elem2.socket_option_tcp_defer_accept &&
218 elem1.socket_option_tcp_nodelay == elem2.socket_option_tcp_nodelay &&
219 elem1.socket_option_tcp_cork == elem2.socket_option_tcp_cork &&
220 elem1.socket_option_tcp_quickack == elem2.socket_option_tcp_quickack &&
221 elem1.socket_option_string == elem2.socket_option_string &&
222 elem1.http_total_count == elem2.http_total_count &&
223 elem1.http_get_count == elem2.http_get_count &&
224 elem1.http_post_count == elem2.http_post_count) {
226 if (elem1.realserver_vector.size() != elem2.realserver_vector.size()) {
229 for (unsigned int i = 0; i < elem1.realserver_vector.size(); ++i) {
230 if (elem1.realserver_vector[i] != elem2.realserver_vector[i]) {
234 if (elem1.protocol_args.size() != elem2.protocol_args.size()) {
237 for (unsigned int i = 0; i < elem1.protocol_args.size(); ++i) {
238 if (elem1.protocol_args[i] != elem2.protocol_args[i]) {
242 if (elem1.access_log_rotate_arguments.size() != elem2.access_log_rotate_arguments.size()) {
245 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, elem1.access_log_rotate_arguments) {
246 access_log_rotate_arguments_map_type::const_iterator it = elem2.access_log_rotate_arguments.find(pair.first);
247 if (elem2.access_log_rotate_arguments.end() == it) {
250 if (it->second != pair.second) {
259 friend bool operator!=(const virtualservice_element &elem1, const virtualservice_element &elem2)
261 if (elem1.udpmode == elem2.udpmode &&
262 elem1.tcp_accept_endpoint == elem2.tcp_accept_endpoint &&
263 elem1.udp_recv_endpoint == elem2.udp_recv_endpoint &&
264 elem1.protocol_module_name == elem2.protocol_module_name &&
265 elem1.sorry_maxconnection == elem2.sorry_maxconnection &&
266 elem1.sorry_flag == elem2.sorry_flag &&
267 elem1.sorry_fwdmode == elem2.sorry_fwdmode &&
268 elem1.qos_upstream == elem2.qos_upstream &&
269 elem1.qos_downstream == elem2.qos_downstream &&
270 elem1.throughput_upstream == elem2.throughput_upstream &&
271 elem1.throughput_downstream == elem2.throughput_downstream &&
272 elem1.access_log_flag == elem2.access_log_flag &&
273 elem1.ssl_file_name == elem2.ssl_file_name &&
274 elem1.access_log_file_name == elem2.access_log_file_name &&
275 elem1.protocol_module_for_indication_options == elem2.protocol_module_for_indication_options &&
276 elem1.access_log_rotate_key_info == elem2.access_log_rotate_key_info &&
277 elem1.access_log_rotate_verbose_info == elem2.access_log_rotate_verbose_info &&
278 elem1.socket_option_tcp_defer_accept == elem2.socket_option_tcp_defer_accept &&
279 elem1.socket_option_tcp_nodelay == elem2.socket_option_tcp_nodelay &&
280 elem1.socket_option_tcp_cork == elem2.socket_option_tcp_cork &&
281 elem1.socket_option_tcp_quickack == elem2.socket_option_tcp_quickack &&
282 elem1.socket_option_string == elem2.socket_option_string &&
283 elem1.http_total_count == elem2.http_total_count &&
284 elem1.http_get_count == elem2.http_get_count &&
285 elem1.http_post_count == elem2.http_post_count ) {
287 if (elem1.realserver_vector.size() != elem2.realserver_vector.size()) {
290 for (unsigned int i = 0; i < elem1.realserver_vector.size(); ++i) {
291 if (elem1.realserver_vector[i] != elem2.realserver_vector[i]) {
295 if (elem1.protocol_args.size() != elem2.protocol_args.size()) {
298 for (unsigned int i = 0; i < elem1.protocol_args.size(); ++i) {
299 if (elem1.protocol_args[i] != elem2.protocol_args[i]) {
303 if (elem1.access_log_rotate_arguments.size() != elem2.access_log_rotate_arguments.size()) {
306 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, elem1.access_log_rotate_arguments) {
307 access_log_rotate_arguments_map_type::const_iterator it = elem2.access_log_rotate_arguments.find(pair.first);
308 if (elem2.access_log_rotate_arguments.end() == it) {
311 if (it->second != pair.second) {
320 friend bool operator<(const virtualservice_element &elem1, const virtualservice_element &elem2)
322 if (!elem1.udpmode && !elem2.udpmode) {
323 return elem1.tcp_accept_endpoint < elem2.tcp_accept_endpoint;
324 } else if (elem1.udpmode && elem2.udpmode) {
325 return elem1.udp_recv_endpoint < elem2.udp_recv_endpoint;
330 template <typename Elem, typename Traits>
331 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, ")
338 % elem.tcp_accept_endpoint
339 % elem.udp_recv_endpoint;
343 BOOST_FOREACH(realserver_element rs_elem, elem.realserver_vector) {
344 os << boost::format("realserver_vector[%d]=") % i;
351 os << boost::format("protocol_module_name=%s, "
352 "schedule_module_name=%s, ")
353 % elem.protocol_module_name
354 % elem.schedule_module_name;
356 std::stringstream access_log_rotate_arguments_stream;
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 << ", ";
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, "
374 "qos_downstream=%d, "
375 "throughput_upstream=%d, "
376 "throughput_downstream=%d, "
377 "access_log_flag=%d, "
379 "access_log_file_name=%s, "
380 "access_log_rotate_arguments=%s, "
381 "protocol_module_for_indication_options=%s, "
382 "access_log_rotate_key_info=%s, "
383 "access_log_rotate_verbose_info=%s, "
384 "socket_option_tcp_defer_accept=%d, "
385 "socket_option_tcp_nodelay=%d, "
386 "socket_option_tcp_cork=%d, "
387 "socket_option_tcp_quickack=%d, "
388 "socket_option_string=%s; "
389 "http_total_count=%d; "
390 "http_get_count=%d; "
391 "http_post_count=%d; }")
393 % elem.sorry_maxconnection
394 % elem.sorry_endpoint
398 % elem.qos_downstream
399 % elem.throughput_upstream
400 % elem.throughput_downstream
401 % elem.access_log_flag
403 % elem.access_log_file_name
404 % access_log_rotate_arguments_stream.str()
405 % elem.protocol_module_for_indication_options
406 % elem.access_log_rotate_key_info
407 % elem.access_log_rotate_verbose_info
408 % elem.socket_option_tcp_defer_accept
409 % elem.socket_option_tcp_nodelay
410 % elem.socket_option_tcp_cork
411 % elem.socket_option_tcp_quickack
412 % elem.socket_option_string
413 % elem.http_total_count
414 % elem.http_get_count
415 % elem.http_post_count;
420 const std::string get_fwdmode_str() {
421 return sorry_fwdmode == FWD_MASQ ? "Masq"
422 : sorry_fwdmode == FWD_TPROXY ? "Tproxy"
427 friend class boost::serialization::access; //! friend boost serializable class
429 //! @brief using boost serializable. class serializable function.
430 //! @param[in] archive
431 //! @param[in] version
432 template <class Archive>
433 void serialize(Archive &ar, const unsigned int version)
436 ar &tcp_accept_endpoint;
437 ar &udp_recv_endpoint;
438 ar &realserver_vector;
439 ar &protocol_module_name;
440 ar &schedule_module_name;
442 ar &sorry_maxconnection;
448 ar &throughput_upstream;
449 ar &throughput_downstream;
452 ar &access_log_file_name;
453 ar &access_log_rotate_arguments;
454 ar &protocol_module_for_indication_options;
455 ar &access_log_rotate_key_info;
456 ar &access_log_rotate_verbose_info;
457 ar &socket_option_tcp_defer_accept;
458 ar &socket_option_tcp_nodelay;
459 ar &socket_option_tcp_cork;
460 ar &socket_option_tcp_quickack;
461 ar &socket_option_string;
462 ar &http_total_count;
469 #endif //L7VS_VIRTUALSERVICE_ELEMENT_H