OSDN Git Service

unitテストのプロトタイプを追加
authornakai <nakai@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Tue, 6 Jan 2009 05:25:45 +0000 (05:25 +0000)
committernakai <nakai@1ed66053-1c2d-0410-8867-f7571e6e31d3>
Tue, 6 Jan 2009 05:25:45 +0000 (05:25 +0000)
git-svn-id: http://10.144.169.20/repos/um/branches/l7vsd-3.x-shamshel@5658 1ed66053-1c2d-0410-8867-f7571e6e31d3

include/l7vs_command.h [moved from include/l7command.h with 93% similarity]
include/l7vs_replication.h [new file with mode: 0644]
include/realserver_element.h
include/virtualservice_element.h
unit_tests/l7vs_command_test/Makefile [new file with mode: 0644]
unit_tests/l7vs_command_test/l7vs_command_ut.cpp [new file with mode: 0644]

similarity index 93%
rename from include/l7command.h
rename to include/l7vs_command.h
index 3449119..2bfbbb6 100644 (file)
@@ -9,8 +9,8 @@
 //     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
 //
 
-#ifndef        L7COMMAND_H
-#define        L7COMMAND_H
+#ifndef        L7VS_COMMAND_H
+#define        L7VS_COMMAND_H
 
 #include <boost/serialization/string.hpp>
 #include <boost/serialization/vector.hpp>
@@ -21,8 +21,7 @@
 #include "logger_enum.h"
 #include "parameter_enum.h"
 #include "l7vs_replication.h"
-#include "l7vs_realserver_element.h"
-#include "l7vs_virtualservice_command_element.h"
+#include "virtualservice_element.h"
 
 namespace l7vs{
 //
@@ -52,7 +51,7 @@ public:
        };
        enum    REPLICATION_COMMAND_TAG{
                REP_NONE = 0,
-               REP_START                               // !< REPLICATION START COMMAND
+               REP_START,                              // !< REPLICATION START COMMAND
                REP_STOP,                               // !< REPLICATION STOP COMMAND
                REP_FORCE,                              // !< REPLICATION FORCE COMMAND
                REP_DUMP                                // !< REPLICATION DUMP COMMAND
@@ -60,11 +59,11 @@ public:
 
        COMMAND_CODE_TAG                        command;
        virtualservice_element          vs_element;
-       REPLICATION_CODE_TAG            replication_command;
+       REPLICATION_COMMAND_TAG         replication_command;
        LOG_CATEGORY_TAG                        log_category;
        LOG_LEVEL_TAG                           log_level;
        PARAMETER_COMPONENT_TAG         reload_param;
-       PARAMETER_COMPONENT_TAG         snmp_log_category;
+       LOG_CATEGORY_TAG                        snmp_log_category;
        LOG_LEVEL_TAG                           snmp_log_level;
        l7vsadm_request() :                     command( CMD_NONE ),
                                                                replication_command( REP_NONE ),
@@ -117,7 +116,7 @@ public:
        
        std::string                             message;
        
-       std::list< l7vs_virtualservice_element >
+       std::list< virtualservice_element >
                                                        virtualservice_status_list;
        
        REPLICATION_MODE_TAG    replication_mode_status;
diff --git a/include/l7vs_replication.h b/include/l7vs_replication.h
new file mode 100644 (file)
index 0000000..494ce2b
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * @file       l7vs_replication.h
+ * @bref       The Replication of data between ACT and STB.
+ *
+ * L7VSD: Linux Virtual Server for Layer7 Load Balancing
+ * Copyright (C) 2005  NTT COMWARE Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ **********************************************************************/
+#ifndef L7VS_REPLICATION_H
+#define L7VS_REPLICATION_H
+
+
+//! Max Number of Components
+#define CMP_MAX        (100)
+
+//! Max Size of Components
+#define CMP_BLOCK_MAX (100000)
+
+//! Key's length of Component ID
+#define ID_LENGTH (17)
+
+//! REPLICATION_SLAVE of Component SIZE
+#define CMP_SIZE_LENGTH (17)
+
+//! Maximum size of input/output raw data
+#define DATA_SIZE (480)
+
+//! Maximum size of input/output raw data
+#define SEND_DATA_SIZE (512)
+
+//! Min Interval
+#define MIN_INTERVAL (10)
+
+//! Max Interval
+#define MAX_INTERVAL (10000)
+
+//! Min Compulsorily Interval
+#define MIN_COMPULSORILRY_INTERVAL (4)
+
+//! Max Compulsorily Interval
+#define MAX_COMPULSORILRY_INTERVAL (400)
+
+//! Set nic length
+#define NIC_LENGTH (128)
+
+//! Dump log data's width
+#define LOG_DATA_WIDTH (16)
+
+//! Replication data ID
+#define REPLICATION_ID (37)
+
+#include <netdb.h>
+#include <stdint.h>
+
+//! Mode Type
+enum REPLICATION_MODE_TAG{
+       REPLICATION_OUT,                //!< Initial
+       REPLICATION_SINGLE,             //!< Single
+       REPLICATION_MASTER,             //!< Master isActive
+       REPLICATION_SLAVE,              //!< Slave isActive
+       REPLICATION_MASTER_STOP,        //!< Master isStop
+       REPLICATION_SLAVE_STOP          //!< Slave isStop
+};
+
+//! Transfer data between active server and standby server.
+struct l7vs_replication_data{
+       unsigned short          id;             //!< ID of Replication Function
+       char                    pad1[6];
+       unsigned long long      serial;         //!< Serial Number
+       unsigned int            block_num;      //!< Block Number in Replication memory
+       char                    pad2[4];
+       uint64_t                size;           //!< Data size for checking packet loss
+       char                    data[DATA_SIZE];//!< Raw data
+};
+
+//! Component information set to SG file.
+struct l7vs_replication_component{
+       char                    id[ID_LENGTH];          //!< ID distinguishes Component
+       unsigned int            block_head;     //!< The first Block Number of Component's memory
+       unsigned int            block_size;     //!< Number of Block allocated in component memory
+};
+
+//! State Infomation struct to execute Replication.
+struct l7vs_replication_state{
+       enum REPLICATION_MODE_TAG       service_status;         //!< States Type of Replication Function
+       unsigned long long              send_time;              //!< Completion last time to send data
+       unsigned int                    last_send_block;        //!< Completion last Block Number to send data
+       unsigned int                    last_recv_block;        //!< Completion last Block Number to receive data
+       unsigned int                    total_block;            //!< The maximum Block Number of Components memory
+       void *                          replication_memory;     //!< Top address in Replication memory
+       void *                          component_memory;       //!< Top address in Component memory
+       uint64_t                        sarface_block_no;       //!< Serial number for respect switch
+       uint64_t *                      sarface_block_array_ptr;//!< Serial number in received respect at every block
+};
+
+//! Essential information set to SG file.
+struct l7vs_replication_info{
+       char    ip_addr[NI_MAXHOST];            //!< Destination IP address (IPv4 or IPv6)
+       char    service_name[NI_MAXSERV];       //!< Destination service name or port number
+       char    nic[NIC_LENGTH];                        //!< Network device (ex. eth0, bond0, hme0, etc.)
+       unsigned short  interval;               //!< Interval when data of one block is sent
+       int             component_num;          //!< Number of components read setting
+       struct  l7vs_replication_component component_info[CMP_MAX];     //!< Information on individual component
+};
+
+
+// External function
+
+// Initialize of Replication Function
+extern int l7vs_replication_init();
+
+// Finalize of Replication Function
+extern void l7vs_replication_fini();
+
+// Switches Slave to Master ( VirtualService is added )
+extern void l7vs_replication_switch_to_master();
+
+// Switches Master to Slave ( VirtualService is deleted )
+extern void l7vs_replication_switch_to_slave();
+
+// Allocate the memory of the component.
+extern void *l7vs_replication_pay_memory( char* component_id, unsigned int* size );
+
+// Replication Callback
+extern int l7vs_replication_send_callback( struct l7vs_iomux *iom );
+
+// Replication Callback
+extern int l7vs_replication_recv_callback( struct l7vs_iomux *iom );
+
+// Dump Replication info to the Log.
+extern void l7vs_replication_dump_memory();
+
+// Starting the Replication
+extern void l7vs_replication_start();
+
+// Stopping the Replication
+extern void l7vs_replication_stop();
+
+// Compulsorily executes the replication.
+extern void l7vs_replication_compulsorily();
+
+// Re-Sets the Interval
+extern void l7vs_replication_reset();
+
+// Acquires the state
+extern enum REPLICATION_MODE_TAG l7vs_replication_get_status();
+
+// Check the interval time
+extern int l7vs_replication_checkinterval();
+
+
+#endif
index 3095bdd..9d395d4 100644 (file)
@@ -1,5 +1,5 @@
 //
-//     @file   l7vs_realserver_element.h
+//     @file   realserver_element.h
 //     @brief  realserver data prototype
 //
 //     copyright (c) sdy corporation. 2008
@@ -8,8 +8,8 @@
 //     Distributed under the Boost Software License, Version 1.0.(See accompanying
 //     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
 //
-#ifndef        L7VS_REALSERVER_ELEMENT_H
-#define        L7VS_REALSERVER_ELEMENT_H
+#ifndef        REALSERVER_ELEMENT_H
+#define        REALSERVER_ELEMENT_H
 #include <boost/asio.hpp>
 
 namespace l7vs{
@@ -49,4 +49,4 @@ public:
 };
 
 }      //namespace l7vsd
-#endif //L7VS_REALSERVER_ELEMENT
+#endif //REALSERVER_ELEMENT
index 6c9a508..1acd00f 100644 (file)
@@ -9,14 +9,12 @@
 //     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
 //
 
-#ifndef        L7VS_VIRTUALSERVICE_COMMAND_ELEMENT
-#define        L7VS_VIRTUALSERVICE_COMMAND_ELEMENT
+#ifndef        VIRTUALSERVICE_COMMAND_ELEMENT
+#define        VIRTUALSERVICE_COMMAND_ELEMENT
 
 #include <vector>
-#include <string>
-#include <boost/asio.hpp>
 #include <boost/foreach.hpp>
-#include "l7vs_realserver_element.h"
+#include "realserver_element.h"
 
 namespace l7vs{
 
@@ -47,7 +45,7 @@ public:
                                sorry_maxconnection(0LL),
                                sorry_flag(false),
                                qos_upstream(0),
-                               os_downstream(0){}
+                               qos_downstream(0){}
                                
        virtualservice_element( const virtualservice_element& in )
                        :       udpmode( in.udpmode ),
diff --git a/unit_tests/l7vs_command_test/Makefile b/unit_tests/l7vs_command_test/Makefile
new file mode 100644 (file)
index 0000000..62a1e38
--- /dev/null
@@ -0,0 +1,33 @@
+#
+#
+#      Makefile for l7vs_command unit test frameworks.
+#
+#
+TARGET         = l7vs_command_ut
+CPP                    = g++
+CPPFLAGS       = -g -Wall -Werror -pthread -O0
+INCLUDES       =       -I../../logger \
+                               -I../../parameter \
+                               -I../../include \
+                               -I../../src
+LIBS           =       -lboost_system-gcc41-mt \
+                               -lboost_thread-gcc41-mt \
+                               -lboost_unit_test_framework-gcc41-mt
+
+LDFLAGS                = -lrt -ldl
+
+SRCS           =       l7vs_command_ut.cpp
+
+OBJS           = $(SRCS:.cpp=.o)
+
+all:   $(TARGET)
+
+$(TARGET):     $(OBJS)
+       $(CPP) $(INCLUDES) -o $@ $(OBJS) $(LIBS)
+
+clean:
+       rm -f $(TARGET) $(OBJS)
+
+.cpp.o:
+       $(CPP) $(CFLAGS) $(INCLUDES) -c $<
+
diff --git a/unit_tests/l7vs_command_test/l7vs_command_ut.cpp b/unit_tests/l7vs_command_test/l7vs_command_ut.cpp
new file mode 100644 (file)
index 0000000..a9141e9
--- /dev/null
@@ -0,0 +1,60 @@
+#include <boost/test/included/unit_test.hpp>
+#include <boost/asio.hpp>
+#include "../../include/l7vs_command.h"
+
+using namespace boost::unit_test;
+using namespace l7vs;
+
+//
+// using string to endpoint template function
+//
+template< typename InternetProtocol >
+boost::asio::ip::basic_endpoint< InternetProtocol > string_to_endpoint( std::string str ){
+       std::string::size_type pos = str.find( ":" );
+       std::string     hostname = str.substr( 0, pos );
+       std::string     portname = str.substr( pos+1, str.length() );
+       boost::asio::io_service         io_service;
+       typename InternetProtocol::resolver                             resolver(io_service);
+       typename InternetProtocol::resolver::query              query( hostname, portname );
+       typename InternetProtocol::resolver::iterator   end;
+       typename InternetProtocol::resolver::iterator   itr = resolver.resolve( query );
+       if( itr == end ) return typename InternetProtocol::endpoint();
+       return *itr;
+}
+
+
+// testcase 1.
+void   realserver_element_test(){
+       realserver_element      rs;
+       boost::asio::ip::tcp::endpoint  tcp_default_endpoint;
+       boost::asio::ip::udp::endpoint  udp_default_endpoint;
+       // unit_test[1] default constractor tcp endpoint test
+       BOOST_CHECK( rs.tcp_endpoint == tcp_default_endpoint );
+       // unit_test[2] default constractor udp endpoint test
+       BOOST_CHECK( rs.udp_endpoint == udp_default_endpoint );
+       // unit_test[3] default constrafctor weight test
+       BOOST_CHECK( rs.weight == -1 );
+       rs.tcp_endpoint = string_to_endpoint<boost::asio::ip::tcp>( "10.10.10.10:6555" );
+       rs.udp_endpoint = string_to_endpoint<boost::asio::ip::udp>( "20.20.20.20:4444" );
+       rs.weight = 255;
+
+       realserver_element      rs2 = rs;
+       // unit_test[4] copy constractor tcp endpoint test
+       BOOST_CHECK( rs.tcp_endpoint == rs2.tcp_endpoint );
+       // unit_test[5] copy constractor udp endpoint test
+       BOOST_CHECK( rs.udp_endpoint == rs2.udp_endpoint );
+       
+}
+
+
+test_suite*    init_unit_test_suite( int argc, char* argv[] ){
+
+       // create unit test suite
+       test_suite* ts = BOOST_TEST_SUITE( "l7vs_command_ut" );
+       ts->add( BOOST_TEST_CASE( &realserver_element_test ) );
+
+       framework::master_test_suite().add( ts );
+
+       return 0;
+}
+