2 * @file snmpagent_impl.h
3 * @brief snmpagent implement module.
5 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6 * Copyright (C) 2010 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 **********************************************************************/
24 #ifndef __SNMPAGENT_IMPL_H__
25 #define __SNMPAGENT_IMPL_H__
28 #include "snmp_info.h"
29 #include <boost/thread.hpp>
30 #include <boost/thread/mutex.hpp>
35 #include "error_code.h"
36 #include "boost/date_time/posix_time/posix_time.hpp"
41 //! @class snmpagent_impl
42 //! @brief this class is snmpagent implement class.
43 class snmpagent_impl : private boost::noncopyable
48 //! trap function type
49 typedef int trapfunc(const std::string&);
51 //!trap function map type
52 typedef std::map<trapmessage::TRAP_TYPE_TAG, trapfunc*> trapfunc_type;
54 //!string log level map type
55 typedef std::map<std::string, LOG_LEVEL_TAG> string_loglevel_map_type;
60 trapfunc_type trapfunc_map;
61 atomic<unsigned int> trap_polling_interval;
62 atomic<unsigned int> trap_queue_max_size;
63 atomic<unsigned int> enabled;
64 unsigned int logtrap_enabled;
65 LOG_LEVEL_TAG logtrap_level;
66 atomic<unsigned int> interval;
67 atomic<time_t> start_date;
68 atomic<time_t> request_last_date;
69 atomic<time_t> trap_last_date;
70 atomic<unsigned long long> snmp_get_requests;
71 atomic<unsigned long long> snmp_set_requests;
72 atomic<unsigned long long> snmp_trap_count;
73 std::deque<trapmessage> trap_msg_queue;
74 boost::condition trap_msg_queue_condition;
75 boost::mutex trap_msg_queue_condition_mutex;
76 string_loglevel_map_type string_loglevel_map;
77 boost::posix_time::ptime mib_collect_last_time;
78 boost::thread trap_thread;
79 boost::thread process_mib_thread;
83 snmpagent_impl(const snmpagent_impl&);
84 snmpagent_impl& operator=(const snmpagent_impl &);
87 * process mib get item thread function.
91 void process_mib_run();
94 * process trap thread function.
101 * check mib data timeout.
105 bool check_timeout();
108 * load configure file setting.
117 * create and return a snmpagent_impl instance.
119 * @retrun snmpagent_impl & snmpagent_impl' instance
121 static snmpagent_impl &get_instance();
124 * snmpagent_impl class initialize.
126 * @param error_code & error code
129 void init(error_code &);
132 * push the trap message into trap message queue.
134 * @param[in] in_trapmessage is trap message
135 * @param[in/out] err is error code
138 void push_trapmessage(trapmessage &in_trapmessage, error_code& err);
141 * snmpagent function start.
143 * @param[in/out] error_code is error code
146 void start(error_code&);
149 * snmpagent function stop.
156 * set snmp function enable
163 * set snmp function disable
170 * set log trap enable
173 void logtrap_enable();
176 * set log trap disable
179 void logtrap_disable();
182 * set log trap level.
184 * @param[in] in_level is log trap level
187 void set_logtrap_level(const LOG_LEVEL_TAG in_level);
190 * set mib cache update interval.
192 * @param[in] in_interval is cache update interval
195 void set_interval(const unsigned int in_interval);
198 * refresh all the statistics.
202 void refresh_all_statistics();
205 * refresh a special virtual service's statistics.
207 * @param[in] vs_endpoint is virtual service's endpoint
208 * @param[in] protocol is virtual service's protocol
211 void refresh_statistics(const boost::asio::ip::tcp::endpoint &vs_endpoint, const std::string &protocol);
214 * set vsd infomation.
216 * @param[in] vsd is vsd pointer.
219 void set_vsd_info(l7vsd *vsd);
222 * get snmp infomation.
224 * @retrun snmp_info is snmp infomation.
226 snmp_info get_snmp_info();
231 * @param[in] error_code is err code.
234 void collect_mibdata(error_code &);
244 * increment get request count.
248 void increment_getrequest_count();
251 * increment set request count.
255 void increment_setrequest_count();
260 #endif //__SNMPAGENT_IMPL_H__