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) {
139 protocol_args.clear();
140 BOOST_FOREACH(std::string str, in.protocol_args) {
141 protocol_args.push_back(str);
143 realserver_vector.clear();
144 BOOST_FOREACH(realserver_element elem, in.realserver_vector) {
145 realserver_vector.push_back(elem);
147 access_log_rotate_arguments.clear();
148 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, in.access_log_rotate_arguments) {
149 access_log_rotate_arguments.insert(pair);
153 virtualservice_element &operator=(const virtualservice_element &in) {
154 udpmode = in.udpmode;
155 tcp_accept_endpoint = in.tcp_accept_endpoint;
156 udp_recv_endpoint = in.udp_recv_endpoint;
157 protocol_module_name = in.protocol_module_name;
158 schedule_module_name = in.schedule_module_name;
159 sorry_maxconnection = in.sorry_maxconnection;
160 sorry_endpoint = in.sorry_endpoint;
161 sorry_flag = in.sorry_flag;
162 sorry_fwdmode = in.sorry_fwdmode;
163 qos_upstream = in.qos_upstream;
164 qos_downstream = in.qos_downstream;
165 throughput_upstream = in.throughput_upstream;
166 throughput_downstream = in.throughput_downstream;
167 access_log_flag = in.access_log_flag;
168 ssl_file_name = in.ssl_file_name;
169 access_log_file_name = in.access_log_file_name;
170 protocol_module_for_indication_options = in.protocol_module_for_indication_options;
171 access_log_rotate_key_info = in.access_log_rotate_key_info;
172 access_log_rotate_verbose_info = in.access_log_rotate_verbose_info;
173 socket_option_tcp_defer_accept = in.socket_option_tcp_defer_accept;
174 socket_option_tcp_nodelay = in.socket_option_tcp_nodelay;
175 socket_option_tcp_cork = in.socket_option_tcp_cork;
176 socket_option_tcp_quickack = in.socket_option_tcp_quickack;
177 socket_option_string = in.socket_option_string;
178 http_total_count = in.http_total_count;
179 http_get_count = in.http_get_count;
180 http_post_count = in.http_post_count;
181 protocol_args.clear();
182 BOOST_FOREACH(std::string str, in.protocol_args) {
183 protocol_args.push_back(str);
185 realserver_vector.clear();
186 BOOST_FOREACH(realserver_element elem, in.realserver_vector) {
187 realserver_vector.push_back(elem);
189 access_log_rotate_arguments.clear();
190 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, in.access_log_rotate_arguments) {
191 access_log_rotate_arguments.insert(pair);
196 friend bool operator==(const virtualservice_element &elem1, const virtualservice_element &elem2) {
197 if (elem1.udpmode == elem2.udpmode &&
198 elem1.tcp_accept_endpoint == elem2.tcp_accept_endpoint &&
199 elem1.udp_recv_endpoint == elem2.udp_recv_endpoint &&
200 elem1.protocol_module_name == elem2.protocol_module_name &&
201 elem1.sorry_maxconnection == elem2.sorry_maxconnection &&
202 elem1.sorry_flag == elem2.sorry_flag &&
203 elem1.sorry_fwdmode == elem2.sorry_fwdmode &&
204 elem1.qos_upstream == elem2.qos_upstream &&
205 elem1.qos_downstream == elem2.qos_downstream &&
206 elem1.throughput_upstream == elem2.throughput_upstream &&
207 elem1.throughput_downstream == elem2.throughput_downstream &&
208 elem1.access_log_flag == elem2.access_log_flag &&
209 elem1.ssl_file_name == elem2.ssl_file_name &&
210 elem1.access_log_file_name == elem2.access_log_file_name &&
211 elem1.protocol_module_for_indication_options == elem2.protocol_module_for_indication_options &&
212 elem1.access_log_rotate_key_info == elem2.access_log_rotate_key_info &&
213 elem1.access_log_rotate_verbose_info == elem2.access_log_rotate_verbose_info &&
214 elem1.socket_option_tcp_defer_accept == elem2.socket_option_tcp_defer_accept &&
215 elem1.socket_option_tcp_nodelay == elem2.socket_option_tcp_nodelay &&
216 elem1.socket_option_tcp_cork == elem2.socket_option_tcp_cork &&
217 elem1.socket_option_tcp_quickack == elem2.socket_option_tcp_quickack &&
218 elem1.socket_option_string == elem2.socket_option_string &&
219 elem1.http_total_count == elem2.http_total_count &&
220 elem1.http_get_count == elem2.http_get_count &&
221 elem1.http_post_count == elem2.http_post_count) {
223 if (elem1.realserver_vector.size() != elem2.realserver_vector.size()) {
226 for (unsigned int i = 0; i < elem1.realserver_vector.size(); ++i) {
227 if (elem1.realserver_vector[i] != elem2.realserver_vector[i]) {
231 if (elem1.protocol_args.size() != elem2.protocol_args.size()) {
234 for (unsigned int i = 0; i < elem1.protocol_args.size(); ++i) {
235 if (elem1.protocol_args[i] != elem2.protocol_args[i]) {
239 if (elem1.access_log_rotate_arguments.size() != elem2.access_log_rotate_arguments.size()) {
242 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, elem1.access_log_rotate_arguments) {
243 access_log_rotate_arguments_map_type::const_iterator it = elem2.access_log_rotate_arguments.find(pair.first);
244 if (elem2.access_log_rotate_arguments.end() == it) {
247 if (it->second != pair.second) {
256 friend bool operator!=(const virtualservice_element &elem1, const virtualservice_element &elem2) {
257 if (elem1.udpmode == elem2.udpmode &&
258 elem1.tcp_accept_endpoint == elem2.tcp_accept_endpoint &&
259 elem1.udp_recv_endpoint == elem2.udp_recv_endpoint &&
260 elem1.protocol_module_name == elem2.protocol_module_name &&
261 elem1.sorry_maxconnection == elem2.sorry_maxconnection &&
262 elem1.sorry_flag == elem2.sorry_flag &&
263 elem1.sorry_fwdmode == elem2.sorry_fwdmode &&
264 elem1.qos_upstream == elem2.qos_upstream &&
265 elem1.qos_downstream == elem2.qos_downstream &&
266 elem1.throughput_upstream == elem2.throughput_upstream &&
267 elem1.throughput_downstream == elem2.throughput_downstream &&
268 elem1.access_log_flag == elem2.access_log_flag &&
269 elem1.ssl_file_name == elem2.ssl_file_name &&
270 elem1.access_log_file_name == elem2.access_log_file_name &&
271 elem1.protocol_module_for_indication_options == elem2.protocol_module_for_indication_options &&
272 elem1.access_log_rotate_key_info == elem2.access_log_rotate_key_info &&
273 elem1.access_log_rotate_verbose_info == elem2.access_log_rotate_verbose_info &&
274 elem1.socket_option_tcp_defer_accept == elem2.socket_option_tcp_defer_accept &&
275 elem1.socket_option_tcp_nodelay == elem2.socket_option_tcp_nodelay &&
276 elem1.socket_option_tcp_cork == elem2.socket_option_tcp_cork &&
277 elem1.socket_option_tcp_quickack == elem2.socket_option_tcp_quickack &&
278 elem1.socket_option_string == elem2.socket_option_string &&
279 elem1.http_total_count == elem2.http_total_count &&
280 elem1.http_get_count == elem2.http_get_count &&
281 elem1.http_post_count == elem2.http_post_count) {
283 if (elem1.realserver_vector.size() != elem2.realserver_vector.size()) {
286 for (unsigned int i = 0; i < elem1.realserver_vector.size(); ++i) {
287 if (elem1.realserver_vector[i] != elem2.realserver_vector[i]) {
291 if (elem1.protocol_args.size() != elem2.protocol_args.size()) {
294 for (unsigned int i = 0; i < elem1.protocol_args.size(); ++i) {
295 if (elem1.protocol_args[i] != elem2.protocol_args[i]) {
299 if (elem1.access_log_rotate_arguments.size() != elem2.access_log_rotate_arguments.size()) {
302 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, elem1.access_log_rotate_arguments) {
303 access_log_rotate_arguments_map_type::const_iterator it = elem2.access_log_rotate_arguments.find(pair.first);
304 if (elem2.access_log_rotate_arguments.end() == it) {
307 if (it->second != pair.second) {
316 friend bool operator<(const virtualservice_element &elem1, const virtualservice_element &elem2) {
317 if (!elem1.udpmode && !elem2.udpmode) {
318 return elem1.tcp_accept_endpoint < elem2.tcp_accept_endpoint;
319 } else if (elem1.udpmode && elem2.udpmode) {
320 return elem1.udp_recv_endpoint < elem2.udp_recv_endpoint;
325 template <typename Elem, typename Traits>
326 friend std::basic_ostream<Elem, Traits>& operator<<(std::basic_ostream<Elem, Traits>& os, const virtualservice_element &elem) {
327 os << "virtualservice_element={";
328 os << boost::format("udpmode=%s, "
329 "tcp_accept_endpoint=%s, "
330 "udp_recv_endpoint=%s, ")
332 % elem.tcp_accept_endpoint
333 % elem.udp_recv_endpoint;
337 BOOST_FOREACH(realserver_element rs_elem, elem.realserver_vector) {
338 os << boost::format("realserver_vector[%d]=") % i;
345 os << boost::format("protocol_module_name=%s, "
346 "schedule_module_name=%s, ")
347 % elem.protocol_module_name
348 % elem.schedule_module_name;
350 std::stringstream access_log_rotate_arguments_stream;
353 BOOST_FOREACH(access_log_rotate_arguments_pair_type pair, elem.access_log_rotate_arguments) {
354 access_log_rotate_arguments_stream << boost::format("access_log_rotate_arguments[%d]=") % i;
355 access_log_rotate_arguments_stream << boost::format("{key=%s, value=%s}") % pair.first % pair.second;
356 access_log_rotate_arguments_stream << ", ";
361 std::string args = boost::algorithm::join(elem.protocol_args, " ");
362 os << boost::format("protocol_args=%s, "
363 "sorry_maxconnection=%d, "
364 "sorry_endpoint=%s, "
368 "qos_downstream=%d, "
369 "throughput_upstream=%d, "
370 "throughput_downstream=%d, "
371 "access_log_flag=%d, "
373 "access_log_file_name=%s, "
374 "access_log_rotate_arguments=%s, "
375 "protocol_module_for_indication_options=%s, "
376 "access_log_rotate_key_info=%s, "
377 "access_log_rotate_verbose_info=%s, "
378 "socket_option_tcp_defer_accept=%d, "
379 "socket_option_tcp_nodelay=%d, "
380 "socket_option_tcp_cork=%d, "
381 "socket_option_tcp_quickack=%d, "
382 "socket_option_string=%s; "
383 "http_total_count=%d; "
384 "http_get_count=%d; "
385 "http_post_count=%d; }")
387 % elem.sorry_maxconnection
388 % elem.sorry_endpoint
392 % elem.qos_downstream
393 % elem.throughput_upstream
394 % elem.throughput_downstream
395 % elem.access_log_flag
397 % elem.access_log_file_name
398 % access_log_rotate_arguments_stream.str()
399 % elem.protocol_module_for_indication_options
400 % elem.access_log_rotate_key_info
401 % elem.access_log_rotate_verbose_info
402 % elem.socket_option_tcp_defer_accept
403 % elem.socket_option_tcp_nodelay
404 % elem.socket_option_tcp_cork
405 % elem.socket_option_tcp_quickack
406 % elem.socket_option_string
407 % elem.http_total_count
408 % elem.http_get_count
409 % elem.http_post_count;
414 const std::string get_fwdmode_str() {
415 return sorry_fwdmode == FWD_MASQ ? "Masq"
416 : sorry_fwdmode == FWD_TPROXY ? "Tproxy"
421 friend class boost::serialization::access; //! friend boost serializable class
423 //! @brief using boost serializable. class serializable function.
424 //! @param[in] archive
425 //! @param[in] version
426 template <class Archive>
427 void serialize(Archive &ar, const unsigned int version) {
429 ar &tcp_accept_endpoint;
430 ar &udp_recv_endpoint;
431 ar &realserver_vector;
432 ar &protocol_module_name;
433 ar &schedule_module_name;
435 ar &sorry_maxconnection;
441 ar &throughput_upstream;
442 ar &throughput_downstream;
445 ar &access_log_file_name;
446 ar &access_log_rotate_arguments;
447 ar &protocol_module_for_indication_options;
448 ar &access_log_rotate_key_info;
449 ar &access_log_rotate_verbose_info;
450 ar &socket_option_tcp_defer_accept;
451 ar &socket_option_tcp_nodelay;
452 ar &socket_option_tcp_cork;
453 ar &socket_option_tcp_quickack;
454 ar &socket_option_string;
455 ar &http_total_count;
462 #endif //L7VS_VIRTUALSERVICE_ELEMENT_H