OSDN Git Service

formatted all files with 'astyle -A8 -HUpc -k3 -z2 -r ./*.cpp ./*.c ./*.h'
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / src / virtualservice.cpp
1 /*!
2  *    @file    virtualservice.cpp
3  *    @brief    VirtualService class implementations
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 #include <new>
26 #include <vector>
27 #include <sstream>
28 #include <boost/date_time/posix_time/posix_time.hpp>
29 #include <boost/bind.hpp>
30 #include <boost/lexical_cast.hpp>
31
32 #include "virtualservice.h"
33 #include "logger_enum.h"
34 #include "logger.h"
35 #include "parameter.h"
36
37 l7vs::virtual_service::virtual_service(const l7vs::l7vsd &invsd,
38                                        const l7vs::replication &inrep,
39                                        const l7vs::virtualservice_element &inelement)
40 {
41         try {
42                 if (inelement.udpmode)
43                         vs = boost::shared_ptr<l7vs::virtualservice_base>(
44                                      dynamic_cast<l7vs::virtualservice_base *>(new l7vs::virtualservice_udp(invsd, inrep, inelement)));
45                 else
46                         vs = boost::shared_ptr<l7vs::virtualservice_base>(
47                                      dynamic_cast<l7vs::virtualservice_base *>(new l7vs::virtualservice_tcp(invsd, inrep, inelement)));
48         } catch (const std::bad_alloc &) {
49                 throw std::bad_alloc();
50         }
51 }
52
53 l7vs::virtual_service::~virtual_service()
54 {
55 }
56
57 void    l7vs::virtual_service::initialize(l7vs::error_code &err)
58 {
59         if (NULL != vs)
60                 vs->initialize(err);
61         else {
62                 err.setter(true, "Fail, create VirtualService");
63         }
64 }
65 void    l7vs::virtual_service::finalize(l7vs::error_code &err)
66 {
67         vs->finalize(err);
68 }
69
70 bool    l7vs::virtual_service::operator==(const l7vs::virtualservice_base &in)
71 {
72         return vs->operator==(in);
73 }
74 bool    l7vs::virtual_service::operator!=(const l7vs::virtualservice_base &in)
75 {
76         return vs->operator!=(in);
77 }
78
79 void    l7vs::virtual_service::set_virtualservice(const l7vs::virtualservice_element &in, l7vs::error_code &err)
80 {
81         vs->set_virtualservice(in, err);
82 }
83 void    l7vs::virtual_service::edit_virtualservice(const l7vs::virtualservice_element &in, l7vs::error_code &err)
84 {
85         vs->edit_virtualservice(in, err);
86 }
87
88 void    l7vs::virtual_service::add_realserver(const l7vs::virtualservice_element &in, l7vs::error_code &err)
89 {
90         vs->add_realserver(in, err);
91 }
92 void    l7vs::virtual_service::edit_realserver(const l7vs::virtualservice_element &in, l7vs::error_code &err)
93 {
94         vs->edit_realserver(in, err);
95 }
96 void    l7vs::virtual_service::del_realserver(const l7vs::virtualservice_element &in, l7vs::error_code &err)
97 {
98         vs->del_realserver(in, err);
99 }
100
101 l7vs::virtualservice_element    &l7vs::virtual_service::get_element()
102 {
103         return vs->get_element();
104 }
105
106 void        l7vs::virtual_service::run()
107 {
108         vs->run();
109 }
110 void        l7vs::virtual_service::stop()
111 {
112         vs->stop();
113 }
114
115 void        l7vs::virtual_service::connection_active(const boost::asio::ip::tcp::endpoint &in)
116 {
117         vs->connection_active(in);
118 }
119 void        l7vs::virtual_service::connection_inactive(const boost::asio::ip::tcp::endpoint &in)
120 {
121         vs->connection_inactive(in);
122 }
123 void        l7vs::virtual_service::release_session(const tcp_session *session_ptr)
124 {
125         vs->release_session(session_ptr);
126 }
127
128 unsigned long long        l7vs::virtual_service::get_qos_upstream()
129 {
130         return vs->get_qos_upstream();
131 }
132 unsigned long long        l7vs::virtual_service::get_qos_downstream()
133 {
134         return vs->get_qos_downstream();
135 }
136 unsigned long long        l7vs::virtual_service::get_throughput_upstream()
137 {
138         return vs->get_throughput_upstream();
139 }
140 unsigned long long        l7vs::virtual_service::get_throughput_downstream()
141 {
142         return vs->get_throughput_downstream();
143 }
144
145 unsigned long long        l7vs::virtual_service::get_up_recv_size()
146 {
147         return vs->get_up_recv_size();
148 }
149
150 unsigned long long        l7vs::virtual_service::get_up_send_size()
151 {
152         return vs->get_up_send_size();
153 }
154
155 unsigned long long        l7vs::virtual_service::get_down_recv_size()
156 {
157         return vs->get_down_recv_size();
158 }
159
160 unsigned long long        l7vs::virtual_service::get_down_send_size()
161 {
162         return vs->get_down_send_size();
163 }
164
165 void        l7vs::virtual_service::update_up_recv_size(unsigned long long    datasize)
166 {
167         vs->update_up_recv_size(datasize);
168 }
169 void        l7vs::virtual_service::update_up_send_size(unsigned long long    datasize)
170 {
171         vs->update_up_send_size(datasize);
172 }
173 void        l7vs::virtual_service::update_down_recv_size(unsigned long long    datasize)
174 {
175         vs->update_down_recv_size(datasize);
176 }
177 void        l7vs::virtual_service::update_down_send_size(unsigned long long    datasize)
178 {
179         vs->update_down_send_size(datasize);
180 }
181
182 l7vs::protocol_module_base*
183 l7vs::virtual_service::get_protocol_module()
184 {
185         return vs->get_protocol_module();
186 }
187 l7vs::schedule_module_base*
188 l7vs::virtual_service::get_schedule_module()
189 {
190         return vs->get_schedule_module();
191 }