GTEST_SRCROOT := ../../../..
include ../../defs.mk
+COMMON_STUB_PATH = ../..
+
EXEC_NAME := tclib_ut
MODULE_SRCROOT = $(GTEST_SRCROOT)/modules
TCLIB_SRCDIR = $(MODULE_SRCROOT)/tclib
-STUB_DIR = stub
+MISC_STUBDIR = $(COMMON_STUB_PATH)/stub/misc
+STUB_DIR = $(COMMON_STUB_PATH)/stub
# Define a list of directories that contain source files.
-ALT_SRCDIRS = $(TCLIB_SRCDIR) $(STUB_DIR)
+ALT_SRCDIRS = $(TCLIB_SRCDIR) $(STUB_DIR) $(MISC_STUBDIR)
CXX_INCDIRS += core/include/cxx
CXX_INCDIRS += core/libs/
+UT_INCDIRS_PREP = ${COMMON_STUB_PATH}
+
EXTRA_CXX_INCDIRS = $(STUB_DIR)/include
EXTRA_CXX_INCDIRS += $(MODULE_SRCROOT)
EXTRA_CXX_INCDIRS += $(GTEST_SRCROOT)/include/unc
TCLIB_SOURCES += tclib_msg_util.cc
STUB_SOURCES = tclib_interface_stub.cc
-STUB_SOURCES += module.cc
STUB_SOURCES += stub_serversess.cc
+MISC_STUB_SOURCES = module.cc
+
UT_SOURCES = tclib_common.cc
UT_SOURCES += audit_operations.cc
UT_SOURCES += commit_driver.cc
CXX_SOURCES += $(UT_SOURCES)
CXX_SOURCES += $(TCLIB_SOURCES)
CXX_SOURCES += $(STUB_SOURCES)
+CXX_SOURCES += $(MISC_STUB_SOURCES)
CXX_SOURCES += $(MAIN_SRC)
EXTRA_CXXFLAGS = -fprofile-arcs -ftest-coverage
#include <tclib_module.hh>
#include <unc/keytype.h>
-#include <tclib_interface_stub.hh>
-#include <libtc_common.hh>
+#include <stub/tclib_module/tclib_interface_stub.hh>
+#include <stub/tclib_module/libtc_common.hh>
#include <gtest/gtest.h>
#include <pfcxx/ipc_server.hh>
#include <pfcxx/ipc_client.hh>
#include <pfcxx/ipc_server.hh>
#include <tclib_module.hh>
#include <unc/keytype.h>
-#include <tclib_interface_stub.hh>
-#include <libtc_common.hh>
+#include <stub/tclib_module/tclib_interface_stub.hh>
+#include <stub/tclib_module/libtc_common.hh>
#include <stdio.h>
using namespace unc::tc;
#include <gtest/gtest.h>
#include <tclib_module.hh>
#include <unc/keytype.h>
-#include <tclib_interface_stub.hh>
-#include <libtc_common.hh>
+#include <stub/tclib_module/tclib_interface_stub.hh>
+#include <stub/tclib_module/libtc_common.hh>
#include <stdio.h>
using namespace unc::tc;
#include <pfcxx/ipc_server.hh>
#include <tclib_module.hh>
#include <unc/keytype.h>
-#include <tclib_interface_stub.hh>
-#include <libtc_common.hh>
+#include <stub/tclib_module/tclib_interface_stub.hh>
+#include <stub/tclib_module/libtc_common.hh>
#include <stdio.h>
using namespace unc::tc;
#include <pfcxx/ipc_server.hh>
#include <tclib_module.hh>
#include <unc/keytype.h>
-#include <tclib_interface_stub.hh>
-#include <libtc_common.hh>
+#include <stub/tclib_module/tclib_interface_stub.hh>
+#include <stub/tclib_module/libtc_common.hh>
#include <tclib_msg_util.hh>
#include <stdio.h>
+++ /dev/null
-/*
- * Copyright (c) 2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this
- * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-#ifndef _INCLUDE_LIB_TC_COMMON_HH_
-#define _INCLUDE_LIB_TC_COMMON_HH_
-
-#include <pfcxx/ipc_server.hh>
-#include <pfcxx/ipc_client.hh>
-#include <pfc/log.h>
-#include <uncxx/tclib/tclib_defs.hh>
-#include <string>
-
-using namespace unc::tclib;
-
-namespace unc {
-
-namespace tc {
-
-#define SESSION_ID 10
-#define CONFIG_ID 200
-
-typedef enum {
- TCUTIL_RET_SUCCESS = 0,
- TCUTIL_RET_FAILURE,
- TCUTIL_RET_FATAL
-} TcUtilRet;
-
-typedef enum {
- LIB_READ_NONE = 0,
- LIB_NOTIFY_SESSION,
- LIB_COMMIT_TRANS_START,
- LIB_COMMIT_TRANS_VOTE_GLOBAL,
- LIB_COMMIT_DRIVER_VOTE_GLOBAL,
- LIB_COMMIT_GLOBAL_ABORT,
- LIB_AUDIT_START,
- LIB_AUDIT_VOTE,
- LIB_AUDIT_DRIVER_VOTE_GLOBAL,
- LIB_AUDIT_GLOBAL_ABORT,
- LIB_COMMON,
- LIB_ABORT_CANDIDATE,
- LIB_AUDIT_CONFIG,
- LIB_UPDATE_KEY_LIST,
- LIB_COMMIT_DRIVER_RESULT,
- LIB_AUDIT_DRIVER_RESULT,
- LIB_WRITE_API,
- LIB_DRIVER_AUDIT
-} SessUint32ReadType;
-
-typedef enum {
- RETURN_SUCCESS = 0,
- RETURN_FAILURE,
- RETURN_FAILURE_1,
- RETURN_FAILURE_2,
- RETURN_FAILURE_3,
- RETURN_FAILURE_4,
- RETURN_FAILURE_5,
- RETURN_STRUCT_FAILURE_1,
- RETURN_STRUCT_FAILURE_2
-} ReturnType;
-
-
-class TcServerSessionUtils {
- public:
- TcServerSessionUtils();
- ~TcServerSessionUtils();
-
- static TcUtilRet get_uint32(
- pfc::core::ipc::ServerSession* ssess,
- uint32_t index,
- uint32_t* data);
-
- static TcUtilRet get_uint8(
- pfc::core::ipc::ServerSession* ssess,
- uint32_t index,
- uint8_t* data);
-
- static TcUtilRet get_string(
- pfc::core::ipc::ServerSession* ssess,
- uint32_t index,
- std::string& data);
-
- static TcUtilRet get_struct(
- pfc::core::ipc::ServerSession* ssess,
- uint32_t index,
- const pfc_ipcstdef_t &def,
- void* data);
-
- static TcUtilRet set_uint32(
- pfc::core::ipc::ServerSession* ssess,
- uint32_t data);
-
- static TcUtilRet set_uint8(
- pfc::core::ipc::ServerSession* ssess,
- uint8_t data);
-
- static TcUtilRet set_string(
- pfc::core::ipc::ServerSession* ssess,
- std::string& data);
-
- static TcUtilRet set_struct(
- pfc::core::ipc::ServerSession* ssess,
- const pfc_ipcstdef_t &def,
- const void* data);
-
- inline static void set_read_type(SessUint32ReadType read_type) {
- read_type_ = read_type;
- }
- static SessUint32ReadType read_type_;
-
- inline static void set_return_type(ReturnType return_type) {
- return_type_ = return_type;
- }
- static ReturnType return_type_;
-
- // audit driver result set failure purpose
- inline static void set_return_type_1(ReturnType return_type) {
- return_type_1_ = return_type;
- }
- static ReturnType return_type_1_;
-
- inline static void set_oper_type(TcMsgOperType oper_type) {
- oper_type_ = oper_type;
- }
- static TcMsgOperType oper_type_;
-
- inline static void set_ctr_type(unc_keytype_ctrtype_t ctr_type) {
- ctr_type_ = ctr_type;
- }
- static unc_keytype_ctrtype_t ctr_type_;
-
- inline static void set_numof_errors(uint32_t num_error) {
- num_of_errors_ = num_error;
- }
- static uint32_t num_of_errors_;
-
- static TcUtilRet update_key_list_handler(uint32_t index,
- uint32_t* data);
-
- inline static void set_updatekey_failure(pfc_bool_t key_failure) {
- update_key_failure_ = key_failure;
- }
- static pfc_bool_t update_key_failure_;
-};
-
-class TcClientSessionUtils {
- public:
- TcClientSessionUtils();
- ~TcClientSessionUtils();
-
- static pfc::core::ipc::ClientSession& create_tc_client_session(
- std::string channel_name,
- uint32_t service_id);
-
- static TcUtilRet tc_session_invoke(pfc::core::ipc::ClientSession* csess,
- pfc_ipcresp_t& response);
-
- static TcUtilRet get_uint32(
- pfc::core::ipc::ClientSession* csess,
- uint32_t index,
- uint32_t* data);
-
- static TcUtilRet get_uint8(
- pfc::core::ipc::ClientSession* csess,
- uint32_t index,
- uint8_t* data);
-
- static TcUtilRet get_string(
- pfc::core::ipc::ClientSession* csess,
- uint32_t index,
- std::string& data);
-
- static TcUtilRet set_uint32(
- pfc::core::ipc::ClientSession* csess,
- uint32_t data);
-
- static TcUtilRet set_uint8(
- pfc::core::ipc::ClientSession* csess,
- uint8_t data);
-
- static TcUtilRet set_string(
- pfc::core::ipc::ClientSession* csess,
- std::string& data);
-
- inline static void set_return_type(ReturnType return_type) {
- return_type_ = return_type;
- }
- static ReturnType return_type_;
-};
-} // namespace tc
-} // namespace unc
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this
- * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-#ifndef _PFCXX_IPC_HH
-#define _PFCXX_IPC_HH
-
-/*
- * Common definitions for C++ language interaces of PFC IPC framework.
- */
-/*
-#if !defined(_PFCXX_IPC_SERVER_HH) && !defined(_PFCXX_IPC_CLIENT_HH)
-#error Never include this file directly!
-#endif // !defined(_PFCXX_IPC_SERVER_HH) && !defined(_PFCXX_IPC_CLIENT_HH)
-*/
-#include <pfc/ipc.h>
-#include <netinet/in.h>
-#include <boost/noncopyable.hpp>
-#include <string>
-
-namespace pfc {
-namespace core {
-namespace ipc {
-
-class ServerEvent;
-class ServerCallback;
-class ClientSession;
-
-/*
- * C++ wrapper for IPC server session instance.
- */
-class ServerSession
- : boost::noncopyable {
- friend class ::pfc::core::ipc::ClientSession;
- friend class ::pfc::core::ipc::ServerEvent;
-
- public:
- /*
- * Constructor.
- */
- explicit ServerSession(pfc_ipcsrv_t *srv);
-
- /*
- * Destructor.
- */
- virtual ~ServerSession() {}
-
- /*
- * Instance methods.
- */
- int setTimeout(const pfc_timespec_t *timeout = NULL);
- int getClientAddress(pfc_ipccladdr_t &claddr);
-
- int addOutput(int8_t data);
- int addOutputInt8(int8_t data);
- int addOutput(uint8_t data);
- int addOutputUint8(uint8_t data);
- int addOutput(int16_t data);
- int addOutputInt16(int16_t data);
- int addOutput(uint16_t data);
- int addOutputUint16(uint16_t data);
- int addOutput(int32_t data);
- int addOutputInt32(int32_t data);
- int addOutput(uint32_t data);
- int addOutputUint32(uint32_t data);
- int addOutput(int64_t data);
- int addOutputInt64(int64_t data);
- int addOutput(uint64_t data);
- int addOutputUint64(uint64_t data);
- int addOutput(float data);
- int addOutputFloat(float data);
- int addOutput(double data);
- int addOutputDouble(double data);
- int addOutput(struct in_addr &data);
- int addOutput(struct in6_addr &data);
- int addOutput(const char *data);
- int addOutput(const std::string &data);
- int addOutput(const uint8_t *data, uint32_t length);
- int addOutput(const pfc_ipcstdef_t &def, pfc_cptr_t data);
- int addOutput(void);
-
- int getArgument(uint32_t index, int8_t &data);
- int getArgument(uint32_t index, uint8_t &data);
- int getArgument(uint32_t index, int16_t &data);
- int getArgument(uint32_t index, uint16_t &data);
- int getArgument(uint32_t index, int32_t &data);
- int getArgument(uint32_t index, uint32_t &data);
- int getArgument(uint32_t index, int64_t &data);
- int getArgument(uint32_t index, uint64_t &data);
- int getArgument(uint32_t index, float &data);
- int getArgument(uint32_t index, double &data);
- int getArgument(uint32_t index, struct in_addr &data);
- int getArgument(uint32_t index, struct in6_addr &data);
- int getArgument(uint32_t index, const char *&data);
- int getArgument(uint32_t index, const uint8_t *&data, uint32_t &length);
- int getArgument(uint32_t index, const pfc_ipcstdef_t &def,
- pfc_ptr_t datap);
-
- uint32_t getArgCount(void);
- int getArgType(uint32_t index, pfc_ipctype_t &type);
-
- int getArgStructName(uint32_t index, const char *&name);
- int getArgStructName(uint32_t index, std::string &name);
-
-/*
- * Import accessor definitions for user-defined IPC structs.
- */
-#define _PFCXX_IPC_IMPORT_STRUCT_SERVER
-#include <pfcxx/ipc_server_proto.hh>
-#undef _PFCXX_IPC_IMPORT_STRUCT_SERVER
-
- int setCallback(pfc_ipcsrvcb_type_t type, ServerCallback *cbp);
- void unsetCallback(pfc_ipcsrvcb_type_t type);
- void clearCallbacks(void);
-
-// private:
- /* Server session instance. */
- pfc_ipcsrv_t *_srv;
-};
-
-/*
- * C++ wrapper for IPC client session instance.
- */
-class ClientSession
- : boost::noncopyable {
- friend class ::pfc::core::ipc::ServerSession;
-
- public:
- /*
- * Constructors.
- */
- ClientSession(const char *name, pfc_ipcid_t service, int &err);
- ClientSession(const char *name, pfc_ipcid_t service, int &err,
- uint32_t flags);
- ClientSession(const std::string &name, pfc_ipcid_t service, int &err);
- ClientSession(const std::string &name, pfc_ipcid_t service, int &err,
- uint32_t flags);
- ClientSession(pfc_ipcconn_t conn, const char *name, pfc_ipcid_t service,
- int &err);
- ClientSession(pfc_ipcconn_t conn, const char *name, pfc_ipcid_t service,
- int &err, uint32_t flags);
- ClientSession(pfc_ipcconn_t conn, const std::string &name,
- pfc_ipcid_t service, int &err);
- ClientSession(pfc_ipcconn_t conn, const std::string &name,
- pfc_ipcid_t service, int &err, uint32_t flags);
- explicit ClientSession(pfc_ipcsess_t *sess);
-
- /*
- * Destructor.
- */
- ~ClientSession();
-
- /*
- * Instance methods.
- */
- int reset(const char *name, pfc_ipcid_t service);
- int reset(const std::string &name, pfc_ipcid_t service);
- int setTimeout(const pfc_timespec_t *timeout = NULL);
- int invoke(pfc_ipcresp_t &response);
- int cancel(pfc_bool_t discard = PFC_FALSE);
- int forward(ClientSession &sess, uint32_t begin = 0,
- uint32_t end = UINT32_MAX);
- int forward(ServerSession &sess, uint32_t begin = 0,
- uint32_t end = UINT32_MAX);
- int forwardTo(ServerSession &sess, uint32_t begin = 0,
- uint32_t end = UINT32_MAX);
-
- int addOutput(int8_t data);
- int addOutputInt8(int8_t data);
- int addOutput(uint8_t data);
- int addOutputUint8(uint8_t data);
- int addOutput(int16_t data);
- int addOutputInt16(int16_t data);
- int addOutput(uint16_t data);
- int addOutputUint16(uint16_t data);
- int addOutput(int32_t data);
- int addOutputInt32(int32_t data);
- int addOutput(uint32_t data);
- int addOutputUint32(uint32_t data);
- int addOutput(int64_t data);
- int addOutputInt64(int64_t data);
- int addOutput(uint64_t data);
- int addOutputUint64(uint64_t data);
- int addOutput(float data);
- int addOutputFloat(float data);
- int addOutput(double data);
- int addOutputDouble(double data);
- int addOutput(struct in_addr &data);
- int addOutput(struct in6_addr &data);
- int addOutput(const char *data);
- int addOutput(const std::string &data);
- int addOutput(const uint8_t *data, uint32_t length);
- int addOutput(const pfc_ipcstdef_t &def, pfc_cptr_t data);
- int addOutput(void);
-
- int getResponse(uint32_t index, int8_t &data);
- int getResponse(uint32_t index, uint8_t &data);
- int getResponse(uint32_t index, int16_t &data);
- int getResponse(uint32_t index, uint16_t &data);
- int getResponse(uint32_t index, int32_t &data);
- int getResponse(uint32_t index, uint32_t &data);
- int getResponse(uint32_t index, int64_t &data);
- int getResponse(uint32_t index, uint64_t &data);
- int getResponse(uint32_t index, float &data);
- int getResponse(uint32_t index, double &data);
- int getResponse(uint32_t index, struct in_addr &data);
- int getResponse(uint32_t index, struct in6_addr &data);
- int getResponse(uint32_t index, const char *&data);
- int getResponse(uint32_t index, const uint8_t *&data, uint32_t &length);
- int getResponse(uint32_t index, const pfc_ipcstdef_t &def,
- pfc_ptr_t datap);
-
- uint32_t getResponseCount(void);
- int getResponseType(uint32_t index, pfc_ipctype_t &type);
-
- int getResponseStructName(uint32_t index, const char *&name);
- int getResponseStructName(uint32_t index, std::string &name);
-
-/*
- * Import accessor definitions for user-defined IPC structs.
- */
-#define _PFCXX_IPC_IMPORT_STRUCT_CLIENT
-#include <pfcxx/ipc_client_proto.hh>
-#undef _PFCXX_IPC_IMPORT_STRUCT_CLIENT
-
- private:
- /* Client session instance. NULL is kept on creation error. */
- pfc_ipcsess_t *_sess;
-};
-
-} // namespace ipc
-} // namespace core
-} // namespace pfc
-
-#endif /* !_PFCXX_IPC_HH */
+++ /dev/null
-/*
- * Copyright (c) 2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this
- * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-#ifndef _PFCXX_MODULE_HH
-#define _PFCXX_MODULE_HH
-
-/*
- * Definitions for C++ module management.
- */
-
-#include <pfc/module.h>
-#include <pfc/log.h>
-#include <boost/noncopyable.hpp>
-#include <pfcxx/conf.hh>
-#include <pfcxx/event.hh>
-#include <pfcxx/ipc_server.hh>
-#include <pfcxx/stubs.hh>
-#include <new>
-#include <string>
-#include <typeinfo>
-#include <exception>
-
-namespace pfc {
-namespace core {
-
-/*
- * Abstract class for module instance.
- * Each module has one Module instance.
- */
-class Module
- : boost::noncopyable {
- public:
- explicit Module(const pfc_modattr_t *attr);
- virtual ~Module(void);
-
- /*
- * Return the module instance associated with the given module name.
- * NULL is returned if not found.
- */
- static Module *getInstance(const char *name);
-
- /*
- * Return the module instance associated with the given pointer type name.
- * NULL is returned if not found.
- */
- static Module *getInstanceByType(const char *tname);
-
- /*
- * Return PFC_TRUE if the given event object is a module specific event.
- */
- static inline pfc_bool_t
- isModuleEvent(Event *eobj) {
- if (PFC_EXPECT_FALSE(eobj == NULL)) {
- return PFC_FALSE;
- }
-
- return pfc_module_is_modevent(eobj->getEvent());
- }
-
- /*
- * Return a string which represents the sender of the given event object.
- *
- * `eobj' must be a pointer to a module specific event object.
- * Specifying a non module specific event object results undefined
- * behavior.
- */
- static inline const char *
- getEventSender(Event *eobj) {
- return pfc_module_event_getsender(eobj->getEvent());
- }
-
- /*
- * Start the module service.
- *
- * This method is called once after the module is loaded into the PFC
- * system. If this method returns PFC_FALSE, the module load is failed.
- */
- virtual pfc_bool_t init(void) = 0;
-
- /*
- * Stop the module service.
- *
- * This method is called once just before the module is unloaded from
- * the PFC system. If this function returns PFC_FALSE, the module is not
- * unloaded from the memory, but its service is stopped.
- */
- virtual pfc_bool_t fini(void) = 0;
-
- /*
- * Get pointer to the module instance, and set it into the specified
- * pointer. NULL is set if the module is not found.
- */
- template <class T>
- inline void getInstance(T *&ptr) {
- Module *m(Module::getInstanceByType(typeid(ptr).name()));
-
- ptr = static_cast<T *>(m);
- }
-
- /*
- * Return module name in C-styled format.
- */
- inline const char *name(void) const {
- return _attr->pma_name;
- }
-
- /*
- * Return module name.
- */
- inline std::string getName(void) const {
- return _name;
- }
-
- /*
- * Return module identifier.
- */
- inline pfc_module_t getModuleId(void) const {
- return _module;
- }
-
- /*
- * Return module version.
- */
- inline uint8_t getVersion(void) const {
- return _attr->pma_version;
- }
-
- /*
- * Return module system version.
- */
- inline uint8_t getSystemVersion(void) const {
- return _attr->pma_sysversion;
- }
-
- /*
- * Return basic attributes of the module.
- * This method is provided only for PFC module subsystem.
- */
- inline const pfc_modattr_t *getAttribute(void) const {
- return _attr;
- }
-
- /*
- * Reload configuration file for this module.
- * Zero is returned on success, error number on failure.
- * Do nothing if this module doesn't use module configuration file.
- */
- inline int
- reloadConf(void) {
- return __pfc_module_conf_reload(_module);
- }
-
- /*
- * Add an event handler which receives module-specific events posted to
- * this module.
- * The handler added by this method will receive all events posted to
- * this module.
- *
- * If `hname' is specified, it is used as event handler's name.
- */
- inline int
- addEventHandler(pfc_evhandler_t &id, event_handler_t &handler,
- uint32_t priority = Event::DEFAULT_PRIORITY,
- const char *hname = PFC_LOG_IDENT) {
- return addEventHandler(id, handler, NULL, priority, hname);
- }
-
- /*
- * Add an event handler which receives module-specific events posted to
- * this module.
- * The handler added by this method will receive events which has the
- * event type specified by the event mask bits.
- *
- * If `hname' is specified, it is used as event handler's name.
- */
- inline int
- addEventHandler(pfc_evhandler_t &id, event_handler_t &handler,
- EventMask &mask,
- uint32_t priority = Event::DEFAULT_PRIORITY,
- const char *hname = PFC_LOG_IDENT) {
- return addEventHandler(id, handler, mask.getMask(), priority, hname);
- }
-
- /*
- * Remove the event handler associated with the specified handler ID.
- */
- inline int
- removeEventHandler(pfc_evhandler_t id,
- const pfc_timespec_t *timeout = NULL) {
- return pfc_event_remove_handler(id, timeout);
- }
-
- /*
- * Post a module-specific event of the type specified by `type'.
- * The event is delivered to only handlers added by the module specified
- * by `target'.
- */
- int postEvent(const char *target, pfc_evtype_t type);
-
- /*
- * Post a module-specific event of the type specified by `type'.
- * This method specifies the target module by std::string.
- */
- inline int
- postEvent(std::string &target, pfc_evtype_t type) {
- return postEvent(target.c_str(), type);
- }
-
- /*
- * IPC service handler.
- * This method must be overridden if the module provides IPC services.
- *
- * `sess' is a instance of IPC server session. Argument sent by the clinet
- * can be obtained via this instance, and arbitrary data can be sent to
- * the client via this instance.
- *
- * `service' is an identifier of the IPC service specified by the client.
- *
- * Calling/Exit State:
- * If PFC_IPCRESP_FATAL (-1) is returned by this method, the IPC
- * framework considers as fatal error. In this case, any data added
- * to the IPC service session is discarded.
- *
- * A value other than PFC_IPCRESP_FATAL is treated as response of the
- * IPC service, and it is sent to the client.
- */
- pfc_ipcresp_t ipcService(ipc::ServerSession &sess,
- pfc_ipcid_t service);
-
- private:
- /* Register module-specific event handler. */
- int addEventHandler(pfc_evhandler_t &id, event_handler_t &handler,
- const pfc_evmask_t *maskp, uint32_t priority,
- const char *hname);
-
- /* Module descriptor. */
- const pfc_modattr_t *_attr;
-
- /* Module name */
- std::string _name;
-
- /* Module identifier */
- pfc_module_t _module;
-};
-
-/*
- * Prototypes.
- */
-extern pfc_module_t module_register(const pfc_modattr_t *mattr,
- pfc_modfac_t factory,
- const char *tname);
-
- /* pma_cfdef */ \
-#define PFC_MODULE_IPC_DECL(module_class, nipcs)
-
-
-/*
- * PFC_MODULE_BUILD is defined by the build system only for PFC module build.
- */
-#ifdef PFC_MODULE_BUILD
-
-/*
- * Declare C++ module.
- * `nipcs' is the number of IPC services provided by this module.
- * Zero means no IPC service is provided.
- */
-#define PFC_MODULE_IPC_DECL(module_class, nipcs) \
- static void * \
- __module_factory(const pfc_modattr_t *mattr) \
- { \
- module_class *obj(new module_class(mattr)); \
- void *ptr(static_cast<pfc::core::Module *>(obj)); \
- \
- if (PFC_EXPECT_FALSE(ptr == NULL)) { \
- delete obj; \
- } \
- \
- return ptr; \
- } \
- \
- static void PFC_FATTR_INIT \
- __module_init(void) \
- { \
- __PFC_MODULE_SECT_DECL; \
- static const pfc_modattr_t mattr = { \
- PFC_MODULE_SYSTEM_VERSION, /* pma_sysversion */ \
- PFC_MODTYPE_CXX, /* pma_type */ \
- MODULE_VERSION, /* pma_version */ \
- 0, /* pma_pad1 */ \
- (nipcs), /* pma_nipcs */ \
- MODULE_NAME, /* pma_name */ \
- NULL, /* pma_ipchdlr */ \
- __PFC_MODULE_SECT_INITIALIZER, /* pma_section */ \
- NULL, /* pma_pad2 */ \
- NULL, /* pma_pad3 */ \
- }; \
- \
- ::__pfc_this_module_name = mattr.pma_name; \
- \
- const char *tname(reinterpret_cast<module_class *>(.name)()); \
- ::__pfc_this_module_id = \
- pfc::core::module_register(&mattr, __module_factory, tname); \
- } \
- \
- pfc_module_t __pfc_this_module_id PFC_ATTR_HIDDEN = PFC_MODULE_INVALID; \
- const char *__pfc_this_module_name PFC_ATTR_HIDDEN
-
-/*
- * Declare C++ module without IPC service.
- */
-#define PFC_MODULE_DECL(module_class) ((void)0)
-// PFC_MODULE_IPC_DECL(module_class, 0)
-
-/*
- * The ModuleConfBlock instance represents a bunch of parameters defined in
- * the module configuration file.
- * This class is only available in module source code.
- */
-class ModuleConfBlock
- : public ConfBlock {
- public:
- /*
- * Create a block handle instance associated with a parameter block
- * in the module configuration file, specified by the block name.
- */
- explicit ModuleConfBlock(const char *bname)
- : ConfBlock(pfc_module_conf_getblock(bname)) {}
-
- explicit ModuleConfBlock(std::string &bname)
- : ConfBlock(pfc_module_conf_getblock(bname.c_str())) {}
-
- /*
- * Create a block handle instance associated with a parameter map block
- * in the module configuration file, specified by the map name and its key.
- */
- ModuleConfBlock(const char *mname, const char *key)
- : ConfBlock(pfc_module_conf_getmap(mname, key)) {}
-
- ModuleConfBlock(std::string &mname, std::string &key)
- : ConfBlock(pfc_module_conf_getmap(mname.c_str(), key.c_str())) {}
-};
-
-#endif /* PFC_MODULE_BUILD */
-
-} // namespace core
-} // namespace pfc
-
-#endif /* !_PFCXX_MODULE_HH */
+++ /dev/null
-/*
- * Copyright (c) 2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this
- * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-#ifndef STUB_SESS_HH
-#define STUB_SESS_HH
-
-#include<libpfc_ipc/ipc_impl.h>
-
-#define MODULE_NAME "tclib"
-
-#undef PFC_ASSERT
-#define PFC_ASSERT(ex) ((void)0)
-
-#undef __PFC_MODULE_SECT_DECL
-#define __PFC_MODULE_SECT_DECL \
- const uint8_t __pfc_module_sect_text[] = {100}; \
- const uint8_t __pfc_module_sect_rodata[] = {100}; \
- const uint8_t __pfc_module_sect_data[] = {100}; \
- const uint8_t __pfc_module_sect_bss[] = {100}; \
- const uint8_t __pfc_module_sect_end[] = {100};
-
-
-#define __PFC_MODULE_SECT_INITIALIZER \
- { \
- __pfc_module_sect_text, \
- __pfc_module_sect_rodata, \
- __pfc_module_sect_data, \
- __pfc_module_sect_bss, \
- __pfc_module_sect_end, \
- }
-
-struct __pfc_ipcsrv {
- pfc_ipcid_t isv_service;
- ipc_msg_t isv_args;
-// pfc_mutex_t isv_mutex; /* mutex */
-// pfc_cond_t isv_cond; /* condition variable */
-}; // duplicate
-
-
-#endif
-
-
+++ /dev/null
-/*
- * Copyright (c) 2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this
- * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-#ifndef _INCLUDE_TCLIB_INTF_STUB_HH_
-#define _INCLUDE_TCLIB_INTF_STUB_HH_
-
-#include <uncxx/tclib/tclib_interface.hh>
-#include <string>
-
-using namespace std;
-
-namespace unc {
-namespace tclib {
-
-class TcLibInterfaceStub : public TcLibInterface {
- public:
- TcLibInterfaceStub();
- /**
- * @Description : This function will be called back when TC sends user
- * commit-transaction start request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleCommitTransactionStart(uint32_t config_id,
- uint32_t session_id) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
-
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * Audit-transaction start request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAuditTransactionStart(uint32_t session_id,
- unc_keytype_ctrtype_t driver_id,
- string controller_id) {
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * commit-transaction end request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleCommitTransactionEnd(uint32_t config_id,
- uint32_t session_id,
- TcTransEndResult end_result) {
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * Audit-transaction End request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAuditTransactionEnd(uint32_t session_id,
- unc_keytype_ctrtype_t driver_id,
- string controller_id,
- TcTransEndResult end_result) {
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * commit vote request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleCommitVoteRequest(uint32_t session_id,
- uint32_t config_id,
- TcDriverInfoMap& driver_info);
- /*
- {
- return TC_SUCCESS;
- }
- */
- /**
- * @Description : This function will be called back when TC sends user
- * Audit vote request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAuditVoteRequest(uint32_t session_id,
- uint32_t driver_id,
- string controller_id,
- TcDriverInfoMap &driver_info);
- /*{
- return TC_SUCCESS;
- }*/
-
- /**
- * @Description : This function will be called back when TC sends user
- * Global commit request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleCommitGlobalCommit(uint32_t config_id,
- uint32_t session_id,
- TcDriverInfoMap& driver_info) {
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * Audit Global Commit request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAuditGlobalCommit(uint32_t session_id,
- uint32_t driver_id,
- string controller_id,
- TcDriverInfoMap &driver_info,
- TcAuditResult& audit_result);
- /*{
- return TC_SUCCESS;
- }*/
-
- /**
- * @Description : This function will be called back when TC sends user
- * Driver Result to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleCommitDriverResult(uint32_t session_id,
- uint32_t config_id,
- TcCommitPhaseType commitphase,
- TcCommitPhaseResult driver_result) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
-
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * Driver Result to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAuditDriverResult(uint32_t session_id,
- string controller_id,
- TcCommitPhaseType commitphase,
- TcCommitPhaseResult driver_result,
- TcAuditResult& audit_result) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
-
- audit_result = TC_AUDIT_FAILURE;
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * Audit Start request to UPPL/UPLL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAuditStart(uint32_t session_id,
- unc_keytype_ctrtype_t driver_id,
- string controller_id) {
- if (tclib_stub_failure_ == PFC_TRUE) {
- return TC_FAILURE;
- }
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * Audit Start request to driver modules
- * This is a virtual function in TCLib
- */
- TcCommonRet HandleAuditStart(uint32_t session_id,
- unc_keytype_ctrtype_t driver_id,
- string controller_id,
- pfc_bool_t force_reconnect) {
- if (tclib_stub_failure_ == PFC_TRUE) {
- return TC_FAILURE;
- }
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * Audit End request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAuditEnd(uint32_t session_id,
- unc_keytype_ctrtype_t driver_id,
- string controller_id,
- TcAuditResult audit_result) {
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * save configuration request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleSaveConfiguration(uint32_t session_id) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
-
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * clear startup request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleClearStartUp(uint32_t session_id) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
-
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends user
- * Abort Candidate request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAbortCandidate(uint32_t session_id, uint32_t config_id) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
-
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends
- * db recovery requests during failover
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAuditConfig(unc_keytype_datatype_t db_target,
- TcServiceType fail_oper) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends
- * abort during transaction phase
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleGlobalAbort(uint32_t session_id, uint32_t config_id,
- TcCommitPhaseType operation_phase) {
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends
- * abort during audit transaction phase
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleAuditGlobalAbort(uint32_t session_id,
- unc_keytype_ctrtype_t driver_id,
- string controller_id,
- TcAuditOpAbortPhase operation_phase);
- /*{
- return TC_SUCCESS;
- }*/
-
- /**
- * @Description : This function will be called back when TC sends
- * load startup configuration request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleSetup() {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This function will be called back when TC sends
- * load startup configuration request to UPPL
- * This is a virtual function in TCLib
- */
-
- TcCommonRet HandleSetupComplete() {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
- return TC_SUCCESS;
- }
-
- /**
- * @Description : This is a dummy function. TcLibInterface has pure virtual
- * functions. All functions has to have an implementiation to
- * avoid runtime conflicts
- */
-
- TcCommonRet HandleCommitVoteRequest(uint32_t session_id, uint32_t config_id,
- TcControllerList controllers) {
- return TC_SUCCESS;
- }
- /**
- * @Description : This is a dummy function. TcLibInterface has pure virtual
- * functions. All functions has to have an implementiation to
- * avoid runtime conflicts
- */
-
- TcCommonRet HandleCommitGlobalCommit(uint32_t session_id, uint32_t config_id,
- TcControllerList controllers) {
- return TC_SUCCESS;
- }
- /**
- * @Description : This is a dummy function. TcLibInterface has pure virtual
- * functions. All functions has to have an implementiation to
- * avoid runtime conflicts
- */
-
- TcCommonRet HandleCommitGlobalAbort(uint32_t session_id, uint32_t config_id,
- TcCommitOpAbortPhase fail_phase);
- /*{
- return TC_SUCCESS;
- }*/
- /**
- * @Description : This is a dummy function. TcLibInterface has pure virtual
- * functions. All functions has to have an implementiation to
- * avoid runtime conflicts
- */
- inline
- TcCommonRet HandleAuditVoteRequest(uint32_t session_id,
- string controller_id,
- TcControllerList controllers) {
- return TC_SUCCESS;
- }
- /**
- * @Description : This is a dummy function. TcLibInterface has pure virtual
- * functions. All functions has to have an implementiation to
- * avoid runtime conflicts
- */
-
- TcCommonRet HandleAuditGlobalCommit(uint32_t session_id, string controller_id,
- TcControllerList controllers) {
- return TC_SUCCESS;
- }
- /**
- * @Description : This is a dummy function. TcLibInterface has pure virtual
- * functions. All functions has to have an implementiation to
- * avoid runtime conflicts
- */
-
- // TODO(phycore) : to be implemented
- TcCommonRet HandleClearStartup(uint32_t session_id) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
-
- return TC_SUCCESS;
- }
- /**
- * @Description : This is a dummy function. TcLibInterface has pure virtual
- * functions. All functions has to have an implementiation to
- * avoid runtime conflicts
- */
-
- // TODO(phycore) : to be implemented
- unc_keytype_ctrtype_t HandleGetControllerType(std::string controller_id) {
- return UNC_CT_PFC;
- }
- /**
- * @Description : This is a dummy function. TcLibInterface has pure virtual
- * functions. All functions has to have an implementiation to
- * avoid runtime conflicts
- */
-
- unc_keytype_ctrtype_t HandleGetControllerType();
-
- unc_keytype_ctrtype_t ctr_type;
- pfc_bool_t fill_driver_info_;
- pfc_bool_t tclib_stub_failure_;
-};
-
-} // namespace tclib
-} // namespace unc
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this
- * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-#include <pfcxx/module.hh>
-#include <pfc/rbtree.h>
-#include <pfc/synch.h>
-#include <pfc/debug.h>
-#include <pfc/log.h>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <exception>
-
-namespace pfc {
-namespace core {
-
-/*
- * Return module instance associated with the specified module descriptor.
- */
-#define PMODULE_INSTANCE(mod)\
- (reinterpret_cast<Module*>(PMODULE_OBJECT_PTR(mod)))
-
-
- /*
- * * Module object entry which keep a pair of module class pointer type name and
- * * module instance. This must be defined as POD because it is passed to
- * * offsetof().
- * */
- extern "C" {
- typedef struct {
- const char *mo_name; /* type identifier */
- pfc_ptr_t mo_object; /* pointer to module instance */
- pfc_rbnode_t mo_node; /* Red-Black Tree node */
- } module_object_t;
- }
-
-#define PMODULE_OBJECT_NODE2PTR(node)\
- PFC_CAST_CONTAINER((node), module_object_t, mo_node)
-
- /*
- * * Module::Module(const pfc_modattr_t *attr)
- * * Constructor of abstract module class.
- * */
- Module::Module(const pfc_modattr_t *attr)
- : _attr(attr), _name(_attr->pma_name) {}
-
- /*
- * * Module::~Module(void)
- * * Destructor of abstract module class.
- * */
- Module::~Module(void) {}
-
-
-} // namespace core
-} // namespace pfc
+++ /dev/null
-/*
- * Copyright (c) 2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this
- * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-#include <pfcxx/module.hh>
-#include <pfcxx/synch.hh>
-#include <libtc_common.hh>
-#include <unc/tc/external/tc_services.h>
-
-int pfc_ipcsrv_getargtype(pfc_ipcsrv_t *PFC_RESTRICT srv,
- uint32_t index,
- pfc_ipctype_t *PFC_RESTRICT typep) {
- if (index == 4)
- *typep = PFC_IPCTYPE_STRING;
- if (index == 7)
- *typep = PFC_IPCTYPE_UINT32;
- return 0;
-}
-
-namespace unc {
-namespace tc {
-
-SessUint32ReadType TcServerSessionUtils::read_type_ = LIB_READ_NONE;
-ReturnType TcServerSessionUtils::return_type_ = RETURN_SUCCESS;
-TcMsgOperType TcServerSessionUtils::oper_type_ = MSG_NONE;
-unc_keytype_ctrtype_t TcServerSessionUtils::ctr_type_ = UNC_CT_UNKNOWN;
-uint32_t TcServerSessionUtils::num_of_errors_ = 0;
-pfc_bool_t TcServerSessionUtils::update_key_failure_ = PFC_FALSE;
-ReturnType TcServerSessionUtils::return_type_1_ = RETURN_SUCCESS;
-
-TcServerSessionUtils::TcServerSessionUtils() {
- read_type_ = LIB_READ_NONE;
- return_type_ = RETURN_SUCCESS;
- oper_type_ = MSG_NONE;
- ctr_type_ = UNC_CT_UNKNOWN;
- num_of_errors_ = 0;
- update_key_failure_ = PFC_FALSE;
-}
-
-TcServerSessionUtils::~TcServerSessionUtils() {
- read_type_ = LIB_READ_NONE;
- return_type_ = RETURN_SUCCESS;
- oper_type_ = MSG_NONE;
- num_of_errors_ = 0;
- ctr_type_ = UNC_CT_UNKNOWN;
- update_key_failure_ = PFC_FALSE;
-}
-
-int getArgType(uint32_t index, pfc_ipctype_t &type) {
- if (index == 4)
- type = PFC_IPCTYPE_STRING;
- if (index == 7)
- type = PFC_IPCTYPE_UINT32;
-
- return 0;
-}
-
-TcUtilRet
-TcServerSessionUtils::update_key_list_handler(uint32_t index,
- uint32_t* data) {
- pfc_log_info("the index=%d", index);
- if (return_type_ == RETURN_SUCCESS) {
- if (( index == 5) || (index == 8))
- *data = 0; // resp_code
- if (index == 6)
- *data = num_of_errors_;
- if (index == 9)
- *data = 1;
-
- if (index == 7)
- *data = 20;
- if (index == 10)
- *data = 21;
- return TCUTIL_RET_SUCCESS;
- }
-
- if ((return_type_ == RETURN_FAILURE_1) && (index == 5)) {
- return TCUTIL_RET_FAILURE;
- }
-
- if ((return_type_ == RETURN_FAILURE_2) && (index == 6)) {
- return TCUTIL_RET_FAILURE;
- }
-
- if ((return_type_ == RETURN_FAILURE_3) && (index == 7)) {
- return TCUTIL_RET_FAILURE;
- }
-
- if ((return_type_ == RETURN_FAILURE_3) && (index == 10)) {
- *data = 21;
- return TCUTIL_RET_FAILURE;
- }
- return TCUTIL_RET_SUCCESS;
-}
-
-TcUtilRet TcServerSessionUtils::get_uint32(
- pfc::core::ipc::ServerSession* ssess,
- uint32_t index,
- uint32_t* data) {
-
- switch (read_type_) {
- case LIB_NOTIFY_SESSION:
- case LIB_ABORT_CANDIDATE:
- if (return_type_ == RETURN_SUCCESS) {
- if (index == 0)
- *data = SESSION_ID;
- if (index == 1)
- *data = CONFIG_ID;
- return TCUTIL_RET_SUCCESS;
- }
- if ((return_type_ == RETURN_FAILURE_1) && (index == 0))
- return TCUTIL_RET_FAILURE;
-
- if ((return_type_ == RETURN_FAILURE_2) && (index == 1))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- case LIB_COMMIT_TRANS_START:
- case LIB_COMMIT_DRIVER_VOTE_GLOBAL:
- case LIB_COMMIT_GLOBAL_ABORT:
- case LIB_COMMIT_DRIVER_RESULT:
- if (return_type_ == RETURN_SUCCESS) {
- if (index == 1)
- *data = SESSION_ID;
- if (index == 2)
- *data = CONFIG_ID;
- /* below two fields are for driver result alone */
- if (index == 5)
- *data = 0; // resp_code
- if (index == 6)
- *data = 0; // num of errors
- return TCUTIL_RET_SUCCESS;
- }
- if ((return_type_ == RETURN_FAILURE_1) && (index == 1))
- return TCUTIL_RET_FAILURE;
-
- if ((return_type_ == RETURN_FAILURE_2) && (index == 2))
- return TCUTIL_RET_FAILURE;
-
- if ((return_type_ == RETURN_FAILURE_4) && (index == 5))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- case LIB_AUDIT_START:
- case LIB_AUDIT_GLOBAL_ABORT:
- case LIB_AUDIT_DRIVER_RESULT:
- if (return_type_ == RETURN_SUCCESS) {
- if (index == 1)
- *data = SESSION_ID;
- return TCUTIL_RET_SUCCESS;
- }
- if ((return_type_ == RETURN_FAILURE_1) && (index == 1))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- case LIB_COMMON:
- if (return_type_ == RETURN_SUCCESS) {
- return TCUTIL_RET_SUCCESS;
- }
- if (return_type_ == RETURN_FAILURE)
- return TCUTIL_RET_FAILURE;
-
- case LIB_UPDATE_KEY_LIST:
- pfc_log_info("About to call ...");
- return update_key_list_handler(index, data);
-
- case LIB_AUDIT_DRIVER_VOTE_GLOBAL:
- if (return_type_ == RETURN_FAILURE_1 ||
- return_type_ == RETURN_FAILURE_3)
- return TCUTIL_RET_FAILURE;
-
- return TCUTIL_RET_SUCCESS;
- default:
- return TCUTIL_RET_SUCCESS;
- }
-}
-
-
-TcUtilRet TcServerSessionUtils::get_uint8(
- pfc::core::ipc::ServerSession* ssess,
- uint32_t index,
- uint8_t* data) {
-
- switch (read_type_) {
- case LIB_COMMIT_TRANS_START:
- case LIB_COMMIT_GLOBAL_ABORT:
- if (index == 0)
- *data = oper_type_;
- if (index == 3)
- *data = 0; // end_result
-
- if ((return_type_ == RETURN_FAILURE) && (index == 0))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_3) && (index == 3))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- case LIB_COMMIT_DRIVER_VOTE_GLOBAL:
- if (index == 0)
- *data = oper_type_;
- if (index == 3)
- *data = 1; // ctrl_count
- if ((return_type_ == RETURN_FAILURE) && (index == 0))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_3) && (index == 3))
- return TCUTIL_RET_FAILURE;
-
- return TCUTIL_RET_SUCCESS;
-
- case LIB_COMMIT_DRIVER_RESULT:
- case LIB_AUDIT_DRIVER_RESULT:
- if (return_type_ == RETURN_SUCCESS) {
- if (index == 0)
- *data = oper_type_;
- if (index == 3)
- *data = 3; // driver result phase
-
- return TCUTIL_RET_SUCCESS;
- }
- if ((return_type_ == RETURN_FAILURE_4) && (index == 0))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_3) && (index == 3))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- case LIB_AUDIT_VOTE:
- if (return_type_ == RETURN_SUCCESS) {
- if (index == 0)
- *data = oper_type_;
- if (index == 2)
- *data = ctr_type_; // ctr_type number
- if (index == 4)
- *data = 0; // audit_result
- if (index == 5)
- *data = 0; // end_result
- return TCUTIL_RET_SUCCESS;
- }
- if ((return_type_ == RETURN_FAILURE) && (index == 0))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- case LIB_AUDIT_DRIVER_VOTE_GLOBAL:
- if (return_type_ == RETURN_SUCCESS) {
- if (index == 0)
- *data = oper_type_;
- if (index == 3)
- *data = 1; // ctr_count
- return TCUTIL_RET_SUCCESS;
- }
- if ((return_type_ == RETURN_FAILURE) && (index == 0))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_1) && (index == 0))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_2) && (index == 3))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- case LIB_AUDIT_GLOBAL_ABORT:
- if (return_type_ == RETURN_SUCCESS) {
- if (index == 0)
- *data = oper_type_;
- if (index == 2)
- *data = 1; // ctr_type
- if (index == 4)
- *data = 1; // phase
-
- return TCUTIL_RET_SUCCESS;
- }
- if ((return_type_ == RETURN_FAILURE_2) && (index == 0))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_3) && (index == 2))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_4) && (index == 4))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- case LIB_AUDIT_CONFIG:
- if (return_type_ == RETURN_SUCCESS) {
- if (index == 0)
- *data = 0;
- if (index == 1)
- *data = 0;
- return TCUTIL_RET_SUCCESS;
- }
- if ((return_type_ == RETURN_FAILURE_1) && (index == 0))
- return TCUTIL_RET_FAILURE;
-
- if ((return_type_ == RETURN_FAILURE_2) && (index == 1))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- case LIB_AUDIT_START:
- if (index == 0)
- *data = oper_type_;
- if (index == 2)
- *data = ctr_type_; // ctr_type number
- if (index == 4)
- *data = 0; // audit_result
- if (index == 5)
- *data = 0; // end_result
- if ((return_type_ == RETURN_FAILURE_2) && (index == 0))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_3) && (index == 2))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_4) && (index == 4))
- return TCUTIL_RET_FAILURE;
- if ((return_type_ == RETURN_FAILURE_5) && (index == 4))
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-
- default:
- return TCUTIL_RET_SUCCESS;
- }
-}
-
-TcUtilRet TcServerSessionUtils::get_string(pfc::core::ipc::ServerSession* ssess,
- uint32_t index,
- std::string& data) {
- if ((read_type_ == LIB_COMMIT_DRIVER_VOTE_GLOBAL) &&
- (return_type_ == RETURN_FAILURE_4) && (index == 4))
- return TCUTIL_RET_FAILURE;
-
- if (return_type_ == RETURN_FAILURE)
- return TCUTIL_RET_FAILURE;
-
- if ((read_type_ == LIB_AUDIT_DRIVER_VOTE_GLOBAL) &&
- (return_type_ == RETURN_FAILURE_4) && (index == 2))
- return TCUTIL_RET_FAILURE;
-
- if ((read_type_ == LIB_AUDIT_DRIVER_VOTE_GLOBAL) &&
- (return_type_ == RETURN_FAILURE_5) && (index == 4))
- return TCUTIL_RET_FAILURE;
-
- if ((return_type_ == RETURN_SUCCESS) &&
- (read_type_ == LIB_COMMIT_DRIVER_RESULT) &&
- (update_key_failure_ == PFC_TRUE) &&
- (index == 4))
- return TCUTIL_RET_FAILURE;
-
- if ((return_type_ == RETURN_SUCCESS) &&
- (read_type_ == LIB_AUDIT_DRIVER_RESULT) &&
- (update_key_failure_ == PFC_TRUE) &&
- (index == 2))
- return TCUTIL_RET_FAILURE;
-
- if (return_type_ == RETURN_FAILURE && read_type_ == LIB_UPDATE_KEY_LIST)
- return TCUTIL_RET_FAILURE;
-
- if (index == 7) {
- const char *temp2= "openflow2";
- data.assign(temp2);
- return TCUTIL_RET_SUCCESS;
- }
- const char *temp1= "openflow1";
- data.assign(temp1);
- return TCUTIL_RET_SUCCESS;
-}
-
-TcUtilRet TcServerSessionUtils::get_struct(
- pfc::core::ipc::ServerSession* ssess,
- uint32_t index,
- const pfc_ipcstdef_t &def,
- void* data) {
- if ((return_type_1_ == RETURN_STRUCT_FAILURE_1) &&
- (index == 8 || index == 11)) {
- return TCUTIL_RET_FAILURE;
- } else if ((return_type_1_ == RETURN_STRUCT_FAILURE_2) &&
- (index == 9 || index ==12)) {
- return TCUTIL_RET_FAILURE;
- }
- return TCUTIL_RET_SUCCESS;
-}
-
-TcUtilRet TcServerSessionUtils::set_uint8(
- pfc::core::ipc::ServerSession* ssess,
- uint8_t data) {
- switch (read_type_) {
- case LIB_COMMIT_TRANS_VOTE_GLOBAL:
- if (return_type_ == RETURN_SUCCESS)
- return TCUTIL_RET_SUCCESS;
-
- // driver info empty and set failure in that case
- if (return_type_ == RETURN_FAILURE_5)
- return TCUTIL_RET_FAILURE;
-
- if ((return_type_ == RETURN_FAILURE_1) /*&& (data == 3)*/) {
- return TCUTIL_RET_FAILURE;
- } else if ((return_type_ == RETURN_FAILURE_2) && (data == 1)) {
- return TCUTIL_RET_FAILURE;
- } else if ((return_type_ == RETURN_FAILURE_3) && (data == 4)) {
- return TCUTIL_RET_FAILURE;
- } else if ((return_type_ == RETURN_FAILURE_4) &&
- (data == tclib::TC_AUDIT_FAILURE)) {
- return TCUTIL_RET_FAILURE;
- }
- return TCUTIL_RET_SUCCESS;
-
- case LIB_AUDIT_DRIVER_RESULT:
- if (return_type_1_ == RETURN_SUCCESS)
- return TCUTIL_RET_SUCCESS;
-
- if (return_type_1_ == RETURN_FAILURE) {
- return TCUTIL_RET_FAILURE;
- }
- return TCUTIL_RET_SUCCESS;
-
- case LIB_DRIVER_AUDIT:
- if ((return_type_ == RETURN_FAILURE_2) && (data == 1)) {
- return TCUTIL_RET_FAILURE;
- }
- return TCUTIL_RET_SUCCESS;
- default:
- return TCUTIL_RET_SUCCESS;
- }
-}
-
-TcUtilRet TcServerSessionUtils::set_string(
- pfc::core::ipc::ServerSession* ssess,
- std::string& data) {
- switch (read_type_) {
- case LIB_COMMIT_TRANS_VOTE_GLOBAL:
- case LIB_WRITE_API:
- case LIB_DRIVER_AUDIT:
- if (return_type_ == RETURN_SUCCESS)
- return TCUTIL_RET_SUCCESS;
- if (return_type_ == RETURN_FAILURE)
- return TCUTIL_RET_FAILURE;
- break;
-
- default:
- return TCUTIL_RET_SUCCESS;
- }
- return TCUTIL_RET_SUCCESS;
-}
-
-TcUtilRet TcServerSessionUtils::set_uint32(
- pfc::core::ipc::ServerSession* ssess,
- uint32_t data) {
-
- if ((return_type_ == RETURN_FAILURE_1) && (data == 0))
- return TCUTIL_RET_FAILURE;
-
- if ((return_type_ == RETURN_FAILURE_1) && (data == 1))
- return TCUTIL_RET_FAILURE;
-
- if ((return_type_ == RETURN_FAILURE_1) && (data == TC_OP_DRIVER_AUDIT))
- return TCUTIL_RET_FAILURE;
-
- return TCUTIL_RET_SUCCESS;
-}
-
-TcUtilRet TcServerSessionUtils::set_struct(
- pfc::core::ipc::ServerSession* ssess,
- const pfc_ipcstdef_t &def,
- const void* data) {
-
- if ((return_type_ == RETURN_FAILURE_1)&&(!strcmp(def.ist_name, "key4"))) {
- return TCUTIL_RET_FAILURE;
- }
- if ((return_type_ == RETURN_FAILURE_1)&&(!strcmp(def.ist_name, "val1"))) {
- return TCUTIL_RET_FAILURE;
- }
-
- return TCUTIL_RET_SUCCESS;
-}
-
-ReturnType TcClientSessionUtils::return_type_ = RETURN_SUCCESS;
-TcClientSessionUtils::TcClientSessionUtils() {
- return_type_ = RETURN_SUCCESS;
-}
-
-TcClientSessionUtils::~TcClientSessionUtils() {
- return_type_ = RETURN_SUCCESS;
-}
-
-TcUtilRet TcClientSessionUtils::set_uint32(
- pfc::core::ipc::ClientSession* csess,
- uint32_t data) {
- if (return_type_ == RETURN_FAILURE_1)
- return TCUTIL_RET_FAILURE;
-
- return TCUTIL_RET_SUCCESS;
-}
-
-TcUtilRet TcClientSessionUtils::set_uint8(
- pfc::core::ipc::ClientSession* csess,
- uint8_t data) {
- if (return_type_ == RETURN_FAILURE_3)
- return TCUTIL_RET_FAILURE;
- if (return_type_ == RETURN_FAILURE && data ==0)
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-}
-
-TcUtilRet TcClientSessionUtils::set_string(
- pfc::core::ipc::ClientSession* csess,
- std::string& data) {
- if (return_type_ == RETURN_FAILURE_2)
- return TCUTIL_RET_FAILURE;
- return TCUTIL_RET_SUCCESS;
-}
-
-} // namespace tc
-} // namespace unc
+++ /dev/null
-/*
- * Copyright (c) 2013 NEC Corporation
- * All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this
- * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-#include <unc/keytype.h>
-#include <tclib_interface_stub.hh>
-
-namespace unc {
-namespace tclib {
-
-TcLibInterfaceStub::TcLibInterfaceStub() {
- ctr_type = UNC_CT_UNKNOWN;
- fill_driver_info_ = PFC_FALSE;
- tclib_stub_failure_ = PFC_FALSE;
-}
-
-unc_keytype_ctrtype_t TcLibInterfaceStub::HandleGetControllerType() {
- if (ctr_type == UNC_CT_PFC)
- return UNC_CT_PFC;
- else if (ctr_type == UNC_CT_VNP)
- return UNC_CT_VNP;
- else
- return UNC_CT_UNKNOWN;
-}
-
-void fill_driver_info(TcDriverInfoMap &drv_map) {
- std::string ctr[] = {"first", "second", "third", "four"};
-
- typedef std::vector<std::string> VEC_CTR;
- VEC_CTR vec_ctr, vec_ctr1, vec_ctr2;
- std::vector<std::string>::iterator it;
-
- it = vec_ctr.begin();
- vec_ctr.assign(ctr, ctr+4);
-
- it = vec_ctr1.begin();
- vec_ctr1.assign(ctr, ctr+4);
-
- it = vec_ctr2.begin();
- vec_ctr2.assign(ctr, ctr+4);
-
- TcDriverInfoMap map_ctr;
- std::map<unc_keytype_ctrtype_t, VEC_CTR> ::iterator it1;
- map_ctr.insert(pair<unc_keytype_ctrtype_t, VEC_CTR>(UNC_CT_PFC, vec_ctr));
- map_ctr.insert(pair<unc_keytype_ctrtype_t, VEC_CTR>(UNC_CT_VNP, vec_ctr1));
-
- for (it1 = map_ctr.begin(); it1 != map_ctr.end(); it1++) {
- VEC_CTR vec_print;
- vec_print = it1->second;
-#if 0
- for (it = vec_print.begin(); it < vec_print.end(); it++)
- std::cout << ' ' << *it;
- std::cout << '\n';
-#endif
- }
- drv_map = map_ctr;
-}
-
-TcCommonRet TcLibInterfaceStub::HandleCommitVoteRequest(
- uint32_t session_id,
- uint32_t config_id,
- TcDriverInfoMap& driver_info) {
-
- if (session_id == 0)
- return TC_FAILURE;
-
- if (fill_driver_info_ == PFC_FALSE) {
- return TC_SUCCESS;
- } else if (fill_driver_info_ == PFC_TRUE) {
- fill_driver_info(driver_info);
- return TC_SUCCESS;
- }
- return TC_SUCCESS;
-}
-
-TcCommonRet
-TcLibInterfaceStub::HandleCommitGlobalAbort(uint32_t session_id,
- uint32_t config_id,
- TcCommitOpAbortPhase fail_phase) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
-
- return TC_SUCCESS;
-}
-
-TcCommonRet
-TcLibInterfaceStub::HandleAuditVoteRequest(uint32_t session_id,
- uint32_t driver_id,
- string controller_id,
- TcDriverInfoMap &driver_info) {
- if (tclib_stub_failure_ == PFC_TRUE) {
- return TC_FAILURE;
- }
-
- return TC_SUCCESS;
-}
-
-TcCommonRet
-TcLibInterfaceStub::HandleAuditGlobalCommit(uint32_t session_id,
- uint32_t driver_id,
- string controller_id,
- TcDriverInfoMap &driver_info,
- TcAuditResult& audit_result) {
- if (fill_driver_info_ == PFC_FALSE) {
- return TC_SUCCESS;
- } else if (fill_driver_info_ == PFC_TRUE) {
- fill_driver_info(driver_info);
- audit_result = TC_AUDIT_FAILURE;
- return TC_SUCCESS;
- }
- return TC_SUCCESS;
-}
-
-TcCommonRet
-TcLibInterfaceStub::HandleAuditGlobalAbort(
- uint32_t session_id,
- unc_keytype_ctrtype_t driver_id,
- string controller_id,
- TcAuditOpAbortPhase operation_phase) {
- if (tclib_stub_failure_ == PFC_TRUE)
- return TC_FAILURE;
-
- return TC_SUCCESS;
-}
-
-} // namespace tclib
-} // namespace unc
-
#include <pfcxx/ipc_server.hh>
#include <tclib_module.hh>
#include <unc/keytype.h>
-#include <tclib_interface_stub.hh>
-#include <libtc_common.hh>
+#include <stub/tclib_module/tclib_interface_stub.hh>
+#include <stub/tclib_module/libtc_common.hh>
#include <stdio.h>
using namespace unc::tc;
*/
#ifdef __cplusplus
-#include "stub/include/pfcxx/ipc.hh"
-#include "stub/include/pfcxx/module.hh"
-#include "stub/include/pfcxx/stubs.hh"
-#include "stub/include/libtc_common.hh"
-#include "stub/include/tclib_interface_stub.hh"
+#include "stub/include/cxx/pfcxx/ipc.hh"
+#include "stub/include/cxx/pfcxx/module.hh"
+#include "stub/include/cxx/pfcxx/stubs.hh"
+#include "stub/tclib_module/libtc_common.hh"
+#include "stub/tclib_module/tclib_interface_stub.hh"
#endif /* __cplusplus */
#endif /* !_TEST_VTNDRVINTF_UT_STUB_H */
#include <pfcxx/ipc_server.hh>
#include <tclib_module.hh>
#include <unc/keytype.h>
-#include <tclib_interface_stub.hh>
-#include <libtc_common.hh>
+#include <stub/tclib_module/tclib_interface_stub.hh>
+#include <stub/tclib_module/libtc_common.hh>
#include <stdio.h>
using namespace unc::tc;