session_map_type pool_sessions;
session_map_type active_sessions;
+ session_map_type sorry_sessions;
boost::mutex sessions_mutex;
void handle_replication_interrupt( const boost::system::error_code& );
if( !err ){
//if active session count equal and element.sorry_maxconnection is over num 1
//active_sessions is include a waiting(prepare accept) session
- if( ( ( 0 < element.sorry_maxconnection ) &&
- ( active_sessions.size() > static_cast<size_t>( element.sorry_maxconnection ) ) ) ||
- ( ( 0 != element.sorry_flag ) && ( INT_MAX != element.sorry_flag ) ) ){
- in_session->get_session()->set_virtual_service_message( l7vs::tcp_session::SORRY_STATE_ENABLE );
+ {
+ boost::mutex::scoped_lock lk( sessions_mutex );
+ if( LOG_LV_DEBUG == l7vs::Logger::getLogLevel( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE_THREAD ) ){
+ boost::format formatter("BEFORE check sorry_maxconnection(%d) : active_sessions.size = %d / sorry_sessions.size = %d");
+ formatter % element.sorry_maxconnection % active_sessions.size() % sorry_sessions.size();
+ l7vs::Logger::putLogDebug( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE_THREAD, 0, formatter.str(), __FILE__, __LINE__ );
+ }
+ if( ( ( 0 < element.sorry_maxconnection ) &&
+ ( ( active_sessions.size() - sorry_sessions.size() ) > static_cast<size_t>( element.sorry_maxconnection ) ) ) ||
+ ( ( 0 != element.sorry_flag ) && ( INT_MAX != element.sorry_flag ) ) ){
+ in_session->get_session()->set_virtual_service_message( l7vs::tcp_session::SORRY_STATE_ENABLE );
+ sorry_sessions.insert( session_map_pair_type( in_session->get_upthread_id(), in_session ) );
+ }
+ if( LOG_LV_DEBUG == l7vs::Logger::getLogLevel( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE_THREAD ) ){
+ boost::format formatter("AFTER check sorry_maxconnection(%d) : active_sessions.size = %d / sorry_sessions.size = %d");
+ formatter % element.sorry_maxconnection % active_sessions.size() % sorry_sessions.size();
+ l7vs::Logger::putLogDebug( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE_THREAD, 0, formatter.str(), __FILE__, __LINE__ );
+ }
}
//switch status runing, session_thread_control
in_session->startupstream();
boost::format fmt2( "active_session.size = %d" );
fmt2 % active_sessions.size();
l7vs::Logger::putLogDebug( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE_THREAD, 0, fmt2.str(), __FILE__, __LINE__ );
+ boost::format fmt3( "sorry_session.size = %d" );
+ fmt3 % sorry_sessions.size();
+ l7vs::Logger::putLogDebug( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE, 0, fmt3.str(), __FILE__, __LINE__ );
}
//regist accept event handler
l7vs::Logger::putLogDebug( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE, 0, fmt2.str(), __FILE__, __LINE__ );
}
+
//clear replication_data
bool replication_status = true;
l7vs::replication& replication = const_cast<l7vs::replication&>( rep );
stc_ptr->get_session()->initialize();
pool_sessions.insert( session_map_pair_type( t_id, stc_ptr ) );
active_sessions.erase( itr );
+ if( sorry_sessions.end() != sorry_sessions.find( t_id ) )
+ sorry_sessions.erase( t_id );
}
if( LOG_LV_DEBUG == l7vs::Logger::getLogLevel( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE ) ){
boost::format fmt1( "pool_session.size = %d" );
boost::format fmt2( "active_session.size = %d" );
fmt2 % active_sessions.size();
l7vs::Logger::putLogDebug( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE, 0, fmt2.str(), __FILE__, __LINE__ );
+ boost::format fmt3( "sorry_session.size = %d" );
+ fmt3 % sorry_sessions.size();
+ l7vs::Logger::putLogDebug( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE, 0, fmt3.str(), __FILE__, __LINE__ );
}
if( LOG_LV_DEBUG == l7vs::Logger::getLogLevel( l7vs::LOG_CAT_L7VSD_VIRTUALSERVICE ) ){
void l7vs::Logger::loadConf(){}
l7vs::LOG_LEVEL_TAG l7vs::Logger::getLogLevel( l7vs::LOG_CATEGORY_TAG ){
- l7vs::LOG_LEVEL_TAG ret_tag = l7vs::LOG_LV_ERROR;
+ l7vs::LOG_LEVEL_TAG ret_tag = debugg_flug_struct::getInstance().stub_loglevel();
return ret_tag;
}
}
void l7vs::tcp_session::up_thread_run(void){
+ size_t count = 0;
std::cout << "active session";
std::cout << boost::this_thread::get_id() << std::endl;
exit_flag = false;
- while(!exit_flag){
-
+ while( !exit_flag ){
+ ++count;
+ if( !debugg_flug_struct::getInstance().session_loop_flag() && (count > 30000) )
+ break;
}
+ std::cout << "release session";
parent_service.release_session( boost::this_thread::get_id() );
}
class debugg_flug_struct{
protected:
bool session_pool_param_flg;
+ bool session_loop_mode;
bool pmcontrol_error_flag;
bool smcontrol_error_flag;
bool pm_function_called;
+ l7vs::LOG_LEVEL_TAG loglevel;
int pm_rep_count;
int sm_rep_count;
debugg_flug_struct() : session_pool_param_flg( false ),
pm_rep_count( 0 ),
sm_rep_count( 0 ) {
+ loglevel = l7vs::LOG_LV_ERROR;
+ session_loop_mode = true;
}
debugg_flug_struct( const debugg_flug_struct & in ){ rep_area = NULL; }
debugg_flug_struct& operator=( const debugg_flug_struct & in ){ return *this; }
static debugg_flug_struct instance;
return instance;
}
+ bool& session_loop_flag(){
+ return session_loop_mode;
+ }
+ l7vs::LOG_LEVEL_TAG& stub_loglevel(){
+ return loglevel;
+ }
bool& param_exist_flag(){
return session_pool_param_flg;
}
typedef boost::asio::ip::tcp::endpoint tcp_ep_type;
typedef boost::asio::ip::udp::endpoint udp_ep_type;
+class client{
+protected:
+ boost::asio::io_service dispatcher;
+ boost::asio::ip::tcp::socket sock;
+ boost::system::error_code err;
+ std::string name;
+public:
+ client( std::string in ) : sock( dispatcher ), name( in ) {}
+ ~client(){}
+ void connect(){
+ sock.connect( tcp_ep_type( boost::asio::ip::address_v4::loopback(), (60000) ), err );
+ if( err )
+ std::cout << err.message() << std::endl;
+ else
+ std::cout << "connect : " << name << std::endl;
+ }
+ void disconnect(){
+ sock.close();
+ std::cout << "disconnect : " << name << std::endl;
+ }
+};
-void virtualservice_tcp_test1(){
+void vs_tcp_test1(){
debugg_flug_struct::getInstance().pmcontrol_err_flag() = false;
debugg_flug_struct::getInstance().smcontrol_err_flag() = false;
debugg_flug_struct::getInstance().param_exist_flag() = false;
}
-void virtualservice_tcp_test2(){
+void vs_tcp_test2(){
l7vs::error_code vs_err;
boost::system::error_code test_err;
debugg_flug_struct::getInstance().create_rep_area();
}
+void vs_tcp_test3(){
+ l7vs::error_code vs_err;
+ boost::system::error_code test_err;
+
+ debugg_flug_struct::getInstance().pmcontrol_err_flag() = false;
+ debugg_flug_struct::getInstance().smcontrol_err_flag() = false;
+ debugg_flug_struct::getInstance().param_exist_flag() = false;
+
+ l7vs::l7vsd vsd;
+ boost::asio::io_service dispatcher;
+ l7vs::replication rep;
+ l7vs::virtualservice_element elem1;
+ //set element value
+ elem1.udpmode = false;
+ elem1.tcp_accept_endpoint = tcp_ep_type( boost::asio::ip::address_v4::loopback(), (60000) );
+ elem1.udp_recv_endpoint = udp_ep_type( boost::asio::ip::address::from_string( "10.144.169.20" ), (50000) );
+ elem1.realserver_vector.clear();
+ elem1.protocol_module_name = "PMtest1";
+ elem1.schedule_module_name = "SMtest1";
+ elem1.protocol_args.clear();
+ elem1.protocol_args.push_back( "testarg" );
+ elem1.protocol_args.push_back( "testarg2" );
+ elem1.sorry_maxconnection = 2LL;
+ elem1.sorry_endpoint = tcp_ep_type( boost::asio::ip::address::from_string( "10.144.169.87" ), (8080) );
+ elem1.sorry_flag = false;
+ elem1.qos_upstream = 0ULL;
+ elem1.qos_downstream = 0ULL;
+
+ l7vs::vs_tcp* vs = new l7vs::vs_tcp( vsd, rep, elem1 );
+ vs->initialize( vs_err );
+ usleep( 1000 );
+ boost::thread vs_main( &l7vs::vs_tcp::run, vs );
+ usleep( 1000 );
+
+ // unit_test[] RSに繋がるSession数がsorry_maxconnectionを越えたときに、Sorry状態ONでSessionをスタートすることを確認する
+ BOOST_MESSAGE( "-------" );
+ debugg_flug_struct::getInstance().stub_loglevel() = l7vs::LOG_LV_DEBUG;
+ debugg_flug_struct::getInstance().session_loop_flag() = false;
+ client cl1("1"),cl2("2"),cl3("3"),cl4("4"),cl5("5");
+ cl1.connect();
+ cl2.connect();
+ cl3.connect();
+ cl4.connect();
+ cl5.connect();
+
+ usleep( 200 );
+ cl1.disconnect();
+ cl2.disconnect();
+ cl3.disconnect();
+ cl4.disconnect();
+ cl5.disconnect();
+ usleep( 1000 );
+ BOOST_MESSAGE( "-------" );
+
+ // unit_test[] RSに繋がるSession数がsorry_maxconenctionを下回ったとき(Sorryへ接続しているSession数はカウントに入れない)、Sorry状態OFFでSessionをスタートすることを確認する
+
+ // unit_test[] session_pool_sizeを上回った接続数でSessionが増えても、切断されれば元の数に戻ることを確認する
+
+
+ vs->finalize( vs_err );
+ debugg_flug_struct::getInstance().stub_loglevel() = l7vs::LOG_LV_ERROR;
+ delete vs;
+}
+
test_suite* init_unit_test_suite( int argc, char* argv[] ){
// create unit test suite
test_suite* ts = BOOST_TEST_SUITE( "virtualservice_tcp_test(UT for IT-bug)" );
// add test case to test suite
- ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test1 ) );
- ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test2 ) );
+ ts->add( BOOST_TEST_CASE( &vs_tcp_test1 ) );
+ ts->add( BOOST_TEST_CASE( &vs_tcp_test2 ) );
+ ts->add( BOOST_TEST_CASE( &vs_tcp_test3 ) );
framework::master_test_suite().add( ts );