connection_state = false;
snmp_acceptor.close();
snmp_socket.close();
+// if( snmp_acceptor.is_open() == true ){
+// snmp_acceptor.close();
+// }
+// if( snmp_socket.is_open() == true ){
+// snmp_socket.close();
+// }
+ if( !send_buffer ){
+ free(send_buffer);
+ send_buffer = NULL;
+ send_buffer_size = 0;
+ }
}
/*!
* @return int
*/
int l7vs::snmpbridge::send_trap( const std::string& message ){
-#if 0
- if( !send_buffer ) free( send_buffer );
+#if 1
+ boost::mutex::scoped_lock lock( send_buffer_mutex );
+
+ if( send_buffer ) free( send_buffer );
send_buffer_size = sizeof( struct l7ag_message_header ) +
sizeof( struct l7ag_payload_header ) +
sizeof( struct l7ag_traprequest_message );
//create message
char oid[] = "1.3.6.1.4.1.60000.1.0.2";
strncpy( trapmes->oid, oid , sizeof( oid ) );
- strncpy( trapmes->message, message, TRAPREQUESTMESSAGESIZE );
+ strncpy( trapmes->message, message.c_str(), TRAPREQUESTMESSAGESIZE );
trapmes->magic[0] = 0x54; // T
trapmes->magic[1] = 0x52; // R
* Reload config command to subagent
*/
void l7vs::snmpbridge::reload_config(){
-#if 0
+#if 1
+ boost::mutex::scoped_lock lock( send_buffer_mutex );
+
if( send_buffer ) free( send_buffer );
send_buffer_size = sizeof( struct l7ag_message_header ) +
sizeof( struct l7ag_payload_header ) +
*/
int l7vs::snmpbridge::change_loglevel( const l7vs::LOG_CATEGORY_TAG snmp_log_category, const l7vs::LOG_LEVEL_TAG loglevel ){
int retval = 0;
-#if 0
+#if 1
+ boost::mutex::scoped_lock lock( send_buffer_mutex );
+
if( send_buffer ) free( send_buffer );
send_buffer_size = sizeof( struct l7ag_message_header ) +
sizeof( struct l7ag_payload_header ) +
*/
int l7vs::snmpbridge::change_loglevel_allcategory( const l7vs::LOG_LEVEL_TAG loglevel ){
int retval = 0;
-#if 0
+#if 1
std::vector<struct l7ag_settingcommand_message> settingcmd_vec;
for( std::map<l7vs::LOG_CATEGORY_TAG,l7vs::LOG_LEVEL_TAG>::iterator it = snmp_param.loglevel.begin();
it != snmp_param.loglevel.end();
param->log_level = loglevel;
settingcmd_vec.push_back( cmd );
}
+ boost::mutex::scoped_lock lock( send_buffer_mutex );
+
if( send_buffer ) free( send_buffer );
send_buffer_size = sizeof( struct l7ag_message_header ) +
sizeof( struct l7ag_payload_header ) * settingcmd_vec.size() +
struct l7ag_message_header* header = (struct l7ag_message_header*) send_buffer;
struct l7ag_payload_header* payloadheader = (struct l7ag_payload_header*) (header + 1);
struct l7ag_settingcommand_message* settingcmd = (struct l7ag_settingcommand_message*) (payloadheader + 1);
+#if 0
struct l7ag_changeloglevel_parameter* param = (l7ag_changeloglevel_parameter*) settingcmd->data;
+#endif
//create message header
header->magic[0] = 0x4d; // M
header->magic[1] = 0x47; // G
int l7vs::snmpbridge::send_mibcollection(struct l7ag_mibrequest_message* payload){
int retval = 0;
#if 0
+ boost::mutex::scoped_lock lock( send_buffer_mutex );
if (send_buffer) {
free(send_buffer);
*
*/
void l7vs::snmpbridge::handle_accept(const boost::system::error_code& error){
+ std::cout << "handle_accept" << std::endl;//debug
connection_state = true;
snmp_socket.async_receive( boost::asio::buffer( recv_buffer, READBUF_SIZE ),
boost::bind(&snmpbridge::handle_receive,
*/
void l7vs::snmpbridge::handle_receive(const boost::system::error_code& error, size_t bytes_transferred){
#if 0
+ size_t len = 0;
+ struct l7ag_message_header* message_header = NULL;
+ struct l7ag_payload_header* payload_header = NULL;
+
+ len = bytes_transferred;//
if ( len < sizeof( l7ag_message_header ) ) return;
message_header = (struct l7ag_message_header*)recv_buffer;
if ( message_header->version != 1 ) return;
// TODO bug if payload_count = 2...
payload_header = (struct l7ag_payload_header*) (message_header + 1);
if (payload_header->magic[0] != 0x50 || payload_header->magic[1] != 0x59) {
-// l7vs_iomux_mod( l7vs_snmp_iomux, iom_read );
continue;
}
struct l7ag_mibrequest_message* payload = (struct l7ag_mibrequest_message*) (payload_header + 1);
switch (payload_header->message_id) {
case MESSAGE_ID_MIBCOLLECTREQUEST:
if (payload->magic[0] != 0x52 || payload->magic[1] != 0x51) {
-// l7vs_iomux_mod( l7vs_snmp_iomux, iom_read );
return;
}
l7vs::snmpbridge::send_mibcollection(payload);
if (send_buffer == NULL || send_buffer_size == 0)
return -1;
+#if 1
snmp_socket.async_send( boost::asio::buffer( send_buffer, send_buffer_size ),
boost::bind(&snmpbridge::handle_send,
this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred ) );
-
+#endif
return 0;
}
snmpbridge_testclass( l7vsd& l7vsd_in, boost::asio::io_service& io_service_in ) : snmpbridge(l7vsd_in, io_service_in){}
void set_snmp_param(l7ag_parameter& snmp_param_in){
-// memcpy(&snmp_param, snmp_param_in, sizeof(snmp_param)); }
snmp_param = snmp_param_in; }
void set_connection_state(bool in){ connection_state = in; }
test.initialize();
- // unit_test[]
- // \90³\8fí
+ // unit_test[] send_trap\81i\90³\8fí\8cn\81j
+ std::string msg = "error message";
int ret = 0;
-// ret = test.send_trap();
- // unit_test[] \96ß\82è\92l\82Í0\82©\81H
+ ret = test.send_trap(msg);
+ // unit_test[] send_trap \96ß\82è\92l\82Í0\82©\81H
BOOST_CHECK_EQUAL( ret, 0 );
- // unit_test[] \91\97\90M\83f\81[\83^\82Ì\90Ý\92è\82Í\90³\82µ\82¢\82©\81H
-
+ // send_trap \91\97\90M\83f\81[\83^\82Ì\90Ý\92è\82Í\90³\82µ\82¢\82©\81H
+ char * buffer;
+ buffer = test.get_send_buffer();
+ struct l7ag_message_header* header = (struct l7ag_message_header*) buffer;
+ struct l7ag_payload_header* payloadheader = (struct l7ag_payload_header*) (header + 1);
+ struct l7ag_traprequest_message* trapmes = (struct l7ag_traprequest_message*) (payloadheader + 1);
+
+ // unit_test[] send_trap header->magic[0]\82Ì\83`\83F\83b\83N
+ BOOST_CHECK_EQUAL( header->magic[0], 0x4d );
+ // unit_test[] send_trap header->magic[1]\82Ì\83`\83F\83b\83N
+ BOOST_CHECK_EQUAL( header->magic[1], 0x47 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( header->version, (unsigned long long)1 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( header->payload_count, (unsigned long long)1 );
+ // unit_test[]
+ size_t send_buffer_size = test.get_send_buffer_size();
+ BOOST_CHECK_EQUAL( header->size, send_buffer_size );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( payloadheader->magic[0], 0x50 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( payloadheader->magic[1], 0x59 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( payloadheader->message_id, (unsigned long long)MESSAGE_ID_TRAPREQUEST );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( payloadheader->payload_datasize, sizeof( struct l7ag_payload_header ) + sizeof( struct l7ag_traprequest_message ) );
+ // unit_test[]
+ char oid[] = "1.3.6.1.4.1.60000.1.0.2";
+ BOOST_CHECK_EQUAL( trapmes->oid, oid );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( trapmes->message, msg.c_str() );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( trapmes->magic[0], 0x54 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( trapmes->magic[1], 0x52 );
// unit_test[] \91\97\90M\83T\83C\83Y\82Í\90³\82µ\82¢\82©\81H
size_t size = 0;
size = sizeof( struct l7ag_message_header ) +
BOOST_CHECK_EQUAL( ret, -1 );
// unit_test[] \91\97\90M\83o\83b\83t\83@\82Ì\83|\83C\83\93\83^\82ÍNULL\82©\81H
- BOOST_CHECK_EQUAL( test.get_send_buffer(), (char *)NULL );
+ buffer = test.get_send_buffer();
+ BOOST_CHECK( buffer == (char *)NULL );
// unit_test[] \91\97\90M\83T\83C\83Y\82Í0\82©\81H
BOOST_CHECK_EQUAL( test.get_send_buffer_size(), (size_t)0 );
BOOST_CHECK_EQUAL( ret, -1 );
// unit_test[] \91\97\90M\83o\83b\83t\83@\82Ì\83|\83C\83\93\83^\82ÍNULL\82©\81H
- BOOST_CHECK_EQUAL( test.get_send_buffer(), (char *)NULL );
+ buffer = test.get_send_buffer();
+ BOOST_CHECK( buffer == (char *)NULL );
// unit_test[] \91\97\90M\83T\83C\83Y\82Í0\82©\81H
BOOST_CHECK_EQUAL( test.get_send_buffer_size(), (size_t)0 );
test.initialize();
- // unit_test[]
- int ret = 0;
- // \90³\8fí
+ // unit_test[] reload_config\81i\90³\8fí\8cn\81j
+// int ret = 0;
// ret = test.reload_config();
- // unit_test[] \96ß\82è\92l\82Í0\82©\81H
- BOOST_CHECK_EQUAL( ret, 0 );
-
- // unit_test[] \91\97\90M\83f\81[\83^\82Ì\90Ý\92è\82Í\90³\82µ\82¢\82©\81H
+ test.reload_config();
+ // unit_test[] reload_config \96ß\82è\92l\82Í0\82©\81H
+// BOOST_CHECK_EQUAL( ret, 0 );
+
+ // reload_config \91\97\90M\83f\81[\83^\82Ì\90Ý\92è\82Í\90³\82µ\82¢\82©\81H
+ char * buffer;
+ buffer = test.get_send_buffer();
+ struct l7ag_message_header* header = (struct l7ag_message_header*) buffer;
+ struct l7ag_payload_header* payloadheader = (struct l7ag_payload_header*) (header + 1);
+ struct l7ag_settingcommand_message* settingcmd = (struct l7ag_settingcommand_message*) (payloadheader + 1);
+
+ // unit_test[] reload_config header->magic[0]\82Ì\83`\83F\83b\83N
+ BOOST_CHECK_EQUAL( header->magic[0], 0x4d );
+ // unit_test[] reload_config header->magic[1]\82Ì\83`\83F\83b\83N
+ BOOST_CHECK_EQUAL( header->magic[1], 0x47 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( header->version, (unsigned long long)1 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( header->payload_count, (unsigned long long)1 );
+ // unit_test[]
+ size_t send_buffer_size = test.get_send_buffer_size();
+ BOOST_CHECK_EQUAL( header->size, send_buffer_size );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( payloadheader->magic[0], 0x50 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( payloadheader->magic[1], 0x59 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( payloadheader->message_id, (unsigned long long)MESSAGE_ID_COMMANDREQUEST );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( payloadheader->payload_datasize, sizeof( struct l7ag_payload_header ) + sizeof( struct l7ag_settingcommand_message ) );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( settingcmd->command_id, (unsigned long long)COMMAND_SETTINGFILE_RELOAD );
+ // unit_test[]
+ unsigned char data[COMMANDDATASIZE];
+ memset( data, 0, COMMANDDATASIZE );
+// BOOST_CHECK_EQUAL( settingcmd->data, data );
+ BOOST_CHECK_EQUAL( settingcmd->data[0], data[0] );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( settingcmd->magic[0], 0x53 );
+ // unit_test[]
+ BOOST_CHECK_EQUAL( settingcmd->magic[1], 0x54 );
// unit_test[] \91\97\90M\83T\83C\83Y\82Í\90³\82µ\82¢\82©\81H
size_t size = 0;
// \83\81\83\82\83\8a\82ª\8am\95Û\82Å\82«\82È\82©\82Á\82½\8fê\8d\87
// ret = test.reload_config();
// unit_test[] \96ß\82è\92l\82Í-1\82©\81H
- BOOST_CHECK_EQUAL( ret, -1 );
+// BOOST_CHECK_EQUAL( ret, -1 );
// unit_test[] \91\97\90M\83o\83b\83t\83@\82Ì\83|\83C\83\93\83^\82ÍNULL\82©\81H
- BOOST_CHECK_EQUAL( test.get_send_buffer(), (char *)NULL );
+ buffer = test.get_send_buffer();
+ BOOST_CHECK( buffer == (char *)NULL );
// unit_test[] \91\97\90M\83T\83C\83Y\82Í0\82©\81H
BOOST_CHECK_EQUAL( test.get_send_buffer_size(), (size_t)0 );
// \91\97\90M\83T\83C\83Y\82ª0\82Ì\8fê\8d\87
// ret = test.reload_config();
// unit_test[] \96ß\82è\92l\82Í-1\82©\81H
- BOOST_CHECK_EQUAL( ret, -1 );
+// BOOST_CHECK_EQUAL( ret, -1 );
// unit_test[] \91\97\90M\83o\83b\83t\83@\82Ì\83|\83C\83\93\83^\82ÍNULL\82©\81H
- BOOST_CHECK_EQUAL( test.get_send_buffer(), (char *)NULL );
+ buffer = test.get_send_buffer();
+ BOOST_CHECK( buffer == (char *)NULL );
// unit_test[] \91\97\90M\83T\83C\83Y\82Í0\82©\81H
BOOST_CHECK_EQUAL( test.get_send_buffer_size(), (size_t)0 );
BOOST_CHECK_EQUAL( ret, -1 );
// unit_test[] \91\97\90M\83o\83b\83t\83@\82Ì\83|\83C\83\93\83^\82ÍNULL\82©\81H
- BOOST_CHECK_EQUAL( test.get_send_buffer(), (char *)NULL );
+// buffer = test.get_send_buffer();
+// BOOST_CHECK( buffer == (char *)NULL );
// unit_test[] \91\97\90M\83T\83C\83Y\82Í0\82©\81H
BOOST_CHECK_EQUAL( test.get_send_buffer_size(), (size_t)0 );
ts->add( BOOST_TEST_CASE( &create_snmpbridge_test ) );
ts->add( BOOST_TEST_CASE( &initialize_snmpbridge_test ) );
ts->add( BOOST_TEST_CASE( &finalize_snmpbridge_test ) );
-// ts->add( BOOST_TEST_CASE( &send_trap_snmpbridge_test ) );
-// ts->add( BOOST_TEST_CASE( &reload_config_snmpbridge_test ) );
+ ts->add( BOOST_TEST_CASE( &send_trap_snmpbridge_test ) );
+ ts->add( BOOST_TEST_CASE( &reload_config_snmpbridge_test ) );
// ts->add( BOOST_TEST_CASE( &change_loglevel_snmpbridge_test ) );
// ts->add( BOOST_TEST_CASE( &change_loglevel_allcategory_snmpbridge_test ) );
// ts->add( BOOST_TEST_CASE( &send_mibcollection_snmpbridge_test ) );