OSDN Git Service

formatted all files with 'astyle -A8 -HUpc -k3 -z2 -r ./*.cpp ./*.c ./*.h'
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / include / l7vs_command.h
1 /*!
2  *    @file    l7vscommand.h
3  *    @brief    l7vsadm and l7vsd connection 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    L7VS_COMMAND_H
26 #define    L7VS_COMMAND_H
27
28 #include <boost/serialization/string.hpp>
29 #include <boost/serialization/vector.hpp>
30 #include <boost/serialization/list.hpp>
31 #include <boost/serialization/utility.hpp>
32 #include <boost/asio.hpp>
33 #include <list>
34 #include <memory>
35 #include "logger_enum.h"
36 #include "parameter_enum.h"
37 #include "replication.h"
38 #include "virtualservice_element.h"
39
40 namespace l7vs
41 {
42 //
43 //! @class l7vsadm_request
44 //! @brief    l7vsadm -> l7vsd request data class
45 class    l7vsadm_request
46 {
47 public:
48         //! @enum COMMAND_CODE_TAG    request command code enum
49         enum    COMMAND_CODE_TAG {
50                 CMD_NONE = 0,
51                 CMD_LIST,                //!< List command(-l,--list)
52                 CMD_LIST_VERBOSE,        //!< Verbose list command(-V,--verbose)
53                 CMD_LIST_KEY,            //!< Key list command(-K, --key)
54                 CMD_ADD_VS,                //!< Add VirtualService command(-A,--add-service)
55                 CMD_DEL_VS,                //!< Delete VirtualService command(-D, --delete-service)
56                 CMD_EDIT_VS,            //!< Edit VirtualService command(-E, --edit-service)
57                 CMD_FLUSH_VS,            //!< Flush VirtualService command(-C, --flush)
58                 CMD_ADD_RS,                //!< Add RealServer command(-a, --add-server)
59                 CMD_DEL_RS,                //!< Delete RealServer command(-d, --delete-server)
60                 CMD_EDIT_RS,            //!< Edit RealServer command(-e.--edit-server)
61                 CMD_REPLICATION,        //!< Replication command(-R, --replication)
62                 CMD_LOG,                //!< Logger command(-L, -log)
63                 CMD_SNMP,                //!< SNMPAgent command(-S, --snmp)
64                 CMD_PARAMETER,            //!< Parameter command(-P, --parameter)
65                 CMD_HELP,                //!< Help command(-h, --help)
66         };
67
68         //! @enum REPLICATION_COMMAND_TAG    replication request command enum
69         enum    REPLICATION_COMMAND_TAG {
70                 REP_NONE = 0,
71                 REP_START,                //!< REPLICATION START COMMAND
72                 REP_STOP,                //!< REPLICATION STOP COMMAND
73                 REP_FORCE,                //!< REPLICATION FORCE COMMAND
74                 REP_DUMP                //!< REPLICATION DUMP COMMAND
75         };
76
77         COMMAND_CODE_TAG            command;                //!< request command
78         virtualservice_element        vs_element;                //!< use VS mode and RealServer mode
79         REPLICATION_COMMAND_TAG        replication_command;    //!< use replication command mode
80         LOG_CATEGORY_TAG            log_category;            //!< use log change mode. target log category
81         LOG_LEVEL_TAG                log_level;                //!< use log level change mode target category log level
82         PARAMETER_COMPONENT_TAG        reload_param;            //!< set reload param mode
83         LOG_CATEGORY_TAG            snmp_log_category;        //!< use snmp mode. target change log category
84         LOG_LEVEL_TAG                snmp_log_level;            //!< use snmp mode. target log category change to log level
85         //! constractor
86         l7vsadm_request() :            command(CMD_NONE),
87                 replication_command(REP_NONE),
88                 log_category(LOG_CAT_NONE),
89                 log_level(LOG_LV_NONE),
90                 reload_param(PARAM_COMP_NOCAT),
91                 snmp_log_category(LOG_CAT_NONE),
92                 snmp_log_level(LOG_LV_NONE) {}
93
94         template <typename Elem, typename Traits>
95         friend std::basic_ostream<Elem, Traits>& operator<<(
96                 std::basic_ostream<Elem, Traits>& os,
97                 const l7vsadm_request &request) {
98
99                 os << "l7vsadm_request={";
100                 os << boost::format("command=%d: "
101                                     "vs_element=%s: "
102                                     "replication_command=%d: "
103                                     "log_category=%d: "
104                                     "log_level=%d: "
105                                     "reload_param=%d: "
106                                     "snmp_log_category=%d: "
107                                     "snmp_log_level=%d: ")
108                    % request.command
109                    % request.vs_element
110                    % request.replication_command
111                    % request.log_category
112                    % request.log_level
113                    % request.reload_param
114                    % request.snmp_log_category
115                    % request.snmp_log_level;
116                 return os;
117         }
118
119 private:
120         friend class    boost::serialization::access;        //!< serializable access class is friend.
121         //! serializable function
122         //! @param[in]    archiver class from boost serializable
123         //! @param[in]    version use boost serializable
124         template <class Archive > void serialize(Archive &ar, const unsigned int version) {
125                 ar &command;
126                 ar &vs_element;
127                 ar &replication_command;
128                 ar &log_category;
129                 ar &log_level;
130                 ar &reload_param;
131                 ar &snmp_log_category;
132                 ar &snmp_log_level;
133         }
134 };
135
136 //
137 //! @class    l7vsd_response
138 //! @brief    l7vsd -> l7vsadm data class
139 class    l7vsd_response
140 {
141 public:
142         enum    COMMAND_RESPONSE_CODE {   //!<    response command code enum
143                 RESPONSE_NONE = 0,            //!<    none
144                 RESPONSE_OK,                //!<    request execute ok
145                 RESPONSE_ERROR,                //!<    request execute error
146                 RESPONSE_LIST_ERROR,        //!<    list request error
147                 RESPONSE_LIST_VERBOSE_ERROR,//!<    list verbose request error
148                 RESPONSE_LIST_KEY_ERROR,    //!<    list key request error
149                 RESPONSE_ADD_VS_ERROR,        //!<    virtual service add error
150                 RESPONSE_DEL_VS_ERROR,        //!<    virtual service delete error
151                 RESPONSE_EDIT_VS_ERROR,        //!<    virtual service edit error
152                 RESPONSE_FLUSH_VS_ERROR,    //!<    virtual service clear error
153                 RESPONSE_ADD_RS_ERROR,        //!<    realserver add error
154                 RESPONSE_DEL_RS_ERROR,        //!<    realserver delete error
155                 RESPONSE_EDIT_RS_ERROR,        //!<    realserver edit error
156                 RESPONSE_REPLICATION_ERROR,    //!<    replication error
157                 RESPONSE_LOG_ERROR,            //!<    logger error
158                 RESPONSE_SNMP_ERROR,        //!<    snmpagent error
159                 RESPONSE_PARAMETER_ERROR    //!<    parameter error
160         };
161
162         typedef    std::pair<LOG_CATEGORY_TAG, LOG_LEVEL_TAG> log_category_level_type;
163
164         l7vsadm_request::COMMAND_CODE_TAG
165         code;    //!<    request command.
166
167         COMMAND_RESPONSE_CODE    status;    //!<    return status.
168
169         std::string                message;//!<    error message
170
171         std::list< virtualservice_element >
172         virtualservice_status_list;//!< virtual service lists
173
174         replication::REPLICATION_MODE_TAG    replication_mode_status;//!< replication status.
175
176         std::list< log_category_level_type >
177         log_status_list;    //!< log cateogries statuses.
178
179         bool                    snmp_connection_status;    //!< snmp connection status
180
181         std::list< log_category_level_type >
182         snmp_log_status_list;    //!< snmp log statuses
183
184         unsigned long long        total_bps;                    //!< l7vsd's total bit par sec
185         unsigned long long        total_client_recv_byte;        //!< l7vsd's total client recive bytes
186         unsigned long long        total_client_send_byte;        //!< l7vsd's total client send bytes
187         unsigned long long        total_realserver_recv_byte;    //!< l7vsd's total realserver recive bytes
188         unsigned long long        total_realserver_send_byte;    //!< l7vsd's total realserver send bytes
189         std::vector<virtualservice_element>
190         virtualservice_vec;            //!< virtualservice lists
191         //! constructor
192         l7vsd_response() :        code(l7vsadm_request::CMD_NONE),
193                 status(RESPONSE_NONE),
194                 message(""),
195                 replication_mode_status(replication::REPLICATION_OUT),
196                 snmp_connection_status(false),
197                 total_bps(0ULL),
198                 total_client_recv_byte(0ULL),
199                 total_client_send_byte(0ULL),
200                 total_realserver_recv_byte(0ULL),
201                 total_realserver_send_byte(0ULL) {}
202
203         template <typename Elem, typename Traits>
204         friend std::basic_ostream<Elem, Traits>& operator<<(
205                 std::basic_ostream<Elem, Traits>& os,
206                 const l7vsd_response &response) {
207
208                 os << "l7vsd_response={";
209                 os << boost::format("code=%d: "
210                                     "status=%d: "
211                                     "message=%s: ")
212                    % response.code
213                    % response.status
214                    % response.message;
215                 {
216                         unsigned int i = 0;
217                         BOOST_FOREACH(virtualservice_element vs_elem, response.virtualservice_status_list) {
218                                 os << boost::format("virtualservice_status_list[%d]=") % i;
219                                 os << vs_elem;
220                                 os << ": ";
221                                 ++i;
222                         }
223                 }
224                 os << boost::format("replication_mode_status=%d: ")
225                    % response.replication_mode_status;
226                 {
227                         unsigned int i = 0;
228                         BOOST_FOREACH(log_category_level_type log_pair, response.log_status_list) {
229                                 os << boost::format("log_status_list[%d]={log_category=%d, log_level=%d}")
230                                    % i
231                                    % log_pair.first
232                                    % log_pair.second;
233                                 os << ": ";
234                                 ++i;
235                         }
236                 }
237                 os << boost::format("snmp_connection_status=%d: ")
238                    % response.snmp_connection_status;
239                 {
240                         unsigned int i = 0;
241                         BOOST_FOREACH(log_category_level_type log_pair, response.snmp_log_status_list) {
242                                 os << boost::format("snmp_log_status_list[%d]={log_category=%d, log_level=%d}")
243                                    % i
244                                    % log_pair.first
245                                    % log_pair.second;
246                                 os << ": ";
247                                 ++i;
248                         }
249                 }
250                 os << boost::format("total_bps=%d: "
251                                     "total_client_recv_byte=%d: "
252                                     "total_client_send_byte=%d: "
253                                     "total_realserver_recv_byte=%d: "
254                                     "total_realserver_send_byte=%d: ")
255                    % response.total_bps
256                    % response.total_client_recv_byte
257                    % response.total_client_send_byte
258                    % response.total_realserver_recv_byte
259                    % response.total_realserver_send_byte;
260                 {
261                         unsigned int i = 0;
262                         BOOST_FOREACH(virtualservice_element vs_elem, response.virtualservice_vec) {
263                                 os << boost::format("virtualservice_vec[%d]=") % i;
264                                 os << vs_elem;
265                                 os << ": ";
266                                 ++i;
267                         }
268                 }
269
270                 return os;
271         }
272
273 private:
274         friend class    boost::serialization::access;        //! friend boost serializable class
275         //! serializable
276         //! @brief using boost serialiable. class serializable function.
277         //! @param[in]    archive
278         //! @param[in]    version
279         template <class Archive > void serialize(Archive &ar, const unsigned int version) {
280                 ar &code;
281                 ar &status;
282                 ar &message;
283                 ar &virtualservice_status_list;
284                 ar &replication_mode_status;
285                 ar &log_status_list;
286                 ar &snmp_connection_status;
287                 ar &snmp_log_status_list;
288                 ar &total_bps;
289                 ar &total_client_recv_byte;
290                 ar &total_client_send_byte;
291                 ar &total_realserver_recv_byte;
292                 ar &total_realserver_send_byte;
293                 ar &virtualservice_vec;
294         }
295 };
296
297 }    // namespase l7vsd
298 #endif    //L7COMMAND_H